From 14d3e2c54aa548d97b955ca0a83177a80835c66f Mon Sep 17 00:00:00 2001 From: RGreenlees Date: Sat, 9 Mar 2024 22:58:24 +0000 Subject: [PATCH] Fixed crash on new map start with bots --- main/source/mod/AIPlayers/AvHAIPlayer.cpp | 2 ++ .../mod/AIPlayers/AvHAIPlayerManager.cpp | 4 ++-- main/source/mod/AIPlayers/AvHAITactical.cpp | 23 +++++++++++++------ main/source/mod/AIPlayers/AvHAITactical.h | 2 +- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/main/source/mod/AIPlayers/AvHAIPlayer.cpp b/main/source/mod/AIPlayers/AvHAIPlayer.cpp index 2a549688..3ef57239 100644 --- a/main/source/mod/AIPlayers/AvHAIPlayer.cpp +++ b/main/source/mod/AIPlayers/AvHAIPlayer.cpp @@ -3457,6 +3457,7 @@ void AIPlayerSetWantsAndNeedsCOMarineTask(AvHAIPlayer* pBot, AvHAIPlayerTask* Ta NearestArmouryFilter.DeployableTeam = pBot->Player->GetTeam(); NearestArmouryFilter.ReachabilityTeam = pBot->Player->GetTeam(); NearestArmouryFilter.ReachabilityFlags = pBot->BotNavInfo.NavProfile.ReachabilityFlag; + NearestArmouryFilter.IncludeStatusFlags = STRUCTURE_STATUS_COMPLETED; NearestArmouryFilter.ExcludeStatusFlags = STRUCTURE_STATUS_RECYCLING; NearestArmouryFilter.MaxSearchRadius = SearchRadius; @@ -3515,6 +3516,7 @@ void AIPlayerSetWantsAndNeedsMarineTask(AvHAIPlayer* pBot, AvHAIPlayerTask* Task NearestArmouryFilter.DeployableTeam = pBot->Player->GetTeam(); NearestArmouryFilter.ReachabilityTeam = pBot->Player->GetTeam(); NearestArmouryFilter.ReachabilityFlags = pBot->BotNavInfo.NavProfile.ReachabilityFlag; + NearestArmouryFilter.IncludeStatusFlags = STRUCTURE_STATUS_COMPLETED; NearestArmouryFilter.ExcludeStatusFlags = STRUCTURE_STATUS_RECYCLING; NearestArmouryFilter.MaxSearchRadius = (bTaskIsUrgent) ? UTIL_MetresToGoldSrcUnits(20.0f) : UTIL_MetresToGoldSrcUnits(5.0f); diff --git a/main/source/mod/AIPlayers/AvHAIPlayerManager.cpp b/main/source/mod/AIPlayers/AvHAIPlayerManager.cpp index cd908f71..377febd8 100644 --- a/main/source/mod/AIPlayers/AvHAIPlayerManager.cpp +++ b/main/source/mod/AIPlayers/AvHAIPlayerManager.cpp @@ -931,7 +931,7 @@ void AIMGR_ResetRound() LastAIPlayerCountUpdate = 0.0f; - AITAC_ClearMapAIData(); + AITAC_ClearMapAIData(false); UTIL_PopulateDoors(); UTIL_PopulateWeldableObstacles(); @@ -1035,7 +1035,7 @@ void AIMGR_NewMap() LastAIPlayerCountUpdate = 0.0f; ALERT(at_console, "AI Manager New Map\n"); - AITAC_ClearMapAIData(); + AITAC_ClearMapAIData(true); if (NavmeshLoaded()) { diff --git a/main/source/mod/AIPlayers/AvHAITactical.cpp b/main/source/mod/AIPlayers/AvHAITactical.cpp index f754ff0b..ecfa22f4 100644 --- a/main/source/mod/AIPlayers/AvHAITactical.cpp +++ b/main/source/mod/AIPlayers/AvHAITactical.cpp @@ -2370,19 +2370,28 @@ void AITAC_ClearStructureNavData() } } -void AITAC_ClearMapAIData() +void AITAC_ClearMapAIData(bool bInitialMapLoad) { UTIL_ClearLocalizations(); ResourceNodes.clear(); - AITAC_ClearHiveInfo(); - - AITAC_ClearStructureNavData(); - - while (!bTileCacheUpToDate) + // If we're clearing AI data due to a map load, then we just clear the hive data immediately since we've reloaded the nav mesh + // If we're clearing AI data due to a round restart, then ensure we properly clear all temp obstacles and connections since we're not reloading the mesh + if (!bInitialMapLoad) { - UTIL_UpdateTileCache(); + AITAC_ClearHiveInfo(); + + AITAC_ClearStructureNavData(); + + while (!bTileCacheUpToDate) + { + UTIL_UpdateTileCache(); + } + } + else + { + Hives.clear(); } MarineDroppedItemMap.clear(); diff --git a/main/source/mod/AIPlayers/AvHAITactical.h b/main/source/mod/AIPlayers/AvHAITactical.h index e34fee7a..e1bba918 100644 --- a/main/source/mod/AIPlayers/AvHAITactical.h +++ b/main/source/mod/AIPlayers/AvHAITactical.h @@ -84,7 +84,7 @@ vector AITAC_GetAllPlayersOnTeamWithLOS(AvHTeamNumber Team, const Ve bool AITAC_ShouldBotBeCautious(AvHAIPlayer* pBot); // Clears out the marine and alien buildable structure maps, resource node and hive lists, and the marine item list -void AITAC_ClearMapAIData(); +void AITAC_ClearMapAIData(bool bInitialMapLoad = false); // Clear out all the hive information void AITAC_ClearHiveInfo();