]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/teams.qh
Merge branch 'master' into z411/bai-server
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / teams.qh
1 #pragma once
2
3 const int NUM_TEAMS = 4; ///< Number of teams in the game.
4
5 #ifdef TEAMNUMBERS_THAT_ARENT_STUPID
6 const int NUM_TEAM_1 = 1; // red
7 const int NUM_TEAM_2 = 2; // blue
8 const int NUM_TEAM_3 = 3; // yellow
9 const int NUM_TEAM_4 = 4; // pink
10 const int NUM_SPECTATOR = 5;
11 #else
12 #ifdef CSQC
13 const int NUM_TEAM_1 = 4; // red
14 const int NUM_TEAM_2 = 13; // blue
15 const int NUM_TEAM_3 = 12; // yellow
16 const int NUM_TEAM_4 = 9; // pink
17 #else
18 const int NUM_TEAM_1 = 5; // red
19 const int NUM_TEAM_2 = 14; // blue
20 const int NUM_TEAM_3 = 13; // yellow
21 const int NUM_TEAM_4 = 10; // pink
22 #endif
23 const int NUM_SPECTATOR = 1337;
24 #endif
25
26 const string COL_TEAM_1 = "^1";
27 const string COL_TEAM_2 = "^4";
28 const string COL_TEAM_3 = "^3";
29 const string COL_TEAM_4 = "^6";
30 // must be #defined, const globals drop the translation attribute
31 #define NAME_TEAM_1 CTX(_("TEAM^Red"))
32 #define NAME_TEAM_2 CTX(_("TEAM^Blue"))
33 #define NAME_TEAM_3 CTX(_("TEAM^Yellow"))
34 #define NAME_TEAM_4 CTX(_("TEAM^Pink"))
35 #define NAME_TEAM _("Team")
36 #define NAME_NEUTRAL _("Neutral")
37
38 // items colors, so they are handled properly in languages which decline things with grammatical gender
39 #define KEY_TEAM_1 CTX(_("KEY^Red"))
40 #define KEY_TEAM_2 CTX(_("KEY^Blue"))
41 #define KEY_TEAM_3 CTX(_("KEY^Yellow"))
42 #define KEY_TEAM_4 CTX(_("KEY^Pink"))
43 #define FLAG_TEAM_1 CTX(_("FLAG^Red"))
44 #define FLAG_TEAM_2 CTX(_("FLAG^Blue"))
45 #define FLAG_TEAM_3 CTX(_("FLAG^Yellow"))
46 #define FLAG_TEAM_4 CTX(_("FLAG^Pink"))
47 #define GENERATOR_TEAM_1 CTX(_("GENERATOR^Red"))
48 #define GENERATOR_TEAM_2 CTX(_("GENERATOR^Blue"))
49 #define GENERATOR_TEAM_3 CTX(_("GENERATOR^Yellow"))
50 #define GENERATOR_TEAM_4 CTX(_("GENERATOR^Pink"))
51
52 // used for replacement in filenames or such where the name CANNOT be allowed to be translated
53 const string STATIC_NAME_TEAM_1 = "Red";
54 const string STATIC_NAME_TEAM_2 = "Blue";
55 const string STATIC_NAME_TEAM_3 = "Yellow";
56 const string STATIC_NAME_TEAM_4 = "Pink";
57
58 #ifdef CSQC
59 bool teamplay;
60 int myteam;
61
62 // z411 used for custom names
63 string teamname_red;
64 string teamname_blue;
65 string teamname_yellow;
66 string teamname_pink;
67 #endif
68
69 string Team_ColorCode(int teamid)
70 {
71         switch(teamid)
72         {
73                 case NUM_TEAM_1: return COL_TEAM_1;
74                 case NUM_TEAM_2: return COL_TEAM_2;
75                 case NUM_TEAM_3: return COL_TEAM_3;
76                 case NUM_TEAM_4: return COL_TEAM_4;
77         }
78
79         return "^7";
80 }
81
82 vector Team_ColorRGB(int teamid)
83 {
84         switch(teamid)
85         {
86                 case NUM_TEAM_1: return '1 0.0625 0.0625'; // 0xFF0F0F
87                 case NUM_TEAM_2: return '0.0625 0.0625 1'; // 0x0F0FFF
88                 case NUM_TEAM_3: return '1 1 0.0625'; // 0xFFFF0F
89                 case NUM_TEAM_4: return '1 0.0625 1'; // 0xFF0FFF
90         }
91
92         return '0 0 0';
93 }
94
95 #ifdef CSQC
96 string Team_CustomName(int teamid)
97 {
98         switch(teamid)
99         {
100                 case NUM_TEAM_1: return ((teamname_red != "") ? teamname_red : "^1RED^7 team");
101                 case NUM_TEAM_2: return ((teamname_blue != "")? teamname_blue : "^4BLUE^7 team");
102                 case NUM_TEAM_3: return ((teamname_yellow != "") ? teamname_yellow : "^3YELLOW^7 team");
103                 case NUM_TEAM_4: return ((teamname_pink != "") ? teamname_pink : "^6PINK^7 team");
104         }
105
106     return NAME_NEUTRAL;
107 }
108 #endif
109
110 string Team_ColorName(int teamid)
111 {
112         switch(teamid)
113         {
114                 case NUM_TEAM_1: return NAME_TEAM_1;
115                 case NUM_TEAM_2: return NAME_TEAM_2;
116                 case NUM_TEAM_3: return NAME_TEAM_3;
117                 case NUM_TEAM_4: return NAME_TEAM_4;
118         }
119
120         return NAME_NEUTRAL;
121 }
122
123 // used for replacement in filenames or such where the name CANNOT be allowed to be translated
124 string Static_Team_ColorName(int teamid)
125 {
126         switch(teamid)
127         {
128                 case NUM_TEAM_1: return STATIC_NAME_TEAM_1;
129                 case NUM_TEAM_2: return STATIC_NAME_TEAM_2;
130                 case NUM_TEAM_3: return STATIC_NAME_TEAM_3;
131                 case NUM_TEAM_4: return STATIC_NAME_TEAM_4;
132         }
133
134         return NAME_NEUTRAL;
135 }
136
137 float Team_ColorToTeam(string team_color)
138 {
139         switch(strtolower(team_color))
140         {
141                 case "red": return NUM_TEAM_1;
142                 case "blue": return NUM_TEAM_2;
143                 case "yellow": return NUM_TEAM_3;
144                 case "pink": return NUM_TEAM_4;
145                 case "auto": return 0;
146         }
147
148         return -1;
149 }
150
151 /// \brief Returns whether team value is valid.
152 /// \param[in] team_num Team to check.
153 /// \return True if team is valid, false otherwise.
154 bool Team_IsValidTeam(int team_num)
155 {
156         switch (team_num)
157         {
158                 case NUM_TEAM_1:
159                 case NUM_TEAM_2:
160                 case NUM_TEAM_3:
161                 case NUM_TEAM_4:
162                 {
163                         return true;
164                 }
165         }
166         return false;
167 }
168
169 /// \brief Returns whether the team index is valid.
170 /// \param[in] index Team index to check.
171 /// \return True if team index is valid, false otherwise.
172 bool Team_IsValidIndex(int index)
173 {
174         switch (index)
175         {
176                 case 1:
177                 case 2:
178                 case 3:
179                 case 4:
180                 {
181                         return true;
182                 }
183         }
184         return false;
185 }
186
187 /// \brief Converts team index into team value.
188 /// \param[in] index Team index to convert.
189 /// \return Team value.
190 int Team_IndexToTeam(int index)
191 {
192         switch (index)
193         {
194                 case 1: return NUM_TEAM_1;
195                 case 2: return NUM_TEAM_2;
196                 case 3: return NUM_TEAM_3;
197                 case 4: return NUM_TEAM_4;
198         }
199         return -1;
200 }
201
202 /// \brief Converts team value into team index.
203 /// \param[in] team_num Team value to convert.
204 /// \return Team index.
205 int Team_TeamToIndex(int team_num)
206 {
207         switch (team_num)
208         {
209                 case NUM_TEAM_1: return 1;
210                 case NUM_TEAM_2: return 2;
211                 case NUM_TEAM_3: return 3;
212                 case NUM_TEAM_4: return 4;
213         }
214         return -1;
215 }
216
217 /// \brief Converts team value into bit value that is used in team bitmasks.
218 /// \param[in] team_num Team value to convert.
219 /// \return Team bit.
220 int Team_TeamToBit(int team_num)
221 {
222         if (!Team_IsValidTeam(team_num))
223         {
224                 return 0;
225         }
226         return BIT(Team_TeamToIndex(team_num) - 1);
227 }
228
229 /// \brief Converts team index into bit value that is used in team bitmasks.
230 /// \param[in] index Team index to convert.
231 /// \return Team bit.
232 int Team_IndexToBit(int index)
233 {
234         return BIT(index - 1);
235 }
236
237
238 // legacy aliases for shitty code
239 #define TeamByColor(teamid) (Team_TeamToIndex(teamid) - 1)
240 #define ColorByTeam(number) Team_IndexToTeam(number + 1)
241
242 // useful aliases
243 #define Team_ColorName_Lower(teamid) strtolower(Team_ColorName(teamid))
244 #define Team_ColorName_Upper(teamid) strtoupper(Team_ColorName(teamid))
245
246 // used for replacement in filenames or such where the name CANNOT be allowed to be translated
247 #define Static_Team_ColorName_Lower(teamid) strtolower(Static_Team_ColorName(teamid))
248 #define Static_Team_ColorName_Upper(teamid) strtoupper(Static_Team_ColorName(teamid))
249
250 #define Team_FullName(teamid) strcat(Team_ColorName(teamid), " ", NAME_TEAM, "^7")
251 #define Team_ColoredFullName(teamid) strcat(Team_ColorCode(teamid), Team_ColorName(teamid), " ", NAME_TEAM, "^7")
252
253 #define Team_IndexToFullName(index) Team_FullName(Team_IndexToTeam(index))
254 #define Team_IndexToColoredFullName(index) Team_ColoredFullName(Team_IndexToTeam(index))
255
256 // replace these flags in a string with the strings provided
257 #define TCR(input,type,team) strreplace("^TC", COL_TEAM_##team, strreplace("^TT", strtoupper(type##_TEAM_##team), input))
258
259 // safe team comparisons
260 #define SAME_TEAM(a,b) (teamplay ? (a.team == b.team) : (a == b))
261 #define DIFF_TEAM(a,b) (teamplay ? (a.team != b.team) : (a != b))