Bazaar developer reference

CvTacticalAI::ExecuteBarbarianMoves(bool)

Defined in
CvTacticalAI.cpp, line 7104
Class
CvTacticalAI
Hook name
CivHooks::CvTacticalAI_ExecuteBarbarianMoves

Hooks

static bool BeforeCvTacticalAI_ExecuteBarbarianMoves(CvTacticalAI* self, bool bAggressive);static void AfterCvTacticalAI_ExecuteBarbarianMoves(CvTacticalAI* self, bool bAggressive);static void ReplaceCvTacticalAI_ExecuteBarbarianMoves(void (*original)(CvTacticalAI*, bool), CvTacticalAI* self, bool bAggressive);CivRegisterBefore<CivHooks::CvTacticalAI_ExecuteBarbarianMoves>(host, &BeforeCvTacticalAI_ExecuteBarbarianMoves);CivRegisterAfter<CivHooks::CvTacticalAI_ExecuteBarbarianMoves>(host, &AfterCvTacticalAI_ExecuteBarbarianMoves);CivRegisterReplace<CivHooks::CvTacticalAI_ExecuteBarbarianMoves>(host, &ReplaceCvTacticalAI_ExecuteBarbarianMoves);

Code

7103/// Move barbarian to a new location7104void CvTacticalAI::ExecuteBarbarianMoves(bool bAggressive)7105{7106	CvPlot* pBestPlot = NULL;7107	CvPlot* pCurrentDestination;7108	CvString strTemp;71097110	for(unsigned int iI = 0; iI < m_CurrentMoveUnits.size(); iI++)7111	{7112		UnitHandle pUnit = m_pPlayer->getUnit(m_CurrentMoveUnits[iI].GetID());7113		if(pUnit)7114		{7115			if(pUnit->isBarbarian())7116			{7117				strTemp = pUnit->getUnitInfo().GetDescription();71187119				// LAND MOVES7120				if(pUnit->getDomainType() == DOMAIN_LAND)7121				{7122					AI_PERF_FORMAT("AI-perf-tact.csv", ("Barb Land Move, Turn %03d, %s", GC.getGame().getElapsedGameTurns(), m_pPlayer->getCivilizationShortDescription()) );71237124					if(bAggressive)7125					{7126						pBestPlot = FindBestBarbarianLandMove(pUnit);7127					}7128					else7129					{7130						pBestPlot = FindPassiveBarbarianLandMove(pUnit);7131					}71327133					if(pBestPlot && MoveToEmptySpaceNearTarget(pUnit, pBestPlot))7134					{7135						pUnit->finishMoves();7136						UnitProcessed(m_CurrentMoveUnits[iI].GetID());7137						if(GC.getLogging() && GC.getAILogging())7138						{7139							CvString strLogString;7140							strLogString.Format("%s moved to empty space near target, X: %d, Y: %d, Current X: %d, Current Y: %d", strTemp.GetCString(),7141							                    pBestPlot->getX(), pBestPlot->getY(), pUnit->getX(), pUnit->getY());7142							LogTacticalMessage(strLogString);7143						}7144					}7145					else7146					{7147						pUnit->finishMoves();7148						UnitProcessed(m_CurrentMoveUnits[iI].GetID());7149						if(GC.getLogging() && GC.getAILogging())7150						{7151							CvString strLogString;7152							strLogString.Format("No target for %s at position, Current X: %d, Current Y: %d", strTemp.GetCString(), pUnit->getX(), pUnit->getY());7153							LogTacticalMessage(strLogString);7154						}7155					}7156				}71577158				// NAVAL MOVES7159				else7160				{71617162					AI_PERF_FORMAT("AI-perf-tact.csv", ("Barb Naval Move, Turn %03d, %s", GC.getGame().getElapsedGameTurns(), m_pPlayer->getCivilizationShortDescription()) );71637164					// Do I still have a destination from a previous turn?7165					pCurrentDestination = pUnit->GetTacticalAIPlot();71667167					// Compute a new destination if I don't have one or am already there7168					if(pCurrentDestination == NULL ||7169					        pCurrentDestination == pUnit->plot())7170					{7171						pBestPlot = FindBestBarbarianSeaMove(pUnit);7172					}71737174					// Otherwise just keep moving there (assuming a path is available)7175					else7176					{7177						if(TurnsToReachTarget(pUnit, pCurrentDestination, true /*bReusePaths*/) != MAX_INT)7178						{7179							pBestPlot = pCurrentDestination;7180						}7181						else7182						{7183							pBestPlot = FindBestBarbarianSeaMove(pUnit);7184						}7185					}71867187					if(pBestPlot != NULL)7188					{7189						pUnit->SetTacticalAIPlot(pBestPlot);7190						pUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), pBestPlot->getX(), pBestPlot->getY());7191						pUnit->finishMoves();7192						UnitProcessed(m_CurrentMoveUnits[iI].GetID());71937194						if(GC.getLogging() && GC.getAILogging())7195						{7196							CvString strLogString;7197							strLogString.Format("Moving %s to new position, X: %d, Y: %d, Current X: %d, Current Y: %d", strTemp.GetCString(),7198							                    pBestPlot->getX(), pBestPlot->getY(), pUnit->getX(), pUnit->getY());7199							LogTacticalMessage(strLogString);7200						}7201					}7202					else7203					{7204						pUnit->SetTacticalAIPlot(NULL);7205						pUnit->finishMoves();7206						UnitProcessed(m_CurrentMoveUnits[iI].GetID());72077208						if(GC.getLogging() && GC.getAILogging())7209						{7210							CvString strLogString;7211							strLogString.Format("No target for %s at position, Current X: %d, Current Y: %d", strTemp.GetCString(), pUnit->getX(), pUnit->getY());7212							LogTacticalMessage(strLogString);7213						}7214					}7215				}7216			}7217		}7218	}7219}

Calls

Called by