Bazaar developer reference

CvHomelandAI::PlotAirliftMoves()

Defined in
CvHomelandAI.cpp, line 2214
Class
CvHomelandAI
Hook name
CivHooks::CvHomelandAI_PlotAirliftMoves

Hooks

static bool BeforeCvHomelandAI_PlotAirliftMoves(CvHomelandAI* self);static void AfterCvHomelandAI_PlotAirliftMoves(CvHomelandAI* self);static void ReplaceCvHomelandAI_PlotAirliftMoves(void (*original)(CvHomelandAI*), CvHomelandAI* self);CivRegisterBefore<CivHooks::CvHomelandAI_PlotAirliftMoves>(host, &BeforeCvHomelandAI_PlotAirliftMoves);CivRegisterAfter<CivHooks::CvHomelandAI_PlotAirliftMoves>(host, &AfterCvHomelandAI_PlotAirliftMoves);CivRegisterReplace<CivHooks::CvHomelandAI_PlotAirliftMoves>(host, &ReplaceCvHomelandAI_PlotAirliftMoves);

Code

2213/// Send spare units to cities that can airlift2214void CvHomelandAI::PlotAirliftMoves()2215{2216	if (m_pPlayer->isHuman())2217	{2218		return;2219	}22202221	// Need at least 2 cities with airports2222	// TODO - WH - relocation - need to allow for AllowsAirliftTo improvements as well as cities2223	vector<CvCity *> aAirliftCities;2224	CvCity *pLoopCity;2225	int iCityLoop;2226	for (pLoopCity = m_pPlayer->firstCity(&iCityLoop); pLoopCity != NULL; pLoopCity = m_pPlayer->nextCity(&iCityLoop))2227	{2228		if (pLoopCity->CanAirlift())2229		{2230			aAirliftCities.push_back(pLoopCity);2231		}2232	}2233	if (aAirliftCities.size() < 2)2234	{2235		return;2236	}22372238	// Create list of empty land plots we own adjacent to airlift cities that are not endangered2239	vector<CvPlot *> aAirliftPlots;2240	CvTacticalAnalysisMap* pMap = GC.getGame().GetTacticalAnalysisMap();2241	CvTacticalDominanceZone *pZone;2242	vector<CvCity *>::const_iterator it;2243	for (it = aAirliftCities.begin(); it != aAirliftCities.end(); it++)2244	{2245		pZone = pMap->GetZoneByCity(*it, false);2246		if (pZone && (pZone->GetDominanceFlag() == TACTICAL_DOMINANCE_FRIENDLY || pZone->GetDominanceFlag() == TACTICAL_DOMINANCE_NO_UNITS_VISIBLE))2247		{2248			for (int iI = 0; iI < NUM_DIRECTION_TYPES; iI++)2249			{2250				CvPlot *pLoopPlot = plotDirection((*it)->getX(), (*it)->getY(), ((DirectionTypes)iI));2251				if (pLoopPlot != NULL && !pLoopPlot->isWater() && !pLoopPlot->isMountain() && pLoopPlot->getOwner() == m_pPlayer->GetID())2252				{2253					UnitHandle pBestDefender = pLoopPlot->getBestDefender(m_pPlayer->GetID());2254					if (pBestDefender)2255					{2256						if (std::find(m_CurrentTurnUnits.begin(), m_CurrentTurnUnits.end(), pBestDefender->GetID()) != m_CurrentTurnUnits.end())2257						{2258							pBestDefender->finishMoves();2259							UnitProcessed(pBestDefender->GetID());2260							if(GC.getLogging() && GC.getAILogging())2261							{2262								CvString strLogString;2263								strLogString.Format("Remaining in place for future airlift - %s, X: %d, Y: %d", pBestDefender->getName().GetCString(), pBestDefender->getX(), pBestDefender->getY());2264								LogHomelandMessage(strLogString);2265							}2266						}2267					}2268					else2269					{2270						aAirliftPlots.push_back(pLoopPlot);2271					}2272				}2273			}2274		}2275	}22762277	vector<CvPlot *>::const_iterator plotIt;2278	for (plotIt = aAirliftPlots.begin(); plotIt != aAirliftPlots.end(); plotIt++)2279	{2280		FindUnitsForThisMove(AI_HOMELAND_MOVE_MOBILE_RESERVE, true);22812282		if(m_CurrentMoveHighPriorityUnits.size() + m_CurrentMoveUnits.size() > 0)2283		{2284			CvPlot *pTarget = *plotIt;22852286			if (GetBestUnitToReachTarget(pTarget, MAX_INT))2287			{2288				ExecuteMoveToTarget(pTarget);22892290				if(GC.getLogging() && GC.getAILogging())2291				{2292					CvString strLogString;2293					strLogString.Format("Moving to airlift origin plot, X: %d, Y: %d", pTarget->getX(), pTarget->getY());2294					LogHomelandMessage(strLogString);2295				}2296			}2297		}2298	}2299}

Calls

Called by