Bazaar developer reference

CvHomelandAI::ExecuteAircraftMoves()

Defined in
CvHomelandAI.cpp, line 4772
Class
CvHomelandAI
Hook name
CivHooks::CvHomelandAI_ExecuteAircraftMoves

Hooks

static bool BeforeCvHomelandAI_ExecuteAircraftMoves(CvHomelandAI* self);static void AfterCvHomelandAI_ExecuteAircraftMoves(CvHomelandAI* self);static void ReplaceCvHomelandAI_ExecuteAircraftMoves(void (*original)(CvHomelandAI*), CvHomelandAI* self);CivRegisterBefore<CivHooks::CvHomelandAI_ExecuteAircraftMoves>(host, &BeforeCvHomelandAI_ExecuteAircraftMoves);CivRegisterAfter<CivHooks::CvHomelandAI_ExecuteAircraftMoves>(host, &AfterCvHomelandAI_ExecuteAircraftMoves);CivRegisterReplace<CivHooks::CvHomelandAI_ExecuteAircraftMoves>(host, &ReplaceCvHomelandAI_ExecuteAircraftMoves);

Code

4771/// Moves an aircraft into an important city near the front to aid its defense (or offense)4772void CvHomelandAI::ExecuteAircraftMoves()4773{4774	FStaticVector< CvHomelandUnit, 64, true, c_eCiv5GameplayDLL >::iterator it;47754776	for(it = m_CurrentMoveUnits.begin(); it != m_CurrentMoveUnits.end(); ++it)4777	{4778		UnitHandle pUnit = m_pPlayer->getUnit(it->GetID());4779		if(!pUnit)4780		{4781			continue;4782		}47834784		CvPlot* pUnitPlot = pUnit->plot();4785		CvUnit* pTransportUnit = NULL;4786		CvPlot* pBestPlot = NULL;4787		int iMostDangerous = 0;47884789		// first look for open carrier slots4790		int iLoopUnit = 0;4791		for(CvUnit* pLoopUnit = m_pPlayer->firstUnit(&iLoopUnit); pLoopUnit != NULL; pLoopUnit = m_pPlayer->nextUnit(&iLoopUnit))4792		{4793			CvPlot* pLoopUnitPlot = pLoopUnit->plot();4794#if defined(MOD_AI_SMART_V3)4795			// AMS: Lets lower the safe point from 80% to 75% remaining life.4796			int iDivisor = MOD_AI_SMART_V3 ? 4 : 5;4797#if defined(MOD_UNITS_MAX_HP)4798			if(pLoopUnit->getDamage() > (pLoopUnit->GetMaxHitPoints() / iDivisor))  // this might not be a good place to land4799#else4800			if(pLoopUnit->getDamage() > (GC.getMAX_HIT_POINTS() / iDivisor))4801#endif4802#else4803#if defined(MOD_UNITS_MAX_HP)4804			if(pLoopUnit->getDamage() > (pLoopUnit->GetMaxHitPoints() / 5))  // this might not be a good place to land4805#else4806			if(pLoopUnit->getDamage() > (GC.getMAX_HIT_POINTS() / 5))  // this might not be a good place to land4807#endif4808#endif4809			{4810				continue;4811			}48124813#if defined(MOD_BUGFIX_MINOR)4814			if(pLoopUnitPlot != pUnitPlot && !pUnit->canRebaseAt(pUnitPlot, pLoopUnitPlot->getX(),pLoopUnitPlot->getY()))4815#else4816			if(pBestPlot != pUnitPlot && !pUnit->canRebaseAt(pUnitPlot, pLoopUnitPlot->getX(),pLoopUnitPlot->getY()))4817#endif4818			{4819				continue;4820			}48214822			if(!pUnit->canLoadUnit(*pLoopUnit, *pLoopUnitPlot))4823			{4824				continue;4825			}48264827#if defined(MOD_AI_SMART_V3)4828			int iPlotDanger = MOD_AI_SMART_V3? pUnit->EnemyScoreAtRange(pLoopUnitPlot, true) * 64 : m_pPlayer->GetPlotDanger(*pLoopUnitPlot);4829			4830			if(MOD_AI_SMART_V3 && iPlotDanger == 0)4831			{4832				iPlotDanger = pUnit->EnemyScoreAtRange(pLoopUnitPlot, false) + GC.getGame().getJonRandNum(5, "ExecuteAircraftMoves: Rebase");4833			}4834#else4835			int iPlotDanger = m_pPlayer->GetPlotDanger(*pLoopUnitPlot);4836#endif4837			if (pLoopUnit->getArmyID() != FFreeList::INVALID_INDEX)4838			{4839				iPlotDanger += 5000;4840			}4841			if(iPlotDanger >= iMostDangerous)4842			{4843				iMostDangerous = iPlotDanger;4844				pBestPlot = pLoopUnitPlot;4845				pTransportUnit = pLoopUnit;4846			}48474848		}48494850		CvCity* pLoopCity;4851		int iLoopCity = 0;4852		for(pLoopCity = m_pPlayer->firstCity(&iLoopCity); pLoopCity != NULL; pLoopCity = m_pPlayer->nextCity(&iLoopCity))4853		{4854			CvPlot* pTarget = pLoopCity->plot();48554856#if defined(MOD_AI_SMART_V3)4857			// AMS: Lets lower the safe point from 80% to 66% remaining life.4858			int iDivisor = MOD_AI_SMART_V3 ? 3 : 5;4859			if(pLoopCity->getDamage() > (pLoopCity->GetMaxHitPoints() / iDivisor))4860#else4861			if(pLoopCity->getDamage() > (pLoopCity->GetMaxHitPoints() / 5))4862#endif4863			{4864				continue;4865			}48664867#if defined(MOD_BUGFIX_MINOR)4868			if(pTarget != pUnitPlot && !pUnit->canRebaseAt(pUnitPlot,pTarget->getX(),pTarget->getY()))4869#else4870			if(pBestPlot != pUnitPlot && !pUnit->canRebaseAt(pUnitPlot,pTarget->getX(),pTarget->getY()))4871#endif4872			{4873				continue;4874			}48754876			if (pLoopCity->IsRazing())4877			{4878				continue;4879			}48804881#if defined(MOD_AI_SMART_V3)4882			int iPlotDanger = MOD_AI_SMART_V3 ? pUnit->EnemyScoreAtRange(pTarget, true) * 64 : m_pPlayer->GetPlotDanger(*pTarget);4883			4884			if(MOD_AI_SMART_V3 && iPlotDanger == 0)4885			{4886				iPlotDanger = pUnit->EnemyScoreAtRange(pTarget, false) + GC.getGame().getJonRandNum(5, "ExecuteAircraftMoves: Rebase");4887			}4888#else4889			int iPlotDanger = m_pPlayer->GetPlotDanger(*pTarget);4890#endif4891			if(iPlotDanger >= iMostDangerous)4892			{4893				iMostDangerous = iPlotDanger;4894				pBestPlot = pTarget;4895				pTransportUnit = NULL;4896			}4897		}48984899		if(pBestPlot && pBestPlot != pUnitPlot)4900		{4901			pUnit->PushMission(CvTypes::getMISSION_REBASE(), pBestPlot->getX(), pBestPlot->getY());4902			pUnit->finishMoves();4903			UnitProcessed(pUnit->GetID());49044905			if(GC.getLogging() && GC.getAILogging())4906			{4907				CvString strLogString;4908				CvString strTemp, strTemp2;4909				strTemp = GC.getUnitInfo(pUnit->getUnitType())->GetDescription();4910				if (pTransportUnit)4911				{4912					strTemp2 = GC.getUnitInfo(pTransportUnit->getUnitType())->GetDescription();4913				}49144915				if (pBestPlot->getPlotCity())4916				{4917					strLogString.Format("Rebasing %s to city garrison, X: %d, Y: %d", strTemp.GetCString(), pBestPlot->getX(), pBestPlot->getY());4918				}4919				else4920				{4921					strLogString.Format("Rebasing %s onto %s, X: %d, Y: %d", strTemp.GetCString(), strTemp2.GetCString(), pBestPlot->getX(), pBestPlot->getY());4922				}4923				LogHomelandMessage(strLogString);4924			}4925		}4926		else4927		{4928			pUnit->finishMoves();4929			UnitProcessed(pUnit->GetID());49304931			if(GC.getLogging() && GC.getAILogging())4932			{4933				CvString strTemp;4934				strTemp = GC.getUnitInfo(pUnit->getUnitType())->GetDescription();4935				CvString strLogString;4936				strLogString.Format("No better place to move %s at, X: %d, Y: %d", strTemp.GetCString(), pUnit->getX(), pUnit->getY());4937				LogHomelandMessage(strLogString);4938			}4939		}4940	}4941}

Calls

Called by