From bc487f7eb135468d695a40b985a13ce6b91ce9c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Wed, 8 Jan 2025 22:56:14 +0100 Subject: [PATCH] Use `CGameClient::IsTeamPlay` function consistently --- src/game/client/components/chat.cpp | 2 +- src/game/client/components/ghost.cpp | 8 ++------ src/game/client/components/hud.cpp | 9 ++++----- src/game/client/components/menus_ingame.cpp | 6 +++--- src/game/client/components/nameplates.cpp | 2 +- src/game/client/components/players.cpp | 11 ++++------- src/game/client/components/scoreboard.cpp | 8 +++----- src/game/client/components/statboard.cpp | 4 ++-- src/game/client/gameclient.cpp | 2 +- 9 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index 0c357ec8836..d55d5ec5610 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -802,7 +802,7 @@ void CChat::AddLine(int ClientId, int Team, const char *pLine) if(LineAuthor.m_Team == TEAM_SPECTATORS) pCurrentLine->m_NameColor = TEAM_SPECTATORS; - if(m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_TEAMS) + if(m_pClient->IsTeamPlay()) { if(LineAuthor.m_Team == TEAM_RED) pCurrentLine->m_NameColor = TEAM_RED; diff --git a/src/game/client/components/ghost.cpp b/src/game/client/components/ghost.cpp index 1554cb7456b..7ce0b49f2fb 100644 --- a/src/game/client/components/ghost.cpp +++ b/src/game/client/components/ghost.cpp @@ -354,14 +354,10 @@ void CGhost::OnRender() const auto *pSkin = m_pClient->m_Skins.FindOrNullptr("x_ninja"); if(pSkin != nullptr) { - bool IsTeamplay = false; - if(m_pClient->m_Snap.m_pGameInfoObj) - IsTeamplay = (m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_TEAMS) != 0; - GhostNinjaRenderInfo = Ghost.m_RenderInfo; GhostNinjaRenderInfo.Apply(pSkin); - GhostNinjaRenderInfo.m_CustomColoredSkin = IsTeamplay; - if(!IsTeamplay) + GhostNinjaRenderInfo.m_CustomColoredSkin = m_pClient->IsTeamPlay(); + if(!GhostNinjaRenderInfo.m_CustomColoredSkin) { GhostNinjaRenderInfo.m_ColorBody = ColorRGBA(1, 1, 1); GhostNinjaRenderInfo.m_ColorFeet = ColorRGBA(1, 1, 1); diff --git a/src/game/client/components/hud.cpp b/src/game/client/components/hud.cpp index 411722b312c..5156492621d 100644 --- a/src/game/client/components/hud.cpp +++ b/src/game/client/components/hud.cpp @@ -179,7 +179,6 @@ void CHud::RenderScoreHud() // render small score hud if(!(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_GAMEOVER)) { - int GameFlags = m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags; float StartY = 229.0f; // the height of this display is 56, so EndY is 285 const float ScoreSingleBoxHeight = 18.0f; @@ -187,7 +186,7 @@ void CHud::RenderScoreHud() bool ForceScoreInfoInit = !m_aScoreInfo[0].m_Initialized || !m_aScoreInfo[1].m_Initialized; m_aScoreInfo[0].m_Initialized = m_aScoreInfo[1].m_Initialized = true; - if(GameFlags & GAMEFLAG_TEAMS && m_pClient->m_Snap.m_pGameDataObj) + if(m_pClient->IsTeamPlay() && m_pClient->m_Snap.m_pGameDataObj) { char aScoreTeam[2][16]; str_format(aScoreTeam[TEAM_RED], sizeof(aScoreTeam[TEAM_RED]), "%d", m_pClient->m_Snap.m_pGameDataObj->m_TeamscoreRed); @@ -213,7 +212,7 @@ void CHud::RenderScoreHud() static float s_TextWidth100 = TextRender()->TextWidth(14.0f, "100", -1, -1.0f); float ScoreWidthMax = maximum(maximum(m_aScoreInfo[0].m_ScoreTextWidth, m_aScoreInfo[1].m_ScoreTextWidth), s_TextWidth100); float Split = 3.0f; - float ImageSize = (GameFlags & GAMEFLAG_FLAGS) ? 16.0f : Split; + float ImageSize = (m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_FLAGS) ? 16.0f : Split; for(int t = 0; t < 2; t++) { // draw box @@ -247,7 +246,7 @@ void CHud::RenderScoreHud() TextRender()->RenderTextContainer(m_aScoreInfo[t].m_TextScoreContainerIndex, TColor, TOutlineColor); } - if(GameFlags & GAMEFLAG_FLAGS) + if(m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_FLAGS) { int BlinkTimer = (m_pClient->m_aFlagDropTick[t] != 0 && (Client()->GameTick(g_Config.m_ClDummy) - m_pClient->m_aFlagDropTick[t]) / Client()->GameTickSpeed() >= 25) ? @@ -571,7 +570,7 @@ void CHud::RenderTeambalanceWarning() { // render prompt about team-balance bool Flash = time() / (time_freq() / 2) % 2 == 0; - if(m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_TEAMS) + if(m_pClient->IsTeamPlay()) { int TeamDiff = m_pClient->m_Snap.m_aTeamSize[TEAM_RED] - m_pClient->m_Snap.m_aTeamSize[TEAM_BLUE]; if(g_Config.m_ClWarningTeambalance && (TeamDiff >= 2 || TeamDiff <= -2)) diff --git a/src/game/client/components/menus_ingame.cpp b/src/game/client/components/menus_ingame.cpp index a939df196cd..9aa64a8876a 100644 --- a/src/game/client/components/menus_ingame.cpp +++ b/src/game/client/components/menus_ingame.cpp @@ -143,7 +143,7 @@ void CMenus::RenderGame(CUIRect MainView) } } - if(m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_TEAMS) + if(m_pClient->IsTeamPlay()) { if(m_pClient->m_Snap.m_pLocalInfo->m_Team != TEAM_RED) { @@ -184,7 +184,7 @@ void CMenus::RenderGame(CUIRect MainView) } } - if(m_pClient->m_Snap.m_pLocalInfo->m_Team != TEAM_SPECTATORS && (ShowDDRaceButtons || !(m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_TEAMS))) + if(m_pClient->m_Snap.m_pLocalInfo->m_Team != TEAM_SPECTATORS && (ShowDDRaceButtons || !m_pClient->IsTeamPlay())) { ButtonBar.VSplitLeft(65.0f, &Button, &ButtonBar); ButtonBar.VSplitLeft(5.0f, nullptr, &ButtonBar); @@ -198,7 +198,7 @@ void CMenus::RenderGame(CUIRect MainView) } } - if(m_pClient->m_ReceivedDDNetPlayer && m_pClient->m_Snap.m_pLocalInfo && m_pClient->m_Snap.m_pGameInfoObj && (ShowDDRaceButtons || !(m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_TEAMS))) + if(m_pClient->m_ReceivedDDNetPlayer && m_pClient->m_Snap.m_pLocalInfo && (ShowDDRaceButtons || !m_pClient->IsTeamPlay())) { if(m_pClient->m_Snap.m_pLocalInfo->m_Team != TEAM_SPECTATORS || Paused || Spec) { diff --git a/src/game/client/components/nameplates.cpp b/src/game/client/components/nameplates.cpp index f6d8cf710c7..ce035af1663 100644 --- a/src/game/client/components/nameplates.cpp +++ b/src/game/client/components/nameplates.cpp @@ -246,7 +246,7 @@ void CNamePlates::RenderNamePlateGame(vec2 Position, const CNetObj_PlayerInfo *p if(g_Config.m_ClNamePlatesTeamcolors) { - if(m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_TEAMS) + if(m_pClient->IsTeamPlay()) { if(ClientData.m_Team == TEAM_RED) Data.m_Color = ColorRGBA(1.0f, 0.5f, 0.5f); diff --git a/src/game/client/components/players.cpp b/src/game/client/components/players.cpp index ceb145fad21..623c9df4f2c 100644 --- a/src/game/client/components/players.cpp +++ b/src/game/client/components/players.cpp @@ -854,12 +854,9 @@ void CPlayers::OnRender() if(Client()->State() != IClient::STATE_ONLINE && Client()->State() != IClient::STATE_DEMOPLAYBACK) return; + // update render info for ninja CTeeRenderInfo aRenderInfo[MAX_CLIENTS]; - - // update RenderInfo for ninja - bool IsTeamplay = false; - if(m_pClient->m_Snap.m_pGameInfoObj) - IsTeamplay = (m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_TEAMS) != 0; + const bool IsTeamPlay = m_pClient->IsTeamPlay(); for(int i = 0; i < MAX_CLIENTS; ++i) { aRenderInfo[i] = m_pClient->m_aClients[i].m_RenderInfo; @@ -882,8 +879,8 @@ void CPlayers::OnRender() aRenderInfo[i].m_aSixup[g_Config.m_ClDummy].Reset(); aRenderInfo[i].Apply(pSkin); - aRenderInfo[i].m_CustomColoredSkin = IsTeamplay; - if(!IsTeamplay) + aRenderInfo[i].m_CustomColoredSkin = IsTeamPlay; + if(!IsTeamPlay) { aRenderInfo[i].m_ColorBody = ColorRGBA(1, 1, 1); aRenderInfo[i].m_ColorFeet = ColorRGBA(1, 1, 1); diff --git a/src/game/client/components/scoreboard.cpp b/src/game/client/components/scoreboard.cpp index 3cee43d06bf..5f9855892e9 100644 --- a/src/game/client/components/scoreboard.cpp +++ b/src/game/client/components/scoreboard.cpp @@ -69,8 +69,6 @@ void CScoreboard::RenderTitle(CUIRect TitleBar, int Team, const char *pTitle) { dbg_assert(Team == TEAM_RED || Team == TEAM_BLUE, "Team invalid"); - const CNetObj_GameInfo *pGameInfoObj = GameClient()->m_Snap.m_pGameInfoObj; - char aScore[128] = ""; if(GameClient()->m_GameInfo.m_TimeScore) { @@ -79,7 +77,7 @@ void CScoreboard::RenderTitle(CUIRect TitleBar, int Team, const char *pTitle) str_time_float(m_ServerRecord, TIME_HOURS, aScore, sizeof(aScore)); } } - else if(pGameInfoObj && (pGameInfoObj->m_GameFlags & GAMEFLAG_TEAMS)) + else if(GameClient()->IsTeamPlay()) { const CNetObj_GameData *pGameDataObj = GameClient()->m_Snap.m_pGameDataObj; if(pGameDataObj) @@ -513,7 +511,7 @@ void CScoreboard::RenderScoreboard(CUIRect Scoreboard, int Team, int CountStart, Graphics()->BlendNormal(); Graphics()->TextureSet(m_DeadTeeTexture); Graphics()->QuadsBegin(); - if(m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_TEAMS) + if(m_pClient->IsTeamPlay()) { Graphics()->SetColor(m_pClient->m_Skins7.GetTeamColor(true, 0, m_pClient->m_aClients[pInfo->m_ClientId].m_Team, protocol7::SKINPART_BODY)); } @@ -654,7 +652,7 @@ void CScoreboard::OnRender() Graphics()->MapScreen(0, 0, Width, Height); const CNetObj_GameInfo *pGameInfoObj = GameClient()->m_Snap.m_pGameInfoObj; - const bool Teams = pGameInfoObj && (pGameInfoObj->m_GameFlags & GAMEFLAG_TEAMS); + const bool Teams = GameClient()->IsTeamPlay(); const auto &aTeamSize = GameClient()->m_Snap.m_aTeamSize; const int NumPlayers = Teams ? maximum(aTeamSize[TEAM_RED], aTeamSize[TEAM_BLUE]) : aTeamSize[TEAM_RED]; diff --git a/src/game/client/components/statboard.cpp b/src/game/client/components/statboard.cpp index 2cfe85b0b95..dd2e84904a9 100644 --- a/src/game/client/components/statboard.cpp +++ b/src/game/client/components/statboard.cpp @@ -165,7 +165,7 @@ void CStatboard::RenderGlobalStats() } // sort blue players by score after - if(m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_TEAMS) + if(m_pClient->IsTeamPlay()) { for(const auto *pInfo : m_pClient->m_Snap.m_apInfoByScore) { @@ -474,7 +474,7 @@ void CStatboard::FormatStats(char *pDest, size_t DestSize) } // sort blue players by score after - if(m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_TEAMS) + if(m_pClient->IsTeamPlay()) { for(const auto *pInfo : m_pClient->m_Snap.m_apInfoByScore) { diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index f3127dd757d..7bebbc6dbb8 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -3104,7 +3104,7 @@ void CGameClient::UpdatePrediction() if(m_Snap.m_aCharacters[i].m_Active) { bool IsLocal = (i == m_Snap.m_LocalClientId || (PredictDummy() && i == m_PredictedDummyId)); - int GameTeam = (m_Snap.m_pGameInfoObj && (m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_TEAMS)) ? m_aClients[i].m_Team : i; + int GameTeam = IsTeamPlay() ? m_aClients[i].m_Team : i; m_GameWorld.NetCharAdd(i, &m_Snap.m_aCharacters[i].m_Cur, m_Snap.m_aCharacters[i].m_HasExtendedData ? &m_Snap.m_aCharacters[i].m_ExtendedData : 0, GameTeam, IsLocal);