Bazaar developer reference

CvHomelandAI::ExecuteMusicianMoves()

Defined in
CvHomelandAI.cpp, line 3540
Class
CvHomelandAI
Hook name
CivHooks::CvHomelandAI_ExecuteMusicianMoves

Hooks

static bool BeforeCvHomelandAI_ExecuteMusicianMoves(CvHomelandAI* self);static void AfterCvHomelandAI_ExecuteMusicianMoves(CvHomelandAI* self);static void ReplaceCvHomelandAI_ExecuteMusicianMoves(void (*original)(CvHomelandAI*), CvHomelandAI* self);CivRegisterBefore<CivHooks::CvHomelandAI_ExecuteMusicianMoves>(host, &BeforeCvHomelandAI_ExecuteMusicianMoves);CivRegisterAfter<CivHooks::CvHomelandAI_ExecuteMusicianMoves>(host, &AfterCvHomelandAI_ExecuteMusicianMoves);CivRegisterReplace<CivHooks::CvHomelandAI_ExecuteMusicianMoves>(host, &ReplaceCvHomelandAI_ExecuteMusicianMoves);

Code

3539/// Expends an artist to start a golden age3540void CvHomelandAI::ExecuteMusicianMoves()3541{3542	FStaticVector< CvHomelandUnit, 64, true, c_eCiv5GameplayDLL >::iterator it;3543	for(it = m_CurrentMoveUnits.begin(); it != m_CurrentMoveUnits.end(); ++it)3544	{3545		UnitHandle pUnit = m_pPlayer->getUnit(it->GetID());3546		if(!pUnit)3547		{3548			continue;3549		}35503551		GreatPeopleDirectiveTypes eDirective = pUnit->GetGreatPeopleDirective();3552		switch(eDirective)3553		{3554		case GREAT_PEOPLE_DIRECTIVE_TOURISM_BLAST:3555			break;35563557		case GREAT_PEOPLE_DIRECTIVE_USE_POWER:3558			{3559				// Do we want to create a Great Work?3560				GreatWorkType eGreatWorkType = pUnit->GetGreatWork();3561				CvCity* pTargetCity = m_pPlayer->GetEconomicAI()->GetBestGreatWorkCity(pUnit->plot(), eGreatWorkType);35623563				// No?  Just move to safety...3564				if (pTargetCity == NULL)3565				{3566					if(GC.getLogging() && GC.getAILogging())3567					{3568						CvString strLogString;3569						strLogString.Format("Great musician can't find a Great Work slot. Running to safety");3570						LogHomelandMessage(strLogString);3571					}35723573					MoveCivilianToSafety(pUnit.pointer());3574				}3575				else3576				{3577					// Already at (or adjacent to) target?3578					if (plotDistance(pUnit->getX(), pUnit->getY(), pTargetCity->getX(), pTargetCity->getY()) <= 1)3579					{3580						pUnit->PushMission(CvTypes::getMISSION_GREAT_WORK());3581						UnitProcessed(pUnit->GetID());3582						if(GC.getLogging() && GC.getAILogging())3583						{3584							CvString strLogString;3585							strLogString.Format("Creating Great Work at, X: %d, Y: %d", pUnit->getX(), pUnit->getY());3586							LogHomelandMessage(strLogString);3587							continue;3588						}3589					}35903591					// No, then move there3592					else3593					{3594						// Find which plot (in or adjacent), we can reach in the fewest turns3595						CvPlot *pBestTarget = NULL;3596						int iBestTurns = MAX_INT;3597						int iTurns;3598						iTurns = TurnsToReachTarget(pUnit, pTargetCity->plot());3599						if (iTurns < iBestTurns)3600						{3601							pBestTarget = pTargetCity->plot();3602						}3603						for(int iI = 0; iI < NUM_DIRECTION_TYPES; iI++)3604						{3605							CvPlot* pAdjacentPlot = plotDirection(pTargetCity->getX(), pTargetCity->getY(), ((DirectionTypes)iI));3606							if(pAdjacentPlot != NULL)3607							{3608								iTurns = TurnsToReachTarget(pUnit, pAdjacentPlot);3609								if (iTurns < iBestTurns)3610								{3611									pBestTarget = pAdjacentPlot;3612									iBestTurns = iTurns;3613								}3614							}3615						}36163617						if (pBestTarget)3618						{3619							// In less than one turn?3620							if (iBestTurns == 0)3621							{3622								pUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), pBestTarget->getX(), pBestTarget->getY());3623								pUnit->PushMission(CvTypes::getMISSION_GREAT_WORK());3624								UnitProcessed(pUnit->GetID());3625								if(GC.getLogging() && GC.getAILogging())3626								{3627									CvString strLogString;3628									strLogString.Format("Moving and creating Great Work at, X: %d, Y: %d", pUnit->getX(), pUnit->getY());3629									LogHomelandMessage(strLogString);3630									continue;3631								}3632							}36333634							// In multiple moves3635							else3636							{3637								pUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), pBestTarget->getX(), pBestTarget->getY());3638								pUnit->finishMoves();3639								UnitProcessed(it->GetID());3640								if(GC.getLogging() && GC.getAILogging())3641								{3642									CvString strLogString;3643									strLogString.Format("Moving Great Musician toward Great Work city at, X: %d, Y: %d", pBestTarget->getX(),  pBestTarget->getY());3644									LogHomelandMessage(strLogString);3645								}3646							}3647						}3648						else3649						{3650							if(GC.getLogging() && GC.getAILogging())3651							{3652								CvString strLogString;3653								strLogString.Format("Could not find a target for Great Musician at, X: %d, Y: %d", pUnit->getX(),  pUnit->getY());3654								LogHomelandMessage(strLogString);3655							}3656						}3657					}3658				}3659			}	3660			break;36613662		case NO_GREAT_PEOPLE_DIRECTIVE_TYPE:3663			MoveCivilianToSafety(pUnit.pointer());3664			break;3665		}3666	}3667}

Calls

Called by