Bazaar developer reference

CvAIOperationFoundCity::Init(int, PlayerTypes, PlayerTypes, int, CvCity *, CvCity *)

Defined in
CvAIOperation.cpp, line 2994
Class
CvAIOperationFoundCity
Hook name
CivHooks::CvAIOperationFoundCity_Init
Overrides
CvAIEscortedOperation::Init(int, PlayerTypes, PlayerTypes, int, CvCity *, CvCity *)
Overridden by
CvAIOperationQuickColonize::Init(int, PlayerTypes, PlayerTypes, int, CvCity *, CvCity *)

Hooks

static bool BeforeCvAIOperationFoundCity_Init(CvAIOperationFoundCity* self, int iID, PlayerTypes eOwner, PlayerTypes arg2, int iDefaultArea, CvCity* arg4, CvCity* arg5);static void AfterCvAIOperationFoundCity_Init(CvAIOperationFoundCity* self, int iID, PlayerTypes eOwner, PlayerTypes arg2, int iDefaultArea, CvCity* arg4, CvCity* arg5);static void ReplaceCvAIOperationFoundCity_Init(void (*original)(CvAIOperationFoundCity*, int, PlayerTypes, PlayerTypes, int, CvCity*, CvCity*), CvAIOperationFoundCity* self, int iID, PlayerTypes eOwner, PlayerTypes arg2, int iDefaultArea, CvCity* arg4, CvCity* arg5);CivRegisterBefore<CivHooks::CvAIOperationFoundCity_Init>(host, &BeforeCvAIOperationFoundCity_Init);CivRegisterAfter<CivHooks::CvAIOperationFoundCity_Init>(host, &AfterCvAIOperationFoundCity_Init);CivRegisterReplace<CivHooks::CvAIOperationFoundCity_Init>(host, &ReplaceCvAIOperationFoundCity_Init);

Code

2994void CvAIOperationFoundCity::Init(int iID, PlayerTypes eOwner, PlayerTypes /*eEnemy*/, int iDefaultArea, CvCity* /*pTarget*/, CvCity* /*pMuster*/)2995{2996	m_iTargetArea = iDefaultArea;2997	CvUnit* pOurCivilian;2998	CvPlot* pTargetSite = NULL;2999	CvPlot* pNewTarget = NULL;30003001	Reset();3002	m_eMoveType = AI_OPERATION_MOVETYPE_SINGLE_HEX;3003	m_iID = iID;3004	m_eOwner = eOwner;30053006	// Find the free civilian (that triggered this operation)3007	pOurCivilian = FindBestCivilian();30083009	if(pOurCivilian != NULL && iID != -1)3010	{3011		// Find a destination (not worrying about safe paths)3012		pTargetSite = FindBestTarget(pOurCivilian, false);30133014		if(pTargetSite != NULL)3015		{3016			SetTargetPlot(pTargetSite);30173018			// create the armies that are needed and set the state to ARMYAISTATE_WAITING_FOR_UNITS_TO_REINFORCE3019			CvArmyAI* pArmyAI = GET_PLAYER(m_eOwner).addArmyAI();3020			if(pArmyAI)3021			{3022				m_viArmyIDs.push_back(pArmyAI->GetID());3023				pArmyAI->Init(pArmyAI->GetID(),m_eOwner,m_iID);3024				pArmyAI->SetArmyAIState(ARMYAISTATE_WAITING_FOR_UNITS_TO_REINFORCE);3025				pArmyAI->SetFormationIndex(GetFormation());30263027				// Figure out the initial rally point - for this operation it is wherever our civilian is standing3028				pArmyAI->SetGoalPlot(pTargetSite);3029				CvPlot* pMusterPt = pOurCivilian->plot();3030				SetMusterPlot(pMusterPt);3031				pArmyAI->SetXY(pMusterPt->getX(), pMusterPt->getY());3032				SetDefaultArea(pMusterPt->getArea());30333034				// Add the settler to our army3035				pArmyAI->AddUnit(pOurCivilian->GetID(), 0);30363037				// Add the escort as a unit we need to build3038				m_viListOfUnitsWeStillNeedToBuild.clear();3039				OperationSlot thisOperationSlot;3040				thisOperationSlot.m_iOperationID = m_iID;3041				thisOperationSlot.m_iArmyID = pArmyAI->GetID();3042				thisOperationSlot.m_iSlotID = 1;3043				m_viListOfUnitsWeStillNeedToBuild.push_back(thisOperationSlot);30443045				// try to get the escort from existing units that are waiting around3046				GrabUnitsFromTheReserves(pMusterPt, pTargetSite);3047				if(pArmyAI->GetNumSlotsFilled() > 1)3048				{3049					pArmyAI->SetArmyAIState(ARMYAISTATE_WAITING_FOR_UNITS_TO_CATCH_UP);3050					m_eCurrentState = AI_OPERATION_STATE_GATHERING_FORCES;3051				}3052				else3053				{3054					// There was no escort immediately available.  Let's look for a "safe" city site instead30553056					if (eOwner == -1 || GET_PLAYER(eOwner).getNumCities() > 1 || GET_PLAYER(eOwner).GetDiplomacyAI()->GetBoldness() > 5) // unless we'd rather play it safe3057					{3058						pNewTarget = FindBestTarget(pOurCivilian, true);3059					}30603061					// If no better target, we'll wait it out for an escort3062					if(pNewTarget == NULL)3063					{3064						// Need to add it back in to list of what to build (was cleared before since marked optional)3065						m_viListOfUnitsWeStillNeedToBuild.clear();3066						OperationSlot thisOperationSlot2;3067						thisOperationSlot2.m_iOperationID = m_iID;3068						thisOperationSlot2.m_iArmyID = pArmyAI->GetID();3069						thisOperationSlot2.m_iSlotID = 1;3070						m_viListOfUnitsWeStillNeedToBuild.push_back(thisOperationSlot2);3071						m_eCurrentState = AI_OPERATION_STATE_RECRUITING_UNITS;3072					}30733074					// Send the settler by himself to this safe location3075					else3076					{3077						m_bEscorted = false;30783079						// Clear the list of units we need3080						m_viListOfUnitsWeStillNeedToBuild.clear();30813082						// Change the muster point3083						pArmyAI->SetGoalPlot(pNewTarget);3084						SetMusterPlot(pOurCivilian->plot());3085						pArmyAI->SetXY(GetMusterPlot()->getX(), GetMusterPlot()->getY());30863087						// Send the settler directly to the target3088						pArmyAI->SetArmyAIState(ARMYAISTATE_MOVING_TO_DESTINATION);3089						m_eCurrentState = AI_OPERATION_STATE_MOVING_TO_TARGET;3090					}3091				}3092				LogOperationStart();3093			}3094		}30953096		else3097		{3098			// Lost our target, abort3099			m_eCurrentState = AI_OPERATION_STATE_ABORTED;3100			m_eAbortReason = AI_ABORT_LOST_TARGET;3101		}3102	}3103}

Calls