MCPcopy Create free account
hub / github.com/Warzone2100/warzone2100 / removeStruct

Function removeStruct

src/structure.cpp:4565–4678  ·  view source on GitHub ↗

remove a structure from a game without any visible effects bDestroy = true if the object is to be destroyed (for example used to change the type of wall at a location)

Source from the content-addressed store, hash-verified

4563// bDestroy = true if the object is to be destroyed
4564// (for example used to change the type of wall at a location)
4565bool removeStruct(STRUCTURE *psDel, bool bDestroy)
4566{
4567 bool resourceFound = false;
4568 FLAG_POSITION *psAssemblyPoint = nullptr;
4569
4570 ASSERT_OR_RETURN(false, psDel != nullptr, "Invalid structure pointer");
4571
4572 int prevResearchState = intGetResearchState();
4573
4574 if (bDestroy)
4575 {
4576 removeStructFromMap(psDel);
4577 }
4578
4579 if (bDestroy)
4580 {
4581 //if the structure is a resource extractor, need to put the resource back in the map
4582 /*ONLY IF ANY POWER LEFT - HACK HACK HACK!!!! OIL POOLS NEED TO KNOW
4583 HOW MUCH IS THERE && NOT RES EXTRACTORS */
4584 if (psDel->pStructureType->type == REF_RESOURCE_EXTRACTOR)
4585 {
4586 FEATURE *psOil = buildFeature(oilResFeature, psDel->pos.x, psDel->pos.y, false);
4587 memcpy(psOil->seenThisTick, psDel->visible, sizeof(psOil->seenThisTick));
4588 resourceFound = true;
4589 }
4590 }
4591
4592 if (psDel->pStructureType->type == REF_RESOURCE_EXTRACTOR)
4593 {
4594 //tell associated Power Gen
4595 releaseResExtractor(psDel);
4596 //tell keybind that this is going away (to prevent dangling pointer in kf_JumpToResourceExtractor)
4597 keybindInformResourceExtractorRemoved(psDel);
4598 }
4599
4600 if (psDel->pStructureType->type == REF_POWER_GEN)
4601 {
4602 //tell associated Res Extractors
4603 releasePowerGen(psDel);
4604 }
4605
4606 //check for a research topic currently under way
4607 if (psDel->pStructureType->type == REF_RESEARCH)
4608 {
4609 if (psDel->pFunctionality->researchFacility.psSubject)
4610 {
4611 //cancel the topic
4612 cancelResearch(psDel, ModeImmediate);
4613 }
4614 }
4615
4616 if (psDel->pStructureType->type == REF_REPAIR_FACILITY)
4617 {
4618 if (psDel->pFunctionality && psDel->pFunctionality->repairFacility.state == RepairState::Repairing)
4619 {
4620 if (psDel->pFunctionality->repairFacility.psObj != nullptr)
4621 {
4622 droidRepairStopped(castDroid(psDel->pFunctionality->repairFacility.psObj), psDel);

Callers 12

applyLimitSetFunction · 0.85
structureBuildFunction · 0.85
buildStructureDirFunction · 0.85
structureUpdateFunction · 0.85
destroyStructFunction · 0.85
structure.cppFile · 0.85
destroyPlayerResourcesFunction · 0.85
destroyMatchingStructsFunction · 0.85
mission.cppFile · 0.85
removeStructMethod · 0.85
makePlayerSpectatorFunction · 0.85

Calls 15

ASSERT_OR_RETURNFunction · 0.85
intGetResearchStateFunction · 0.85
removeStructFromMapFunction · 0.85
buildFeatureFunction · 0.85
releaseResExtractorFunction · 0.85
releasePowerGenFunction · 0.85
cancelResearchFunction · 0.85
droidRepairStoppedFunction · 0.85
castDroidFunction · 0.85
cancelProductionFunction · 0.85
cancelDeliveryReposFunction · 0.85

Tested by

no test coverage detected