Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
teams.qh
Go to the documentation of this file.
1#pragma once
2
3const int NUM_TEAMS = 4;
4
5#ifdef TEAMNUMBERS_THAT_ARENT_STUPID
6const int NUM_TEAM_1 = 1; // red
7const int NUM_TEAM_2 = 2; // blue
8const int NUM_TEAM_3 = 3; // yellow
9const int NUM_TEAM_4 = 4; // pink
10const int NUM_SPECTATOR = 5;
11#else
12#ifdef CSQC
13const int NUM_TEAM_1 = 4; // red
14const int NUM_TEAM_2 = 13; // blue
15const int NUM_TEAM_3 = 12; // yellow
16const int NUM_TEAM_4 = 9; // pink
17#else
18const int NUM_TEAM_1 = 5; // red
19const int NUM_TEAM_2 = 14; // blue
20const int NUM_TEAM_3 = 13; // yellow
21const int NUM_TEAM_4 = 10; // pink
22#endif
23const int NUM_SPECTATOR = 1337;
24#endif
25
26const string COL_TEAM_1 = "^1";
27const string COL_TEAM_2 = "^4";
28const string COL_TEAM_3 = "^3";
29const 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
53const string STATIC_NAME_TEAM_1 = "Red";
54const string STATIC_NAME_TEAM_2 = "Blue";
55const string STATIC_NAME_TEAM_3 = "Yellow";
56const string STATIC_NAME_TEAM_4 = "Pink";
57
58#ifdef CSQC
61#endif
62
63string 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
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 '1 1 1';
87}
88
89string 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
103string 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
116float 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
133bool 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
151bool 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
169int 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
184int 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
199int 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
211int 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_WithSuffixColor(teamid, suf_col) strcat(Team_ColorName(teamid), " ", NAME_TEAM, suf_col)
230#define Team_FullName(teamid) Team_FullName_WithSuffixColor(teamid, "^7")
231#define Team_ColoredFullName_WithSuffixColor(teamid, suf_col) strcat(Team_ColorCode(teamid), Team_ColorName(teamid), " ", NAME_TEAM, suf_col)
232#define Team_ColoredFullName(teamid) Team_ColoredFullName_WithSuffixColor(teamid, "^7")
233
234#define Team_IndexToFullName(index) Team_FullName(Team_IndexToTeam(index))
235#define Team_IndexToColoredFullName(index) Team_ColoredFullName(Team_IndexToTeam(index))
236
237// replace these flags in a string with the strings provided
238#define TCR(input,type,team) strreplace("^TC", COL_TEAM_##team, strreplace("^TT", strtoupper(type##_TEAM_##team), input))
239
240// safe team comparisons
241#define SAME_TEAM(a,b) (teamplay ? (a.team == b.team) : (a == b))
242#define DIFF_TEAM(a,b) (teamplay ? (a.team != b.team) : (a != b))
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition bits.qh:8
string strtolower(string s)
vector
Definition self.qh:92
const string STATIC_NAME_TEAM_4
Definition teams.qh:56
const string COL_TEAM_4
Definition teams.qh:29
string Static_Team_ColorName(int teamid)
Definition teams.qh:103
bool Team_IsValidTeam(int team_num)
Returns whether team value is valid.
Definition teams.qh:133
int myteam
Definition teams.qh:60
const string COL_TEAM_3
Definition teams.qh:28
int Team_TeamToBit(int team_num)
Converts team value into bit value that is used in team bitmasks.
Definition teams.qh:199
#define NAME_TEAM_2
Definition teams.qh:32
const int NUM_TEAM_2
Definition teams.qh:14
bool Team_IsValidIndex(int index)
Returns whether the team index is valid.
Definition teams.qh:151
const int NUM_SPECTATOR
Definition teams.qh:23
string Team_ColorName(int teamid)
Definition teams.qh:89
#define NAME_TEAM_1
Definition teams.qh:31
#define NAME_TEAM_4
Definition teams.qh:34
const string STATIC_NAME_TEAM_2
Definition teams.qh:54
const int NUM_TEAM_4
Definition teams.qh:16
#define NAME_TEAM_3
Definition teams.qh:33
vector Team_ColorRGB(int teamid)
Definition teams.qh:76
int Team_TeamToIndex(int team_num)
Converts team value into team index.
Definition teams.qh:184
const string STATIC_NAME_TEAM_1
Definition teams.qh:53
const int NUM_TEAM_3
Definition teams.qh:15
int Team_IndexToTeam(int index)
Converts team index into team value.
Definition teams.qh:169
const string COL_TEAM_1
Definition teams.qh:26
const int NUM_TEAMS
Number of teams in the game.
Definition teams.qh:3
bool teamplay
Definition teams.qh:59
const string STATIC_NAME_TEAM_3
Definition teams.qh:55
int Team_IndexToBit(int index)
Converts team index into bit value that is used in team bitmasks.
Definition teams.qh:211
string Team_ColorCode(int teamid)
Definition teams.qh:63
float Team_ColorToTeam(string team_color)
Definition teams.qh:116
#define NAME_NEUTRAL
Definition teams.qh:36
const string COL_TEAM_2
Definition teams.qh:27
const int NUM_TEAM_1
Definition teams.qh:13