Bazaar developer reference

CvHomelandAI::ExecuteProphetMoves()

Defined in
CvHomelandAI.cpp, line 3900
Class
CvHomelandAI
Hook name
CivHooks::CvHomelandAI_ExecuteProphetMoves

Hooks

static bool BeforeCvHomelandAI_ExecuteProphetMoves(CvHomelandAI* self);static void AfterCvHomelandAI_ExecuteProphetMoves(CvHomelandAI* self);static void ReplaceCvHomelandAI_ExecuteProphetMoves(void (*original)(CvHomelandAI*), CvHomelandAI* self);CivRegisterBefore<CivHooks::CvHomelandAI_ExecuteProphetMoves>(host, &BeforeCvHomelandAI_ExecuteProphetMoves);CivRegisterAfter<CivHooks::CvHomelandAI_ExecuteProphetMoves>(host, &AfterCvHomelandAI_ExecuteProphetMoves);CivRegisterReplace<CivHooks::CvHomelandAI_ExecuteProphetMoves>(host, &ReplaceCvHomelandAI_ExecuteProphetMoves);

Code

3900void CvHomelandAI::ExecuteProphetMoves()3901{3902	FStaticVector< CvHomelandUnit, 64, true, c_eCiv5GameplayDLL >::iterator it;3903	for(it = m_CurrentMoveUnits.begin(); it != m_CurrentMoveUnits.end(); ++it)3904	{3905		UnitHandle pUnit = m_pPlayer->getUnit(it->GetID());3906		if(!pUnit)3907		{3908			continue;3909		}39103911		GreatPeopleDirectiveTypes eDirective = pUnit->GetGreatPeopleDirective();3912		switch(eDirective)3913		{3914		case GREAT_PEOPLE_DIRECTIVE_CONSTRUCT_IMPROVEMENT:3915			ExecuteWorkerMove(pUnit.pointer());3916			break;39173918		case GREAT_PEOPLE_DIRECTIVE_USE_POWER:39193920			// Can I found a religion?3921			if(pUnit->CanFoundReligion(pUnit->plot()))3922			{3923				CvString strLogString;3924				strLogString.Format("Great Prophet founding a religion, X: %d, Y: %d", pUnit->plot()->getX(), pUnit->plot()->getY());3925				LogHomelandMessage(strLogString);39263927				pUnit->DoFoundReligion();3928			}39293930			// Can I enhance a religion?3931			else if(pUnit->CanEnhanceReligion(pUnit->plot()))3932			{3933				CvString strLogString;3934				strLogString.Format("Great Prophet enhancing a religion, X: %d, Y: %d", pUnit->plot()->getX(), pUnit->plot()->getY());3935				LogHomelandMessage(strLogString);39363937				pUnit->DoEnhanceReligion();3938			}39393940			// Move to closest city without a civilian in it3941			else3942			{3943				CvCity* pLoopCity;3944				int iLoopCity = 0;3945				int iBestTurns = MAX_INT;3946				CvPlot* pBestCityPlot = NULL;3947				for(pLoopCity = m_pPlayer->firstCity(&iLoopCity); pLoopCity != NULL; pLoopCity = m_pPlayer->nextCity(&iLoopCity))3948				{3949					bool bSkipCity = false;39503951					CvPlot* pTarget = pLoopCity->plot();3952					for(int iUnitLoop = 0; iUnitLoop < pTarget->getNumUnits(); iUnitLoop++)3953					{3954						// Don't go here if a civilian is already present3955						if(!pTarget->getUnitByIndex(iUnitLoop)->IsCombatUnit())3956						{3957							bSkipCity = true;3958							break;3959						}3960					}39613962					if(!bSkipCity)3963					{3964						int iTurns = TurnsToReachTarget(pUnit, pTarget);3965						if(iTurns < iBestTurns)3966						{3967							iBestTurns = iTurns;3968							pBestCityPlot = pTarget;3969						}3970					}3971				}39723973				if(pBestCityPlot)3974				{3975					pUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), pBestCityPlot->getX(), pBestCityPlot->getY());3976					pUnit->finishMoves();3977					UnitProcessed(pUnit->GetID());39783979					if(GC.getLogging() && GC.getAILogging())3980					{3981						CvString strLogString;3982						strLogString.Format("Moving Great Prophet to nearest city without civilian, X: %d, Y: %d", pBestCityPlot->getX(), pBestCityPlot->getY());3983						LogHomelandMessage(strLogString);3984					}3985				}3986				else3987				{3988					pUnit->finishMoves();3989					UnitProcessed(pUnit->GetID());39903991					if(GC.getLogging() && GC.getAILogging())3992					{3993						CvString strLogString;3994						strLogString.Format("No place to move Great Prophet at, X: %d, Y: %d", pUnit->getX(), pUnit->getY());3995						LogHomelandMessage(strLogString);3996					}3997				}3998			}39994000			break;40014002		case GREAT_PEOPLE_DIRECTIVE_SPREAD_RELIGION:4003			{4004				int iTargetTurns;4005				CvPlot* pTarget = m_pPlayer->GetReligionAI()->ChooseProphetTargetPlot(pUnit, &iTargetTurns);4006				if(pTarget)4007				{4008					if(pUnit->plot() == pTarget)4009					{4010						pUnit->PushMission(CvTypes::getMISSION_SPREAD_RELIGION());40114012						if(GC.getLogging() && GC.getAILogging())4013						{4014							CvString strLogString;4015							strLogString.Format("Spreading religion, X: %d, Y: %d", pTarget->getX(), pTarget->getY());4016							LogHomelandMessage(strLogString);4017						}4018					}4019					else if(iTargetTurns < 1)4020					{4021						pUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), pTarget->getX(), pTarget->getY());40224023						if(pUnit->plot() == pTarget && pUnit->canMove())4024						{4025							pUnit->PushMission(CvTypes::getMISSION_SPREAD_RELIGION());40264027							if(GC.getLogging() && GC.getAILogging())4028							{4029								CvString strLogString;4030								strLogString.Format("Move to spread religion, X: %d, Y: %d", pTarget->getX(), pTarget->getY());4031								LogHomelandMessage(strLogString);4032							}4033						}4034						else4035						{4036							CvAssertMsg(false, "Internal error with Prophet spread religion AI move, contact Ed.");4037						}4038					}4039					else4040					{4041						4042						m_CurrentBestMoveHighPriorityUnit = NULL;4043						m_CurrentBestMoveUnit = m_pPlayer->getUnit(it->GetID());4044						ExecuteMoveToTarget(pTarget);40454046						if(GC.getLogging() && GC.getAILogging())4047						{4048							CvString strLogString;4049							strLogString.Format("Moving to plot adjacent to conversion city, X: %d, Y: %d, Currently at, X: %d, Y: %d", pTarget->getX(), pTarget->getY(), pUnit->getX(), pUnit->getY());4050							LogHomelandMessage(strLogString);4051						}4052					}4053				}4054			}4055			break;40564057		case NO_GREAT_PEOPLE_DIRECTIVE_TYPE:4058			MoveCivilianToSafety(pUnit.pointer());4059			break;4060		}4061	}4062}

Calls

Called by