Bazaar developer reference

CvTacticalAI::PlotDefensiveAirlifts()

Defined in
CvTacticalAI.cpp, line 3486
Class
CvTacticalAI
Hook name
CivHooks::CvTacticalAI_PlotDefensiveAirlifts

Hooks

static bool BeforeCvTacticalAI_PlotDefensiveAirlifts(CvTacticalAI* self);static void AfterCvTacticalAI_PlotDefensiveAirlifts(CvTacticalAI* self);static void ReplaceCvTacticalAI_PlotDefensiveAirlifts(void (*original)(CvTacticalAI*), CvTacticalAI* self);CivRegisterBefore<CivHooks::CvTacticalAI_PlotDefensiveAirlifts>(host, &BeforeCvTacticalAI_PlotDefensiveAirlifts);CivRegisterAfter<CivHooks::CvTacticalAI_PlotDefensiveAirlifts>(host, &AfterCvTacticalAI_PlotDefensiveAirlifts);CivRegisterReplace<CivHooks::CvTacticalAI_PlotDefensiveAirlifts>(host, &ReplaceCvTacticalAI_PlotDefensiveAirlifts);

Code

3485/// Spend money to buy defenses3486void CvTacticalAI::PlotDefensiveAirlifts()3487{3488	vector<int> aProcessedUnits;3489	list<int>::iterator it;3490	CvTacticalUnit unit;3491	CvCity* pCity;34923493	if(m_pPlayer->isMinorCiv())3494	{3495		return;3496	}34973498	// Is this a dominance zone where we're defending a city and that city has an airport?3499	CvTacticalDominanceZone* pZone = GC.getGame().GetTacticalAnalysisMap()->GetZone(m_iCurrentZoneIndex);3500	// TODO - WH - relocation - should also check for an AllowsAirliftTo improvement3501	pCity = pZone->GetClosestCity();3502	if(pCity && pCity->getOwner() == m_pPlayer->GetID() && pZone->GetTerritoryType() == TACTICAL_TERRITORY_FRIENDLY && pCity->CanAirlift()&& pZone->GetEnemyUnitCount() > 0)3503	{3504		// Loop through all recruited units3505		for (it = m_CurrentTurnUnits.begin(); it != m_CurrentTurnUnits.end(); it++)3506		{3507			UnitHandle pUnit = m_pPlayer->getUnit(*it);3508			if(pUnit)3509			{3510				// If there a hex adjacent to city they can airlift to?3511				for (int iI = 0; iI < NUM_DIRECTION_TYPES; iI++)3512				{3513					CvPlot *pLoopPlot = plotDirection(pCity->getX(), pCity->getY(), ((DirectionTypes)iI));3514					if (pLoopPlot != NULL)3515					{3516						if (pUnit->canAirliftAt(pUnit->plot(), pLoopPlot->getX(), pLoopPlot->getY()))3517						{3518							pUnit->airlift(pLoopPlot->getX(), pLoopPlot->getY());35193520							aProcessedUnits.push_back(pUnit->GetID());35213522							if(GC.getLogging() && GC.getAILogging())3523							{3524								CvString strLogString;3525								strLogString.Format("Airlifting %s to city of %s, Current X: %d, Current Y: %d", pUnit->getName().GetCString(), pCity->getName().GetCString(), pUnit->getX(), pUnit->getY());3526								LogTacticalMessage(strLogString, false);3527							}35283529							break;3530						}3531					}3532				}3533			}3534		}3535	}35363537	// Mark units processed3538	vector<int>::const_iterator unitIt;3539	for (unitIt = aProcessedUnits.begin(); unitIt != aProcessedUnits.end(); unitIt++)3540	{3541		UnitProcessed(*unitIt);3542	}3543}

Calls

Called by