]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/teams.qh
Merge branch 'terencehill/eraseable_functions'
[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 float Team_NumberToTeam(float number)
129 {
130         switch(number)
131         {
132                 case 1: return NUM_TEAM_1;
133                 case 2: return NUM_TEAM_2;
134                 case 3: return NUM_TEAM_3;
135                 case 4: return NUM_TEAM_4;
136         }
137
138         return -1;
139 }
140
141 float Team_TeamToNumber(float teamid)
142 {
143         switch(teamid)
144         {
145                 case NUM_TEAM_1: return 1;
146                 case NUM_TEAM_2: return 2;
147                 case NUM_TEAM_3: return 3;
148                 case NUM_TEAM_4: return 4;
149         }
150
151         return -1;
152 }
153
154
155 // legacy aliases for shitty code
156 #define TeamByColor(teamid) (Team_TeamToNumber(teamid) - 1)
157 #define ColorByTeam(number) Team_NumberToTeam(number + 1)
158
159 // useful aliases
160 #define Team_ColorName_Lower(teamid) strtolower(Team_ColorName(teamid))
161 #define Team_ColorName_Upper(teamid) strtoupper(Team_ColorName(teamid))
162
163 // used for replacement in filenames or such where the name CANNOT be allowed to be translated
164 #define Static_Team_ColorName_Lower(teamid) strtolower(Static_Team_ColorName(teamid))
165 #define Static_Team_ColorName_Upper(teamid) strtoupper(Static_Team_ColorName(teamid))
166
167 #define Team_FullName(teamid) strcat(Team_ColorName(teamid), " ", NAME_TEAM, "^7")
168 #define Team_ColoredFullName(teamid) strcat(Team_ColorCode(teamid), Team_ColorName(teamid), " ", NAME_TEAM, "^7")
169
170 #define Team_NumberToFullName(number) Team_FullName(Team_NumberToTeam(number))
171 #define Team_NumberToColoredFullName(number) Team_ColoredFullName(Team_NumberToTeam(number))
172
173 // replace these flags in a string with the strings provided
174 #define TCR(input,type,team) strreplace("^TC", COL_TEAM_##team, strreplace("^TT", strtoupper(type##_TEAM_##team), input))
175
176 // safe team comparisons
177 #define SAME_TEAM(a,b) (teamplay ? (a.team == b.team) : (a == b))
178 #define DIFF_TEAM(a,b) (teamplay ? (a.team != b.team) : (a != b))