]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Teams: register
authorTimePath <andrew.hardaker1995@gmail.com>
Thu, 17 Mar 2016 04:50:54 +0000 (15:50 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Thu, 17 Mar 2016 04:50:54 +0000 (15:50 +1100)
qcsrc/client/main.qc
qcsrc/client/miscfunctions.qc
qcsrc/client/miscfunctions.qh
qcsrc/client/scoreboard.qc
qcsrc/client/scoreboard.qh
qcsrc/common/teams.qh

index ded6d5b32a9f2d1d4321dbea3b8b37254533684b..ebfc3b161f552c8f6541ed36f4af90533c3d2dcb 100644 (file)
@@ -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;
                }
index fd83aa2d11ed8a9791a4f539a9b0045e111cf00a..e876e3ea8acab50c56662e15e5b8cf045197880f 100644 (file)
@@ -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;
index 32563598b3f79ad2189aa2f2b48d54c9ea0e3b24..53c0d0737b406031ebef60062607c27ea7c6f44d 100644 (file)
@@ -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);
 
index a99db0360c01da61abcca4fc96161ca44c5a6b6e..53539e625927585f03b8ffd8bd2705592cd3ce60 100644 (file)
@@ -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);
        }
 }
 
index 8fccae94845577193f1fbbb2997859707bf5e735..44fbc49367db3fa9e60f421c0bcc588f5443b3ff 100644 (file)
@@ -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();
index 0c0dd7568790ac5955f196249cdec79cc8440ac9..641acb8c2c56582b9e07ee68ab4831ef84de8d8c 100644 (file)
 #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