mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
cleaned up gameclients player/team calculation
This commit is contained in:
parent
b1d28c5740
commit
65448ea7b0
|
@ -401,8 +401,7 @@ void CHud::RenderTeambalanceWarning()
|
|||
bool Flash = time_get()/(time_freq()/2)%2 == 0;
|
||||
if(m_pClient->m_GameInfo.m_GameFlags&GAMEFLAG_TEAMS)
|
||||
{
|
||||
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))
|
||||
if(g_Config.m_ClWarningTeambalance && absolute(m_pClient->m_GameInfo.m_aTeamSize[TEAM_RED]-m_pClient->m_GameInfo.m_aTeamSize[TEAM_BLUE]) >= 2)
|
||||
{
|
||||
const char *pText = Localize("Please balance teams!");
|
||||
if(Flash)
|
||||
|
|
|
@ -347,7 +347,7 @@ void CMenus::RenderServerInfo(CUIRect MainView)
|
|||
Localize("Map"), CurrentServerInfo.m_aMap,
|
||||
Localize("Score limit"), m_pClient->m_GameInfo.m_ScoreLimit,
|
||||
Localize("Time limit"), m_pClient->m_GameInfo.m_TimeLimit,
|
||||
Localize("Players"), m_pClient->m_Snap.m_NumPlayers, CurrentServerInfo.m_MaxClients
|
||||
Localize("Players"), m_pClient->m_GameInfo.m_NumPlayers, CurrentServerInfo.m_MaxClients
|
||||
);
|
||||
TextRender()->Text(0, GameInfo.x+x, GameInfo.y+y, 20, aBuf, 250);
|
||||
|
||||
|
|
|
@ -172,13 +172,13 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch
|
|||
float LineHeight = 60.0f;
|
||||
float TeeSizeMod = 1.0f;
|
||||
float Spacing = 16.0f;
|
||||
if(m_pClient->m_Snap.m_aTeamSize[Team] > 12)
|
||||
if(m_pClient->m_GameInfo.m_aTeamSize[Team] > 12)
|
||||
{
|
||||
LineHeight = 40.0f;
|
||||
TeeSizeMod = 0.8f;
|
||||
Spacing = 0.0f;
|
||||
}
|
||||
else if(m_pClient->m_Snap.m_aTeamSize[Team] > 8)
|
||||
else if(m_pClient->m_GameInfo.m_aTeamSize[Team] > 8)
|
||||
{
|
||||
LineHeight = 50.0f;
|
||||
TeeSizeMod = 0.9f;
|
||||
|
|
|
@ -335,6 +335,8 @@ void CGameClient::OnReset()
|
|||
m_All.m_paComponents[i]->OnReset();
|
||||
|
||||
m_LocalClientID = -1;
|
||||
m_GameInfo.m_NumPlayers = 0;
|
||||
m_GameInfo.m_aTeamSize[TEAM_RED] = m_GameInfo.m_aTeamSize[TEAM_BLUE] = 0;
|
||||
m_DemoSpecID = SPEC_FREEVIEW;
|
||||
m_Tuning = CTuningParams();
|
||||
}
|
||||
|
@ -548,6 +550,11 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker)
|
|||
m_aClients[pMsg->m_ClientID].m_Friend = Friends()->IsFriend(m_aClients[pMsg->m_ClientID].m_aName, m_aClients[pMsg->m_ClientID].m_aClan, true);
|
||||
|
||||
m_aClients[pMsg->m_ClientID].UpdateRenderInfo(true);
|
||||
|
||||
m_GameInfo.m_NumPlayers++;
|
||||
// calculate team-balance
|
||||
if(m_aClients[pMsg->m_ClientID].m_Team != TEAM_SPECTATORS)
|
||||
m_GameInfo.m_aTeamSize[m_aClients[pMsg->m_ClientID].m_Team]++;
|
||||
}
|
||||
else if(MsgId == NETMSGTYPE_SV_CLIENTDROP)
|
||||
{
|
||||
|
@ -567,6 +574,11 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker)
|
|||
str_format(aBuf, sizeof(aBuf), Localize("'%s' has left the game"), m_aClients[pMsg->m_ClientID].m_aName);
|
||||
m_pChat->AddLine(-1, 0, aBuf);
|
||||
|
||||
m_GameInfo.m_NumPlayers--;
|
||||
// calculate team-balance
|
||||
if(m_aClients[pMsg->m_ClientID].m_Team != TEAM_SPECTATORS)
|
||||
m_GameInfo.m_aTeamSize[m_aClients[pMsg->m_ClientID].m_Team]--;
|
||||
|
||||
m_aClients[pMsg->m_ClientID].Reset();
|
||||
}
|
||||
else if(MsgId == NETMSGTYPE_SV_GAMEINFO)
|
||||
|
@ -584,7 +596,12 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker)
|
|||
else if(MsgId == NETMSGTYPE_SV_TEAM)
|
||||
{
|
||||
CNetMsg_Sv_Team *pMsg = (CNetMsg_Sv_Team *)pRawMsg;
|
||||
// calculate team-balance
|
||||
if(m_aClients[pMsg->m_ClientID].m_Team != TEAM_SPECTATORS)
|
||||
m_GameInfo.m_aTeamSize[m_aClients[pMsg->m_ClientID].m_Team]--;
|
||||
m_aClients[pMsg->m_ClientID].m_Team = pMsg->m_Team;
|
||||
if(m_aClients[pMsg->m_ClientID].m_Team != TEAM_SPECTATORS)
|
||||
m_GameInfo.m_aTeamSize[m_aClients[pMsg->m_ClientID].m_Team]++;
|
||||
if(pMsg->m_Silent == 0)
|
||||
{
|
||||
char aBuf[128];
|
||||
|
@ -754,8 +771,6 @@ void CGameClient::OnNewSnapshot()
|
|||
|
||||
// go trough all the items in the snapshot and gather the info we want
|
||||
{
|
||||
m_Snap.m_aTeamSize[TEAM_RED] = m_Snap.m_aTeamSize[TEAM_BLUE] = 0;
|
||||
|
||||
int Num = Client()->SnapNumItems(IClient::SNAP_CURRENT);
|
||||
for(int i = 0; i < Num; i++)
|
||||
{
|
||||
|
@ -805,7 +820,6 @@ void CGameClient::OnNewSnapshot()
|
|||
m_Snap.m_paPlayerInfos[ClientID] = pInfo;
|
||||
m_Snap.m_aInfoByScore[ClientID].m_pPlayerInfo = pInfo;
|
||||
m_Snap.m_aInfoByScore[ClientID].m_ClientID = ClientID;
|
||||
m_Snap.m_NumPlayers++;
|
||||
|
||||
if(m_LocalClientID == ClientID)
|
||||
{
|
||||
|
@ -817,10 +831,6 @@ void CGameClient::OnNewSnapshot()
|
|||
m_Snap.m_SpecInfo.m_SpectatorID = SPEC_FREEVIEW;
|
||||
}
|
||||
}
|
||||
|
||||
// calculate team-balance
|
||||
if(m_aClients[ClientID].m_Team != TEAM_SPECTATORS)
|
||||
m_Snap.m_aTeamSize[m_aClients[ClientID].m_Team]++;
|
||||
}
|
||||
else if(Item.m_Type == NETOBJTYPE_CHARACTER)
|
||||
{
|
||||
|
|
|
@ -131,9 +131,6 @@ public:
|
|||
CPlayerInfoItem m_aInfoByScore[MAX_CLIENTS];
|
||||
CPlayerInfoItem m_aInfoByTeam[MAX_CLIENTS];
|
||||
|
||||
int m_NumPlayers;
|
||||
int m_aTeamSize[2];
|
||||
|
||||
// spectate data
|
||||
struct CSpectateInfo
|
||||
{
|
||||
|
@ -198,6 +195,9 @@ public:
|
|||
int m_TimeLimit;
|
||||
int m_MatchNum;
|
||||
int m_MatchCurrent;
|
||||
|
||||
int m_NumPlayers;
|
||||
int m_aTeamSize[NUM_TEAMS];
|
||||
};
|
||||
|
||||
CGameInfo m_GameInfo;
|
||||
|
|
Loading…
Reference in a new issue