Skip to content

Commit

Permalink
fix setting rd_player_bots_allowed to 0 in an active lobby removing a…
Browse files Browse the repository at this point in the history
…ll marines rather than leaving every player with one
  • Loading branch information
BenLubar committed Jun 1, 2024
1 parent ef577c4 commit b4b2da2
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions src/game/shared/swarm/asw_gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,32 +273,52 @@ extern ConVar old_radius_damage;

// reactivedrop: this callback function is called when rd_player_bots_allowed cvar is
// changed. If the value is 0 it will remove all bots from the briefing
static void DeselectMarineBots( IConVar *pConVar = NULL, const char *pOldValue = NULL, float flOldValue = 0.0f )
static void DeselectMarineBots( IConVar *pConVar, const char *pOldValue, float flOldValue )
{
ConVarRef rd_player_bots_allowed( "rd_player_bots_allowed" );
extern ConVar rd_player_bots_allowed;
if ( rd_player_bots_allowed.GetBool() )
return;

if ( ASWGameRules() && ASWGameResource() )
if ( !ASWGameRules() || ASWGameRules()->GetGameState() != ASW_GS_BRIEFING )
return;

CASW_Game_Resource *pGameResource = ASWGameResource();
if ( !pGameResource )
return;

CUtlVector<CASW_Marine_Resource *> toDelete;

for ( int i = 1; i <= gpGlobals->maxClients; i++ )
{
for ( int i = 0; i < ASW_MAX_MARINE_RESOURCES; i++ )
CBasePlayer *pPlayer = UTIL_PlayerByIndex( i );
if ( !pPlayer )
continue;

bool bHaveMarine = false;
for ( int j = 0; j < ASW_MAX_MARINE_RESOURCES; j++ )
{
CASW_Marine_Resource *pMR = ASWGameResource()->GetMarineResource( i );
CASW_Marine_Resource *pMR = pGameResource->GetMarineResource( j );
if ( !pMR )
{
continue;
}

CASW_Player *pPlayer = pMR->GetCommander();
if ( !pPlayer )
if ( pMR->GetCommander() != pPlayer )
continue;

if ( !bHaveMarine )
{
bHaveMarine = true;
continue;
}

COMPILE_TIME_ASSERT( ASW_NUM_MARINE_PROFILES == 8 );
engine->ClientCommand( pPlayer->edict(), "cl_dselectm 0;cl_dselectm 1;cl_dselectm 2;cl_dselectm 3;cl_dselectm 4;cl_dselectm 5;cl_dselectm 6;cl_dselectm 7;" );
toDelete.AddToTail( pMR );
}
}

DevMsg( "Removing %d bot marines from the lobby.\n", toDelete.Count() );
FOR_EACH_VEC( toDelete, i )
{
pGameResource->DeleteMarineResource( toDelete[i] );
}
}
#endif

Expand Down

0 comments on commit b4b2da2

Please sign in to comment.