]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/teams.qh
9342b4c00f4949de2f4e50befe8baf1cc99f7e85
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / teams.qh
1 #ifndef TEAMS_H
2 #define TEAMS_H
3
4 REGISTRY(Teams, BITS(5))
5 #define Teams_from(i) _Teams_from(i, TEAM_SPECTATOR)
6 REGISTER_REGISTRY(Teams)
7 REGISTRY_CHECK(Teams)
8
9 CLASS(Team, Object)
10     ATTRIB(Team, m_name, string, string_null)
11     ATTRIB(Team, m_name_nonls, string, string_null)
12     ATTRIB(Team, m_playercolor, int, 0)
13     ATTRIB(Team, m_colorstr, string, string_null)
14     ATTRIB(Team, m_color, vector, '0 0 0')
15     CONSTRUCTOR(Team, string _name, string _name_nonls, int _playercolor, string _colorstr, vector _color) {
16         CONSTRUCT(Team);
17         #ifndef CSQC
18         _playercolor++;
19         #endif
20         this.team = _playercolor; // for team numbers that aren't stupid, use `this.m_id`
21
22         this.m_name = _name;
23         this.m_name_nonls = _name_nonls;
24         this.m_playercolor = _playercolor;
25         this.m_colorstr = _colorstr;
26         this.m_color = _color;
27     }
28 ENDCLASS(Team)
29
30 #define TEAM(id, ...) REGISTER(Teams, id, m_id, NEW(Team, __VA_ARGS__))
31
32 TEAM(TEAM_1,    _("Red"),       "Red",      4,      "^1", '1      0.0625 0.0625'); // 0xFF0F0F
33 TEAM(TEAM_2,    _("Blue"),      "Blue",     13,     "^4", '0.0625 0.0625 1     '); // 0x0F0FFF
34 TEAM(TEAM_3,    _("Yellow"),    "Yellow",   12,     "^3", '1      1      0.0625'); // 0xFFFF0F
35 TEAM(TEAM_4,    _("Pink"),      "Pink",     9,      "^6", '1      0.0625 1     '); // 0xFF0FFF
36 TEAM(TEAM_SPEC, _("Neutral"),   "Neutral",  1337,   "^7", '0      0      0     ');
37
38 #define NUM_TEAM_1 (TEAM_1.m_playercolor)
39 #define NUM_TEAM_2 (TEAM_2.m_playercolor)
40 #define NUM_TEAM_3 (TEAM_3.m_playercolor)
41 #define NUM_TEAM_4 (TEAM_4.m_playercolor)
42 #define NUM_SPECTATOR (TEAM_SPEC.m_playercolor)
43
44 #define COL_TEAM_1 (TEAM_1.m_colorstr)
45 #define COL_TEAM_2 (TEAM_2.m_colorstr)
46 #define COL_TEAM_3 (TEAM_3.m_colorstr)
47 #define COL_TEAM_4 (TEAM_4.m_colorstr)
48 /** must be #defined, const globals drop the translation attribute */
49 #define NAME_TEAM _("Team")
50 #define NAME_TEAM_1 (TEAM_1.m_name)
51 #define NAME_TEAM_2 (TEAM_2.m_name)
52 #define NAME_TEAM_3 (TEAM_3.m_name)
53 #define NAME_TEAM_4 (TEAM_4.m_name)
54 #define NAME_NEUTRAL (TEAM_SPEC.m_name)
55
56 // used for replacement in filenames or such where the name CANNOT be allowed to be translated
57 #define STATIC_NAME_TEAM_1 (TEAM_1.m_name_nonls)
58 #define STATIC_NAME_TEAM_2 (TEAM_2.m_name_nonls)
59 #define STATIC_NAME_TEAM_3 (TEAM_3.m_name_nonls)
60 #define STATIC_NAME_TEAM_4 (TEAM_4.m_name_nonls)
61
62 #ifdef CSQC
63 float teamplay;
64 float myteam;
65 #endif
66
67 Team TM(int teamid) {
68     if (teamid == 0) return NULL;
69     FOREACH(Teams, it.team == teamid, return it);
70     LOG_SEVEREF("Unknown team: %d", teamid);
71     return NULL;
72 }
73
74 #define Team_ColorCode(this) (TM(this).m_colorstr)
75
76 #define Team_ColorRGB(this) (TM(this).m_color)
77
78 #define Team_ColorName(this) (TM(this).m_name_nonls)
79
80 // used for replacement in filenames or such where the name CANNOT be allowed to be translated
81 #define Static_Team_ColorName(this) (TM(this).m_name)
82
83 int Team_ColorToTeam(string team_color)
84 {
85         switch(strtolower(team_color))
86         {
87                 case "red": return NUM_TEAM_1;
88         case "blue": return NUM_TEAM_2;
89         case "yellow": return NUM_TEAM_3;
90         case "pink": return NUM_TEAM_4;
91         case "auto": return 0;
92         }
93
94         return -1;
95 }
96
97 int Team_NumberToTeam(int number)
98 {
99         switch(number)
100         {
101                 case 1: return NUM_TEAM_1;
102                 case 2: return NUM_TEAM_2;
103                 case 3: return NUM_TEAM_3;
104                 case 4: return NUM_TEAM_4;
105         }
106
107         return -1;
108 }
109
110 int Team_TeamToNumber(int teamid)
111 {
112         switch(teamid)
113         {
114                 case NUM_TEAM_1: return 1;
115                 case NUM_TEAM_2: return 2;
116                 case NUM_TEAM_3: return 3;
117                 case NUM_TEAM_4: return 4;
118         }
119
120         return -1;
121 }
122
123
124 // legacy aliases for shitty code
125 #define ColorByTeam(number) Team_NumberToTeam(number + 1)
126
127 // useful aliases
128 #define Team_ColorName_Lower(teamid) strtolower(Team_ColorName(teamid))
129 #define Team_ColorName_Upper(teamid) strtoupper(Team_ColorName(teamid))
130
131 // used for replacement in filenames or such where the name CANNOT be allowed to be translated
132 #define Static_Team_ColorName_Lower(teamid) strtolower(Static_Team_ColorName(teamid))
133 #define Static_Team_ColorName_Upper(teamid) strtoupper(Static_Team_ColorName(teamid))
134
135 #define Team_FullName(teamid) strcat(Team_ColorName(teamid), " ", NAME_TEAM, "^7")
136 #define Team_ColoredFullName(teamid) strcat(Team_ColorCode(teamid), Team_ColorName(teamid), " ", NAME_TEAM, "^7")
137
138 #define Team_NumberToFullName(number) Team_FullName(Team_NumberToTeam(number))
139 #define Team_NumberToColoredFullName(number) Team_ColoredFullName(Team_NumberToTeam(number))
140
141 // replace these flags in a string with the strings provided
142 #define TCR(input,teamcolor,teamtext) strreplace("^TC", teamcolor, strreplace("^TT", teamtext, input))
143
144 // safe team comparisons
145 #define SAME_TEAM(a,b) (teamplay ? (a.team == b.team) : (a == b))
146 #define DIFF_TEAM(a,b) (teamplay ? (a.team != b.team) : (a != b))
147
148 #endif