From 4619e825f3907772fac625b7398355fba1324066 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Mon, 14 Mar 2022 13:25:47 +0100 Subject: [PATCH] make spectators team independent --- src/engine/shared/protocol.h | 1 + src/game/client/components/menus_ingame.cpp | 3 --- src/game/client/components/nameplates.cpp | 2 +- src/game/client/components/scoreboard.cpp | 4 ++-- src/game/client/components/spectator.cpp | 2 +- src/game/client/gameclient.cpp | 8 +++++++- src/game/server/player.cpp | 10 ++++++---- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/engine/shared/protocol.h b/src/engine/shared/protocol.h index 275c9dc9c..92e8148c5 100644 --- a/src/engine/shared/protocol.h +++ b/src/engine/shared/protocol.h @@ -117,6 +117,7 @@ enum VERSION_DDNET_GAMETICK = 10042, VERSION_DDNET_MSG_LEGACY = 15040, VERSION_DDNET_SWITCH = 15060, + VERSION_DDNET_INDEPENDENT_SPECTATORS_TEAM = 16000, }; #endif diff --git a/src/game/client/components/menus_ingame.cpp b/src/game/client/components/menus_ingame.cpp index 96c5dd2c4..8b4aee9c5 100644 --- a/src/game/client/components/menus_ingame.cpp +++ b/src/game/client/components/menus_ingame.cpp @@ -170,10 +170,7 @@ void CMenus::RenderGame(CUIRect MainView) } } } - } - if(m_pClient->m_Snap.m_pLocalInfo && m_pClient->m_Snap.m_pGameInfoObj) - { if(m_pClient->m_Snap.m_pLocalInfo->m_Team != TEAM_SPECTATORS) { ButtonBar.VSplitLeft(5.0f, 0, &ButtonBar); diff --git a/src/game/client/components/nameplates.cpp b/src/game/client/components/nameplates.cpp index 8c9133d6d..02c9b357d 100644 --- a/src/game/client/components/nameplates.cpp +++ b/src/game/client/components/nameplates.cpp @@ -241,7 +241,7 @@ void CNamePlates::RenderNameplatePos(vec2 Position, const CNetObj_PlayerInfo *pP if((g_Config.m_Debug || g_Config.m_ClNameplatesStrong) && g_Config.m_ClNameplates) { - if(m_pClient->m_Snap.m_aCharacters[pPlayerInfo->m_ClientID].m_HasExtendedData && m_pClient->m_Snap.m_aCharacters[m_pClient->m_Snap.m_LocalClientID].m_HasExtendedData) + if(m_pClient->m_Snap.m_LocalClientID != -1 && m_pClient->m_Snap.m_aCharacters[pPlayerInfo->m_ClientID].m_HasExtendedData && m_pClient->m_Snap.m_aCharacters[m_pClient->m_Snap.m_LocalClientID].m_HasExtendedData) { CCharacter *pLocalChar = m_pClient->m_GameWorld.GetCharacterByID(m_pClient->m_Snap.m_LocalClientID); CCharacter *pCharacter = m_pClient->m_GameWorld.GetCharacterByID(pPlayerInfo->m_ClientID); diff --git a/src/game/client/components/scoreboard.cpp b/src/game/client/components/scoreboard.cpp index d73a779f0..abe5fa19e 100644 --- a/src/game/client/components/scoreboard.cpp +++ b/src/game/client/components/scoreboard.cpp @@ -413,7 +413,7 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch OldDDTeam = DDTeam; // background so it's easy to find the local player or the followed one in spectator mode - if(pInfo->m_Local || (m_pClient->m_Snap.m_SpecInfo.m_Active && pInfo->m_ClientID == m_pClient->m_Snap.m_SpecInfo.m_SpectatorID)) + if((!m_pClient->m_Snap.m_SpecInfo.m_Active && pInfo->m_Local) || (m_pClient->m_Snap.m_SpecInfo.m_SpectatorID == SPEC_FREEVIEW && pInfo->m_Local) || (m_pClient->m_Snap.m_SpecInfo.m_Active && pInfo->m_ClientID == m_pClient->m_Snap.m_SpecInfo.m_SpectatorID)) { Graphics()->TextureClear(); Graphics()->QuadsBegin(); @@ -701,7 +701,7 @@ bool CScoreboard::Active() if(m_Active) return true; - if(m_pClient->m_Snap.m_pLocalInfo && m_pClient->m_Snap.m_pLocalInfo->m_Team != TEAM_SPECTATORS) + if(m_pClient->m_Snap.m_pLocalInfo && !m_pClient->m_Snap.m_SpecInfo.m_Active) { // we are not a spectator, check if we are dead if(!m_pClient->m_Snap.m_pLocalCharacter && g_Config.m_ClScoreboardOnDeath) diff --git a/src/game/client/components/spectator.cpp b/src/game/client/components/spectator.cpp index 839400ea0..6072b858f 100644 --- a/src/game/client/components/spectator.cpp +++ b/src/game/client/components/spectator.cpp @@ -136,7 +136,7 @@ void CSpectator::ConSpectateClosest(IConsole::IResult *pResult, void *pUserData) int ClosestDistance = INT_MAX; for(int i = 0; i < MAX_CLIENTS; i++) { - if(i == SpectatorID || !Snap.m_paPlayerInfos[i] || Snap.m_paPlayerInfos[i]->m_Team == TEAM_SPECTATORS) + if(i == SpectatorID || !Snap.m_paPlayerInfos[i] || Snap.m_paPlayerInfos[i]->m_Team == TEAM_SPECTATORS || (SpectatorID == SPEC_FREEVIEW && i == Snap.m_LocalClientID)) continue; const CNetObj_Character &MaybeClosestCharacter = Snap.m_aCharacters[i].m_Cur; int Distance = distance(CurPosition, vec2(MaybeClosestCharacter.m_X, MaybeClosestCharacter.m_Y)); diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 0221f5f9d..924c0e6a0 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -1245,6 +1245,12 @@ void CGameClient::OnNewSnapshot() m_aClients[Item.m_ID].m_Afk = pInfo->m_Flags & EXPLAYERFLAG_AFK; m_aClients[Item.m_ID].m_Paused = pInfo->m_Flags & EXPLAYERFLAG_PAUSED; m_aClients[Item.m_ID].m_Spec = pInfo->m_Flags & EXPLAYERFLAG_SPEC; + + if(Item.m_ID == m_Snap.m_LocalClientID && (m_aClients[Item.m_ID].m_Paused || m_aClients[Item.m_ID].m_Spec)) + { + m_Snap.m_SpecInfo.m_Active = true; + m_Snap.m_SpecInfo.m_SpectatorID = SPEC_FREEVIEW; + } } } else if(Item.m_Type == NETOBJTYPE_CHARACTER) @@ -2591,7 +2597,7 @@ bool CGameClient::IsOtherTeam(int ClientID) if(m_Snap.m_LocalClientID < 0) return false; - else if((m_aClients[m_Snap.m_LocalClientID].m_Team == TEAM_SPECTATORS && m_Snap.m_SpecInfo.m_SpectatorID == SPEC_FREEVIEW) || ClientID < 0) + else if((m_Snap.m_SpecInfo.m_Active && m_Snap.m_SpecInfo.m_SpectatorID == SPEC_FREEVIEW) || ClientID < 0) return false; else if(m_Snap.m_SpecInfo.m_Active && m_Snap.m_SpecInfo.m_SpectatorID != SPEC_FREEVIEW) { diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index 0702fd70b..30b485b7c 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -359,10 +359,12 @@ void CPlayer::Snap(int SnappingClient) pPlayerInfo->m_Score = Score; pPlayerInfo->m_Local = (int)(m_ClientID == SnappingClient && (m_Paused != PAUSE_PAUSED || SnappingClientVersion >= VERSION_DDNET_OLD)); pPlayerInfo->m_ClientID = id; - pPlayerInfo->m_Team = (SnappingClientVersion < VERSION_DDNET_OLD || m_Paused != PAUSE_PAUSED || m_ClientID != SnappingClient) && m_Paused < PAUSE_SPEC ? m_Team : TEAM_SPECTATORS; - - if(m_ClientID == SnappingClient && m_Paused == PAUSE_PAUSED && SnappingClientVersion < VERSION_DDNET_OLD) - pPlayerInfo->m_Team = TEAM_SPECTATORS; + pPlayerInfo->m_Team = m_Team; + if(SnappingClientVersion < VERSION_DDNET_INDEPENDENT_SPECTATORS_TEAM) + { + // In older versions the SPECTATORS TEAM was also used if the own player is in PAUSE_PAUSED or if any player is in PAUSE_SPEC. + pPlayerInfo->m_Team = (m_Paused != PAUSE_PAUSED || m_ClientID != SnappingClient) && m_Paused < PAUSE_SPEC ? m_Team : TEAM_SPECTATORS; + } } else {