Hooks
static bool BeforeCvAIOperationBasicCityAttack_Init(CvAIOperationBasicCityAttack* self, int iID, PlayerTypes eOwner, PlayerTypes eEnemy, int arg3, CvCity* pTarget, CvCity* pMuster);static void AfterCvAIOperationBasicCityAttack_Init(CvAIOperationBasicCityAttack* self, int iID, PlayerTypes eOwner, PlayerTypes eEnemy, int arg3, CvCity* pTarget, CvCity* pMuster);static void ReplaceCvAIOperationBasicCityAttack_Init(void (*original)(CvAIOperationBasicCityAttack*, int, PlayerTypes, PlayerTypes, int, CvCity*, CvCity*), CvAIOperationBasicCityAttack* self, int iID, PlayerTypes eOwner, PlayerTypes eEnemy, int arg3, CvCity* pTarget, CvCity* pMuster);CivRegisterBefore<CivHooks::CvAIOperationBasicCityAttack_Init>(host, &BeforeCvAIOperationBasicCityAttack_Init);CivRegisterAfter<CivHooks::CvAIOperationBasicCityAttack_Init>(host, &AfterCvAIOperationBasicCityAttack_Init);CivRegisterReplace<CivHooks::CvAIOperationBasicCityAttack_Init>(host, &ReplaceCvAIOperationBasicCityAttack_Init);
Code
2072/// Kick off this operation2073void CvAIOperationBasicCityAttack::Init(int iID, PlayerTypes eOwner, PlayerTypes eEnemy, int /* iDefaultArea */, CvCity* pTarget, CvCity* pMuster)2074{2075 Reset();2076 m_eMoveType = AI_OPERATION_MOVETYPE_ENEMY_TERRITORY;2077 m_iID = iID;2078 m_eOwner = eOwner;2079 m_eEnemy = eEnemy;2080 SetStartCityPlot(pMuster->plot());20812082 if(iID != -1)2083 {2084 // create the armies that are needed and set the state to ARMYAISTATE_WAITING_FOR_UNITS_TO_REINFORCE2085 CvPlayer& kPlayer = GET_PLAYER(m_eOwner);2086 CvArmyAI* pArmyAI = kPlayer.addArmyAI();2087 if(pArmyAI)2088 {2089 m_viArmyIDs.push_back(pArmyAI->GetID());2090 pArmyAI->Init(pArmyAI->GetID(),m_eOwner,m_iID);2091 pArmyAI->SetArmyAIState(ARMYAISTATE_WAITING_FOR_UNITS_TO_REINFORCE);2092 pArmyAI->SetFormationIndex(GetFormation());20932094 if(pTarget)2095 {2096 SetTargetPlot(pTarget->plot());2097 pArmyAI->SetGoalPlot(GetTargetPlot());2098 SetMusterPlot(GetStartCityPlot());2099 pArmyAI->SetXY(GetMusterPlot()->getX(), GetMusterPlot()->getY());2100 SetDefaultArea(GetMusterPlot()->getArea());21012102 // Reset our destination to be a few plots shy of the final target2103 CvPlot* pDeployPt;2104 pDeployPt = GC.getStepFinder().GetXPlotsFromEnd(GetOwner(), GetEnemy(), GetMusterPlot(), GetTargetPlot(), (GetDeployRange() / 2), true);2105 if (pDeployPt)2106 {2107 pArmyAI->SetGoalPlot(pDeployPt);21082109 // Find the list of units we need to build before starting this operation in earnest2110 BuildListOfUnitsWeStillNeedToBuild();21112112 // try to get as many units as possible from existing units that are waiting around2113 if(GrabUnitsFromTheReserves(GetMusterPlot(), GetTargetPlot()))2114 {2115 pArmyAI->SetArmyAIState(ARMYAISTATE_WAITING_FOR_UNITS_TO_CATCH_UP);2116 m_eCurrentState = AI_OPERATION_STATE_GATHERING_FORCES;2117 }2118 else2119 {2120 m_eCurrentState = AI_OPERATION_STATE_RECRUITING_UNITS;2121 }21222123 LogOperationStart();2124 }2125 else2126 {2127 m_eCurrentState = AI_OPERATION_STATE_ABORTED;2128 m_eAbortReason = AI_ABORT_LOST_PATH;2129 }2130 }21312132 else2133 {2134 // Lost our target, abort2135 m_eCurrentState = AI_OPERATION_STATE_ABORTED;2136 m_eAbortReason = AI_ABORT_LOST_TARGET;2137 }2138 }2139 }2140}