MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / getDisconnectedFacilities

Method getDisconnectedFacilities

src/Savegame/Base.cpp:1337–1420  ·  view source on GitHub ↗

* Gets a sorted list of the facilities(=iterators) NOT connected to the Access Lift. * @param remove Facility to ignore (in case of facility dismantling). * @return a sorted list of iterators pointing to elements in _facilities. */

Source from the content-addressed store, hash-verified

1335 * @return a sorted list of iterators pointing to elements in _facilities.
1336 */
1337std::list<std::vector<BaseFacility*>::iterator> Base::getDisconnectedFacilities(BaseFacility *remove)
1338{
1339 std::list<std::vector<BaseFacility*>::iterator> result;
1340
1341 if (remove != 0 && remove->getRules()->isLift())
1342 { // Theoretically this is impossible, but sanity check is good :)
1343 for (std::vector<BaseFacility*>::iterator i = _facilities.begin(); i != _facilities.end(); ++i)
1344 {
1345 if ((*i) != remove) result.push_back(i);
1346 }
1347 return result;
1348 }
1349
1350 std::vector<std::pair<std::vector<BaseFacility*>::iterator, bool>*> facilitiesConnStates;
1351 std::pair<std::vector<BaseFacility*>::iterator, bool> *grid[BASE_SIZE][BASE_SIZE];
1352 BaseFacility *lift = 0;
1353
1354 for (int x = 0; x < BASE_SIZE; ++x)
1355 {
1356 for (int y = 0; y < BASE_SIZE; ++y)
1357 {
1358 grid[x][y] = 0;
1359 }
1360 }
1361
1362 // Ok, fill up the grid(+facilitiesConnStates), and search the lift
1363 for (std::vector<BaseFacility*>::iterator i = _facilities.begin(); i != _facilities.end(); ++i)
1364 {
1365 if ((*i) != remove)
1366 {
1367 if ((*i)->getRules()->isLift()) lift = (*i);
1368 for (int x = 0; x != (*i)->getRules()->getSize(); ++x)
1369 {
1370 for (int y = 0; y != (*i)->getRules()->getSize(); ++y)
1371 {
1372 std::pair<std::vector<BaseFacility*>::iterator, bool> *p = new std::pair<std::vector<BaseFacility*>::iterator, bool>(i,false);
1373 facilitiesConnStates.push_back(p);
1374 grid[(*i)->getX() + x][(*i)->getY() + y] = p;
1375 }
1376 }
1377 }
1378 }
1379
1380 // we're in real trouble if this happens...
1381 if (lift == 0)
1382 {
1383 //TODO: something clever.
1384 return result;
1385 }
1386
1387 // Now make the recursion manually using a stack
1388 std::stack<std::pair<int, int> > stack;
1389 stack.push(std::make_pair(lift->getX(),lift->getY()));
1390 while (!stack.empty())
1391 {
1392 int x = stack.top().first, y = stack.top().second;
1393 stack.pop();
1394 if (x >= 0 && x < BASE_SIZE && y >= 0 && y < BASE_SIZE && grid[x][y] != 0 && !grid[x][y]->second)

Callers 1

viewLeftClickMethod · 0.80

Calls 10

isLiftMethod · 0.80
pushMethod · 0.80
topMethod · 0.80
popMethod · 0.80
getRulesMethod · 0.45
getSizeMethod · 0.45
getXMethod · 0.45
getYMethod · 0.45
emptyMethod · 0.45
getBuildTimeMethod · 0.45

Tested by

no test coverage detected