mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Code Style of some files converted from K&R to BSD/Allman
This commit is contained in:
parent
b909829b61
commit
22aa8940a7
|
@ -581,7 +581,8 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker)
|
||||||
else
|
else
|
||||||
g_GameClient.m_pSounds->Play(CSounds::CHN_GLOBAL, pMsg->m_Soundid, 1.0f, vec2(0,0));
|
g_GameClient.m_pSounds->Play(CSounds::CHN_GLOBAL, pMsg->m_Soundid, 1.0f, vec2(0,0));
|
||||||
}
|
}
|
||||||
else if(MsgId == NETMSGTYPE_CL_TEAMSSTATE) {
|
else if(MsgId == NETMSGTYPE_CL_TEAMSSTATE)
|
||||||
|
{
|
||||||
CNetMsg_Cl_TeamsState *pMsg = (CNetMsg_Cl_TeamsState *)pRawMsg;
|
CNetMsg_Cl_TeamsState *pMsg = (CNetMsg_Cl_TeamsState *)pRawMsg;
|
||||||
m_Teams.Team(0, pMsg->m_Tee0);
|
m_Teams.Team(0, pMsg->m_Tee0);
|
||||||
m_Teams.Team(1, pMsg->m_Tee1);
|
m_Teams.Team(1, pMsg->m_Tee1);
|
||||||
|
@ -600,10 +601,10 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker)
|
||||||
m_Teams.Team(14, pMsg->m_Tee14);
|
m_Teams.Team(14, pMsg->m_Tee14);
|
||||||
m_Teams.Team(15, pMsg->m_Tee15);
|
m_Teams.Team(15, pMsg->m_Tee15);
|
||||||
for(int i = 0; i < MAX_CLIENTS; i++)
|
for(int i = 0; i < MAX_CLIENTS; i++)
|
||||||
{
|
|
||||||
dbg_msg1("Teams", "Team = %d", m_Teams.Team(i));
|
dbg_msg1("Teams", "Team = %d", m_Teams.Team(i));
|
||||||
}
|
}
|
||||||
} else if(MsgId == NETMSGTYPE_SV_PLAYERTIME) {
|
else if(MsgId == NETMSGTYPE_SV_PLAYERTIME)
|
||||||
|
{
|
||||||
CNetMsg_Sv_PlayerTime *pMsg = (CNetMsg_Sv_PlayerTime *)pRawMsg;
|
CNetMsg_Sv_PlayerTime *pMsg = (CNetMsg_Sv_PlayerTime *)pRawMsg;
|
||||||
m_aClients[pMsg->m_Cid].m_Score = pMsg->m_Time;
|
m_aClients[pMsg->m_Cid].m_Score = pMsg->m_Time;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
#include "teams.h"
|
#include "teams.h"
|
||||||
#include <engine/shared/config.h>
|
#include <engine/shared/config.h>
|
||||||
|
|
||||||
CGameTeams::CGameTeams(CGameContext *pGameContext) : m_pGameContext(pGameContext) {
|
CGameTeams::CGameTeams(CGameContext *pGameContext) : m_pGameContext(pGameContext)
|
||||||
|
{
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGameTeams::Reset() {
|
void CGameTeams::Reset()
|
||||||
|
{
|
||||||
m_Core.Reset();
|
m_Core.Reset();
|
||||||
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
for(int i = 0; i < MAX_CLIENTS; ++i)
|
||||||
|
{
|
||||||
m_TeamState[i] = EMPTY;
|
m_TeamState[i] = EMPTY;
|
||||||
m_TeeFinished[i] = false;
|
m_TeeFinished[i] = false;
|
||||||
m_MembersCount[i] = 0;
|
m_MembersCount[i] = 0;
|
||||||
|
@ -15,7 +18,7 @@ void CGameTeams::Reset() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGameTeams::OnCharacterStart(int id) {
|
void CGameTeams::OnCharacterStart(int id){
|
||||||
int Tick = Server()->Tick();
|
int Tick = Server()->Tick();
|
||||||
CCharacter* StartingChar = Character(id);
|
CCharacter* StartingChar = Character(id);
|
||||||
if(!StartingChar)
|
if(!StartingChar)
|
||||||
|
@ -77,7 +80,8 @@ void CGameTeams::OnCharacterStart(int id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGameTeams::OnCharacterFinish(int id) {
|
void CGameTeams::OnCharacterFinish(int id)
|
||||||
|
{
|
||||||
if(m_Core.Team(id) == TEAM_FLOCK || m_Core.Team(id) == TEAM_SUPER)
|
if(m_Core.Team(id) == TEAM_FLOCK || m_Core.Team(id) == TEAM_SUPER)
|
||||||
{
|
{
|
||||||
Character(id)->OnFinish();
|
Character(id)->OnFinish();
|
||||||
|
@ -111,32 +115,26 @@ void CGameTeams::OnCharacterFinish(int id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CGameTeams::SetCharacterTeam(int id, int Team) {
|
bool CGameTeams::SetCharacterTeam(int id, int Team)
|
||||||
|
{
|
||||||
//Check on wrong parameters. +1 for TEAM_SUPER
|
//Check on wrong parameters. +1 for TEAM_SUPER
|
||||||
if(id < 0 || id >= MAX_CLIENTS || Team < 0 || Team >= MAX_CLIENTS + 1) {
|
if(id < 0 || id >= MAX_CLIENTS || Team < 0 || Team >= MAX_CLIENTS + 1)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
//You can join to TEAM_SUPER at any time, but any other group you cannot if it started
|
//You can join to TEAM_SUPER at any time, but any other group you cannot if it started
|
||||||
if(Team != TEAM_SUPER && m_TeamState[Team] >= CLOSED) {
|
if(Team != TEAM_SUPER && m_TeamState[Team] >= CLOSED)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
//No need to switch team if you there
|
//No need to switch team if you there
|
||||||
if(m_Core.Team(id) == Team) {
|
if(m_Core.Team(id) == Team)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
//You cannot be in TEAM_SUPER if you not super
|
//You cannot be in TEAM_SUPER if you not super
|
||||||
if(Team == TEAM_SUPER && !Character(id)->m_Super) return false;
|
if(Team == TEAM_SUPER && !Character(id)->m_Super) return false;
|
||||||
//if you begin race
|
//if you begin race
|
||||||
if(Character(id)->m_DDRaceState != DDRACE_NONE) {
|
if(Character(id)->m_DDRaceState != DDRACE_NONE)
|
||||||
//you will be killed if you try to join FLOCK
|
//you will be killed if you try to join FLOCK
|
||||||
if(Team == TEAM_FLOCK && m_Core.Team(id) != TEAM_FLOCK) {
|
if(Team == TEAM_FLOCK && m_Core.Team(id) != TEAM_FLOCK)
|
||||||
Character(id)->GetPlayer()->KillCharacter(WEAPON_GAME);
|
Character(id)->GetPlayer()->KillCharacter(WEAPON_GAME);
|
||||||
} else {
|
else if(Team != TEAM_SUPER)
|
||||||
if(Team != TEAM_SUPER) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SetForceCharacterTeam(id, Team);
|
SetForceCharacterTeam(id, Team);
|
||||||
|
|
||||||
|
|
||||||
|
@ -144,28 +142,28 @@ bool CGameTeams::SetCharacterTeam(int id, int Team) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGameTeams::SetForceCharacterTeam(int id, int Team) {
|
void CGameTeams::SetForceCharacterTeam(int id, int Team)
|
||||||
|
{
|
||||||
m_TeeFinished[id] = false;
|
m_TeeFinished[id] = false;
|
||||||
if(m_Core.Team(id) != TEAM_FLOCK
|
if(m_Core.Team(id) != TEAM_FLOCK
|
||||||
&& m_Core.Team(id) != TEAM_SUPER
|
&& m_Core.Team(id) != TEAM_SUPER
|
||||||
&& m_TeamState[m_Core.Team(id)] != EMPTY) {
|
&& m_TeamState[m_Core.Team(id)] != EMPTY)
|
||||||
|
{
|
||||||
bool NoOneInOldTeam = true;
|
bool NoOneInOldTeam = true;
|
||||||
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
for(int i = 0; i < MAX_CLIENTS; ++i)
|
||||||
if(i != id && m_Core.Team(id) == m_Core.Team(i)) {
|
if(i != id && m_Core.Team(id) == m_Core.Team(i))
|
||||||
|
{
|
||||||
NoOneInOldTeam = false;//all good exists someone in old team
|
NoOneInOldTeam = false;//all good exists someone in old team
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
if(NoOneInOldTeam)
|
||||||
if(NoOneInOldTeam) {
|
|
||||||
m_TeamState[m_Core.Team(id)] = EMPTY;
|
m_TeamState[m_Core.Team(id)] = EMPTY;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(Count(m_Core.Team(id)) > 0) m_MembersCount[m_Core.Team(id)]--;
|
if(Count(m_Core.Team(id)) > 0) m_MembersCount[m_Core.Team(id)]--;
|
||||||
m_Core.Team(id, Team);
|
m_Core.Team(id, Team);
|
||||||
if(m_Core.Team(id) != TEAM_SUPER) m_MembersCount[m_Core.Team(id)]++;
|
if(m_Core.Team(id) != TEAM_SUPER) m_MembersCount[m_Core.Team(id)]++;
|
||||||
if(Team != TEAM_SUPER && m_TeamState[Team] == EMPTY) {
|
if(Team != TEAM_SUPER && m_TeamState[Team] == EMPTY)
|
||||||
ChangeTeamState(Team, OPEN);
|
ChangeTeamState(Team, OPEN);
|
||||||
}
|
|
||||||
dbg_msg1("Teams", "Id = %d Team = %d", id, Team);
|
dbg_msg1("Teams", "Id = %d Team = %d", id, Team);
|
||||||
|
|
||||||
for (int ClientID = 0; ClientID < MAX_CLIENTS; ++ClientID)
|
for (int ClientID = 0; ClientID < MAX_CLIENTS; ++ClientID)
|
||||||
|
@ -175,41 +173,42 @@ void CGameTeams::SetForceCharacterTeam(int id, int Team) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int CGameTeams::Count(int Team) const{
|
int CGameTeams::Count(int Team) const
|
||||||
|
{
|
||||||
if(Team == TEAM_SUPER) return -1;
|
if(Team == TEAM_SUPER) return -1;
|
||||||
return m_MembersCount[Team];
|
return m_MembersCount[Team];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CGameTeams::ChangeTeamState(int Team, int State) {
|
void CGameTeams::ChangeTeamState(int Team, int State)
|
||||||
|
{
|
||||||
m_TeamState[Team] = State;
|
m_TeamState[Team] = State;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool CGameTeams::TeamFinished(int Team) {
|
bool CGameTeams::TeamFinished(int Team)
|
||||||
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
{
|
||||||
if(m_Core.Team(i) == Team && !m_TeeFinished[i]) {
|
for(int i = 0; i < MAX_CLIENTS; ++i)
|
||||||
|
if(m_Core.Team(i) == Team && !m_TeeFinished[i])
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CGameTeams::TeamMask(int Team) {
|
int CGameTeams::TeamMask(int Team)
|
||||||
|
{
|
||||||
if(Team == TEAM_SUPER) return -1;
|
if(Team == TEAM_SUPER) return -1;
|
||||||
int Mask = 0;
|
int Mask = 0;
|
||||||
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
for(int i = 0; i < MAX_CLIENTS; ++i)
|
||||||
if((Character(i) && (m_Core.Team(i) == Team || m_Core.Team(i) == TEAM_SUPER))
|
if((Character(i) && (m_Core.Team(i) == Team || m_Core.Team(i) == TEAM_SUPER))
|
||||||
|| (GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() == -1)) {
|
|| (GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() == -1))
|
||||||
Mask |= 1 << i;
|
Mask |= 1 << i;
|
||||||
}
|
|
||||||
}
|
|
||||||
return Mask;
|
return Mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGameTeams::SendTeamsState(int Cid) {
|
void CGameTeams::SendTeamsState(int Cid)
|
||||||
|
{
|
||||||
CNetMsg_Cl_TeamsState Msg;
|
CNetMsg_Cl_TeamsState Msg;
|
||||||
Msg.m_Tee0 = m_Core.Team(0);
|
Msg.m_Tee0 = m_Core.Team(0);
|
||||||
Msg.m_Tee1 = m_Core.Team(1);
|
Msg.m_Tee1 = m_Core.Team(1);
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
#include <game/teamscore.h>
|
#include <game/teamscore.h>
|
||||||
#include <game/server/gamecontext.h>
|
#include <game/server/gamecontext.h>
|
||||||
|
|
||||||
class CGameTeams {
|
class CGameTeams
|
||||||
|
{
|
||||||
int m_TeamState[MAX_CLIENTS];
|
int m_TeamState[MAX_CLIENTS];
|
||||||
int m_MembersCount[MAX_CLIENTS];
|
int m_MembersCount[MAX_CLIENTS];
|
||||||
bool m_TeeFinished[MAX_CLIENTS];
|
bool m_TeeFinished[MAX_CLIENTS];
|
||||||
|
@ -13,7 +14,8 @@ class CGameTeams {
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum {
|
enum
|
||||||
|
{
|
||||||
EMPTY,
|
EMPTY,
|
||||||
OPEN,
|
OPEN,
|
||||||
CLOSED,
|
CLOSED,
|
||||||
|
|
|
@ -1,28 +1,33 @@
|
||||||
#include "teamscore.h"
|
#include "teamscore.h"
|
||||||
|
|
||||||
CTeamsCore::CTeamsCore() {
|
CTeamsCore::CTeamsCore()
|
||||||
|
{
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CTeamsCore::SameTeam(int Cid1, int Cid2) {
|
bool CTeamsCore::SameTeam(int Cid1, int Cid2)
|
||||||
|
{
|
||||||
return m_Team[Cid1] == m_Team[Cid2];
|
return m_Team[Cid1] == m_Team[Cid2];
|
||||||
}
|
}
|
||||||
|
|
||||||
int CTeamsCore::Team(int Cid) {
|
int CTeamsCore::Team(int Cid)
|
||||||
|
{
|
||||||
return m_Team[Cid];
|
return m_Team[Cid];
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTeamsCore::Team(int Cid, int Team) {
|
void CTeamsCore::Team(int Cid, int Team)
|
||||||
|
{
|
||||||
m_Team[Cid] = Team;
|
m_Team[Cid] = Team;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CTeamsCore::CanCollide(int Cid1, int Cid2) {
|
bool CTeamsCore::CanCollide(int Cid1, int Cid2)
|
||||||
|
{
|
||||||
if(m_Team[Cid1] == TEAM_SUPER || m_Team[Cid2] == TEAM_SUPER) return true;
|
if(m_Team[Cid1] == TEAM_SUPER || m_Team[Cid2] == TEAM_SUPER) return true;
|
||||||
return m_Team[Cid1] == m_Team[Cid2];
|
return m_Team[Cid1] == m_Team[Cid2];
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTeamsCore::Reset() {
|
void CTeamsCore::Reset()
|
||||||
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
{
|
||||||
|
for(int i = 0; i < MAX_CLIENTS; ++i)
|
||||||
m_Team[i] = TEAM_FLOCK;
|
m_Team[i] = TEAM_FLOCK;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue