]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/teams.qh
1b03540dd7fd008dfe45dda3d461a34ac63cdc02
[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 float teamplay;
60 float myteam;
61 #endif
62
63 string Team_ColorCode(float teamid)
64 {
65         switch(teamid)
66         {
67                 case NUM_TEAM_1: return COL_TEAM_1;
68                 case NUM_TEAM_2: return COL_TEAM_2;
69                 case NUM_TEAM_3: return COL_TEAM_3;
70                 case NUM_TEAM_4: return COL_TEAM_4;
71         }
72
73         return "^7";
74 }
75
76 vector Team_ColorRGB(float teamid)
77 {
78         switch(teamid)
79         {
80                 case NUM_TEAM_1: return '1 0.0625 0.0625'; // 0xFF0F0F
81                 case NUM_TEAM_2: return '0.0625 0.0625 1'; // 0x0F0FFF
82                 case NUM_TEAM_3: return '1 1 0.0625'; // 0xFFFF0F
83                 case NUM_TEAM_4: return '1 0.0625 1'; // 0xFF0FFF
84         }
85
86     return '0 0 0';
87 }
88
89 string Team_ColorName(float teamid)
90 {
91         switch(teamid)
92         {
93                 case NUM_TEAM_1: return NAME_TEAM_1;
94                 case NUM_TEAM_2: return NAME_TEAM_2;
95                 case NUM_TEAM_3: return NAME_TEAM_3;
96                 case NUM_TEAM_4: return NAME_TEAM_4;
97         }
98
99     return NAME_NEUTRAL;
100 }
101
102 // used for replacement in filenames or such where the name CANNOT be allowed to be translated
103 string Static_Team_ColorName(float teamid)
104 {
105         switch(teamid)
106         {
107                 case NUM_TEAM_1: return STATIC_NAME_TEAM_1;
108                 case NUM_TEAM_2: return STATIC_NAME_TEAM_2;
109                 case NUM_TEAM_3: return STATIC_NAME_TEAM_3;
110                 case NUM_TEAM_4: return STATIC_NAME_TEAM_4;
111         }
112
113     return NAME_NEUTRAL;
114 }
115
116 float Team_ColorToTeam(string team_color)
117 {
118         switch(strtolower(team_color))
119         {
120                 case "red": return NUM_TEAM_1;
121                 case "blue": return NUM_TEAM_2;
122                 case "yellow": return NUM_TEAM_3;
123                 case "pink": return NUM_TEAM_4;
124                 case "auto": return 0;
125         }
126
127         return -1;
128 }
129
130 /// \brief Returns whether team is valid.
131 /// \param[in] team_ Team to check.
132 /// \return True if team is valid, false otherwise.
133 bool Team_IsValidTeam(int team_)
134 {
135         switch (team_)
136         {
137                 case NUM_TEAM_1:
138                 case NUM_TEAM_2:
139                 case NUM_TEAM_3:
140                 case NUM_TEAM_4:
141                 {
142                         return true;
143                 }
144         }
145         return false;
146 }
147
148 /// \brief Returns whether the team index is valid.
149 /// \param[in] index Team index to check.
150 /// \return True if team index is valid, false otherwise.
151 bool Team_IsValidIndex(int index)
152 {
153         switch (index)
154         {
155                 case 1:
156                 case 2:
157                 case 3:
158                 case 4:
159                 {
160                         return true;
161                 }
162         }
163         return false;
164 }
165
166 float Team_NumberToTeam(float number)
167 {
168         switch(number)
169         {
170                 case 1: return NUM_TEAM_1;
171                 case 2: return NUM_TEAM_2;
172                 case 3: return NUM_TEAM_3;
173                 case 4: return NUM_TEAM_4;
174         }
175
176         return -1;
177 }
178
179 float Team_TeamToNumber(float teamid)
180 {
181         switch(teamid)
182         {
183                 case NUM_TEAM_1: return 1;
184                 case NUM_TEAM_2: return 2;
185                 case NUM_TEAM_3: return 3;
186                 case NUM_TEAM_4: return 4;
187         }
188
189         return -1;
190 }
191
192 /// \brief Converts team index into bit value that is used in team bitmasks.
193 /// \param[in] index Team index to convert.
194 /// \return Team bit.
195 int Team_IndexToBit(int index)
196 {
197         return BIT(index - 1);
198 }
199
200
201 // legacy aliases for shitty code
202 #define TeamByColor(teamid) (Team_TeamToNumber(teamid) - 1)
203 #define ColorByTeam(number) Team_NumberToTeam(number + 1)
204
205 // useful aliases
206 #define Team_ColorName_Lower(teamid) strtolower(Team_ColorName(teamid))
207 #define Team_ColorName_Upper(teamid) strtoupper(Team_ColorName(teamid))
208
209 // used for replacement in filenames or such where the name CANNOT be allowed to be translated
210 #define Static_Team_ColorName_Lower(teamid) strtolower(Static_Team_ColorName(teamid))
211 #define Static_Team_ColorName_Upper(teamid) strtoupper(Static_Team_ColorName(teamid))
212
213 #define Team_FullName(teamid) strcat(Team_ColorName(teamid), " ", NAME_TEAM, "^7")
214 #define Team_ColoredFullName(teamid) strcat(Team_ColorCode(teamid), Team_ColorName(teamid), " ", NAME_TEAM, "^7")
215
216 #define Team_NumberToFullName(number) Team_FullName(Team_NumberToTeam(number))
217 #define Team_NumberToColoredFullName(number) Team_ColoredFullName(Team_NumberToTeam(number))
218
219 // replace these flags in a string with the strings provided
220 #define TCR(input,type,team) strreplace("^TC", COL_TEAM_##team, strreplace("^TT", strtoupper(type##_TEAM_##team), input))
221
222 // safe team comparisons
223 #define SAME_TEAM(a,b) (teamplay ? (a.team == b.team) : (a == b))
224 #define DIFF_TEAM(a,b) (teamplay ? (a.team != b.team) : (a != b))