From f38e046bc18a94d000d38bd7e465b135e0f3da56 Mon Sep 17 00:00:00 2001 From: TimePath Date: Thu, 17 Mar 2016 15:50:54 +1100 Subject: [PATCH] Teams: register --- qcsrc/client/main.qc | 32 +++---- qcsrc/client/miscfunctions.qc | 36 ++++---- qcsrc/client/miscfunctions.qh | 6 +- qcsrc/client/scoreboard.qc | 18 ++-- qcsrc/client/scoreboard.qh | 2 +- qcsrc/common/teams.qh | 152 ++++++++++++++++------------------ 6 files changed, 120 insertions(+), 126 deletions(-) diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index ded6d5b32..ebfc3b161 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -217,13 +217,13 @@ void Shutdown() } .float has_team; -float SetTeam(entity o, int Team) +float SetTeam(entity o, int _team) { - devassert_once(Team); + devassert_once(_team); entity tm; if(teamplay) { - switch(Team) + switch(_team) { case -1: case NUM_TEAM_1: @@ -232,31 +232,31 @@ float SetTeam(entity o, int Team) case NUM_TEAM_4: break; default: - if(GetTeam(Team, false) == world) + if(GetTeam(_team, false) == world) { - LOG_TRACEF("trying to switch to unsupported team %d\n", Team); - Team = NUM_SPECTATOR; + LOG_TRACEF("trying to switch to unsupported team %d\n", _team); + _team = NUM_SPECTATOR; } break; } } else { - switch(Team) + switch(_team) { case -1: case 0: break; default: - if(GetTeam(Team, false) == world) + if(GetTeam(_team, false) == world) { - LOG_TRACEF("trying to switch to unsupported team %d\n", Team); - Team = NUM_SPECTATOR; + LOG_TRACEF("trying to switch to unsupported team %d\n", _team); + _team = NUM_SPECTATOR; } break; } } - if(Team == -1) // leave + if(_team == -1) // leave { if(o.has_team) { @@ -270,18 +270,18 @@ float SetTeam(entity o, int Team) { if (!o.has_team) { - o.team = Team; - tm = GetTeam(Team, true); + o.team = _team; + tm = GetTeam(_team, true); tm.team_size += 1; o.has_team = 1; return true; } - else if(Team != o.team) + else if(_team != o.team) { tm = GetTeam(o.team, false); tm.team_size -= 1; - o.team = Team; - tm = GetTeam(Team, true); + o.team = _team; + tm = GetTeam(_team, true); tm.team_size += 1; return true; } diff --git a/qcsrc/client/miscfunctions.qc b/qcsrc/client/miscfunctions.qc index fd83aa2d1..e876e3ea8 100644 --- a/qcsrc/client/miscfunctions.qc +++ b/qcsrc/client/miscfunctions.qc @@ -77,31 +77,31 @@ void MoveToLast(entity e) AuditLists(); } -float RegisterTeam(entity Team) +float RegisterTeam(entity _team) { - assert_once(Team.team, eprint(Team)); + assert_once(_team.team, eprint(_team)); entity tm; AuditLists(); for(tm = teams.sort_next; tm; tm = tm.sort_next) - if(tm == Team) - error("Team already registered!"); - Team.sort_next = teams.sort_next; - Team.sort_prev = teams; + if(tm == _team) + error("_team already registered!"); + _team.sort_next = teams.sort_next; + _team.sort_prev = teams; if(teams.sort_next) - teams.sort_next.sort_prev = Team; - teams.sort_next = Team; - if(Team.team && Team.team != NUM_SPECTATOR) + teams.sort_next.sort_prev = _team; + teams.sort_next = _team; + if(_team.team && _team.team != NUM_SPECTATOR) ++team_count; AuditLists(); return true; } -void RemoveTeam(entity Team) +void RemoveTeam(entity _team) { entity tm, parent; AuditLists(); parent = teams; - for(tm = teams.sort_next; tm && tm != Team; tm = tm.sort_next) + for(tm = teams.sort_next; tm && tm != _team; tm = tm.sort_next) parent = tm; if(!tm) @@ -109,23 +109,23 @@ void RemoveTeam(entity Team) LOG_INFO(_("Trying to remove a team which is not in the teamlist!")); return; } - parent.sort_next = Team.sort_next; - if(Team.sort_next) - Team.sort_next.sort_prev = parent; - if(Team.team && Team.team != NUM_SPECTATOR) + parent.sort_next = _team.sort_next; + if(_team.sort_next) + _team.sort_next.sort_prev = parent; + if(_team.team && _team.team != NUM_SPECTATOR) --team_count; AuditLists(); } -entity GetTeam(int Team, bool add) +entity GetTeam(int _team, bool add) { - int num = (Team == NUM_SPECTATOR) ? 16 : Team; + int num = (_team == NUM_SPECTATOR) ? 16 : _team; if(teamslots[num]) return teamslots[num]; if (!add) return world; entity tm = new_pure(team); - tm.team = Team; + tm.team = _team; teamslots[num] = tm; RegisterTeam(tm); return tm; diff --git a/qcsrc/client/miscfunctions.qh b/qcsrc/client/miscfunctions.qh index 32563598b..53c0d0737 100644 --- a/qcsrc/client/miscfunctions.qh +++ b/qcsrc/client/miscfunctions.qh @@ -21,11 +21,11 @@ void RemovePlayer(entity player); void MoveToLast(entity e); -float RegisterTeam(entity Team); +float RegisterTeam(entity _team); -void RemoveTeam(entity Team); +void RemoveTeam(entity _team); -entity GetTeam(int Team, bool add); +entity GetTeam(int _team, bool add); vector HUD_GetFontsize(string cvarname); diff --git a/qcsrc/client/scoreboard.qc b/qcsrc/client/scoreboard.qc index a99db0360..53539e625 100644 --- a/qcsrc/client/scoreboard.qc +++ b/qcsrc/client/scoreboard.qc @@ -98,11 +98,11 @@ void HUD_InitScores() Cmd_HUD_SetFields(0); } -float SetTeam(entity pl, float Team); +float SetTeam(entity pl, float _team); //float lastpnum; void HUD_UpdatePlayerTeams() { - float Team; + float _team; entity pl, tmp; float num; @@ -110,8 +110,8 @@ void HUD_UpdatePlayerTeams() for(pl = players.sort_next; pl; pl = pl.sort_next) { num += 1; - Team = entcs_GetScoreTeam(pl.sv_entnum); - if(SetTeam(pl, Team)) + _team = entcs_GetScoreTeam(pl.sv_entnum); + if(SetTeam(pl, _team)) { tmp = pl.sort_prev; HUD_UpdatePlayerPos(pl); @@ -233,15 +233,15 @@ float HUD_CompareTeamScores(entity left, entity right) return false; } -void HUD_UpdateTeamPos(entity Team) +void HUD_UpdateTeamPos(entity _team) { - for(other = Team.sort_next; other && HUD_CompareTeamScores(Team, other); other = Team.sort_next) + for(other = _team.sort_next; other && HUD_CompareTeamScores(_team, other); other = _team.sort_next) { - SORT_SWAP(Team, other); + SORT_SWAP(_team, other); } - for(other = Team.sort_prev; other != teams && HUD_CompareTeamScores(other, Team); other = Team.sort_prev) + for(other = _team.sort_prev; other != teams && HUD_CompareTeamScores(other, _team); other = _team.sort_prev) { - SORT_SWAP(other, Team); + SORT_SWAP(other, _team); } } diff --git a/qcsrc/client/scoreboard.qh b/qcsrc/client/scoreboard.qh index 8fccae948..44fbc4936 100644 --- a/qcsrc/client/scoreboard.qh +++ b/qcsrc/client/scoreboard.qh @@ -9,5 +9,5 @@ void Cmd_HUD_SetFields(float argc); void HUD_DrawScoreboard(); void HUD_InitScores(); void HUD_UpdatePlayerPos(entity pl); -void HUD_UpdateTeamPos(entity Team); +void HUD_UpdateTeamPos(entity _team); float HUD_WouldDrawScoreboard(); diff --git a/qcsrc/common/teams.qh b/qcsrc/common/teams.qh index 0c0dd7568..641acb8c2 100644 --- a/qcsrc/common/teams.qh +++ b/qcsrc/common/teams.qh @@ -1,104 +1,99 @@ #ifndef TEAMS_H #define TEAMS_H -#ifdef TEAMNUMBERS_THAT_ARENT_STUPID -const int NUM_TEAM_1 = 1; // red -const int NUM_TEAM_2 = 2; // blue -const int NUM_TEAM_3 = 3; // yellow -const int NUM_TEAM_4 = 4; // pink -const int NUM_SPECTATOR = 5; -#else -#ifdef CSQC -const int NUM_TEAM_1 = 4; // red -const int NUM_TEAM_2 = 13; // blue -const int NUM_TEAM_3 = 12; // yellow -const int NUM_TEAM_4 = 9; // pink -#else -const int NUM_TEAM_1 = 5; // red -const int NUM_TEAM_2 = 14; // blue -const int NUM_TEAM_3 = 13; // yellow -const int NUM_TEAM_4 = 10; // pink -#endif -const int NUM_SPECTATOR = 1337; -#endif - -const string COL_TEAM_1 = "^1"; -const string COL_TEAM_2 = "^4"; -const string COL_TEAM_3 = "^3"; -const string COL_TEAM_4 = "^6"; -// must be #defined, const globals drop the translation attribute -#define NAME_TEAM_1 _("Red") -#define NAME_TEAM_2 _("Blue") -#define NAME_TEAM_3 _("Yellow") -#define NAME_TEAM_4 _("Pink") +REGISTRY(Teams, BITS(5)) +#define Teams_from(i) _Teams_from(i, TEAM_SPECTATOR) +REGISTER_REGISTRY(Teams) +REGISTRY_CHECK(Teams) + +CLASS(Team, Object) + ATTRIB(Team, m_name, string, string_null) + ATTRIB(Team, m_name_nonls, string, string_null) + ATTRIB(Team, m_playercolor, int, 0) + ATTRIB(Team, m_colorstr, string, string_null) + ATTRIB(Team, m_color, vector, '0 0 0') + CONSTRUCTOR(Team, string _name, string _name_nonls, int _playercolor, string _colorstr, vector _color) { + CONSTRUCT(Team); + #ifndef CSQC + _playercolor++; + #endif + this.team = _playercolor; // for team numbers that aren't stupid, use `this.m_id` + + this.m_name = _name; + this.m_name_nonls = _name_nonls; + this.m_playercolor = _playercolor; + this.m_colorstr = _colorstr; + this.m_color = _color; + } +ENDCLASS(Team) + +#define TEAM(id, ...) REGISTER(Teams, id, m_id, NEW(Team, __VA_ARGS__)) + +TEAM(TEAM_1, _("Red"), "Red", 4, "^1", '1 0.0625 0.0625'); // 0xFF0F0F +TEAM(TEAM_2, _("Blue"), "Blue", 13, "^4", '0.0625 0.0625 1 '); // 0x0F0FFF +TEAM(TEAM_3, _("Yellow"), "Yellow", 12, "^3", '1 1 0.0625'); // 0xFFFF0F +TEAM(TEAM_4, _("Pink"), "Pink", 9, "^6", '1 0.0625 1 '); // 0xFF0FFF +TEAM(TEAM_SPEC, _("Neutral"), "Neutral", 1337, "^7", '0 0 0 '); + +#define NUM_TEAM_1 (TEAM_1.m_playercolor) +#define NUM_TEAM_2 (TEAM_2.m_playercolor) +#define NUM_TEAM_3 (TEAM_3.m_playercolor) +#define NUM_TEAM_4 (TEAM_4.m_playercolor) +#define NUM_SPECTATOR (TEAM_SPEC.m_playercolor) + +#define COL_TEAM_1 (TEAM_1.m_colorstr) +#define COL_TEAM_2 (TEAM_2.m_colorstr) +#define COL_TEAM_3 (TEAM_3.m_colorstr) +#define COL_TEAM_4 (TEAM_4.m_colorstr) +/** must be #defined, const globals drop the translation attribute */ #define NAME_TEAM _("Team") -#define NAME_NEUTRAL _("Neutral") +#define NAME_TEAM_1 (TEAM_1.m_name) +#define NAME_TEAM_2 (TEAM_2.m_name) +#define NAME_TEAM_3 (TEAM_3.m_name) +#define NAME_TEAM_4 (TEAM_4.m_name) +#define NAME_NEUTRAL (TEAM_SPEC.m_name) // used for replacement in filenames or such where the name CANNOT be allowed to be translated -const string STATIC_NAME_TEAM_1 = "Red"; -const string STATIC_NAME_TEAM_2 = "Blue"; -const string STATIC_NAME_TEAM_3 = "Yellow"; -const string STATIC_NAME_TEAM_4 = "Pink"; +#define STATIC_NAME_TEAM_1 (TEAM_1.m_name_nonls) +#define STATIC_NAME_TEAM_2 (TEAM_2.m_name_nonls) +#define STATIC_NAME_TEAM_3 (TEAM_3.m_name_nonls) +#define STATIC_NAME_TEAM_4 (TEAM_4.m_name_nonls) #ifdef CSQC float teamplay; float myteam; #endif -string Team_ColorCode(float teamid) +string Team_ColorCode(int teamid) { - switch(teamid) - { - case NUM_TEAM_1: return COL_TEAM_1; - case NUM_TEAM_2: return COL_TEAM_2; - case NUM_TEAM_3: return COL_TEAM_3; - case NUM_TEAM_4: return COL_TEAM_4; - } - - return "^7"; + Team t = TEAM_SPEC; + FOREACH(Teams, it.team == teamid, t = it; break); + return t.m_colorstr; } -vector Team_ColorRGB(float teamid) +vector Team_ColorRGB(int teamid) { - switch(teamid) - { - case NUM_TEAM_1: return '1 0.0625 0.0625'; // 0xFF0F0F - case NUM_TEAM_2: return '0.0625 0.0625 1'; // 0x0F0FFF - case NUM_TEAM_3: return '1 1 0.0625'; // 0xFFFF0F - case NUM_TEAM_4: return '1 0.0625 1'; // 0xFF0FFF - } - - return '0 0 0'; + Team t = TEAM_SPEC; + FOREACH(Teams, it.team == teamid, t = it; break); + return t.m_color; } -string Team_ColorName(float teamid) +string Team_ColorName(int teamid) { - switch(teamid) - { - case NUM_TEAM_1: return NAME_TEAM_1; - case NUM_TEAM_2: return NAME_TEAM_2; - case NUM_TEAM_3: return NAME_TEAM_3; - case NUM_TEAM_4: return NAME_TEAM_4; - } - - return NAME_NEUTRAL; + Team t = TEAM_SPEC; + FOREACH(Teams, it.team == teamid, t = it; break); + return t.m_name_nonls; } // used for replacement in filenames or such where the name CANNOT be allowed to be translated -string Static_Team_ColorName(float teamid) +string Static_Team_ColorName(int teamid) { - switch(teamid) - { - case NUM_TEAM_1: return STATIC_NAME_TEAM_1; - case NUM_TEAM_2: return STATIC_NAME_TEAM_2; - case NUM_TEAM_3: return STATIC_NAME_TEAM_3; - case NUM_TEAM_4: return STATIC_NAME_TEAM_4; - } - - return NAME_NEUTRAL; + Team t = TEAM_SPEC; + FOREACH(Teams, it.team == teamid, t = it; break); + return t.m_name; } -float Team_ColorToTeam(string team_color) +int Team_ColorToTeam(string team_color) { switch(strtolower(team_color)) { @@ -112,7 +107,7 @@ float Team_ColorToTeam(string team_color) return -1; } -float Team_NumberToTeam(float number) +int Team_NumberToTeam(int number) { switch(number) { @@ -125,7 +120,7 @@ float Team_NumberToTeam(float number) return -1; } -float Team_TeamToNumber(float teamid) +int Team_TeamToNumber(int teamid) { switch(teamid) { @@ -140,7 +135,6 @@ float Team_TeamToNumber(float teamid) // legacy aliases for shitty code -#define TeamByColor(teamid) (Team_TeamToNumber(teamid) - 1) #define ColorByTeam(number) Team_NumberToTeam(number + 1) // useful aliases -- 2.39.2