mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
Merge pull request #1824 from Dune-jr/fix-readystate
Fix readystate when player leaves or spectates (#1784)
This commit is contained in:
commit
80843bcf27
|
@ -100,10 +100,12 @@ void IGameController::DoActivityCheck()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IGameController::GetPlayersReadyState()
|
bool IGameController::GetPlayersReadyState(int WithoutID)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < MAX_CLIENTS; ++i)
|
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)
|
if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS && !GameServer()->m_apPlayers[i]->m_IsReadyToPlay)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -352,6 +354,8 @@ void IGameController::OnPlayerDisconnect(CPlayer *pPlayer)
|
||||||
--m_aTeamSize[pPlayer->GetTeam()];
|
--m_aTeamSize[pPlayer->GetTeam()];
|
||||||
m_UnbalancedTick = TBALANCE_CHECK;
|
m_UnbalancedTick = TBALANCE_CHECK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CheckReadyStates(ClientID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IGameController::OnPlayerInfoChange(CPlayer *pPlayer)
|
void IGameController::OnPlayerInfoChange(CPlayer *pPlayer)
|
||||||
|
@ -365,29 +369,36 @@ void IGameController::OnPlayerReadyChange(CPlayer *pPlayer)
|
||||||
// change players ready state
|
// change players ready state
|
||||||
pPlayer->m_IsReadyToPlay ^= 1;
|
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)
|
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:
|
case IGS_WARMUP_USER:
|
||||||
// all players are ready -> end warmup
|
// all players are ready -> end warmup
|
||||||
if(GetPlayersReadyState())
|
if(GetPlayersReadyState(WithoutID))
|
||||||
SetGameState(IGS_WARMUP_USER, 0);
|
SetGameState(IGS_WARMUP_USER, 0);
|
||||||
break;
|
break;
|
||||||
case IGS_GAME_PAUSED:
|
case IGS_GAME_PAUSED:
|
||||||
// all players are ready -> unpause the game
|
// all players are ready -> unpause the game
|
||||||
if(GetPlayersReadyState())
|
if(GetPlayersReadyState(WithoutID))
|
||||||
SetGameState(IGS_GAME_PAUSED, 0);
|
SetGameState(IGS_GAME_PAUSED, 0);
|
||||||
break;
|
break;
|
||||||
|
case IGS_GAME_RUNNING:
|
||||||
case IGS_WARMUP_GAME:
|
case IGS_WARMUP_GAME:
|
||||||
case IGS_START_COUNTDOWN:
|
case IGS_START_COUNTDOWN:
|
||||||
case IGS_END_MATCH:
|
case IGS_END_MATCH:
|
||||||
case IGS_END_ROUND:
|
case IGS_END_ROUND:
|
||||||
// not effected
|
// not affected
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1129,6 +1140,7 @@ void IGameController::DoTeamChange(CPlayer *pPlayer, int Team, bool DoChatMsg)
|
||||||
}
|
}
|
||||||
OnPlayerInfoChange(pPlayer);
|
OnPlayerInfoChange(pPlayer);
|
||||||
GameServer()->OnClientTeamChange(ClientID);
|
GameServer()->OnClientTeamChange(ClientID);
|
||||||
|
CheckReadyStates();
|
||||||
|
|
||||||
// reset inactivity counter when joining the game
|
// reset inactivity counter when joining the game
|
||||||
if(OldTeam == TEAM_SPECTATORS)
|
if(OldTeam == TEAM_SPECTATORS)
|
||||||
|
|
|
@ -19,8 +19,9 @@ class IGameController
|
||||||
|
|
||||||
// activity
|
// activity
|
||||||
void DoActivityCheck();
|
void DoActivityCheck();
|
||||||
bool GetPlayersReadyState();
|
bool GetPlayersReadyState(int WithoutID = -1);
|
||||||
void SetPlayersReadyState(bool ReadyState);
|
void SetPlayersReadyState(bool ReadyState);
|
||||||
|
void CheckReadyStates(int WithoutID = -1);
|
||||||
|
|
||||||
// balancing
|
// balancing
|
||||||
enum
|
enum
|
||||||
|
|
Loading…
Reference in a new issue