Xonotic
teams.qh
Go to the documentation of this file.
1 #pragma once
2 
3 const int NUM_TEAMS = 4;
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 #endif
62 
63 string Team_ColorCode(int 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(int 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(int 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(int 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 
133 bool Team_IsValidTeam(int team_num)
134 {
135  switch (team_num)
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 
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 
169 int Team_IndexToTeam(int index)
170 {
171  switch (index)
172  {
173  case 1: return NUM_TEAM_1;
174  case 2: return NUM_TEAM_2;
175  case 3: return NUM_TEAM_3;
176  case 4: return NUM_TEAM_4;
177  }
178  return -1;
179 }
180 
184 int Team_TeamToIndex(int team_num)
185 {
186  switch (team_num)
187  {
188  case NUM_TEAM_1: return 1;
189  case NUM_TEAM_2: return 2;
190  case NUM_TEAM_3: return 3;
191  case NUM_TEAM_4: return 4;
192  }
193  return -1;
194 }
195 
199 int Team_TeamToBit(int team_num)
200 {
201  if (!Team_IsValidTeam(team_num))
202  {
203  return 0;
204  }
205  return BIT(Team_TeamToIndex(team_num) - 1);
206 }
207 
211 int Team_IndexToBit(int index)
212 {
213  return BIT(index - 1);
214 }
215 
216 
217 // legacy aliases for shitty code
218 #define TeamByColor(teamid) (Team_TeamToIndex(teamid) - 1)
219 #define ColorByTeam(number) Team_IndexToTeam(number + 1)
220 
221 // useful aliases
222 #define Team_ColorName_Lower(teamid) strtolower(Team_ColorName(teamid))
223 #define Team_ColorName_Upper(teamid) strtoupper(Team_ColorName(teamid))
224 
225 // used for replacement in filenames or such where the name CANNOT be allowed to be translated
226 #define Static_Team_ColorName_Lower(teamid) strtolower(Static_Team_ColorName(teamid))
227 #define Static_Team_ColorName_Upper(teamid) strtoupper(Static_Team_ColorName(teamid))
228 
229 #define Team_FullName(teamid) strcat(Team_ColorName(teamid), " ", NAME_TEAM, "^7")
230 #define Team_ColoredFullName(teamid) strcat(Team_ColorCode(teamid), Team_ColorName(teamid), " ", NAME_TEAM, "^7")
231 
232 #define Team_IndexToFullName(index) Team_FullName(Team_IndexToTeam(index))
233 #define Team_IndexToColoredFullName(index) Team_ColoredFullName(Team_IndexToTeam(index))
234 
235 // replace these flags in a string with the strings provided
236 #define TCR(input,type,team) strreplace("^TC", COL_TEAM_##team, strreplace("^TT", strtoupper(type##_TEAM_##team), input))
237 
238 // safe team comparisons
239 #define SAME_TEAM(a,b) (teamplay ? (a.team == b.team) : (a == b))
240 #define DIFF_TEAM(a,b) (teamplay ? (a.team != b.team) : (a != b))
const int NUM_TEAMS
Number of teams in the game.
Definition: teams.qh:3
int Team_IndexToBit(int index)
Converts team index into bit value that is used in team bitmasks.
Definition: teams.qh:211
const int NUM_SPECTATOR
Definition: teams.qh:23
const int NUM_TEAM_2
Definition: teams.qh:19
const string STATIC_NAME_TEAM_1
Definition: teams.qh:53
const string COL_TEAM_3
Definition: teams.qh:28
vector Team_ColorRGB(int teamid)
Definition: teams.qh:76
const string COL_TEAM_4
Definition: teams.qh:29
#define NAME_TEAM_3
Definition: teams.qh:33
bool Team_IsValidIndex(int index)
Returns whether the team index is valid.
Definition: teams.qh:151
const string COL_TEAM_2
Definition: teams.qh:27
string Static_Team_ColorName(int teamid)
Definition: teams.qh:103
#define NAME_TEAM_1
Definition: teams.qh:31
const string STATIC_NAME_TEAM_3
Definition: teams.qh:55
const string STATIC_NAME_TEAM_2
Definition: teams.qh:54
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition: bits.qh:8
#define NAME_TEAM_4
Definition: teams.qh:34
#define NAME_NEUTRAL
Definition: teams.qh:36
float teamplay
Definition: progsdefs.qc:31
const string STATIC_NAME_TEAM_4
Definition: teams.qh:56
int Team_TeamToIndex(int team_num)
Converts team value into team index.
Definition: teams.qh:184
vector(float skel, float bonenum) _skel_get_boneabs_hidden
const int NUM_TEAM_4
Definition: teams.qh:21
float Team_ColorToTeam(string team_color)
Definition: teams.qh:116
string Team_ColorCode(int teamid)
Definition: teams.qh:63
string Team_ColorName(int teamid)
Definition: teams.qh:89
int Team_IndexToTeam(int index)
Converts team index into team value.
Definition: teams.qh:169
const int NUM_TEAM_1
Definition: teams.qh:18
int Team_TeamToBit(int team_num)
Converts team value into bit value that is used in team bitmasks.
Definition: teams.qh:199
bool Team_IsValidTeam(int team_num)
Returns whether team value is valid.
Definition: teams.qh:133
#define NAME_TEAM_2
Definition: teams.qh:32
const int NUM_TEAM_3
Definition: teams.qh:20
const string COL_TEAM_1
Definition: teams.qh:26