Bazaar developer reference

CvHomelandAI::ExecuteArtistMoves()

Defined in
CvHomelandAI.cpp, line 3409
Class
CvHomelandAI
Hook name
CivHooks::CvHomelandAI_ExecuteArtistMoves

Hooks

static bool BeforeCvHomelandAI_ExecuteArtistMoves(CvHomelandAI* self);static void AfterCvHomelandAI_ExecuteArtistMoves(CvHomelandAI* self);static void ReplaceCvHomelandAI_ExecuteArtistMoves(void (*original)(CvHomelandAI*), CvHomelandAI* self);CivRegisterBefore<CivHooks::CvHomelandAI_ExecuteArtistMoves>(host, &BeforeCvHomelandAI_ExecuteArtistMoves);CivRegisterAfter<CivHooks::CvHomelandAI_ExecuteArtistMoves>(host, &AfterCvHomelandAI_ExecuteArtistMoves);CivRegisterReplace<CivHooks::CvHomelandAI_ExecuteArtistMoves>(host, &ReplaceCvHomelandAI_ExecuteArtistMoves);

Code

3408/// Expends an artist to start a golden age3409void CvHomelandAI::ExecuteArtistMoves()3410{3411	FStaticVector< CvHomelandUnit, 64, true, c_eCiv5GameplayDLL >::iterator it;3412	for(it = m_CurrentMoveUnits.begin(); it != m_CurrentMoveUnits.end(); ++it)3413	{3414		UnitHandle pUnit = m_pPlayer->getUnit(it->GetID());3415		if(!pUnit)3416		{3417			continue;3418		}34193420		GreatPeopleDirectiveTypes eDirective = pUnit->GetGreatPeopleDirective();3421		switch(eDirective)3422		{3423		case GREAT_PEOPLE_DIRECTIVE_GOLDEN_AGE:3424			ExecuteGoldenAgeMove(pUnit.pointer());3425			break;34263427		case GREAT_PEOPLE_DIRECTIVE_USE_POWER:3428			{3429				// Do we want to create a Great Work?3430				GreatWorkType eGreatWorkType = pUnit->GetGreatWork();3431				CvCity* pTargetCity = m_pPlayer->GetEconomicAI()->GetBestGreatWorkCity(pUnit->plot(), eGreatWorkType);34323433				// No?  Just move to safety...3434				if (pTargetCity == NULL)3435				{3436					if(GC.getLogging() && GC.getAILogging())3437					{3438						CvString strLogString;3439						strLogString.Format("Great artist can't find a Great Work slot. Running to safety");3440						LogHomelandMessage(strLogString);3441					}34423443					MoveCivilianToSafety(pUnit.pointer());3444				}3445				else3446				{3447					// Already at (or adjacent to) target?3448					if (plotDistance(pUnit->getX(), pUnit->getY(), pTargetCity->getX(), pTargetCity->getY()) <= 1)3449					{3450						pUnit->PushMission(CvTypes::getMISSION_GREAT_WORK());3451						UnitProcessed(pUnit->GetID());3452						if(GC.getLogging() && GC.getAILogging())3453						{3454							CvString strLogString;3455							strLogString.Format("Creating Great Work at, X: %d, Y: %d", pUnit->getX(), pUnit->getY());3456							LogHomelandMessage(strLogString);3457							continue;3458						}3459					}34603461					// No, then move there3462					else3463					{3464						// Find which plot (in or adjacent), we can reach in the fewest turns3465						CvPlot *pBestTarget = NULL;3466						int iBestTurns = MAX_INT;3467						int iTurns;3468						iTurns = TurnsToReachTarget(pUnit, pTargetCity->plot());3469						if (iTurns < iBestTurns)3470						{3471							pBestTarget = pTargetCity->plot();3472						}3473						for(int iI = 0; iI < NUM_DIRECTION_TYPES; iI++)3474						{3475							CvPlot* pAdjacentPlot = plotDirection(pTargetCity->getX(), pTargetCity->getY(), ((DirectionTypes)iI));3476							if(pAdjacentPlot != NULL)3477							{3478								iTurns = TurnsToReachTarget(pUnit, pAdjacentPlot);3479								if (iTurns < iBestTurns)3480								{3481									pBestTarget = pAdjacentPlot;3482									iBestTurns = iTurns;3483								}3484							}3485						}34863487						if (pBestTarget)3488						{3489							// In less than one turn?3490							if (iBestTurns == 0)3491							{3492								pUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), pBestTarget->getX(), pBestTarget->getY());3493								pUnit->PushMission(CvTypes::getMISSION_GREAT_WORK());3494								UnitProcessed(pUnit->GetID());3495								if(GC.getLogging() && GC.getAILogging())3496								{3497									CvString strLogString;3498									strLogString.Format("Moving and creating Great Work at, X: %d, Y: %d", pUnit->getX(), pUnit->getY());3499									LogHomelandMessage(strLogString);3500									continue;3501								}3502							}35033504							// In multiple moves3505							else3506							{3507								pUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), pBestTarget->getX(), pBestTarget->getY());3508								pUnit->finishMoves();3509								UnitProcessed(it->GetID());3510								if(GC.getLogging() && GC.getAILogging())3511								{3512									CvString strLogString;3513									strLogString.Format("Moving Great Artist toward Great Work city at, X: %d, Y: %d", pBestTarget->getX(),  pBestTarget->getY());3514									LogHomelandMessage(strLogString);3515								}3516							}3517						}3518						else3519						{3520							if(GC.getLogging() && GC.getAILogging())3521							{3522								CvString strLogString;3523								strLogString.Format("Could not find a target for Great Artist at, X: %d, Y: %d", pUnit->getX(),  pUnit->getY());3524								LogHomelandMessage(strLogString);3525							}3526						}3527					}3528				}3529			}	3530			break;35313532		case NO_GREAT_PEOPLE_DIRECTIVE_TYPE:3533			MoveCivilianToSafety(pUnit.pointer());3534			break;3535		}3536	}3537}

Calls

Called by