Hooks
static bool BeforeCvAINavalEscortedOperation_Init(CvAINavalEscortedOperation* self, int iID, PlayerTypes eOwner, PlayerTypes arg2, int iDefaultArea, CvCity* arg4, CvCity* arg5);static void AfterCvAINavalEscortedOperation_Init(CvAINavalEscortedOperation* self, int iID, PlayerTypes eOwner, PlayerTypes arg2, int iDefaultArea, CvCity* arg4, CvCity* arg5);static void ReplaceCvAINavalEscortedOperation_Init(void (*original)(CvAINavalEscortedOperation*, int, PlayerTypes, PlayerTypes, int, CvCity*, CvCity*), CvAINavalEscortedOperation* self, int iID, PlayerTypes eOwner, PlayerTypes arg2, int iDefaultArea, CvCity* arg4, CvCity* arg5);CivRegisterBefore<CivHooks::CvAINavalEscortedOperation_Init>(host, &BeforeCvAINavalEscortedOperation_Init);CivRegisterAfter<CivHooks::CvAINavalEscortedOperation_Init>(host, &AfterCvAINavalEscortedOperation_Init);CivRegisterReplace<CivHooks::CvAINavalEscortedOperation_Init>(host, &ReplaceCvAINavalEscortedOperation_Init);
Code
5047/// Kick off this operation5048void CvAINavalEscortedOperation::Init(int iID, PlayerTypes eOwner, PlayerTypes /*eEnemy*/, int iDefaultArea, CvCity* /*pTarget*/, CvCity* /*pMuster*/)5049{5050 Reset();5051 m_eMoveType = AI_OPERATION_MOVETYPE_NAVAL_ESCORT;5052 m_iID = iID;5053 m_eOwner = eOwner;5054 SetDefaultArea(iDefaultArea); // Area settler starts in50555056 // Find the free civilian (that triggered this operation)5057 CvUnit* pOurCivilian = FindBestCivilian();5058 m_iInitialAreaID = (pOurCivilian != NULL)? pOurCivilian->getArea() : -1;50595060 CvCity* pStartCity = GetOperationStartCity();50615062 if(pOurCivilian != NULL && iID != -1 && pStartCity)5063 {5064 // Find a destination (not worrying about safe paths)5065 CvPlot* pTargetSite = FindBestTarget(pOurCivilian);50665067 if(pTargetSite != NULL)5068 {5069 SetTargetPlot(pTargetSite);50705071 // create the armies that are needed and set the state to ARMYAISTATE_WAITING_FOR_UNITS_TO_REINFORCE5072 CvArmyAI* pArmyAI = GET_PLAYER(m_eOwner).addArmyAI();5073 if(pArmyAI)5074 {5075 m_viArmyIDs.push_back(pArmyAI->GetID());5076 pArmyAI->Init(pArmyAI->GetID(),m_eOwner,m_iID);5077 pArmyAI->SetArmyAIState(ARMYAISTATE_WAITING_FOR_UNITS_TO_REINFORCE);5078 pArmyAI->SetFormationIndex(GetFormation());50795080 pArmyAI->SetGoalPlot(pTargetSite);5081 CvPlot* pMusterPt = pStartCity->plot();5082 SetMusterPlot(pMusterPt);5083 pArmyAI->SetXY(pMusterPt->getX(), pMusterPt->getY());50845085 // Add the settler to our army5086 pArmyAI->AddUnit(pOurCivilian->GetID(), 0);50875088 // try to get the escort from existing units that are waiting around5089 BuildListOfUnitsWeStillNeedToBuild();50905091 // Try to get as many units as possible from existing units that are waiting around5092 if(GrabUnitsFromTheReserves(GetMusterPlot(), NULL))5093 {5094 pArmyAI->SetArmyAIState(ARMYAISTATE_WAITING_FOR_UNITS_TO_CATCH_UP);5095 m_eCurrentState = AI_OPERATION_STATE_GATHERING_FORCES;5096 }5097 else5098 {5099 m_eCurrentState = AI_OPERATION_STATE_RECRUITING_UNITS;5100 }5101 LogOperationStart();5102 }5103 }51045105 else5106 {5107 // Lost our target, abort5108 m_eCurrentState = AI_OPERATION_STATE_ABORTED;5109 m_eAbortReason = AI_ABORT_LOST_TARGET;5110 }5111 }5112}