Bazaar developer reference

CvPlayerAI::AI_unitUpdate()

Defined in
CvPlayerAI.cpp, line 215
Class
CvPlayerAI
Hook name
CivHooks::CvPlayerAI_AI_unitUpdate
Overrides
CvPlayer::AI_unitUpdate()
Lua events
GameEvents.PlayerPreAIUnitUpdate

Hooks

static bool BeforeCvPlayerAI_AI_unitUpdate(CvPlayerAI* self);static void AfterCvPlayerAI_AI_unitUpdate(CvPlayerAI* self);static void ReplaceCvPlayerAI_AI_unitUpdate(void (*original)(CvPlayerAI*), CvPlayerAI* self);CivRegisterBefore<CivHooks::CvPlayerAI_AI_unitUpdate>(host, &BeforeCvPlayerAI_AI_unitUpdate);CivRegisterAfter<CivHooks::CvPlayerAI_AI_unitUpdate>(host, &AfterCvPlayerAI_AI_unitUpdate);CivRegisterReplace<CivHooks::CvPlayerAI_AI_unitUpdate>(host, &ReplaceCvPlayerAI_AI_unitUpdate);

Code

215void CvPlayerAI::AI_unitUpdate()216{217	GC.getPathFinder().ForceReset();218	GC.getIgnoreUnitsPathFinder().ForceReset();219	GC.getRouteFinder().ForceReset();220	GC.GetWaterRouteFinder().ForceReset();221222	// Set individual pathers as MP cache safe.  A global for all pathers might be simpler,223	// but this will allow selective control in case one type of pather is causing out-of-syncs.224	bool bCommonPathFinderMPCaching = GC.getPathFinder().SetMPCacheSafe(true);225	bool bIgnoreUnitsPathFinderMPCaching = GC.getIgnoreUnitsPathFinder().SetMPCacheSafe(true);226	bool bTacticalPathFinderMPCaching = GC.GetTacticalAnalysisMapFinder().SetMPCacheSafe(true);227	bool bInfluencePathFinderMPCaching = GC.getInfluenceFinder().SetMPCacheSafe(true);228	bool bRoutePathFinderMPCaching = GC.getRouteFinder().SetMPCacheSafe(true);229	bool bWaterRoutePathFinderMPCaching = GC.GetWaterRouteFinder().SetMPCacheSafe(true);230231	ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();232	if(pkScriptSystem)233	{234		CvLuaArgsHandle args;235		args->Push(GetID());236237		bool bResult;238		LuaSupport::CallHook(pkScriptSystem, "PlayerPreAIUnitUpdate", args.get(), bResult);239	}240241	//GC.getGame().GetTacticalAnalysisMap()->RefreshDataForNextPlayer(this);242243	// this was a !hasBusyUnit around the entire rest of the function, so I tried to make it a bit flatter.244	if(hasBusyUnitOrCity())245	{246		return;247	}248249	if(isHuman())250	{251		CvUnit::dispatchingNetMessage(true);252		// The homeland AI goes first.253		GetHomelandAI()->FindAutomatedUnits();254		GetHomelandAI()->Update();255		CvUnit::dispatchingNetMessage(false);256	}257	else258	{259		// Update tactical AI260		GetTacticalAI()->CommandeerUnits();261262		// Now let the tactical AI run.  Putting it after the operations update allows units who have263		// just been handed off to the tactical AI to get a move in the same turn they switch between264		// AI subsystems265		GetTacticalAI()->Update();266267		// Skip homeland AI processing if a barbarian268		if(m_eID != BARBARIAN_PLAYER)269		{270			// Now its the homeland AI's turn.271			GetHomelandAI()->RecruitUnits();272			GetHomelandAI()->Update();273		}274	}275276	GC.getPathFinder().SetMPCacheSafe(bCommonPathFinderMPCaching);277	GC.getIgnoreUnitsPathFinder().SetMPCacheSafe(bIgnoreUnitsPathFinderMPCaching);278	GC.GetTacticalAnalysisMapFinder().SetMPCacheSafe(bTacticalPathFinderMPCaching);279	GC.getInfluenceFinder().SetMPCacheSafe(bInfluencePathFinderMPCaching);280	GC.getRouteFinder().SetMPCacheSafe(bRoutePathFinderMPCaching);281	GC.GetWaterRouteFinder().SetMPCacheSafe(bWaterRoutePathFinderMPCaching);282}

Calls