Bazaar developer reference

CvArmyAI::AddUnit(int, int)

Defined in
CvArmyAI.cpp, line 654
Class
CvArmyAI
Hook name
CivHooks::CvArmyAI_AddUnit

Hooks

static bool BeforeCvArmyAI_AddUnit(CvArmyAI* self, int iUnitID, int iSlotNum);static void AfterCvArmyAI_AddUnit(CvArmyAI* self, int iUnitID, int iSlotNum);static void ReplaceCvArmyAI_AddUnit(void (*original)(CvArmyAI*, int, int), CvArmyAI* self, int iUnitID, int iSlotNum);CivRegisterBefore<CivHooks::CvArmyAI_AddUnit>(host, &BeforeCvArmyAI_AddUnit);CivRegisterAfter<CivHooks::CvArmyAI_AddUnit>(host, &AfterCvArmyAI_AddUnit);CivRegisterReplace<CivHooks::CvArmyAI_AddUnit>(host, &ReplaceCvArmyAI_AddUnit);

Code

653/// Add a unit to our army (and we know which slot)654void CvArmyAI::AddUnit(int iUnitID, int iSlotNum)655{656	CvAssertMsg(iUnitID != ARMY_NO_UNIT,"Expect unit to be non-NULL");657658	CvPlayer& thisPlayer = GET_PLAYER(m_eOwner);659	UnitHandle pThisUnit = thisPlayer.getUnit(iUnitID);660661	// remove this unit from an army if it is already in one662	thisPlayer.removeFromArmy(pThisUnit->getArmyID(), GetID());663664	m_FormationEntries[iSlotNum].SetUnitID(iUnitID);665	pThisUnit->setArmyID(GetID());666667	// Finally, compute when we think this unit will arrive at the next checkpoint668	CvPlot* pMusterPlot = GC.getMap().plot(GetX(), GetY());669	if(pMusterPlot)670	{671		int iTurnsToReachCheckpoint = TurnsToReachTarget(pThisUnit, pMusterPlot, true /*bReusePaths*/, true, true);672		if(iTurnsToReachCheckpoint < MAX_INT)673		{674			SetEstimatedTurn(iSlotNum, iTurnsToReachCheckpoint);675		}676	}677}

Calls

Called by