Bazaar developer reference

CvHomelandAI::ExecuteWriterMoves()

Defined in
CvHomelandAI.cpp, line 3278
Class
CvHomelandAI
Hook name
CivHooks::CvHomelandAI_ExecuteWriterMoves

Hooks

static bool BeforeCvHomelandAI_ExecuteWriterMoves(CvHomelandAI* self);static void AfterCvHomelandAI_ExecuteWriterMoves(CvHomelandAI* self);static void ReplaceCvHomelandAI_ExecuteWriterMoves(void (*original)(CvHomelandAI*), CvHomelandAI* self);CivRegisterBefore<CivHooks::CvHomelandAI_ExecuteWriterMoves>(host, &BeforeCvHomelandAI_ExecuteWriterMoves);CivRegisterAfter<CivHooks::CvHomelandAI_ExecuteWriterMoves>(host, &AfterCvHomelandAI_ExecuteWriterMoves);CivRegisterReplace<CivHooks::CvHomelandAI_ExecuteWriterMoves>(host, &ReplaceCvHomelandAI_ExecuteWriterMoves);

Code

3277/// Great writer moves3278void CvHomelandAI::ExecuteWriterMoves()3279{3280	FStaticVector< CvHomelandUnit, 64, true, c_eCiv5GameplayDLL >::iterator it;3281	for(it = m_CurrentMoveUnits.begin(); it != m_CurrentMoveUnits.end(); ++it)3282	{3283		UnitHandle pUnit = m_pPlayer->getUnit(it->GetID());3284		if(!pUnit)3285		{3286			continue;3287		}32883289		GreatPeopleDirectiveTypes eDirective = pUnit->GetGreatPeopleDirective();3290		switch(eDirective)3291		{3292		case GREAT_PEOPLE_DIRECTIVE_CULTURE_BLAST:3293			ExecuteCultureBlast(pUnit.pointer());3294			break;32953296		case GREAT_PEOPLE_DIRECTIVE_USE_POWER:3297			{3298				// Do we want to create a Great Work?3299				GreatWorkType eGreatWorkType = pUnit->GetGreatWork();3300				CvCity* pTargetCity = m_pPlayer->GetEconomicAI()->GetBestGreatWorkCity(pUnit->plot(), eGreatWorkType);33013302				// No?  Just move to safety...3303				if (pTargetCity == NULL)3304				{3305					if(GC.getLogging() && GC.getAILogging())3306					{3307						CvString strLogString;3308						strLogString.Format("Great writer can't find a Great Work slot. Running to safety");3309						LogHomelandMessage(strLogString);3310					}33113312					MoveCivilianToSafety(pUnit.pointer());3313				}3314				else3315				{3316					// Already at (or adjacent to) target?3317					if (plotDistance(pUnit->getX(), pUnit->getY(), pTargetCity->getX(), pTargetCity->getY()) <= 1)3318					{3319						pUnit->PushMission(CvTypes::getMISSION_GREAT_WORK());3320						UnitProcessed(pUnit->GetID());3321						if(GC.getLogging() && GC.getAILogging())3322						{3323							CvString strLogString;3324							strLogString.Format("Creating Great Work at, X: %d, Y: %d", pUnit->getX(), pUnit->getY());3325							LogHomelandMessage(strLogString);3326							continue;3327						}3328					}33293330					// No, then move there3331					else3332					{3333						// Find which plot (in or adjacent), we can reach in the fewest turns3334						CvPlot *pBestTarget = NULL;3335						int iBestTurns = MAX_INT;3336						int iTurns;3337						iTurns = TurnsToReachTarget(pUnit, pTargetCity->plot());3338						if (iTurns < iBestTurns)3339						{3340							pBestTarget = pTargetCity->plot();3341						}3342						for(int iI = 0; iI < NUM_DIRECTION_TYPES; iI++)3343						{3344							CvPlot* pAdjacentPlot = plotDirection(pTargetCity->getX(), pTargetCity->getY(), ((DirectionTypes)iI));3345							if(pAdjacentPlot != NULL)3346							{3347								iTurns = TurnsToReachTarget(pUnit, pAdjacentPlot);3348								if (iTurns < iBestTurns)3349								{3350									pBestTarget = pAdjacentPlot;3351									iBestTurns = iTurns;3352								}3353							}3354						}33553356						if (pBestTarget)3357						{3358							// In less than one turn?3359							if (iBestTurns == 0)3360							{3361								pUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), pBestTarget->getX(), pBestTarget->getY());3362								pUnit->PushMission(CvTypes::getMISSION_GREAT_WORK());3363								UnitProcessed(pUnit->GetID());3364								if(GC.getLogging() && GC.getAILogging())3365								{3366									CvString strLogString;3367									strLogString.Format("Moving and creating Great Work at, X: %d, Y: %d", pUnit->getX(), pUnit->getY());3368									LogHomelandMessage(strLogString);3369									continue;3370								}3371							}33723373							// In multiple moves3374							else3375							{3376								pUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), pBestTarget->getX(), pBestTarget->getY());3377								pUnit->finishMoves();3378								UnitProcessed(it->GetID());3379								if(GC.getLogging() && GC.getAILogging())3380								{3381									CvString strLogString;3382									strLogString.Format("Moving Great Writer toward Great Work city at, X: %d, Y: %d", pBestTarget->getX(),  pBestTarget->getY());3383									LogHomelandMessage(strLogString);3384								}3385							}3386						}3387						else3388						{3389							if(GC.getLogging() && GC.getAILogging())3390							{3391								CvString strLogString;3392								strLogString.Format("Could not find a target for Great Writer at, X: %d, Y: %d", pUnit->getX(),  pUnit->getY());3393								LogHomelandMessage(strLogString);3394							}3395						}3396					}3397				}3398			}	3399			break;34003401		case NO_GREAT_PEOPLE_DIRECTIVE_TYPE:3402			MoveCivilianToSafety(pUnit.pointer());3403			break;3404		}3405	}3406}

Calls

Called by