Merge pull request #1824 from Dune-jr/fix-readystate

Fix readystate when player leaves or spectates (#1784)
This commit is contained in:
oy 2018-12-09 18:28:06 +01:00 committed by GitHub
commit 80843bcf27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 11 deletions

View file

@ -100,10 +100,12 @@ void IGameController::DoActivityCheck()
}
}
bool IGameController::GetPlayersReadyState()
bool IGameController::GetPlayersReadyState(int WithoutID)
{
for(int i = 0; i < MAX_CLIENTS; ++i)
{
if(i == WithoutID)
continue; // skip
if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS && !GameServer()->m_apPlayers[i]->m_IsReadyToPlay)
return false;
}
@ -352,6 +354,8 @@ void IGameController::OnPlayerDisconnect(CPlayer *pPlayer)
--m_aTeamSize[pPlayer->GetTeam()];
m_UnbalancedTick = TBALANCE_CHECK;
}
CheckReadyStates(ClientID);
}
void IGameController::OnPlayerInfoChange(CPlayer *pPlayer)
@ -365,29 +369,36 @@ void IGameController::OnPlayerReadyChange(CPlayer *pPlayer)
// change players ready state
pPlayer->m_IsReadyToPlay ^= 1;
// check if it effects current game state
if(m_GameState == IGS_GAME_RUNNING && !pPlayer->m_IsReadyToPlay)
SetGameState(IGS_GAME_PAUSED, TIMER_INFINITE); // one player isn't ready -> pause the game
CheckReadyStates();
}
}
// to be called when a player changes state, spectates or disconnects
void IGameController::CheckReadyStates(int WithoutID)
{
if(g_Config.m_SvPlayerReadyMode)
{
switch(m_GameState)
{
case IGS_GAME_RUNNING:
// one player isn't ready -> pause the game
if(!pPlayer->m_IsReadyToPlay)
SetGameState(IGS_GAME_PAUSED, TIMER_INFINITE);
break;
case IGS_WARMUP_USER:
// all players are ready -> end warmup
if(GetPlayersReadyState())
if(GetPlayersReadyState(WithoutID))
SetGameState(IGS_WARMUP_USER, 0);
break;
case IGS_GAME_PAUSED:
// all players are ready -> unpause the game
if(GetPlayersReadyState())
if(GetPlayersReadyState(WithoutID))
SetGameState(IGS_GAME_PAUSED, 0);
break;
case IGS_GAME_RUNNING:
case IGS_WARMUP_GAME:
case IGS_START_COUNTDOWN:
case IGS_END_MATCH:
case IGS_END_ROUND:
// not effected
// not affected
break;
}
}
@ -1129,6 +1140,7 @@ void IGameController::DoTeamChange(CPlayer *pPlayer, int Team, bool DoChatMsg)
}
OnPlayerInfoChange(pPlayer);
GameServer()->OnClientTeamChange(ClientID);
CheckReadyStates();
// reset inactivity counter when joining the game
if(OldTeam == TEAM_SPECTATORS)

View file

@ -19,8 +19,9 @@ class IGameController
// activity
void DoActivityCheck();
bool GetPlayersReadyState();
bool GetPlayersReadyState(int WithoutID = -1);
void SetPlayersReadyState(bool ReadyState);
void CheckReadyStates(int WithoutID = -1);
// balancing
enum