From 57387b5965e5b59b73b129c23323052dc1ebcd08 Mon Sep 17 00:00:00 2001 From: trml Date: Mon, 8 Nov 2021 23:51:09 +0100 Subject: [PATCH] Fix switch state when spectating other players --- src/game/client/components/items.cpp | 8 ++++---- src/game/client/gameclient.cpp | 18 ++++++++++++++---- src/game/client/gameclient.h | 3 ++- src/game/server/gamecontroller.cpp | 4 ++++ 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/game/client/components/items.cpp b/src/game/client/components/items.cpp index 61c8cac9e..5a5cb2419 100644 --- a/src/game/client/components/items.cpp +++ b/src/game/client/components/items.cpp @@ -310,7 +310,7 @@ void CItems::OnRender() bool BlinkingProj = (Ticks % 20) < 2; bool BlinkingProjEx = (Ticks % 6) < 2; bool BlinkingLight = (Ticks % 6) < 2; - int OwnTeam = m_pClient->OwnTeam(); + int SwitcherTeam = m_pClient->SwitchStateTeam(); int DraggerStartTick = maximum((Client()->GameTick(g_Config.m_ClDummy) / 7) * 7, Client()->GameTick(g_Config.m_ClDummy) - 4); bool UsePredicted = GameClient()->Predict() && GameClient()->AntiPingGunfire(); @@ -318,7 +318,7 @@ void CItems::OnRender() { for(auto *pProj = (CProjectile *)GameClient()->m_PredictedWorld.FindFirst(CGameWorld::ENTTYPE_PROJECTILE); pProj; pProj = (CProjectile *)pProj->NextEntity()) { - if(!IsSuper && pProj->m_Number > 0 && pProj->m_Number < Collision()->m_NumSwitchers + 1 && !Collision()->m_pSwitchers[pProj->m_Number].m_Status[OwnTeam] && (pProj->m_Explosive ? BlinkingProjEx : BlinkingProj)) + if(!IsSuper && pProj->m_Number > 0 && pProj->m_Number < Collision()->m_NumSwitchers + 1 && !Collision()->m_pSwitchers[pProj->m_Number].m_Status[SwitcherTeam] && (pProj->m_Explosive ? BlinkingProjEx : BlinkingProj)) continue; CProjectileData Data = pProj->GetData(); @@ -334,7 +334,7 @@ void CItems::OnRender() } for(auto *pPickup = (CPickup *)GameClient()->m_PredictedWorld.FindFirst(CGameWorld::ENTTYPE_PICKUP); pPickup; pPickup = (CPickup *)pPickup->NextEntity()) { - if(!IsSuper && pPickup->m_Layer == LAYER_SWITCH && pPickup->m_Number > 0 && pPickup->m_Number < Collision()->m_NumSwitchers + 1 && !Collision()->m_pSwitchers[pPickup->m_Number].m_Status[OwnTeam] && BlinkingPickup) + if(!IsSuper && pPickup->m_Layer == LAYER_SWITCH && pPickup->m_Number > 0 && pPickup->m_Number < Collision()->m_NumSwitchers + 1 && !Collision()->m_pSwitchers[pPickup->m_Number].m_Status[SwitcherTeam] && BlinkingPickup) continue; if(pPickup->InDDNetTile()) @@ -358,7 +358,7 @@ void CItems::OnRender() bool Inactive = false; if(pEntEx) - Inactive = !IsSuper && pEntEx->m_SwitchNumber > 0 && pEntEx->m_SwitchNumber < Collision()->m_NumSwitchers + 1 && !Collision()->m_pSwitchers[pEntEx->m_SwitchNumber].m_Status[OwnTeam]; + Inactive = !IsSuper && pEntEx->m_SwitchNumber > 0 && pEntEx->m_SwitchNumber < Collision()->m_NumSwitchers + 1 && !Collision()->m_pSwitchers[pEntEx->m_SwitchNumber].m_Status[SwitcherTeam]; if(Item.m_Type == NETOBJTYPE_PROJECTILE || Item.m_Type == NETOBJTYPE_DDNETPROJECTILE) { diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 246bfe98c..610ad2629 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -277,6 +277,8 @@ void CGameClient::OnInit() m_DDRaceMsgSent[1] = false; m_ShowOthers[0] = -1; m_ShowOthers[1] = -1; + m_SwitchStateTeam[0] = -1; + m_SwitchStateTeam[1] = -1; m_LastZoom = .0; m_LastScreenAspect = .0; @@ -1146,6 +1148,8 @@ void CGameClient::OnNewSnapshot() #endif bool FoundGameInfoEx = false; + bool GotSwitchStateTeam = false; + m_SwitchStateTeam[g_Config.m_ClDummy] = -1; for(auto &Client : m_aClients) { @@ -1440,6 +1444,12 @@ void CGameClient::OnNewSnapshot() Collision()->m_pSwitchers[i].m_Type[Team] = TILE_SWITCHCLOSE; Collision()->m_pSwitchers[i].m_EndTick[Team] = 0; } + + if(!GotSwitchStateTeam) + m_SwitchStateTeam[g_Config.m_ClDummy] = Team; + else + m_SwitchStateTeam[g_Config.m_ClDummy] = -1; + GotSwitchStateTeam = true; } } } @@ -2591,11 +2601,11 @@ bool CGameClient::IsOtherTeam(int ClientID) return m_Teams.Team(ClientID) != m_Teams.Team(m_Snap.m_LocalClientID); } -int CGameClient::OwnTeam() +int CGameClient::SwitchStateTeam() { - if(m_Snap.m_LocalClientID < 0) - return 0; - else if(m_aClients[m_Snap.m_LocalClientID].m_Team == TEAM_SPECTATORS && m_Snap.m_SpecInfo.m_SpectatorID == SPEC_FREEVIEW) + if(m_SwitchStateTeam[g_Config.m_ClDummy] >= 0) + return m_SwitchStateTeam[g_Config.m_ClDummy]; + else if(m_Snap.m_LocalClientID < 0) return 0; else if(m_Snap.m_SpecInfo.m_Active && m_Snap.m_SpecInfo.m_SpectatorID != SPEC_FREEVIEW) return m_Teams.Team(m_Snap.m_SpecInfo.m_SpectatorID); diff --git a/src/game/client/gameclient.h b/src/game/client/gameclient.h index 04ca27822..c21e0b388 100644 --- a/src/game/client/gameclient.h +++ b/src/game/client/gameclient.h @@ -520,7 +520,7 @@ public: void DummyResetInput(); void Echo(const char *pString); bool IsOtherTeam(int ClientID); - int OwnTeam(); + int SwitchStateTeam(); bool IsLocalCharSuper(); bool CanDisplayWarning(); bool IsDisplayingWarning(); @@ -657,6 +657,7 @@ private: int m_IsDummySwapping; CCharOrder m_CharOrder; class CCharacter m_aLastWorldCharacters[MAX_CLIENTS]; + int m_SwitchStateTeam[NUM_DUMMIES]; enum { diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index 929c53700..2ce0cd8b5 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -632,6 +632,10 @@ void IGameController::Snap(int SnappingClient) if(GameServer()->Collision()->m_pSwitchers) { int Team = pPlayer && pPlayer->GetCharacter() ? pPlayer->GetCharacter()->Team() : 0; + + if(pPlayer && (pPlayer->GetTeam() == TEAM_SPECTATORS || pPlayer->IsPaused()) && pPlayer->m_SpectatorID != SPEC_FREEVIEW && GameServer()->m_apPlayers[pPlayer->m_SpectatorID] && GameServer()->m_apPlayers[pPlayer->m_SpectatorID]->GetCharacter()) + Team = GameServer()->m_apPlayers[pPlayer->m_SpectatorID]->GetCharacter()->Team(); + CNetObj_SwitchState *pSwitchState = static_cast(Server()->SnapNewItem(NETOBJTYPE_SWITCHSTATE, Team, sizeof(CNetObj_SwitchState))); if(!pSwitchState) return;