/*called when a Template is deleted in the Design screen*/ void deleteTemplateFromProduction(DROID_TEMPLATE *psTemplate, unsigned player, QUEUE_MODE mode) { STRUCTURE *psStruct; STRUCTURE *psList; //see if any factory is currently using the template for (unsigned i = 0; i < 2; ++i) { psList = NULL; switch (i) { case 0: psList = apsStructLists[player]; break; case 1: psList = mission.apsStructLists[player]; break; } for (psStruct = psList; psStruct != NULL; psStruct = psStruct->psNext) { if (StructIsFactory(psStruct)) { FACTORY *psFactory = &psStruct->pFunctionality->factory; if (psFactory->psAssemblyPoint->factoryInc < asProductionRun[psFactory->psAssemblyPoint->factoryType].size()) { ProductionRun &productionRun = asProductionRun[psFactory->psAssemblyPoint->factoryType][psFactory->psAssemblyPoint->factoryInc]; for (unsigned inc = 0; inc < productionRun.size(); ++inc) { if (productionRun[inc].psTemplate->multiPlayerID == psTemplate->multiPlayerID && mode == ModeQueue) { //just need to erase this production run entry productionRun.erase(productionRun.begin() + inc); --inc; } } } if (psFactory->psSubject == NULL) { continue; } // check not being built in the factory for the template player if (psTemplate->multiPlayerID == psFactory->psSubject->multiPlayerID && mode == ModeImmediate) { syncDebugStructure(psStruct, '<'); syncDebug("Clearing production"); // Clear the factory's subject, and returns power. cancelProduction(psStruct, ModeImmediate, false); // Check to see if anything left to produce. (Also calls cancelProduction again, if nothing left to produce, which is a no-op. But if other things are left to produce, doesn't call cancelProduction, so wouldn't return power without the explicit cancelProduction call above.) doNextProduction(psStruct, NULL, ModeImmediate); //tell the interface intManufactureFinished(psStruct); syncDebugStructure(psStruct, '>'); } } } } }
/*called when a Template is deleted in the Design screen*/ void deleteTemplateFromProduction(DROID_TEMPLATE *psTemplate, unsigned player, QUEUE_MODE mode) { STRUCTURE *psStruct; STRUCTURE *psList; //see if any factory is currently using the template for (unsigned i = 0; i < 2; ++i) { psList = NULL; switch (i) { case 0: psList = apsStructLists[player]; break; case 1: psList = mission.apsStructLists[player]; break; } for (psStruct = psList; psStruct != NULL; psStruct = psStruct->psNext) { if (StructIsFactory(psStruct)) { FACTORY *psFactory = &psStruct->pFunctionality->factory; if (psFactory->psAssemblyPoint->factoryInc < asProductionRun[psFactory->psAssemblyPoint->factoryType].size()) { ProductionRun &productionRun = asProductionRun[psFactory->psAssemblyPoint->factoryType][psFactory->psAssemblyPoint->factoryInc]; for (unsigned inc = 0; inc < productionRun.size(); ++inc) { if (productionRun[inc].psTemplate->multiPlayerID == psTemplate->multiPlayerID && mode == ModeQueue) { //just need to erase this production run entry productionRun.erase(productionRun.begin() + inc); --inc; } } } if (psFactory->psSubject == NULL) { continue; } // check not being built in the factory for the template player if (psTemplate->multiPlayerID == psFactory->psSubject->multiPlayerID && mode == ModeImmediate) { syncDebugStructure(psStruct, '<'); syncDebug("Clearing production"); // Clear the factory's subject. psFactory->psSubject = NULL; if (player == productionPlayer) { //check to see if anything left to produce DROID_TEMPLATE *psNextTemplate = factoryProdUpdate(psStruct, NULL); //power is returned by factoryProdAdjust() if (psNextTemplate) { structSetManufacture(psStruct, psNextTemplate, ModeQueue); // ModeQueue because production lists aren't synchronised. } } //tell the interface intManufactureFinished(psStruct); syncDebugStructure(psStruct, '>'); } } } } }