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