Bazaar developer reference

CvHomelandAI::ExecuteEngineerMoves()

Defined in
CvHomelandAI.cpp, line 3708
Class
CvHomelandAI
Hook name
CivHooks::CvHomelandAI_ExecuteEngineerMoves

Hooks

static bool BeforeCvHomelandAI_ExecuteEngineerMoves(CvHomelandAI* self);static void AfterCvHomelandAI_ExecuteEngineerMoves(CvHomelandAI* self);static void ReplaceCvHomelandAI_ExecuteEngineerMoves(void (*original)(CvHomelandAI*), CvHomelandAI* self);CivRegisterBefore<CivHooks::CvHomelandAI_ExecuteEngineerMoves>(host, &BeforeCvHomelandAI_ExecuteEngineerMoves);CivRegisterAfter<CivHooks::CvHomelandAI_ExecuteEngineerMoves>(host, &AfterCvHomelandAI_ExecuteEngineerMoves);CivRegisterReplace<CivHooks::CvHomelandAI_ExecuteEngineerMoves>(host, &ReplaceCvHomelandAI_ExecuteEngineerMoves);

Code

3707/// Expends an engineer to gain a wonder (or a very emergency build)3708void CvHomelandAI::ExecuteEngineerMoves()3709{3710	CvCity* pWonderCity;3711	int iTurnsToTarget;37123713	FStaticVector< CvHomelandUnit, 64, true, c_eCiv5GameplayDLL >::iterator it;3714	for(it = m_CurrentMoveUnits.begin(); it != m_CurrentMoveUnits.end(); ++it)3715	{3716		UnitHandle pUnit = m_pPlayer->getUnit(it->GetID());3717		if(!pUnit)3718		{3719			continue;3720		}37213722		GreatPeopleDirectiveTypes eDirective = pUnit->GetGreatPeopleDirective();3723		switch(eDirective)3724		{3725		case GREAT_PEOPLE_DIRECTIVE_CONSTRUCT_IMPROVEMENT:3726			ExecuteWorkerMove(pUnit.pointer());3727			break;3728		case GREAT_PEOPLE_DIRECTIVE_GOLDEN_AGE:3729			ExecuteGoldenAgeMove(pUnit.pointer());3730			break;3731		case GREAT_PEOPLE_DIRECTIVE_USE_POWER:3732		{3733			// Do we want to build any wonder?3734			int iNextWonderWeight;3735			CvCity* pCityToBuildAt = 0;3736			BuildingTypes eNextWonderDesired = m_pPlayer->GetWonderProductionAI()->ChooseWonderForGreatEngineer(false, iNextWonderWeight, pCityToBuildAt);37373738			// No?  Just move to safety...3739			if(eNextWonderDesired == NO_BUILDING)3740			{3741				if(GC.getLogging() && GC.getAILogging())3742				{3743					CvString strLogString;3744					strLogString.Format("Great builder can't find a good wonder to build. Running to safety");3745					LogHomelandMessage(strLogString);3746				}37473748				MoveCivilianToSafety(pUnit.pointer());3749			}3750			else3751			{3752				bool bForceWonderCity = true;37533754				// Are we less than 25% done building the most desired wonder chosen by the city specialization AI?3755				pWonderCity = m_pPlayer->GetCitySpecializationAI()->GetWonderBuildCity();3756				if(pWonderCity)3757				{3758					int iProductionSoFar = pWonderCity->getProduction();3759					int iProductionRemaining = pWonderCity->getProductionNeeded(eNextWonderDesired);37603761					if(pWonderCity->getProductionBuilding() == eNextWonderDesired && iProductionSoFar * 3 < iProductionRemaining)3762					{3763						// If engineer can move to city before half done3764						int iTurnsRemaining = pWonderCity->getProductionTurnsLeft();3765						iTurnsToTarget = TurnsToReachTarget(pUnit, pWonderCity->plot(), true /*bReusePaths*/, true);3766						if(iTurnsToTarget * 3 < iTurnsRemaining)3767						{3768							bForceWonderCity = false;37693770							// Already at target and the wonder is underway?3771							if(pWonderCity->getProductionBuilding() == eNextWonderDesired && iTurnsToTarget == 0 && pUnit->plot() == pWonderCity->plot())3772							{3773								pUnit->PushMission(CvTypes::getMISSION_HURRY());3774								UnitProcessed(pUnit->GetID());3775								if(GC.getLogging() && GC.getAILogging())3776								{3777									CvString strLogString;3778									strLogString.Format("Great Engineer hurrying wonder chosen by city specialization AI at, X: %d, Y: %d", pUnit->getX(), pUnit->getY());3779									LogHomelandMessage(strLogString);3780									continue;3781								}3782							}37833784							// No, then move there3785							else3786							{3787								if(GetBestUnitToReachTarget(pWonderCity->plot(), MAX_INT))3788								{3789									ExecuteMoveToTarget(pWonderCity->plot());37903791									if(GC.getLogging() && GC.getAILogging())3792									{3793										CvString strLogString;3794										strLogString.Format("Moving Great Engineer to city specialization wonder city at, X: %d, Y: %d", pWonderCity->getX(),  pWonderCity->getY());3795										LogHomelandMessage(strLogString);3796									}3797								}3798							}3799						}3800					}3801				}38023803				if(bForceWonderCity)3804				{3805					pWonderCity = pCityToBuildAt;38063807					if(pWonderCity)3808					{3809						iTurnsToTarget = TurnsToReachTarget(pUnit, pWonderCity->plot(), false /*bReusePaths*/, true);38103811						// Already at target?3812						if(iTurnsToTarget == 0 && pUnit->plot() == pWonderCity->plot())3813						{3814							// Switch production3815							pWonderCity->pushOrder(ORDER_CONSTRUCT, eNextWonderDesired, -1, false, false, false);38163817							if (pWonderCity->getProductionTurnsLeft() > 1)3818							{3819								// Rush it3820								pUnit->PushMission(CvTypes::getMISSION_HURRY());3821								UnitProcessed(pUnit->GetID());3822								if(GC.getLogging() && GC.getAILogging())3823								{3824									CvString strLogString;3825									strLogString.Format("Great Engineer hurrying free wonder at, X: %d, Y: %d", pUnit->getX(), pUnit->getY());3826									LogHomelandMessage(strLogString);3827									continue;3828								}3829							}3830							else3831							{3832								if(GC.getLogging() && GC.getAILogging())3833								{3834									CvString strLogString;3835									strLogString.Format("Great Engineer not needed to hurry 1-turn wonder at, X: %d, Y: %d", pUnit->getX(), pUnit->getY());3836									LogHomelandMessage(strLogString);3837									continue;3838								}3839							}3840						}38413842						// No, then move there3843						else3844						{3845							if(GetBestUnitToReachTarget(pWonderCity->plot(), MAX_INT))3846							{3847								ExecuteMoveToTarget(pWonderCity->plot());38483849								if(GC.getLogging() && GC.getAILogging())3850								{3851									CvString strLogString;3852									strLogString.Format("Moving Great Engineer for free wonder to city at, X: %d, Y: %d", pWonderCity->getX(),  pWonderCity->getY());3853									LogHomelandMessage(strLogString);3854								}3855							}3856						}38573858					}3859				}3860			}3861		}3862		break;3863		case NO_GREAT_PEOPLE_DIRECTIVE_TYPE:3864			MoveCivilianToSafety(pUnit.pointer());3865			break;3866		}3867	}3868}

Calls

Called by