]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/teams.qh
Merge branch 'master' into terencehill/translate_colors_2
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / teams.qh
1 #ifndef TEAMS_H
2 #define TEAMS_H
3
4 #ifdef TEAMNUMBERS_THAT_ARENT_STUPID
5 const int NUM_TEAM_1 = 1;  // red
6 const int NUM_TEAM_2 = 2; // blue
7 const int NUM_TEAM_3 = 3; // yellow
8 const int NUM_TEAM_4 = 4; // pink
9 const int NUM_SPECTATOR = 5;
10 #else
11 #ifdef CSQC
12 const int NUM_TEAM_1 = 4;  // red
13 const int NUM_TEAM_2 = 13; // blue
14 const int NUM_TEAM_3 = 12; // yellow
15 const int NUM_TEAM_4 = 9; // pink
16 #else
17 const int NUM_TEAM_1 = 5;  // red
18 const int NUM_TEAM_2 = 14; // blue
19 const int NUM_TEAM_3 = 13; // yellow
20 const int NUM_TEAM_4 = 10; // pink
21 #endif
22 const int NUM_SPECTATOR = 1337;
23 #endif
24
25 const string COL_TEAM_1 = "^1";
26 const string COL_TEAM_2 = "^4";
27 const string COL_TEAM_3 = "^3";
28 const string COL_TEAM_4 = "^6";
29 // must be #defined, const globals drop the translation attribute
30 #define NAME_TEAM_1 _("Red")
31 #define NAME_TEAM_2 _("Blue")
32 #define NAME_TEAM_3 _("Yellow")
33 #define NAME_TEAM_4 _("Pink")
34 #define NAME_TEAM _("Team")
35 #define NAME_NEUTRAL _("Neutral")
36
37 // used for replacement in filenames or such where the name CANNOT be allowed to be translated
38 const string STATIC_NAME_TEAM_1 = "Red";
39 const string STATIC_NAME_TEAM_2 = "Blue";
40 const string STATIC_NAME_TEAM_3 = "Yellow";
41 const string STATIC_NAME_TEAM_4 = "Pink";
42
43 #ifdef CSQC
44 float teamplay;
45 float myteam;
46 #endif
47
48 string Team_ColorCode(float teamid)
49 {
50         switch(teamid)
51         {
52                 case NUM_TEAM_1: return COL_TEAM_1;
53                 case NUM_TEAM_2: return COL_TEAM_2;
54                 case NUM_TEAM_3: return COL_TEAM_3;
55                 case NUM_TEAM_4: return COL_TEAM_4;
56         }
57
58         return "^7";
59 }
60
61 vector Team_ColorRGB(float teamid)
62 {
63         switch(teamid)
64         {
65                 case NUM_TEAM_1: return '1 0.0625 0.0625'; // 0xFF0F0F
66                 case NUM_TEAM_2: return '0.0625 0.0625 1'; // 0x0F0FFF
67                 case NUM_TEAM_3: return '1 1 0.0625'; // 0xFFFF0F
68                 case NUM_TEAM_4: return '1 0.0625 1'; // 0xFF0FFF
69         }
70
71     return '0 0 0';
72 }
73
74 string Team_ColorName(float teamid)
75 {
76         switch(teamid)
77         {
78                 case NUM_TEAM_1: return NAME_TEAM_1;
79                 case NUM_TEAM_2: return NAME_TEAM_2;
80                 case NUM_TEAM_3: return NAME_TEAM_3;
81                 case NUM_TEAM_4: return NAME_TEAM_4;
82         }
83
84     return NAME_NEUTRAL;
85 }
86
87 // used for replacement in filenames or such where the name CANNOT be allowed to be translated
88 string Static_Team_ColorName(float teamid)
89 {
90         switch(teamid)
91         {
92                 case NUM_TEAM_1: return STATIC_NAME_TEAM_1;
93                 case NUM_TEAM_2: return STATIC_NAME_TEAM_2;
94                 case NUM_TEAM_3: return STATIC_NAME_TEAM_3;
95                 case NUM_TEAM_4: return STATIC_NAME_TEAM_4;
96         }
97
98     return NAME_NEUTRAL;
99 }
100
101 float Team_ColorToTeam(string team_color)
102 {
103         switch(strtolower(team_color))
104         {
105                 case "red": return NUM_TEAM_1;
106                 case "blue": return NUM_TEAM_2;
107                 case "yellow": return NUM_TEAM_3;
108                 case "pink": return NUM_TEAM_4;
109                 case "auto": return 0;
110         }
111
112         return -1;
113 }
114
115 float Team_NumberToTeam(float number)
116 {
117         switch(number)
118         {
119                 case 1: return NUM_TEAM_1;
120                 case 2: return NUM_TEAM_2;
121                 case 3: return NUM_TEAM_3;
122                 case 4: return NUM_TEAM_4;
123         }
124
125         return -1;
126 }
127
128 float Team_TeamToNumber(float teamid)
129 {
130         switch(teamid)
131         {
132                 case NUM_TEAM_1: return 1;
133                 case NUM_TEAM_2: return 2;
134                 case NUM_TEAM_3: return 3;
135                 case NUM_TEAM_4: return 4;
136         }
137
138         return -1;
139 }
140
141
142 // legacy aliases for shitty code
143 #define TeamByColor(teamid) (Team_TeamToNumber(teamid) - 1)
144 #define ColorByTeam(number) Team_NumberToTeam(number + 1)
145
146 // useful aliases
147 #define Team_ColorName_Lower(teamid) strtolower(Team_ColorName(teamid))
148 #define Team_ColorName_Upper(teamid) strtoupper(Team_ColorName(teamid))
149
150 // used for replacement in filenames or such where the name CANNOT be allowed to be translated
151 #define Static_Team_ColorName_Lower(teamid) strtolower(Static_Team_ColorName(teamid))
152 #define Static_Team_ColorName_Upper(teamid) strtoupper(Static_Team_ColorName(teamid))
153
154 #define Team_FullName(teamid) strcat(Team_ColorName(teamid), " ", NAME_TEAM, "^7")
155 #define Team_ColoredFullName(teamid) strcat(Team_ColorCode(teamid), Team_ColorName(teamid), " ", NAME_TEAM, "^7")
156
157 #define Team_NumberToFullName(number) Team_FullName(Team_NumberToTeam(number))
158 #define Team_NumberToColoredFullName(number) Team_ColoredFullName(Team_NumberToTeam(number))
159
160 // replace these flags in a string with the strings provided
161 #define TCR(input,teamcolor,teamtext) strreplace("^TC", teamcolor, strreplace("^TT", teamtext, input))
162
163 // safe team comparisons
164 #define SAME_TEAM(a,b) (teamplay ? (a.team == b.team) : (a == b))
165 #define DIFF_TEAM(a,b) (teamplay ? (a.team != b.team) : (a != b))
166
167 #endif