Bazaar developer reference

CvHomelandAI::PlotGarrisonMoves(bool)

Defined in
CvHomelandAI.cpp, line 917
Class
CvHomelandAI
Hook name
CivHooks::CvHomelandAI_PlotGarrisonMoves

Hooks

static bool BeforeCvHomelandAI_PlotGarrisonMoves(CvHomelandAI* self, bool bCityStateOnly);static void AfterCvHomelandAI_PlotGarrisonMoves(CvHomelandAI* self, bool bCityStateOnly);static void ReplaceCvHomelandAI_PlotGarrisonMoves(void (*original)(CvHomelandAI*, bool), CvHomelandAI* self, bool bCityStateOnly);CivRegisterBefore<CivHooks::CvHomelandAI_PlotGarrisonMoves>(host, &BeforeCvHomelandAI_PlotGarrisonMoves);CivRegisterAfter<CivHooks::CvHomelandAI_PlotGarrisonMoves>(host, &AfterCvHomelandAI_PlotGarrisonMoves);CivRegisterReplace<CivHooks::CvHomelandAI_PlotGarrisonMoves>(host, &ReplaceCvHomelandAI_PlotGarrisonMoves);

Code

916/// Send units to garrison cities917void CvHomelandAI::PlotGarrisonMoves(bool bCityStateOnly)918{919	// City state garrisoning has a separate priority, so only do it when the flag is on920	if(bCityStateOnly != m_pPlayer->isMinorCiv())921	{922		return;923	}924925	// Do we have any targets of this type?926	if(m_TargetedCities.size() > 0)927	{928		for(unsigned int iI = 0; iI < m_TargetedCities.size(); iI++)929		{930			CvPlot* pTarget = GC.getMap().plot(m_TargetedCities[iI].GetTargetX(), m_TargetedCities[iI].GetTargetY());931			CvCity* pCity = pTarget->getPlotCity();932933			if(pCity && pCity->GetLastTurnGarrisonAssigned() < GC.getGame().getGameTurn())934			{935				// Grab units that make sense for this move type936				FindUnitsForThisMove(AI_HOMELAND_MOVE_GARRISON, (iI == 0)/*bFirstTime*/);937938				if(m_CurrentMoveHighPriorityUnits.size() + m_CurrentMoveUnits.size() > 0)939				{940					if(GetBestUnitToReachTarget(pTarget, m_iDefensiveMoveTurns))941					{942						ExecuteMoveToTarget(pTarget);943944						if(GC.getLogging() && GC.getAILogging())945						{946							CvString strLogString;947							strLogString.Format("Moving to garrison, X: %d, Y: %d, Priority: %d", m_TargetedCities[iI].GetTargetX(), m_TargetedCities[iI].GetTargetY(), m_TargetedCities[iI].GetAuxIntData());948							LogHomelandMessage(strLogString);949						}950951						pCity->SetLastTurnGarrisonAssigned(GC.getGame().getGameTurn());952					}953				}954			}955		}956	}957}

Calls

Called by