Added round restart and new map detection for AI system

Push before new project added for detour
This commit is contained in:
RGreenlees 2023-09-22 10:59:30 +01:00 committed by pierow
parent 777025e794
commit 699396af06
3 changed files with 41 additions and 0 deletions

View file

@ -255,6 +255,13 @@ void AIMGR_AddAIPlayerToTeam(int Team)
int NewBotIndex = -1;
edict_t* BotEnt = nullptr;
// If game has ended, don't allow new bots to be added
if (GetGameRules()->GetVictoryTeam() != TEAM_IND)
{
return;
}
for (int i = 0; i < MAX_PLAYERS; i++)
{
if (!ActiveAIPlayers[i].Player)
@ -287,6 +294,7 @@ void AIMGR_AddAIPlayerToTeam(int Team)
}
// Retrieve the current bot name and then cycle the index so the names are always unique
// Slap a [BOT] tag too so players know they're not human
string NewName = "[BOT]" + BotNames[BotNameIndex];
BotEnt = (*g_engfuncs.pfnCreateFakeClient)(NewName.c_str());
@ -474,4 +482,18 @@ void AIMGR_RemoveBotsInReadyRoom()
memset(&ActiveAIPlayers[i], 0, sizeof(AvHAIPlayer));
}
}
}
void AIMGR_ResetRound()
{
if (avh_botsenabled.value == 0) { return; } // Do nothing if we're not using bots
ALERT(at_console, "AI Manager Reset Round\n");
}
void AIMGR_NewMap()
{
if (avh_botsenabled.value == 0) { return; } // Do nothing if we're not using bots
ALERT(at_console, "AI Manager New Map\n");
}

View file

@ -6,17 +6,33 @@
// Max rate bot can run its logic, default is 1/60th second. WARNING: Increasing the rate past 100hz causes bots to move and turn slowly due to GoldSrc limits!
static const double BOT_MIN_FRAME_TIME = (1.0 / 60.0);
// Called when the round restarts. Clears all tactical information but keeps navigation data.
void AIMGR_ResetRound();
// Called when a new map is loaded. Clears all tactical information AND loads new navmesh.
void AIMGR_NewMap();
// Adds a new AI player to a team (0 = Auto-assign, 1 = Team A, 2 = Team B)
void AIMGR_AddAIPlayerToTeam(int Team);
// Removed an AI player from the team (0 = Auto-select team, 1 = Team A, 2 = Team B)
void AIMGR_RemoveAIPlayerFromTeam(int Team);
// Run AI player logic
void AIMGR_UpdateAIPlayers();
// Kicks all bots in the ready room (used at round end when everyone is booted back to the ready room)
void AIMGR_RemoveBotsInReadyRoom();
// Delta between last bot frame and this one (default is 60hz = 0.0166666)
float AIMGR_GetBotDeltaTime();
// Called every 0.2s to determine if bots need to be added/removed. Calls UpdateTeamBalance or UpdateFillTeams depending on auto-mode
void AIMGR_UpdateAIPlayerCounts();
// Called by UpdateAIPlayerCounts. If auto-mode is for balance only, will add/remove bots needed to keep teams even
void AIMGR_UpdateTeamBalance();
// Called by UpdateAIPlayerCounts. If auto-mode is fill teams, will add/remove bots needed to maintain minimum player counts and balance
void AIMGR_UpdateFillTeams();
// How many AI players are in the game (does not include third-party bots like RCBot/Whichbot)
int AIMGR_GetNumAIPlayers();
// Returns true if an AI player is on the requested team (does NOT include third-party bots like RCBot/Whichbot)
int AIMGR_AIPlayerExistsOnTeam(AvHTeamNumber Team);
#endif

View file

@ -400,6 +400,7 @@ AvHGamerules::AvHGamerules() : mTeamA(TEAM_ONE), mTeamB(TEAM_TWO)
this->mGameInReset = false;
AIMGR_NewMap();
this->ResetGame();
}
@ -2692,6 +2693,8 @@ void AvHGamerules::ResetGame(bool inPreserveTeams)
gSvCheatsLastUpdateTime = -1.0f;
this->mHasPlayersToReset = false;
this->mLastPlayerResetTime = -1.0f;
AIMGR_ResetRound();
}
void AvHGamerules::RecalculateMapMode( void )