/// Remove a unit from the army bool CvArmyAI::RemoveUnit(int iUnitToRemoveID) { for(int iI = 0; iI < (int)m_FormationEntries.size(); iI++) { CvArmyFormationSlot slot = m_FormationEntries[iI]; if(slot.GetUnitID() == iUnitToRemoveID) { CvUnit* pThisUnit = GET_PLAYER(GetOwner()).getUnit(iUnitToRemoveID); if(pThisUnit) { // Clears unit's army ID and erase from formation entries pThisUnit->setArmyID(-1); pThisUnit->AI_setUnitAIType(pThisUnit->getUnitInfo().GetDefaultUnitAIType()); // Tell the associate operation that a unit was lost CvAIOperation* pThisOperation = GET_PLAYER(GetOwner()).getAIOperation(m_iOperationID); if(pThisOperation) pThisOperation->UnitWasRemoved(GetID(), iI); return true; } } } return false; }
/// Deallocate memory void CvArmyAI::ReleaseUnits(bool bAddUnitsToTacticalAI) { for (size_t i = 0; i<m_FormationEntries.size(); i++) { if (!m_FormationEntries[i].IsUsed()) continue; CvUnit* pThisUnit = GET_PLAYER(GetOwner()).getUnit(m_FormationEntries[i].GetUnitID()); if (pThisUnit) { pThisUnit->setArmyID(-1); pThisUnit->AI_setUnitAIType(pThisUnit->getUnitInfo().GetDefaultUnitAIType()); if (bAddUnitsToTacticalAI) //for stupid reasons we first recruit units and then disband armies ... GET_PLAYER(GetOwner()).GetTacticalAI()->AddCurrentTurnUnit(pThisUnit); } } m_FormationEntries.clear(); }