Bazaar developer reference

CvTacticalAI::MoveGreatGeneral(CvArmyAI *)

Defined in
CvTacticalAI.cpp, line 10847
Class
CvTacticalAI
Hook name
CivHooks::CvTacticalAI_MoveGreatGeneral

Hooks

static bool BeforeCvTacticalAI_MoveGreatGeneral(CvTacticalAI* self, CvArmyAI* pArmyAI);static void AfterCvTacticalAI_MoveGreatGeneral(CvTacticalAI* self, CvArmyAI* pArmyAI);static void ReplaceCvTacticalAI_MoveGreatGeneral(void (*original)(CvTacticalAI*, CvArmyAI*), CvTacticalAI* self, CvArmyAI* pArmyAI);CivRegisterBefore<CivHooks::CvTacticalAI_MoveGreatGeneral>(host, &BeforeCvTacticalAI_MoveGreatGeneral);CivRegisterAfter<CivHooks::CvTacticalAI_MoveGreatGeneral>(host, &AfterCvTacticalAI_MoveGreatGeneral);CivRegisterReplace<CivHooks::CvTacticalAI_MoveGreatGeneral>(host, &ReplaceCvTacticalAI_MoveGreatGeneral);

Code

10846/// Move a great general with an operation10847void CvTacticalAI::MoveGreatGeneral(CvArmyAI* pArmyAI)10848{10849	UnitHandle pGeneral;10850	int iRange;1085110852	for (unsigned int iI = 0; iI < m_GeneralsToMove.size(); iI++)10853	{10854		CvPlot* pBestPlot = NULL;10855		int iBestScore = -1;10856		pGeneral = m_pPlayer->getUnit(m_GeneralsToMove[iI].GetUnitID());1085710858		if(pGeneral)10859		{10860			iRange = (pGeneral->maxMoves() * 3) / GC.getMOVE_DENOMINATOR();  // Enough to make a decent road move10861			for(int iX = -iRange; iX <= iRange; iX++)10862			{10863				for(int iY = -iRange; iY <= iRange; iY++)10864				{10865					CvPlot* pEvalPlot = NULL;10866					pEvalPlot = plotXYWithRangeCheck(pGeneral->getX(), pGeneral->getY(), iX, iY, iRange);10867					if(!pEvalPlot)10868					{10869						continue;10870					}1087110872					if(CanReachInXTurns(pGeneral, pEvalPlot, 1))10873					{10874						int iScore = ScoreGreatGeneralPlot(pGeneral, pEvalPlot, pArmyAI);1087510876						if(iScore > iBestScore && iScore > 0)10877						{10878							iBestScore = iScore;10879							pBestPlot = pEvalPlot;10880						}10881					}1088210883				}10884			}1088510886			if(pBestPlot != NULL)10887			{10888				ExecuteMoveToPlot(pGeneral, pBestPlot);1088910890				if(GC.getLogging() && GC.getAILogging())10891				{10892					int iDistToOperationCenter = -1;1089310894					if(pArmyAI)10895					{10896						CvPlot* pCOM = pArmyAI->GetCenterOfMass(NO_DOMAIN);10897						if(pCOM)10898						{10899							iDistToOperationCenter = plotDistance(pBestPlot->getX(), pBestPlot->getY(), pCOM->getX(), pCOM->getY());10900						}10901					}1090210903					CvString strMsg;10904					strMsg.Format("Deploying %s, To X: %d, To Y: %d, At X: %d, At Y: %d, Plot Score: %d, Dist from COM: %d",10905					              pGeneral->getName().GetCString(), pBestPlot->getX(), pBestPlot->getY(),10906					              pGeneral->getX(), pGeneral->getY(), iBestScore, iDistToOperationCenter);10907					LogTacticalMessage(strMsg);10908				}10909			}10910		}10911	}1091210913	return;10914}

Calls

Called by