]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/miscfunctions.qc
remove all 2.4.2 compatibility code (do not merge this into 2.5 bugfix releases)
[divverent/nexuiz.git] / data / qcsrc / client / miscfunctions.qc
1 var float(string text, float handleColors) stringwidth;
2
3 entity players;
4 entity teams;
5
6 void restartAnnouncer_Think() {
7         float countdown_rounded, countdown;
8         countdown = getstatf(STAT_GAMESTARTTIME) - time;
9         countdown_rounded = floor(0.5 + countdown);
10         if(countdown <= 0) {
11                 if (!spectatee_status) //do cprint only for players
12                         centerprint("^1Begin!");
13
14                 sound(self, CHAN_VOICE, "announcer/robotic/begin.wav", VOL_BASEVOICE, ATTN_NONE);
15                 remove(self);
16                 return;
17         }
18         else {
19                 if (!spectatee_status) //do cprint only for players
20                         centerprint(strcat("^1Game starts in ", ftos(countdown_rounded), " seconds"));
21
22                 if(countdown_rounded <= 3 && countdown_rounded >= 1) {
23                         sound(self, CHAN_VOICE, strcat("announcer/robotic/", ftos(countdown_rounded), ".wav"), VOL_BASEVOICE, ATTN_NONE);
24                 }
25
26                 self.nextthink = getstatf(STAT_GAMESTARTTIME) - (countdown - 1);
27         }
28 }
29
30 void AuditLists()
31 {
32         entity e;
33         entity prev;
34
35         prev = players;
36         for(e = prev.sort_next; e; prev = e, e = e.sort_next)
37         {
38                 if(prev != e.sort_prev)
39                         error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
40         }
41
42         prev = teams;
43         for(e = prev.sort_next; e; prev = e, e = e.sort_next)
44         {
45                 if(prev != e.sort_prev)
46                         error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
47         }
48 }
49
50
51 float RegisterPlayer(entity player)
52 {
53         entity pl;
54         AuditLists();
55         for(pl = players.sort_next; pl; pl = pl.sort_next)
56                 if(pl == player)
57                         error("Player already registered!");
58         player.sort_next = players.sort_next;
59         player.sort_prev = players;
60         if(players.sort_next)
61                 players.sort_next.sort_prev = player;
62         players.sort_next = player;
63         AuditLists();
64         return true;
65 }
66
67 void RemovePlayer(entity player)
68 {
69         entity pl, parent;
70         AuditLists();
71         parent = players;
72         for(pl = players.sort_next; pl && pl != player; pl = pl.sort_next)
73                 parent = pl;
74
75         if(!pl)
76         {
77                 error("Trying to remove a player which is not in the playerlist!");
78                 return;
79         }
80         parent.sort_next = player.sort_next;
81         if(player.sort_next)
82                 player.sort_next.sort_prev = parent;
83         AuditLists();
84 }
85
86 void MoveToLast(entity e)
87 {
88         AuditLists();
89         other = e.sort_next;
90         while(other)
91         {
92                 SORT_SWAP(other, e);
93                 other = e.sort_next;
94         }
95         AuditLists();
96 }
97
98 float RegisterTeam(entity Team)
99 {
100         entity tm;
101         AuditLists();
102         for(tm = teams.sort_next; tm; tm = tm.sort_next)
103                 if(tm == Team)
104                         error("Team already registered!");
105         Team.sort_next = teams.sort_next;
106         Team.sort_prev = teams;
107         if(teams.sort_next)
108                 teams.sort_next.sort_prev = Team;
109         teams.sort_next = Team;
110         AuditLists();
111         return true;
112 }
113
114 void RemoveTeam(entity Team)
115 {
116         entity tm, parent;
117         AuditLists();
118         parent = teams;
119         for(tm = teams.sort_next; tm && tm != Team; tm = tm.sort_next)
120                 parent = tm;
121
122         if(!tm)
123         {
124                 print("Trying to remove a team which is not in the teamlist!");
125                 return;
126         }
127         parent.sort_next = Team.sort_next;
128         if(Team.sort_next)
129                 Team.sort_next.sort_prev = parent;
130         AuditLists();
131 }
132
133 entity GetTeam(float Team, float add)
134 {
135         float num;
136         entity tm;
137         num = (Team == COLOR_SPECTATOR) ? 16 : Team;
138         if(teamslots[num])
139                 return teamslots[num];
140         if not(add)
141                 return NULL;
142         tm = spawn();
143         tm.team = Team;
144         teamslots[num] = tm;
145         RegisterTeam(tm);
146         return tm;
147 }
148
149 void CSQC_CheckEngine()
150 {
151         sbar_font = FONT_USER+1;
152         sbar_bigfont = FONT_USER+2;
153 }
154
155 vector Sbar_GetFontsize(string cvarname)
156 {
157         vector v;
158         v = stov(cvar_string(cvarname));
159         if(v_x == 0)
160                 v = '8 8 0';
161         if(v_y == 0)
162                 v_y = v_x;
163         v_z = 0;
164         return v;
165 }
166
167 float Sbar_GetWidth(float teamcolumnwidth)
168 {
169         float f;
170         f = stof(cvar_string("sbar_width"));
171         if(f == 0)
172                 f = 640;
173         if(f < 320)
174                 f = 320;
175         if(f > vid_conwidth - 2 * teamcolumnwidth)
176                 f = vid_conwidth - 2 * teamcolumnwidth;
177         return f;
178 }
179
180 float PreviewExists(string name)
181 {
182         float f;
183         string file;
184
185         if(cvar("cl_readpicture_force"))
186                 return false;
187
188         file = strcat(name, ".tga");
189         f = fopen(file, FILE_READ);
190         if(f >= 0)
191         {
192                 fclose(f);
193                 return true;
194         }
195         file = strcat(name, ".png");
196         f = fopen(file, FILE_READ);
197         if(f >= 0)
198         {
199                 fclose(f);
200                 return true;
201         }
202         file = strcat(name, ".jpg");
203         f = fopen(file, FILE_READ);
204         if(f >= 0)
205         {
206                 fclose(f);
207                 return true;
208         }
209         file = strcat(name, ".pcx");
210         f = fopen(file, FILE_READ);
211         if(f >= 0)
212         {
213                 fclose(f);
214                 return true;
215         }
216         return false;
217 }
218
219 float PI      = 3.14159265359;
220 float DEG2RAD = 0.01745329252;
221 vector rotate(vector v, float a)
222 {
223         vector w;
224         // FTEQCC SUCKS AGAIN
225         w_x =      v_x * cos(a) + v_y * sin(a);
226         w_y = -1 * v_x * sin(a) + v_y * cos(a);
227         return w;
228 }
229
230 float ColorTranslateMode;
231
232 string ColorTranslateRGB(string s)
233 {
234         if(ColorTranslateMode & 1)
235                 return strdecolorize(s);
236         else
237                 return s;
238 }
239
240 float cvar_or(string cv, float v)
241 {
242         string s;
243         s = cvar_string(cv);
244         if(s == "")
245                 return v;
246         else
247                 return stof(s);
248 }
249
250 vector project_3d_to_2d(vector vec)
251
252         vec = cs_project(vec);
253         if(cs_project_is_b0rked)
254         {
255                 vec_x += vid_width / 2;
256                 vec_y += vid_height / 2;
257         }
258         vec_x *= vid_conwidth / vid_width;
259         vec_y *= vid_conheight / vid_height;
260         return vec;
261 }
262
263 void dummyfunction(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8)
264 {
265 }
266
267 float expandingbox_sizefactor_from_fadelerp(float fadelerp)
268 {
269         return 1.2 / (1.2 - fadelerp);
270 }
271
272 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor)
273 {
274         boxsize_x *= boxxsizefactor; // easier interface for text
275         return boxsize * (0.5 * (1 - sz));
276 }
277
278 void drawpic_expanding(vector position, string pic, vector scale, vector rgb, float alpha, float flag, float fadelerp)
279 {
280         float sz;
281         sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
282
283         drawpic(position + expandingbox_resize_centered_box_offset(sz, scale, 1), pic, scale * sz, rgb, alpha * (1 - fadelerp), flag);
284 }
285
286 void drawpic_expanding_two(vector position, string pic, vector scale, vector rgb, float alpha, float flag, float fadelerp)
287 {
288         drawpic_expanding(position, pic, scale, rgb, alpha, flag, fadelerp);
289         drawpic(position, pic, scale, rgb, alpha * fadelerp, flag);
290 }
291
292 void drawstring_expanding(vector position, string text, vector scale, vector rgb, float alpha, float flag, float fadelerp)
293 {
294         float sz;
295         sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
296
297         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
298         drawstring(position + expandingbox_resize_centered_box_offset(sz, scale, stringwidth(text, FALSE)), text, scale * sz, rgb, alpha * (1 - fadelerp), flag);
299 }
300
301 void drawcolorcodedstring_expanding(vector position, string text, vector scale, float alpha, float flag, float fadelerp)
302 {
303         float sz;
304         sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
305
306         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
307         drawcolorcodedstring(position + expandingbox_resize_centered_box_offset(sz, scale, stringwidth(text, TRUE)), text, scale * sz, alpha * (1 - fadelerp), flag);
308 }