Bazaar developer reference

CvArmyAI::RemoveUnit(int)

Defined in
CvArmyAI.cpp, line 680
Class
CvArmyAI
Hook name
CivHooks::CvArmyAI_RemoveUnit

Hooks

static bool BeforeCvArmyAI_RemoveUnit(CvArmyAI* self, int iUnitToRemoveID, bool& result);static void AfterCvArmyAI_RemoveUnit(CvArmyAI* self, int iUnitToRemoveID, bool& result);static bool ReplaceCvArmyAI_RemoveUnit(bool (*original)(CvArmyAI*, int), CvArmyAI* self, int iUnitToRemoveID);CivRegisterBefore<CivHooks::CvArmyAI_RemoveUnit>(host, &BeforeCvArmyAI_RemoveUnit);CivRegisterAfter<CivHooks::CvArmyAI_RemoveUnit>(host, &AfterCvArmyAI_RemoveUnit);CivRegisterReplace<CivHooks::CvArmyAI_RemoveUnit>(host, &ReplaceCvArmyAI_RemoveUnit);

Code

679/// Remove a unit from the army680bool CvArmyAI::RemoveUnit(int iUnitToRemoveID)681{682	bool bWasOneOrMoreRemoved = false;683	CvArmyFormationSlot slot;684685	for(int iI = 0; iI < (int)m_FormationEntries.size(); iI++)686	{687		slot = m_FormationEntries[iI];688		if(slot.GetUnitID() == iUnitToRemoveID)689		{690			UnitHandle pThisUnit = GET_PLAYER(GetOwner()).getUnit(iUnitToRemoveID);691			if(pThisUnit)692			{693				// Clears unit's army ID and erase from formation entries694				pThisUnit->setArmyID(FFreeList::INVALID_INDEX);695				m_FormationEntries[iI].SetUnitID(ARMY_NO_UNIT);696				bWasOneOrMoreRemoved = true;697698				// Tell the associate operation that a unit was lost699				CvAIOperation* pThisOperation = GET_PLAYER(GetOwner()).getAIOperation(m_iOperationID);700				if(pThisOperation)701				{702					pThisOperation->UnitWasRemoved(GetID(), iI);703				}704			}705		}706	}707708	return bWasOneOrMoreRemoved;709}

Calls

Called by