Skip to content

Commit

Permalink
Merge pull request ddnet#9501 from Robyt3/Client-IsTeamPlay-Refactoring
Browse files Browse the repository at this point in the history
Use `CGameClient::IsTeamPlay` function consistently
  • Loading branch information
def- authored Jan 9, 2025
2 parents e061efc + bc487f7 commit bb2afcc
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/game/client/components/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 2 additions & 6 deletions src/game/client/components/ghost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 4 additions & 5 deletions src/game/client/components/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,14 @@ 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;

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);
Expand All @@ -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
Expand Down Expand Up @@ -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) ?
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions src/game/client/components/menus_ingame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/game/client/components/nameplates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 4 additions & 7 deletions src/game/client/components/players.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions src/game/client/components/scoreboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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];

Expand Down
4 changes: 2 additions & 2 deletions src/game/client/components/statboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/game/client/gameclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit bb2afcc

Please sign in to comment.