Attempt to port the shownames feature from Xonotic (floating names above players...
[voretournament/voretournament.git] / data / qcsrc / client / miscfunctions.qc
1 var float(string text, float handleColors, vector fontSize) stringwidth;\r
2 \r
3 entity players;\r
4 entity teams;\r
5 \r
6 void serverAnnouncer()\r
7 {\r
8         // check for pending announcement, play it and remove it\r
9         if(announce_snd != "")\r
10         {\r
11                 sound(self, CHAN_VOICE, strcat("announcer/", cvar_string("cl_announcer"), "/", announce_snd, ".wav"), VOL_BASEVOICE, ATTN_NONE);\r
12                 strunzone(announce_snd);\r
13                 announce_snd = "";\r
14         }\r
15 }\r
16 \r
17 void restartAnnouncer_Think() {\r
18         float countdown_rounded, countdown;\r
19         countdown = getstatf(STAT_GAMESTARTTIME) - time;\r
20         countdown_rounded = floor(0.5 + countdown);\r
21         if(countdown <= 0) {\r
22                 if (!spectatee_status) //do cprint only for players\r
23                         centerprint("^1Begin!");\r
24 \r
25                 sound(self, CHAN_VOICE, strcat("announcer/", cvar_string("cl_announcer"), "/begin.wav"), VOL_BASEVOICE, ATTN_NONE);\r
26                 //reset maptime announcers now as well\r
27                 announcer_5min = announcer_1min = FALSE;\r
28 \r
29                 remove(self);\r
30                 return;\r
31         }\r
32         else {\r
33                 if (!spectatee_status) //do cprint only for players\r
34                         centerprint(strcat("^1Game starts in ", ftos(countdown_rounded), " seconds"));\r
35 \r
36                 if(countdown_rounded <= 3 && countdown_rounded >= 1) {\r
37                         sound(self, CHAN_VOICE, strcat("announcer/", cvar_string("cl_announcer"), "/", ftos(countdown_rounded), ".wav"), VOL_BASEVOICE, ATTN_NONE);\r
38                 }\r
39 \r
40                 self.nextthink = getstatf(STAT_GAMESTARTTIME) - (countdown - 1);\r
41         }\r
42 }\r
43 \r
44 /**\r
45  * Plays the 1minute or 5 minutes (of maptime) remaining sound, if client wants it\r
46  */\r
47 void maptimeAnnouncer() {\r
48     float timelimit;\r
49     timelimit = getstatf(STAT_TIMELIMIT);\r
50     float timeleft;\r
51     timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);\r
52 \r
53     float warmuplimit;\r
54     float warmuptimeleft;\r
55     if(warmup_stage) {\r
56         warmuplimit = cvar("g_warmup_limit");\r
57         if(warmuplimit > 0) {\r
58            warmuptimeleft = max(0, warmuplimit + getstatf(STAT_GAMESTARTTIME) - time); \r
59         }\r
60     }\r
61 \r
62     //5 minute check\r
63     if (cvar("cl_sound_maptime_warning") >= 2) {\r
64         //make sure that after connect (and e.g. 4 minutes left) we will not get a wrong sound\r
65         if(announcer_5min)\r
66         {\r
67                         if(((!warmup_stage || warmuplimit == 0) && timeleft > 300) || (warmup_stage && warmuplimit > 0 && warmuptimeleft > 300))\r
68                                 announcer_5min = FALSE;\r
69         }\r
70         else if (((!warmup_stage || warmuplimit == 0) && timelimit > 0 && timeleft < 300 && timeleft > 299) || (warmup_stage && warmuplimit > 0 && warmuptimeleft < 300 && warmuptimeleft > 299))\r
71         //if we're in warmup mode, check whether there's a warmup timelimit\r
72         if not (warmuplimit == -1 && warmup_stage) {\r
73                         announcer_5min = TRUE;\r
74                         //dprint("i will play the sound, I promise!\n");\r
75                         sound(self, CHAN_VOICE, strcat("announcer/", cvar_string("cl_announcer"), "/5minutesremain.wav"), VOL_BASEVOICE, ATTN_NONE);\r
76                 }\r
77     }\r
78 \r
79     //1 minute check\r
80     if (cvar("cl_sound_maptime_warning") == 1 || cvar("cl_sound_maptime_warning") == 3) {\r
81         if (announcer_1min)\r
82         {\r
83                         if(((!warmup_stage || warmuplimit == 0) && timeleft > 60) || (warmup_stage && warmuplimit > 0 && warmuptimeleft > 60))\r
84                                 announcer_1min = FALSE;\r
85         }\r
86         else if (((!warmup_stage || warmuplimit == 0) && timelimit > 0 && timeleft < 60) || (warmup_stage && warmuplimit > 0 && warmuptimeleft < 60))\r
87         //if we're in warmup mode, check whether there's a warmup timelimit\r
88         if not (warmuplimit == -1 && warmup_stage) {\r
89                         announcer_1min = TRUE;\r
90                         sound(self, CHAN_VOICE, strcat("announcer/", cvar_string("cl_announcer"), "/1minuteremains.wav"), VOL_BASEVOICE, ATTN_NONE);\r
91         }\r
92         }\r
93 }\r
94 \r
95  /**\r
96  * Announce carried items (e.g. flags in CTF).\r
97  */\r
98 float redflag_prev;\r
99 float blueflag_prev;\r
100 void carrierAnnouncer() {\r
101         float stat_items, redflag, blueflag;\r
102         float pickup;\r
103         string item;\r
104 \r
105         if not(cvar("cl_notify_carried_items"))\r
106                 return;\r
107 \r
108         stat_items = getstati(STAT_ITEMS);\r
109 \r
110         redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;\r
111         blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;\r
112 \r
113         if (redflag == 3 && redflag != redflag_prev) {\r
114                 item = "^1RED^7 flag";\r
115                 pickup = (redflag_prev == 2);\r
116         }\r
117 \r
118         if (blueflag == 3 && blueflag != blueflag_prev) {\r
119                 item = "^4BLUE^7 flag";\r
120                 pickup = (blueflag_prev == 2);\r
121         }\r
122 \r
123         if (item)\r
124         {\r
125                 if (pickup) {\r
126                         if (cvar("cl_notify_carried_items") & 2)\r
127                                 centerprint(strcat("You picked up the ", item, "!"));\r
128                 }\r
129                 else {\r
130                         if (cvar("cl_notify_carried_items") & 1)\r
131                                 centerprint(strcat("You got the ", item, "!"));\r
132                 }\r
133         }\r
134 \r
135         blueflag_prev = blueflag;\r
136         redflag_prev = redflag;\r
137 }\r
138 \r
139 /**\r
140  * Add all future announcer sounds precaches here.\r
141  * TODO: announcer queues\r
142  */\r
143 void Announcer_Precache () {\r
144         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/1minuteremains.wav"));\r
145         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/5minutesremain.wav"));\r
146 \r
147         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/airshot.wav"));\r
148         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/03kills.wav"));\r
149         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/05kills.wav"));\r
150         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/10kills.wav"));\r
151         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/15kills.wav"));\r
152         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/20kills.wav"));\r
153         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/25kills.wav"));\r
154         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/30kills.wav"));\r
155         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/botlike.wav"));\r
156         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/yoda.wav"));\r
157         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/amazing.wav"));\r
158         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/awesome.wav"));\r
159         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/headshot.wav"));\r
160         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/impressive.wav"));\r
161 \r
162         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/prepareforbattle.wav"));\r
163         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/begin.wav"));\r
164         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/timeoutcalled.wav"));\r
165         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/1fragleft.wav"));\r
166         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/2fragsleft.wav"));\r
167         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/3fragsleft.wav"));\r
168         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/terminated.wav"));\r
169 \r
170         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/1.wav"));\r
171         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/2.wav"));\r
172         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/3.wav"));\r
173         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/4.wav"));\r
174         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/5.wav"));\r
175         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/6.wav"));\r
176         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/7.wav"));\r
177         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/8.wav"));\r
178         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/9.wav"));\r
179         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/10.wav"));\r
180 \r
181         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/lastsecond.wav"));\r
182         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/narrowly.wav"));\r
183 }\r
184 \r
185 void AuditLists()\r
186 {\r
187         entity e;\r
188         entity prev;\r
189 \r
190         prev = players;\r
191         for(e = prev.sort_next; e; prev = e, e = e.sort_next)\r
192         {\r
193                 if(prev != e.sort_prev)\r
194                         error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));\r
195         }\r
196 \r
197         prev = teams;\r
198         for(e = prev.sort_next; e; prev = e, e = e.sort_next)\r
199         {\r
200                 if(prev != e.sort_prev)\r
201                         error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));\r
202         }\r
203 }\r
204 \r
205 \r
206 float RegisterPlayer(entity player)\r
207 {\r
208         entity pl;\r
209         AuditLists();\r
210         for(pl = players.sort_next; pl; pl = pl.sort_next)\r
211                 if(pl == player)\r
212                         error("Player already registered!");\r
213         player.sort_next = players.sort_next;\r
214         player.sort_prev = players;\r
215         if(players.sort_next)\r
216                 players.sort_next.sort_prev = player;\r
217         players.sort_next = player;\r
218         AuditLists();\r
219         return true;\r
220 }\r
221 \r
222 void RemovePlayer(entity player)\r
223 {\r
224         entity pl, parent;\r
225         AuditLists();\r
226         parent = players;\r
227         for(pl = players.sort_next; pl && pl != player; pl = pl.sort_next)\r
228                 parent = pl;\r
229 \r
230         if(!pl)\r
231         {\r
232                 error("Trying to remove a player which is not in the playerlist!");\r
233                 return;\r
234         }\r
235         parent.sort_next = player.sort_next;\r
236         if(player.sort_next)\r
237                 player.sort_next.sort_prev = parent;\r
238         AuditLists();\r
239 }\r
240 \r
241 void MoveToLast(entity e)\r
242 {\r
243         AuditLists();\r
244         other = e.sort_next;\r
245         while(other)\r
246         {\r
247                 SORT_SWAP(other, e);\r
248                 other = e.sort_next;\r
249         }\r
250         AuditLists();\r
251 }\r
252 \r
253 float RegisterTeam(entity Team)\r
254 {\r
255         entity tm;\r
256         AuditLists();\r
257         for(tm = teams.sort_next; tm; tm = tm.sort_next)\r
258                 if(tm == Team)\r
259                         error("Team already registered!");\r
260         Team.sort_next = teams.sort_next;\r
261         Team.sort_prev = teams;\r
262         if(teams.sort_next)\r
263                 teams.sort_next.sort_prev = Team;\r
264         teams.sort_next = Team;\r
265         AuditLists();\r
266         return true;\r
267 }\r
268 \r
269 void RemoveTeam(entity Team)\r
270 {\r
271         entity tm, parent;\r
272         AuditLists();\r
273         parent = teams;\r
274         for(tm = teams.sort_next; tm && tm != Team; tm = tm.sort_next)\r
275                 parent = tm;\r
276 \r
277         if(!tm)\r
278         {\r
279                 print("Trying to remove a team which is not in the teamlist!");\r
280                 return;\r
281         }\r
282         parent.sort_next = Team.sort_next;\r
283         if(Team.sort_next)\r
284                 Team.sort_next.sort_prev = parent;\r
285         AuditLists();\r
286 }\r
287 \r
288 entity GetTeam(float Team, float add)\r
289 {\r
290         float num;\r
291         entity tm;\r
292         num = (Team == COLOR_SPECTATOR) ? 16 : Team;\r
293         if(teamslots[num])\r
294                 return teamslots[num];\r
295         if not(add)\r
296                 return NULL;\r
297         tm = spawn();\r
298         tm.team = Team;\r
299         teamslots[num] = tm;\r
300         RegisterTeam(tm);\r
301         return tm;\r
302 }\r
303 \r
304 void CSQC_CheckEngine()\r
305 {\r
306         sbar_font = FONT_USER+1;\r
307         sbar_bigfont = FONT_USER+2;\r
308 }\r
309 \r
310 vector Sbar_GetFontsize(string cvarname)\r
311 {\r
312         vector v;\r
313         v = stov(cvar_string(cvarname));\r
314         if(v_x == 0)\r
315                 v = '8 8 0';\r
316         if(v_y == 0)\r
317                 v_y = v_x;\r
318         v_z = 0;\r
319         return v;\r
320 }\r
321 \r
322 float Sbar_GetWidth(float teamcolumnwidth)\r
323 {\r
324         float f;\r
325         f = cvar("sbar_width");\r
326         if(f == 0)\r
327                 f = 640;\r
328         if(f < 320)\r
329                 f = 320;\r
330         if(f > vid_conwidth - 2 * teamcolumnwidth)\r
331                 f = vid_conwidth - 2 * teamcolumnwidth;\r
332         return f;\r
333 }\r
334 \r
335 float PreviewExists(string name)\r
336 {\r
337         float f;\r
338         string file;\r
339 \r
340         if(cvar("cl_readpicture_force"))\r
341                 return false;\r
342 \r
343         file = strcat(name, ".tga");\r
344         f = fopen(file, FILE_READ);\r
345         if(f >= 0)\r
346         {\r
347                 fclose(f);\r
348                 return true;\r
349         }\r
350         file = strcat(name, ".png");\r
351         f = fopen(file, FILE_READ);\r
352         if(f >= 0)\r
353         {\r
354                 fclose(f);\r
355                 return true;\r
356         }\r
357         file = strcat(name, ".jpg");\r
358         f = fopen(file, FILE_READ);\r
359         if(f >= 0)\r
360         {\r
361                 fclose(f);\r
362                 return true;\r
363         }\r
364         file = strcat(name, ".pcx");\r
365         f = fopen(file, FILE_READ);\r
366         if(f >= 0)\r
367         {\r
368                 fclose(f);\r
369                 return true;\r
370         }\r
371         return false;\r
372 }\r
373 \r
374 vector rotate(vector v, float a)\r
375 {\r
376         vector w;\r
377         // FTEQCC SUCKS AGAIN\r
378         w_x =      v_x * cos(a) + v_y * sin(a);\r
379         w_y = -1 * v_x * sin(a) + v_y * cos(a);\r
380         return w;\r
381 }\r
382 \r
383 float ColorTranslateMode;\r
384 \r
385 string ColorTranslateRGB(string s)\r
386 {\r
387         if(ColorTranslateMode & 1)\r
388                 return strdecolorize(s);\r
389         else\r
390                 return s;\r
391 }\r
392 \r
393 string Team_ColorCode(float teamid)\r
394 {\r
395     if (teamid == COLOR_TEAM1)\r
396         return "^1";\r
397     else if (teamid == COLOR_TEAM2)\r
398         return "^4";\r
399     else if (teamid == COLOR_TEAM3)\r
400         return "^3";\r
401     else if (teamid == COLOR_TEAM4)\r
402         return "^6";\r
403     else\r
404         return "^7";\r
405 }\r
406 \r
407 // decolorizes and team colors the player name when needed\r
408 string playername(string thename, float teamid)\r
409 {\r
410     string t;\r
411     if (teamplay)\r
412     {\r
413         t = Team_ColorCode(teamid);\r
414         return strcat(t, strdecolorize(thename));\r
415     }\r
416     else\r
417         return strdecolorize(thename);\r
418 }\r
419 \r
420 float cvar_or(string cv, float v)\r
421 {\r
422         string s;\r
423         s = cvar_string(cv);\r
424         if(s == "")\r
425                 return v;\r
426         else\r
427                 return stof(s);\r
428 }\r
429 \r
430 vector project_3d_to_2d(vector vec)\r
431 {\r
432         vec = cs_project(vec);\r
433         if(cs_project_is_b0rked > 0)\r
434         {\r
435                 vec_x *= vid_conwidth / vid_width;\r
436                 vec_y *= vid_conheight / vid_height;\r
437         }\r
438         return vec;\r
439 }\r
440 \r
441 void dummyfunction(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8)\r
442 {\r
443 }\r
444 \r
445 float expandingbox_sizefactor_from_fadelerp(float fadelerp)\r
446 {\r
447         return 1.2 / (1.2 - fadelerp);\r
448 }\r
449 \r
450 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor)\r
451 {\r
452         boxsize_x *= boxxsizefactor; // easier interface for text\r
453         return boxsize * (0.5 * (1 - sz));\r
454 }\r
455 \r
456 void drawborderlines(float thickness, vector pos, vector dim, vector color, float alpha, float drawflag)\r
457 {\r
458         vector line_dim;\r
459 \r
460         // left and right lines\r
461         pos_x -= thickness;\r
462         line_dim_x = thickness;\r
463         line_dim_y = dim_y;\r
464         drawfill(pos, line_dim, color, alpha, drawflag);\r
465         drawfill(pos + (dim_x + thickness) * '1 0 0', line_dim, color, alpha, drawflag);\r
466 \r
467         // upper and lower lines\r
468         pos_y -= thickness;\r
469         line_dim_x = dim_x + thickness * 2; // make upper and lower lines longer\r
470         line_dim_y = thickness;\r
471         drawfill(pos, line_dim, color, alpha, drawflag);\r
472         drawfill(pos + (dim_y + thickness) * '0 1 0', line_dim, color, alpha, drawflag);\r
473 }\r
474 \r
475 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float alpha, float drawflag)\r
476 {\r
477         vector current_pos, end_pos, new_size, ratio;\r
478         end_pos = pos + area;\r
479 \r
480         current_pos_y = pos_y;\r
481         while (current_pos_y < end_pos_y)\r
482         {\r
483                 current_pos_x = pos_x;\r
484                 while (current_pos_x < end_pos_x)\r
485                 {\r
486                         new_size_x = min(sz_x, end_pos_x - current_pos_x);\r
487                         new_size_y = min(sz_y, end_pos_y - current_pos_y);\r
488                         ratio_x = new_size_x / sz_x;\r
489                         ratio_y = new_size_y / sz_y;\r
490                         drawsubpic(current_pos, new_size, pic, '0 0 0', ratio, color, alpha, drawflag);\r
491                         current_pos_x += sz_x;\r
492                 }\r
493                 current_pos_y += sz_y;\r
494         }\r
495 }\r
496 \r
497 void drawpic_expanding(vector position, string pic, vector scale, vector rgb, float alpha, float flag, float fadelerp)\r
498 {\r
499         float sz;\r
500         sz = expandingbox_sizefactor_from_fadelerp(fadelerp);\r
501 \r
502         drawpic(position + expandingbox_resize_centered_box_offset(sz, scale, 1), pic, scale * sz, rgb, alpha * (1 - fadelerp), flag);\r
503 }\r
504 \r
505 void drawpic_expanding_two(vector position, string pic, vector scale, vector rgb, float alpha, float flag, float fadelerp)\r
506 {\r
507         drawpic_expanding(position, pic, scale, rgb, alpha, flag, fadelerp);\r
508         drawpic(position, pic, scale, rgb, alpha * fadelerp, flag);\r
509 }\r
510 \r
511 vector drawfontscale;\r
512 void drawstring_expanding(vector position, string text, vector scale, vector rgb, float alpha, float flag, float fadelerp)\r
513 {\r
514         float sz;\r
515         sz = expandingbox_sizefactor_from_fadelerp(fadelerp);\r
516 \r
517         if(cvar("menu_font_size_snapping_fix"))\r
518                 drawfontscale = sz * '1 1 0';\r
519         else\r
520                 drawfontscale = '1 1 0';\r
521         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);\r
522         drawstring(position + expandingbox_resize_centered_box_offset(sz, scale, stringwidth(text, FALSE, scale * (sz / drawfontscale_x)) / (scale_x * sz)), text, scale * (sz / drawfontscale_x), rgb, alpha * (1 - fadelerp), flag);\r
523         // width parameter:\r
524         //    (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)\r
525         //    SIZE1\r
526 \r
527         if(cvar("menu_font_size_snapping_fix"))\r
528                 drawfontscale = '1 1 0';\r
529 }\r
530 \r
531 void drawcolorcodedstring_expanding(vector position, string text, vector scale, float alpha, float flag, float fadelerp)\r
532 {\r
533         float sz;\r
534         sz = expandingbox_sizefactor_from_fadelerp(fadelerp);\r
535 \r
536         if(cvar("menu_font_size_snapping_fix"))\r
537                 drawfontscale = sz * '1 1 0';\r
538         else\r
539                 drawfontscale = '1 1 0';\r
540         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);\r
541         drawcolorcodedstring(position + expandingbox_resize_centered_box_offset(sz, scale, stringwidth(text, TRUE, scale * (sz / drawfontscale_x)) / (scale_x * sz)), text, scale * (sz / drawfontscale_x), alpha * (1 - fadelerp), flag);\r
542 \r
543         if(cvar("menu_font_size_snapping_fix"))\r
544                 drawfontscale = '1 1 0';\r
545 }\r
546 \r
547 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...\r
548 void PolyDrawModel(entity e)\r
549 {\r
550         float i_s, i_t;\r
551         float n_t;\r
552         vector tri;\r
553         string tex;\r
554         for(i_s = 0; ; ++i_s)\r
555         {\r
556                 tex = getsurfacetexture(e, i_s);\r
557                 if not(tex)\r
558                         break; // this is beyond the last one\r
559                 n_t = getsurfacenumtriangles(e, i_s);\r
560                 for(i_t = 0; i_t < n_t; ++i_t)\r
561                 {\r
562                         tri = getsurfacetriangle(e, i_s, i_t);\r
563                         R_BeginPolygon(tex, 0);\r
564                         R_PolygonVertex(getsurfacepoint(e, i_s, tri_x), getsurfacepointattribute(e, i_s, tri_x, SPA_TEXCOORDS0), '1 1 1', 1);\r
565                         R_PolygonVertex(getsurfacepoint(e, i_s, tri_y), getsurfacepointattribute(e, i_s, tri_y, SPA_TEXCOORDS0), '1 1 1', 1);\r
566                         R_PolygonVertex(getsurfacepoint(e, i_s, tri_z), getsurfacepointattribute(e, i_s, tri_z, SPA_TEXCOORDS0), '1 1 1', 1);\r
567                         R_EndPolygon();\r
568                 }\r
569         }\r
570 }\r
571 \r
572 void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vector rgb, float a, float drawflag)\r
573 {\r
574         float x, y, q, d;\r
575         vector ringsize, v, t;\r
576         ringsize = radius * '1 1 0';\r
577 \r
578         x = cos(f * 2 * M_PI);\r
579         y = sin(f * 2 * M_PI);\r
580         q = fabs(x) + fabs(y);\r
581         x /= q;\r
582         y /= q;\r
583 \r
584         if(f >= 1)\r
585         {\r
586                 // draw full rectangle\r
587                 R_BeginPolygon(pic, drawflag);\r
588                         v = centre;                     t = '0.5 0.5 0';\r
589                         v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';\r
590                         R_PolygonVertex(v, t, rgb, a);\r
591 \r
592                         v = centre;                     t = '0.5 0.5 0';\r
593                         v_y += 0.5 * ringsize_y;        t += '0.5 -0.5 0';\r
594                         R_PolygonVertex(v, t, rgb, a);\r
595 \r
596                         v = centre;                     t = '0.5 0.5 0';\r
597                         v_x -= 0.5 * ringsize_x;        t -= '0.5 0.5 0';\r
598                         R_PolygonVertex(v, t, rgb, a);\r
599 \r
600                         v = centre;                     t = '0.5 0.5 0';\r
601                         v_y -= 0.5 * ringsize_y;        t -= '0.5 -0.5 0';\r
602                         R_PolygonVertex(v, t, rgb, a);\r
603                 R_EndPolygon();\r
604 \r
605                 d = q - 1;\r
606                 if(d > 0)\r
607                 {\r
608                         R_BeginPolygon(pic, drawflag);\r
609                                 v = centre;                     t = '0.5 0.5 0';\r
610                                 R_PolygonVertex(v, t, rgb, a);\r
611 \r
612                                 v = centre;                     t = '0.5 0.5 0';\r
613                                 v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';\r
614                                 R_PolygonVertex(v, t, rgb, a);\r
615                 }\r
616         }\r
617         else if(f > 0.75)\r
618         {\r
619                 // draw upper and first triangle\r
620                 R_BeginPolygon(pic, drawflag);\r
621                         v = centre;                     t = '0.5 0.5 0';\r
622                         v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';\r
623                         R_PolygonVertex(v, t, rgb, a);\r
624 \r
625                         v = centre;                     t = '0.5 0.5 0';\r
626                         v_y += 0.5 * ringsize_y;        t += '0.5 -0.5 0';\r
627                         R_PolygonVertex(v, t, rgb, a);\r
628 \r
629                         v = centre;                     t = '0.5 0.5 0';\r
630                         v_x -= 0.5 * ringsize_x;        t -= '0.5 0.5 0';\r
631                         R_PolygonVertex(v, t, rgb, a);\r
632                 R_EndPolygon();\r
633                 R_BeginPolygon(pic, drawflag);\r
634                         v = centre;                     t = '0.5 0.5 0';\r
635                         R_PolygonVertex(v, t, rgb, a);\r
636 \r
637                         v = centre;                     t = '0.5 0.5 0';\r
638                         v_x -= 0.5 * ringsize_x;        t -= '0.5 0.5 0';\r
639                         R_PolygonVertex(v, t, rgb, a);\r
640 \r
641                         v = centre;                     t = '0.5 0.5 0';\r
642                         v_y -= 0.5 * ringsize_y;        t -= '0.5 -0.5 0';\r
643                         R_PolygonVertex(v, t, rgb, a);\r
644 \r
645                 d = q - 0.75;\r
646                 if(d <= 0)\r
647                         R_EndPolygon();\r
648         }\r
649         else if(f > 0.5)\r
650         {\r
651                 // draw upper triangle\r
652                 R_BeginPolygon(pic, drawflag);\r
653                         v = centre;                     t = '0.5 0.5 0';\r
654                         v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';\r
655                         R_PolygonVertex(v, t, rgb, a);\r
656 \r
657                         v = centre;                     t = '0.5 0.5 0';\r
658                         v_y += 0.5 * ringsize_y;        t += '0.5 -0.5 0';\r
659                         R_PolygonVertex(v, t, rgb, a);\r
660 \r
661                         v = centre;                     t = '0.5 0.5 0';\r
662                         v_x -= 0.5 * ringsize_x;        t -= '0.5 0.5 0';\r
663                         R_PolygonVertex(v, t, rgb, a);\r
664                 R_EndPolygon();\r
665 \r
666                 d = q - 0.5;\r
667                 if(d > 0)\r
668                 {\r
669                         R_BeginPolygon(pic, drawflag);\r
670                                 v = centre;                     t = '0.5 0.5 0';\r
671                                 R_PolygonVertex(v, t, rgb, a);\r
672 \r
673                                 v = centre;                     t = '0.5 0.5 0';\r
674                                 v_x -= 0.5 * ringsize_x;        t -= '0.5 0.5 0';\r
675                                 R_PolygonVertex(v, t, rgb, a);\r
676                 }\r
677         }\r
678         else if(f > 0.25)\r
679         {\r
680                 // draw first triangle\r
681                 R_BeginPolygon(pic, drawflag);\r
682                         v = centre;                     t = '0.5 0.5 0';\r
683                         R_PolygonVertex(v, t, rgb, a);\r
684 \r
685                         v = centre;                     t = '0.5 0.5 0';\r
686                         v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';\r
687                         R_PolygonVertex(v, t, rgb, a);\r
688 \r
689                         v = centre;                     t = '0.5 0.5 0';\r
690                         v_y += 0.5 * ringsize_y;        t += '0.5 -0.5 0';\r
691                         R_PolygonVertex(v, t, rgb, a);\r
692 \r
693                 d = q - 0.25;\r
694                 if(d <= 0)\r
695                         R_EndPolygon();\r
696         }\r
697         else\r
698         {\r
699                 d = q;\r
700                 if(d > 0)\r
701                 {\r
702                         R_BeginPolygon(pic, drawflag);\r
703                                 v = centre;                     t = '0.5 0.5 0';\r
704                                 R_PolygonVertex(v, t, rgb, a);\r
705 \r
706                                 v = centre;                     t = '0.5 0.5 0';\r
707                                 v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';\r
708                                 R_PolygonVertex(v, t, rgb, a);\r
709                 }\r
710         }\r
711 \r
712         if(d > 0)\r
713         {\r
714                         v = centre;                     t = '0.5 0.5 0';\r
715                         v_x += x * 0.5 * ringsize_x;    t += x * '0.5 0.5 0';\r
716                         v_y += y * 0.5 * ringsize_y;    t += y * '0.5 -0.5 0';\r
717                         R_PolygonVertex(v, t, rgb, a);\r
718                 R_EndPolygon();\r
719         }\r
720 }\r
721 \r
722 const vector GETPLAYERORIGIN_ERROR = '1123581321 2357111317 3141592653'; // way out of bounds for anything on the map\r
723 vector getplayerorigin(float pl)\r
724 {\r
725         string s;\r
726         entity e;\r
727 \r
728         s = getplayerkey(pl, "TEMPHACK_origin");\r
729         if(s != "")\r
730                 return stov(s);\r
731 \r
732         e = entcs_receiver[pl];\r
733         if(e)\r
734                 return e.origin;\r
735 \r
736         return GETPLAYERORIGIN_ERROR;\r
737 }\r