cleaned up gameclients player/team calculation

This commit is contained in:
oy 2012-08-03 18:46:41 +02:00
parent b1d28c5740
commit 65448ea7b0
5 changed files with 24 additions and 15 deletions

View file

@ -401,8 +401,7 @@ void CHud::RenderTeambalanceWarning()
bool Flash = time_get()/(time_freq()/2)%2 == 0; bool Flash = time_get()/(time_freq()/2)%2 == 0;
if(m_pClient->m_GameInfo.m_GameFlags&GAMEFLAG_TEAMS) 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 && absolute(m_pClient->m_GameInfo.m_aTeamSize[TEAM_RED]-m_pClient->m_GameInfo.m_aTeamSize[TEAM_BLUE]) >= 2)
if (g_Config.m_ClWarningTeambalance && (TeamDiff >= 2 || TeamDiff <= -2))
{ {
const char *pText = Localize("Please balance teams!"); const char *pText = Localize("Please balance teams!");
if(Flash) if(Flash)

View file

@ -347,7 +347,7 @@ void CMenus::RenderServerInfo(CUIRect MainView)
Localize("Map"), CurrentServerInfo.m_aMap, Localize("Map"), CurrentServerInfo.m_aMap,
Localize("Score limit"), m_pClient->m_GameInfo.m_ScoreLimit, Localize("Score limit"), m_pClient->m_GameInfo.m_ScoreLimit,
Localize("Time limit"), m_pClient->m_GameInfo.m_TimeLimit, 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); TextRender()->Text(0, GameInfo.x+x, GameInfo.y+y, 20, aBuf, 250);

View file

@ -172,13 +172,13 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch
float LineHeight = 60.0f; float LineHeight = 60.0f;
float TeeSizeMod = 1.0f; float TeeSizeMod = 1.0f;
float Spacing = 16.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; LineHeight = 40.0f;
TeeSizeMod = 0.8f; TeeSizeMod = 0.8f;
Spacing = 0.0f; 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; LineHeight = 50.0f;
TeeSizeMod = 0.9f; TeeSizeMod = 0.9f;

View file

@ -335,6 +335,8 @@ void CGameClient::OnReset()
m_All.m_paComponents[i]->OnReset(); m_All.m_paComponents[i]->OnReset();
m_LocalClientID = -1; 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_DemoSpecID = SPEC_FREEVIEW;
m_Tuning = CTuningParams(); 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].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_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) 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); 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_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(); m_aClients[pMsg->m_ClientID].Reset();
} }
else if(MsgId == NETMSGTYPE_SV_GAMEINFO) else if(MsgId == NETMSGTYPE_SV_GAMEINFO)
@ -584,7 +596,12 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker)
else if(MsgId == NETMSGTYPE_SV_TEAM) else if(MsgId == NETMSGTYPE_SV_TEAM)
{ {
CNetMsg_Sv_Team *pMsg = (CNetMsg_Sv_Team *)pRawMsg; 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; 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) if(pMsg->m_Silent == 0)
{ {
char aBuf[128]; char aBuf[128];
@ -754,8 +771,6 @@ void CGameClient::OnNewSnapshot()
// go trough all the items in the snapshot and gather the info we want // 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); int Num = Client()->SnapNumItems(IClient::SNAP_CURRENT);
for(int i = 0; i < Num; i++) for(int i = 0; i < Num; i++)
{ {
@ -805,7 +820,6 @@ void CGameClient::OnNewSnapshot()
m_Snap.m_paPlayerInfos[ClientID] = pInfo; m_Snap.m_paPlayerInfos[ClientID] = pInfo;
m_Snap.m_aInfoByScore[ClientID].m_pPlayerInfo = pInfo; m_Snap.m_aInfoByScore[ClientID].m_pPlayerInfo = pInfo;
m_Snap.m_aInfoByScore[ClientID].m_ClientID = ClientID; m_Snap.m_aInfoByScore[ClientID].m_ClientID = ClientID;
m_Snap.m_NumPlayers++;
if(m_LocalClientID == ClientID) if(m_LocalClientID == ClientID)
{ {
@ -817,10 +831,6 @@ void CGameClient::OnNewSnapshot()
m_Snap.m_SpecInfo.m_SpectatorID = SPEC_FREEVIEW; 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) else if(Item.m_Type == NETOBJTYPE_CHARACTER)
{ {

View file

@ -131,9 +131,6 @@ public:
CPlayerInfoItem m_aInfoByScore[MAX_CLIENTS]; CPlayerInfoItem m_aInfoByScore[MAX_CLIENTS];
CPlayerInfoItem m_aInfoByTeam[MAX_CLIENTS]; CPlayerInfoItem m_aInfoByTeam[MAX_CLIENTS];
int m_NumPlayers;
int m_aTeamSize[2];
// spectate data // spectate data
struct CSpectateInfo struct CSpectateInfo
{ {
@ -198,6 +195,9 @@ public:
int m_TimeLimit; int m_TimeLimit;
int m_MatchNum; int m_MatchNum;
int m_MatchCurrent; int m_MatchCurrent;
int m_NumPlayers;
int m_aTeamSize[NUM_TEAMS];
}; };
CGameInfo m_GameInfo; CGameInfo m_GameInfo;