Bazaar developer reference

CvAIOperationConcertTour::ArmyInPosition(CvArmyAI *)

Defined in
CvAIOperation.cpp, line 3610
Class
CvAIOperationConcertTour
Hook name
CivHooks::CvAIOperationConcertTour_ArmyInPosition
Overrides
CvAIOperation::ArmyInPosition(CvArmyAI *)

Hooks

static bool BeforeCvAIOperationConcertTour_ArmyInPosition(CvAIOperationConcertTour* self, CvArmyAI* pArmy, bool& result);static void AfterCvAIOperationConcertTour_ArmyInPosition(CvAIOperationConcertTour* self, CvArmyAI* pArmy, bool& result);static bool ReplaceCvAIOperationConcertTour_ArmyInPosition(bool (*original)(CvAIOperationConcertTour*, CvArmyAI*), CvAIOperationConcertTour* self, CvArmyAI* pArmy);CivRegisterBefore<CivHooks::CvAIOperationConcertTour_ArmyInPosition>(host, &BeforeCvAIOperationConcertTour_ArmyInPosition);CivRegisterAfter<CivHooks::CvAIOperationConcertTour_ArmyInPosition>(host, &AfterCvAIOperationConcertTour_ArmyInPosition);CivRegisterReplace<CivHooks::CvAIOperationConcertTour_ArmyInPosition>(host, &ReplaceCvAIOperationConcertTour_ArmyInPosition);

Code

3609/// If at target, rock on! If at muster point, merge musician and escort and move out3610bool CvAIOperationConcertTour::ArmyInPosition(CvArmyAI* pArmy)3611{3612	int iUnitID = 0;3613	bool bStateChanged = false;3614	CvUnit* pMusician = 0, *pEscort = 0;3615	CvString strMsg;36163617	switch(m_eCurrentState)3618	{3619		// If we were gathering forces, we have to insist that any escort is in the same plot as the merchant.3620		// If not we'll fall through and just stay in this state.3621	case AI_OPERATION_STATE_GATHERING_FORCES:36223623		// No escort, can just let base class handle it3624		if(!m_bEscorted)3625		{3626			return CvAIOperation::ArmyInPosition(pArmy);3627		}36283629		// More complex if we are waiting for an escort3630		else3631		{3632			iUnitID = pArmy->GetFirstUnitID();3633			if(iUnitID != -1)3634			{3635				pMusician = GET_PLAYER(m_eOwner).getUnit(iUnitID);3636			}3637			iUnitID = pArmy->GetNextUnitID();3638			if(iUnitID != -1)3639			{3640				pEscort = GET_PLAYER(m_eOwner).getUnit(iUnitID);3641			}3642			else3643			{3644				// Escort died while gathering forces.  Abort (and return TRUE since state changed)3645				m_eCurrentState = AI_OPERATION_STATE_ABORTED;3646				m_eAbortReason = AI_ABORT_ESCORT_DIED;3647				return true;3648			}3649			if(pMusician != NULL && pEscort != NULL && pMusician->plot() == pEscort->plot())3650			{3651				// let's see if the target still makes sense (this is modified from RetargetCivilian)3652				CvPlot* pBetterTarget = FindBestTarget(pMusician, true);36533654				// No targets at all!  Abort3655				if(pBetterTarget == NULL)3656				{3657					m_eCurrentState = AI_OPERATION_STATE_ABORTED;3658					m_eAbortReason = AI_ABORT_NO_TARGET;3659					return false;3660				}3661				// If we have a target3662				else3663				{3664					SetTargetPlot(pBetterTarget);3665					pArmy->SetGoalPlot(pBetterTarget);3666				}3667				return CvAIOperation::ArmyInPosition(pArmy);3668			}3669		}3670		break;36713672	case AI_OPERATION_STATE_MOVING_TO_TARGET:3673	case AI_OPERATION_STATE_AT_TARGET:36743675		// Call base class version and see if it thinks we're done3676		bStateChanged = CvAIOperation::ArmyInPosition(pArmy);36773678		// Now get the musician3679		iUnitID = pArmy->GetFirstUnitID();3680		if(iUnitID != -1)3681		{3682			pMusician = GET_PLAYER(m_eOwner).getUnit(iUnitID);3683		}36843685		if(pMusician != NULL)3686		{3687			// If the merchant made it, we don't care about the entire army3688			if(pMusician->plot() == GetTargetPlot() && pMusician->canMove() && pMusician->canBlastTourism(pMusician->plot()))3689			{3690				pMusician->PushMission(CvTypes::getMISSION_ONE_SHOT_TOURISM());3691				if(GC.getLogging() && GC.getAILogging())3692				{3693					strMsg.Format("Great Musician performing concert tour, At X=%d, At Y=%d", pMusician->plot()->getX(), pMusician->plot()->getY());3694					LogOperationSpecialMessage(strMsg);3695				}36963697				m_eCurrentState = AI_OPERATION_STATE_SUCCESSFUL_FINISH;3698			}36993700			// Does it look like we should be done?3701			else if(pMusician->plot() == GetTargetPlot())3702			{3703				// We're at our target but can no longer perform concert, enemy city was probably conquered3704				if(!pMusician->canBlastTourism(pMusician->plot()))3705				{3706					if(GC.getLogging() && GC.getAILogging())3707					{3708						strMsg.Format("At target but can no longer hold concert here. Target was (X=%d Y=%d)", GetTargetPlot()->getX(), GetTargetPlot()->getY());3709						LogOperationSpecialMessage(strMsg);3710					}3711					RetargetCivilian(pMusician, pArmy);3712					pMusician->finishMoves();3713					iUnitID = pArmy->GetNextUnitID();3714					if(iUnitID != -1)3715					{3716						pEscort = GET_PLAYER(m_eOwner).getUnit(iUnitID);3717						pEscort->finishMoves();3718					}3719				}3720			}3721		}3722		break;37233724		// In all other cases use base class version3725	case AI_OPERATION_STATE_ABORTED:3726	case AI_OPERATION_STATE_RECRUITING_UNITS:3727		return CvAIOperation::ArmyInPosition(pArmy);3728		break;3729	};37303731	return bStateChanged;3732}

Calls