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

Method destroyFacility

src/Savegame/Base.cpp:1426–1595  ·  view source on GitHub ↗

* Removes a base module, and deals with the ramifications thereof. * @param facility An iterator reference to the facility to destroy and remove. */

Source from the content-addressed store, hash-verified

1424 * @param facility An iterator reference to the facility to destroy and remove.
1425 */
1426void Base::destroyFacility(std::vector<BaseFacility*>::iterator facility)
1427{
1428 if ((*facility)->getRules()->getCrafts() > 0)
1429 {
1430 // hangar destruction - destroy crafts and any production of crafts
1431 // if this will mean there is no hangar to contain it
1432 if ((*facility)->getCraft())
1433 {
1434 // remove all soldiers
1435 if ((*facility)->getCraft()->getNumSoldiers())
1436 {
1437 for (std::vector<Soldier*>::iterator i = _soldiers.begin(); i != _soldiers.end(); ++i)
1438 {
1439 if ((*i)->getCraft() == (*facility)->getCraft())
1440 {
1441 (*i)->setCraft(0);
1442 }
1443 }
1444 }
1445 // remove all items
1446 while (!(*facility)->getCraft()->getItems()->getContents()->empty())
1447 {
1448 std::map<std::string, int>::iterator i = (*facility)->getCraft()->getItems()->getContents()->begin();
1449 _items->addItem(i->first, i->second);
1450 (*facility)->getCraft()->getItems()->removeItem(i->first, i->second);
1451 }
1452 for (std::vector<Craft*>::iterator i = _crafts.begin(); i != _crafts.end(); ++i)
1453 {
1454 if (*i == (*facility)->getCraft())
1455 {
1456 delete (*i);
1457 _crafts.erase(i);
1458 break;
1459 }
1460 }
1461 }
1462 else
1463 {
1464 bool remove = true;
1465 // no craft - check productions.
1466 for (std::vector<Production*>::iterator i = _productions.begin(); i != _productions.end();)
1467 {
1468 if (getAvailableHangars() - getUsedHangars() - (*facility)->getRules()->getCrafts() < 0 && (*i)->getRules()->getCategory() == "STR_CRAFT")
1469 {
1470 _engineers += (*i)->getAssignedEngineers();
1471 delete *i;
1472 _productions.erase(i);
1473 remove = false;
1474 break;
1475 }
1476 else
1477 {
1478 ++i;
1479 }
1480 }
1481 if (remove && !_transfers.empty())
1482 {
1483 for (std::vector<Transfer*>::iterator i = _transfers.begin(); i != _transfers.end(); )

Callers 1

prepareDebriefingMethod · 0.80

Calls 15

getNumSoldiersMethod · 0.80
getContentsMethod · 0.80
getCategoryMethod · 0.80
getAssignedEngineersMethod · 0.80
getPsiLaboratoriesMethod · 0.80
isInPsiTrainingMethod · 0.80
setPsiTrainingMethod · 0.80
getLaboratoriesMethod · 0.80
getAssignedMethod · 0.80
setAssignedMethod · 0.80
getWorkshopsMethod · 0.80
setAssignedEngineersMethod · 0.80

Tested by

no test coverage detected