Bazaar developer reference

CvAIOperationFoundCity::ArmyInPosition(CvArmyAI *)

Defined in
CvAIOperation.cpp, line 3107
Class
CvAIOperationFoundCity
Hook name
CivHooks::CvAIOperationFoundCity_ArmyInPosition
Overrides
CvAIOperation::ArmyInPosition(CvArmyAI *)

Hooks

static bool BeforeCvAIOperationFoundCity_ArmyInPosition(CvAIOperationFoundCity* self, CvArmyAI* pArmy, bool& result);static void AfterCvAIOperationFoundCity_ArmyInPosition(CvAIOperationFoundCity* self, CvArmyAI* pArmy, bool& result);static bool ReplaceCvAIOperationFoundCity_ArmyInPosition(bool (*original)(CvAIOperationFoundCity*, CvArmyAI*), CvAIOperationFoundCity* self, CvArmyAI* pArmy);CivRegisterBefore<CivHooks::CvAIOperationFoundCity_ArmyInPosition>(host, &BeforeCvAIOperationFoundCity_ArmyInPosition);CivRegisterAfter<CivHooks::CvAIOperationFoundCity_ArmyInPosition>(host, &AfterCvAIOperationFoundCity_ArmyInPosition);CivRegisterReplace<CivHooks::CvAIOperationFoundCity_ArmyInPosition>(host, &ReplaceCvAIOperationFoundCity_ArmyInPosition);

Code

3106/// If at target, found city; if at muster point, merge settler and escort and move out3107bool CvAIOperationFoundCity::ArmyInPosition(CvArmyAI* pArmy)3108{3109	int iUnitID = 0;3110	bool bStateChanged = false;3111	CvUnit* pSettler = 0, *pEscort = 0;3112	CvString strMsg;31133114	switch(m_eCurrentState)3115	{3116		// If we were gathering forces, we have to insist that any escort is in the same plot as the settler.3117		// If not we'll fall through and just stay in this state.3118	case AI_OPERATION_STATE_GATHERING_FORCES:31193120		// No escort, can just let base class handle it3121		if(!m_bEscorted)3122		{3123			return CvAIOperation::ArmyInPosition(pArmy);3124		}31253126		// More complex if we are waiting for an escort3127		else3128		{3129			iUnitID = pArmy->GetFirstUnitID();3130			if(iUnitID != -1)3131			{3132				pSettler = GET_PLAYER(m_eOwner).getUnit(iUnitID);3133			}3134			iUnitID = pArmy->GetNextUnitID();3135			if(iUnitID != -1)3136			{3137				pEscort = GET_PLAYER(m_eOwner).getUnit(iUnitID);3138			}3139			else3140			{3141				// Escort died while gathering forces.  Abort (and return TRUE since state changed)3142				m_eCurrentState = AI_OPERATION_STATE_ABORTED;3143				m_eAbortReason = AI_ABORT_ESCORT_DIED;3144				return true;3145			}3146			if(pSettler != NULL && pEscort != NULL && pSettler->plot() == pEscort->plot())3147			{3148				// let's see if the target still makes sense (this is modified from RetargetCivilian)3149				CvPlot* pBetterTarget = FindBestTarget(pSettler, true);31503151				// No targets at all!  Abort3152				if(pBetterTarget == NULL)3153				{3154					m_eCurrentState = AI_OPERATION_STATE_ABORTED;3155					m_eAbortReason = AI_ABORT_NO_TARGET;3156					return false;3157				}3158				// If we have a target3159				else3160				{3161					SetTargetPlot(pBetterTarget);3162					pArmy->SetGoalPlot(pBetterTarget);3163				}3164				return CvAIOperation::ArmyInPosition(pArmy);3165			}3166		}3167		break;31683169	case AI_OPERATION_STATE_MOVING_TO_TARGET:3170	case AI_OPERATION_STATE_AT_TARGET:31713172		// Call base class version and see if it thinks we're done3173		bStateChanged = CvAIOperation::ArmyInPosition(pArmy);31743175		// Now get the settler3176		iUnitID = pArmy->GetFirstUnitID();3177		if(iUnitID != -1)3178		{3179			pSettler = GET_PLAYER(m_eOwner).getUnit(iUnitID);3180		}31813182		if(pSettler != NULL)3183		{3184			if((GetTargetPlot()->getOwner() != NO_PLAYER && GetTargetPlot()->getOwner() != m_eOwner) || GetTargetPlot()->IsAdjacentOwnedByOtherTeam(pSettler->getTeam()))3185			{3186				if(GC.getLogging() && GC.getAILogging())3187				{3188					strMsg.Format("Now at target but can no longer settle here. Target was (X=%d Y=%d)", GetTargetPlot()->getX(), GetTargetPlot()->getY());3189					LogOperationSpecialMessage(strMsg);3190				}3191				RetargetCivilian(pSettler, pArmy);3192				pSettler->finishMoves();3193				iUnitID = pArmy->GetNextUnitID();3194				if(iUnitID != -1)3195				{3196					pEscort = GET_PLAYER(m_eOwner).getUnit(iUnitID);3197					pEscort->finishMoves();3198				}3199			}3200			// If the settler made it, we don't care about the entire army3201			else if(pSettler->plot() == GetTargetPlot() && pSettler->canMove() && pSettler->canFound(pSettler->plot()))3202			{3203				CvPlot* pCityPlot = pSettler->plot();3204				int iPlotValue = GC.getGame().GetSettlerSiteEvaluator()->PlotFoundValue(pCityPlot, &GET_PLAYER(m_eOwner), NO_YIELD, false);32053206				pSettler->PushMission(CvTypes::getMISSION_FOUND());32073208				if(GC.getLogging() && GC.getAILogging())3209				{3210					CvArea* pArea = pCityPlot->area();3211					CvCity* pCity = pCityPlot->getPlotCity();32123213					if (pCity != NULL)3214					{3215						strMsg.Format("City founded, At X=%d, At Y=%d, %s, %d, %d", pCityPlot->getX(), pCityPlot->getY(), pCity->getName().GetCString(), iPlotValue, pArea->getTotalFoundValue());3216						LogOperationSpecialMessage(strMsg);3217					}3218				}3219				m_eCurrentState = AI_OPERATION_STATE_SUCCESSFUL_FINISH;3220			}32213222			// If we're at our target but can no longer found a city, might be someone else beat us to this area3223			// So move back out, picking a new target3224			else if(pSettler->plot() == GetTargetPlot() && !pSettler->canFound(pSettler->plot()))3225			{3226				if(GC.getLogging() && GC.getAILogging())3227				{3228					strMsg.Format("At target but can no longer settle here. Target was (X=%d Y=%d)", GetTargetPlot()->getX(), GetTargetPlot()->getY());3229					LogOperationSpecialMessage(strMsg);3230				}3231				RetargetCivilian(pSettler, pArmy);3232				pSettler->finishMoves();3233				iUnitID = pArmy->GetNextUnitID();3234				if(iUnitID != -1)3235				{3236					pEscort = GET_PLAYER(m_eOwner).getUnit(iUnitID);3237					pEscort->finishMoves();3238				}3239			}3240		}3241		break;32423243		// In all other cases use base class version3244	case AI_OPERATION_STATE_ABORTED:3245	case AI_OPERATION_STATE_RECRUITING_UNITS:3246		return CvAIOperation::ArmyInPosition(pArmy);3247		break;3248	};32493250	return bStateChanged;3251}

Calls