Bazaar developer reference

CvAIOperation::PercentFromMusterPointToTarget()

Defined in
CvAIOperation.cpp, line 730
Class
CvAIOperation
Hook name
CivHooks::CvAIOperation_PercentFromMusterPointToTarget

Hooks

static bool BeforeCvAIOperation_PercentFromMusterPointToTarget(CvAIOperation* self, int& result);static void AfterCvAIOperation_PercentFromMusterPointToTarget(CvAIOperation* self, int& result);static int ReplaceCvAIOperation_PercentFromMusterPointToTarget(int (*original)(CvAIOperation*), CvAIOperation* self);CivRegisterBefore<CivHooks::CvAIOperation_PercentFromMusterPointToTarget>(host, &BeforeCvAIOperation_PercentFromMusterPointToTarget);CivRegisterAfter<CivHooks::CvAIOperation_PercentFromMusterPointToTarget>(host, &AfterCvAIOperation_PercentFromMusterPointToTarget);CivRegisterReplace<CivHooks::CvAIOperation_PercentFromMusterPointToTarget>(host, &ReplaceCvAIOperation_PercentFromMusterPointToTarget);

Code

729/// Report percentage distance traveled from muster point to target (using army that is furthest along)730int CvAIOperation::PercentFromMusterPointToTarget()731{732	int iRtnValue = 0;733734	switch(m_eCurrentState)735	{736	case AI_OPERATION_STATE_GATHERING_FORCES:737	case AI_OPERATION_STATE_ABORTED:738	case AI_OPERATION_STATE_RECRUITING_UNITS:739		return 0;740741	case AI_OPERATION_STATE_AT_TARGET:742	case AI_OPERATION_STATE_SUCCESSFUL_FINISH:743		return 100;744745	case AI_OPERATION_STATE_MOVING_TO_TARGET:746	{747		// Let each army perform its own update748		for(unsigned int uiI = 0; uiI < m_viArmyIDs.size(); uiI++)749		{750			CvArmyAI* pArmy = GET_PLAYER(m_eOwner).getArmyAI(m_viArmyIDs[uiI]);751752			if (pArmy->GetGoalPlot())753			{754				int iDistanceMusterToTarget;755				int iDistanceCurrentToTarget;756757				CvPlot *pCenterOfMass = pArmy->GetCenterOfMass(IsAllNavalOperation() || IsMixedLandNavalOperation() ? DOMAIN_SEA : DOMAIN_LAND);758759				// Use the step path finder to compute distance760				iDistanceMusterToTarget = GC.getStepFinder().GetStepDistanceBetweenPoints(m_eOwner, m_eEnemy, GetMusterPlot(), pArmy->GetGoalPlot());761				iDistanceCurrentToTarget = GC.getStepFinder().GetStepDistanceBetweenPoints(m_eOwner, m_eEnemy, pCenterOfMass, pArmy->GetGoalPlot());762763				if(iDistanceMusterToTarget <= 0)764				{765					return 0;766				}767	768				// If within 2 of the final goal, consider ourselves there769				else if (iDistanceCurrentToTarget <= 2)770				{771					return 100;772				}773774				else775				{776					int iTempValue = 100 - (100 * iDistanceCurrentToTarget / iDistanceMusterToTarget);777					if(iTempValue > iRtnValue)778					{779						iRtnValue = iTempValue;780					}781				}782			}783			else 784			{785				CvAssertMsg (false, "Operational AI army without a goal plot!  Send save to Ed");786			}787		}788	}789	break;790	}791792	return iRtnValue;793}

Calls

Called by