Bazaar developer reference

CvTacticalAI::ExecuteEscortEmbarkedMoves()

Defined in
CvTacticalAI.cpp, line 8792
Class
CvTacticalAI
Hook name
CivHooks::CvTacticalAI_ExecuteEscortEmbarkedMoves

Hooks

static bool BeforeCvTacticalAI_ExecuteEscortEmbarkedMoves(CvTacticalAI* self);static void AfterCvTacticalAI_ExecuteEscortEmbarkedMoves(CvTacticalAI* self);static void ReplaceCvTacticalAI_ExecuteEscortEmbarkedMoves(void (*original)(CvTacticalAI*), CvTacticalAI* self);CivRegisterBefore<CivHooks::CvTacticalAI_ExecuteEscortEmbarkedMoves>(host, &BeforeCvTacticalAI_ExecuteEscortEmbarkedMoves);CivRegisterAfter<CivHooks::CvTacticalAI_ExecuteEscortEmbarkedMoves>(host, &AfterCvTacticalAI_ExecuteEscortEmbarkedMoves);CivRegisterReplace<CivHooks::CvTacticalAI_ExecuteEscortEmbarkedMoves>(host, &ReplaceCvTacticalAI_ExecuteEscortEmbarkedMoves);

Code

8791/// Move naval units on top of embarked units in danger8792void CvTacticalAI::ExecuteEscortEmbarkedMoves()8793{8794	for(unsigned int iI = 0; iI < m_CurrentMoveUnits.size(); iI++)8795	{8796		UnitHandle pUnit = m_pPlayer->getUnit(m_CurrentMoveUnits[iI].GetID());8797		if(pUnit)8798		{8799			CvPlot *pBestTarget = NULL;8800			int iHighestDanger = -1;8801			int iMovementRate = pUnit->getMoves() / GC.getMOVE_DENOMINATOR();88028803			// Loop through all my embarked units that are: alone, have already moved this turn, within range8804			UnitHandle pLoopUnit;8805			int iLoop;8806			for(pLoopUnit = m_pPlayer->firstUnit(&iLoop); pLoopUnit; pLoopUnit = m_pPlayer->nextUnit(&iLoop))8807			{8808				if (pLoopUnit->getDomainType() != DOMAIN_LAND)8809				{8810					continue;8811				}8812				else if (!pLoopUnit->isEmbarked())8813				{8814					continue;8815				}8816				else if (pLoopUnit->plot()->getNumUnits() > 1)8817				{8818					continue;8819				}8820				else if (pLoopUnit->canMove())8821				{8822					continue;8823				}8824				else if (plotDistance(pUnit->getX(), pUnit->getY(), pLoopUnit->getX(), pLoopUnit->getY()) > iMovementRate)8825				{8826					continue;8827				}88288829				// Can this unit get to the embarked unit in one move?8830				CvPlot *pTarget = pLoopUnit->plot();8831				if (TurnsToReachTarget(pUnit, pTarget) <= 1)8832				{8833					int iDanger = m_pPlayer->GetPlotDanger(*pTarget);8834					if (iDanger > iHighestDanger)8835					{8836						iHighestDanger = iDanger;8837						pBestTarget = pTarget;8838					}8839				}8840			}88418842			if (pBestTarget)8843			{8844				ExecuteMoveToPlot(pUnit, pBestTarget);8845				UnitProcessed(m_CurrentMoveUnits[iI].GetID());88468847				if(GC.getLogging() && GC.getAILogging())8848				{8849					CvString strLogString;8850					strLogString.Format("%s escorted embarked unit at, Current X: %d, Current Y: %d", pUnit->getName().GetCString(), pUnit->getX(), pUnit->getY());8851					LogTacticalMessage(strLogString, false);8852				}8853			}8854		}8855	}8856}

Calls

Called by