]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/modicons.qc
Merge branch 'master' into Mario/overkill
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / modicons.qc
1 #include "modicons.qh"
2
3 #include <common/mapinfo.qh>
4 #include <common/ent_cs.qh>
5 #include <server/mutators/mutator/gamemode_ctf.qh> // TODO: remove
6
7 // Mod icons (#10)
8
9 bool mod_active; // is there any active mod icon?
10
11 void DrawCAItem(vector myPos, vector mySize, float aspect_ratio, int layout, int i)
12 {
13     TC(int, layout); TC(int, i);
14         int stat = -1;
15         string pic = "";
16         vector color = '0 0 0';
17         switch(i)
18         {
19                 case 0: stat = STAT(REDALIVE); pic = "player_red"; color = '1 0 0'; break;
20                 case 1: stat = STAT(BLUEALIVE); pic = "player_blue"; color = '0 0 1'; break;
21                 case 2: stat = STAT(YELLOWALIVE); pic = "player_yellow"; color = '1 1 0'; break;
22                 default:
23                 case 3: stat = STAT(PINKALIVE); pic = "player_pink"; color = '1 0 1'; break;
24         }
25
26         if(mySize.x/mySize.y > aspect_ratio)
27         {
28                 i = aspect_ratio * mySize.y;
29                 myPos.x = myPos.x + (mySize.x - i) / 2;
30                 mySize.x = i;
31         }
32         else
33         {
34                 i = 1/aspect_ratio * mySize.x;
35                 myPos.y = myPos.y + (mySize.y - i) / 2;
36                 mySize.y = i;
37         }
38
39         if(layout)
40         {
41                 drawpic_aspect_skin(myPos, pic, eX * 0.7 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
42                 drawstring_aspect(myPos + eX * 0.7 * mySize.x, ftos(stat), eX * 0.3 * mySize.x + eY * mySize.y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
43         }
44         else
45                 drawstring_aspect(myPos, ftos(stat), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
46 }
47
48 // Clan Arena and Freeze Tag HUD modicons
49 void HUD_Mod_CA(vector myPos, vector mySize)
50 {
51         mod_active = 1; // required in each mod function that always shows something
52
53         int layout;
54         if(gametype == MAPINFO_TYPE_CA)
55                 layout = autocvar_hud_panel_modicons_ca_layout;
56         else //if(gametype == MAPINFO_TYPE_FREEZETAG)
57                 layout = autocvar_hud_panel_modicons_freezetag_layout;
58         int rows, columns;
59         float aspect_ratio;
60         aspect_ratio = (layout) ? 2 : 1;
61         rows = HUD_GetRowCount(team_count, mySize, aspect_ratio);
62         columns = ceil(team_count/rows);
63
64         int i;
65         float row = 0, column = 0;
66         vector pos, itemSize;
67         itemSize = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
68         for(i=0; i<team_count; ++i)
69         {
70                 pos = myPos + eX * column * itemSize.x + eY * row * itemSize.y;
71
72                 DrawCAItem(pos, itemSize, aspect_ratio, layout, i);
73
74                 ++row;
75                 if(row >= rows)
76                 {
77                         row = 0;
78                         ++column;
79                 }
80         }
81 }
82
83 // CTF HUD modicon section
84 int redflag_prevframe, blueflag_prevframe, yellowflag_prevframe, pinkflag_prevframe, neutralflag_prevframe; // status during previous frame
85 int redflag_prevstatus, blueflag_prevstatus, yellowflag_prevstatus, pinkflag_prevstatus, neutralflag_prevstatus; // last remembered status
86 float redflag_statuschange_time, blueflag_statuschange_time, yellowflag_statuschange_time, pinkflag_statuschange_time, neutralflag_statuschange_time; // time when the status changed
87
88 void HUD_Mod_CTF_Reset()
89 {
90         redflag_prevstatus = blueflag_prevstatus = yellowflag_prevstatus = pinkflag_prevstatus = neutralflag_prevstatus = 0;
91         redflag_prevframe = blueflag_prevframe = yellowflag_prevframe = pinkflag_prevframe = neutralflag_prevframe = 0;
92         redflag_statuschange_time = blueflag_statuschange_time = yellowflag_statuschange_time = pinkflag_statuschange_time = neutralflag_statuschange_time = 0;
93 }
94
95 int autocvar__teams_available;
96 void HUD_Mod_CTF(vector pos, vector mySize)
97 {
98         vector redflag_pos, blueflag_pos, yellowflag_pos, pinkflag_pos, neutralflag_pos;
99         vector flag_size;
100         float f; // every function should have that
101
102         int redflag, blueflag, yellowflag, pinkflag, neutralflag; // current status
103         float redflag_statuschange_elapsedtime = 0, blueflag_statuschange_elapsedtime = 0, yellowflag_statuschange_elapsedtime = 0, pinkflag_statuschange_elapsedtime = 0, neutralflag_statuschange_elapsedtime = 0; // time since the status changed
104         bool ctf_oneflag; // one-flag CTF mode enabled/disabled
105         bool ctf_stalemate; // currently in stalemate
106         int stat_items = STAT(CTF_FLAGSTATUS);
107         float fs, fs2, fs3, size1, size2;
108         vector e1, e2;
109
110         int nteams = autocvar__teams_available;
111
112         redflag = (stat_items/CTF_RED_FLAG_TAKEN) & 3;
113         blueflag = (stat_items/CTF_BLUE_FLAG_TAKEN) & 3;
114         yellowflag = (stat_items/CTF_YELLOW_FLAG_TAKEN) & 3;
115         pinkflag = (stat_items/CTF_PINK_FLAG_TAKEN) & 3;
116         neutralflag = (stat_items/CTF_NEUTRAL_FLAG_TAKEN) & 3;
117
118         ctf_oneflag = (stat_items & CTF_FLAG_NEUTRAL);
119
120         ctf_stalemate = (stat_items & CTF_STALEMATE);
121
122         mod_active = (redflag || blueflag || yellowflag || pinkflag || neutralflag || (stat_items & CTF_SHIELDED));
123
124         if (autocvar__hud_configure) {
125                 redflag = 1;
126                 blueflag = 2;
127                 if (nteams & BIT(2))
128                         yellowflag = 2;
129                 if (nteams & BIT(3))
130                         pinkflag = 3;
131                 ctf_oneflag = neutralflag = 0; // disable neutral flag in hud editor?
132         }
133
134         // when status CHANGES, set old status into prevstatus and current status into status
135         #define X(team) MACRO_BEGIN {                                                                                                   \
136                 if (team##flag != team##flag_prevframe) {                                                                       \
137                 team##flag_statuschange_time = time;                                                                    \
138                 team##flag_prevstatus = team##flag_prevframe;                                                   \
139                 team##flag_prevframe = team##flag;                                                                              \
140         }                                                                                                                                                       \
141         team##flag_statuschange_elapsedtime = time - team##flag_statuschange_time;      \
142     } MACRO_END
143         X(red);
144         X(blue);
145         X(yellow);
146         X(pink);
147         X(neutral);
148         #undef X
149
150         const float BLINK_FACTOR = 0.15;
151         const float BLINK_BASE = 0.85;
152         // note:
153         //   RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
154         // thus
155         //   BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
156         // ensure RMS == 1
157         const float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
158
159         #define X(team, cond) \
160         string team##_icon = string_null, team##_icon_prevstatus = string_null; \
161         int team##_alpha, team##_alpha_prevstatus; \
162         team##_alpha = team##_alpha_prevstatus = 1; \
163         MACRO_BEGIN { \
164                 switch (team##flag) { \
165                         case 1: team##_icon = "flag_" #team "_taken"; break; \
166                         case 2: team##_icon = "flag_" #team "_lost"; break; \
167                         case 3: team##_icon = "flag_" #team "_carrying"; team##_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break; \
168                         default: \
169                                 if ((stat_items & CTF_SHIELDED) && (cond)) { \
170                                         team##_icon = "flag_" #team "_shielded"; \
171                                 } else { \
172                                         team##_icon = string_null; \
173                                 } \
174                                 break; \
175                 } \
176                 switch (team##flag_prevstatus) { \
177                         case 1: team##_icon_prevstatus = "flag_" #team "_taken"; break; \
178                         case 2: team##_icon_prevstatus = "flag_" #team "_lost"; break; \
179                         case 3: team##_icon_prevstatus = "flag_" #team "_carrying"; team##_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break; \
180                         default: \
181                                 if (team##flag == 3) { \
182                                         team##_icon_prevstatus = "flag_" #team "_carrying"; /* make it more visible */\
183                                 } else if((stat_items & CTF_SHIELDED) && (cond)) { \
184                                         team##_icon_prevstatus = "flag_" #team "_shielded"; \
185                                 } else { \
186                                         team##_icon_prevstatus = string_null; \
187                                 } \
188                                 break; \
189                 } \
190         } MACRO_END
191         X(red, myteam != NUM_TEAM_1 && (nteams & BIT(0)));
192         X(blue, myteam != NUM_TEAM_2 && (nteams & BIT(1)));
193         X(yellow, myteam != NUM_TEAM_3 && (nteams & BIT(2)));
194         X(pink, myteam != NUM_TEAM_4 && (nteams & BIT(3)));
195         X(neutral, ctf_oneflag);
196         #undef X
197
198         int tcount = 2;
199         if(nteams & BIT(2))
200                 tcount = 3;
201         if(nteams & BIT(3))
202                 tcount = 4;
203
204         if (ctf_oneflag) {
205                 // hacky, but these aren't needed
206                 red_icon = red_icon_prevstatus = blue_icon = blue_icon_prevstatus = yellow_icon = yellow_icon_prevstatus = pink_icon = pink_icon_prevstatus = string_null;
207                 fs = fs2 = fs3 = 1;
208         } else switch (tcount) {
209                 default:
210                 case 2: fs = 0.5; fs2 = 0.5; fs3 = 0.5; break;
211                 case 3: fs = 1; fs2 = 0.35; fs3 = 0.35; break;
212                 case 4: fs = 0.75; fs2 = 0.25; fs3 = 0.5; break;
213         }
214
215         if (mySize_x > mySize_y) {
216                 size1 = mySize_x;
217                 size2 = mySize_y;
218                 e1 = eX;
219                 e2 = eY;
220         } else {
221                 size1 = mySize_y;
222                 size2 = mySize_x;
223                 e1 = eY;
224                 e2 = eX;
225         }
226
227         switch (myteam) {
228                 default:
229                 case NUM_TEAM_1: {
230                         redflag_pos = pos;
231                         blueflag_pos = pos + eX * fs2 * size1;
232                         yellowflag_pos = pos - eX * fs2 * size1;
233                         pinkflag_pos = pos + eX * fs3 * size1;
234                         break;
235                 }
236                 case NUM_TEAM_2: {
237                         redflag_pos = pos + eX * fs2 * size1;
238                         blueflag_pos = pos;
239                         yellowflag_pos = pos - eX * fs2 * size1;
240                         pinkflag_pos = pos + eX * fs3 * size1;
241                         break;
242                 }
243                 case NUM_TEAM_3: {
244                         redflag_pos = pos + eX * fs3 * size1;
245                         blueflag_pos = pos - eX * fs2 * size1;
246                         yellowflag_pos = pos;
247                         pinkflag_pos = pos + eX * fs2 * size1;
248                         break;
249                 }
250                 case NUM_TEAM_4: {
251                         redflag_pos = pos - eX * fs2 * size1;
252                         blueflag_pos = pos + eX * fs3 * size1;
253                         yellowflag_pos = pos + eX * fs2 * size1;
254                         pinkflag_pos = pos;
255                         break;
256                 }
257         }
258         neutralflag_pos = pos;
259         flag_size = e1 * fs * size1 + e2 * size2;
260
261         #define X(team) MACRO_BEGIN { \
262                 f = bound(0, team##flag_statuschange_elapsedtime * 2, 1); \
263                 if (team##_icon && ctf_stalemate) \
264                         drawpic_aspect_skin(team##flag_pos, "flag_stalemate", flag_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); \
265                 if (team##_icon_prevstatus && f < 1) \
266                         drawpic_aspect_skin_expanding(team##flag_pos, team##_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * team##_alpha_prevstatus, DRAWFLAG_NORMAL, f); \
267                 if (team##_icon) \
268                         drawpic_aspect_skin(team##flag_pos, team##_icon, flag_size, '1 1 1', panel_fg_alpha * team##_alpha * f, DRAWFLAG_NORMAL); \
269         } MACRO_END
270         X(red);
271         X(blue);
272         X(yellow);
273         X(pink);
274         X(neutral);
275         #undef X
276 }
277
278 // Keyhunt HUD modicon section
279 vector KH_SLOTS[4];
280
281 void HUD_Mod_KH(vector pos, vector mySize)
282 {
283         mod_active = 1; // keyhunt should never hide the mod icons panel
284
285         // Read current state
286         int state = STAT(KH_KEYS);
287         if(!state) return;
288
289         int i, key_state;
290         int all_keys, team1_keys, team2_keys, team3_keys, team4_keys, dropped_keys, carrying_keys;
291         all_keys = team1_keys = team2_keys = team3_keys = team4_keys = dropped_keys = carrying_keys = 0;
292
293         for(i = 0; i < 4; ++i)
294         {
295                 key_state = (bitshift(state, i * -5) & 31) - 1;
296
297                 if(key_state == -1)
298                         continue;
299
300                 if(key_state == 30)
301                 {
302                         ++carrying_keys;
303                         key_state = myteam;
304                 }
305
306                 switch(key_state)
307                 {
308                         case NUM_TEAM_1: ++team1_keys; break;
309                         case NUM_TEAM_2: ++team2_keys; break;
310                         case NUM_TEAM_3: ++team3_keys; break;
311                         case NUM_TEAM_4: ++team4_keys; break;
312                         case 29: ++dropped_keys; break;
313                 }
314
315                 ++all_keys;
316         }
317
318         // Calculate slot measurements
319         vector slot_size;
320         if(all_keys == 4 && mySize.x * 0.5 < mySize.y && mySize.y * 0.5 < mySize.x)
321         {
322                 // Quadratic arrangement
323                 slot_size = eX * mySize.x * 0.5 + eY * mySize.y * 0.5;
324                 KH_SLOTS[0] = pos;
325                 KH_SLOTS[1] = pos + eX * slot_size.x;
326                 KH_SLOTS[2] = pos + eY * slot_size.y;
327                 KH_SLOTS[3] = pos + eX * slot_size.x + eY * slot_size.y;
328         }
329         else
330         {
331                 if(mySize.x > mySize.y)
332                 {
333                         // Horizontal arrangement
334                         slot_size = eX * mySize.x / all_keys + eY * mySize.y;
335                         for(i = 0; i < all_keys; ++i)
336                                 KH_SLOTS[i] = pos + eX * slot_size.x * i;
337                 }
338                 else
339                 {
340                         // Vertical arrangement
341                         slot_size = eX * mySize.x + eY * mySize.y / all_keys;
342                         for(i = 0; i < all_keys; ++i)
343                                 KH_SLOTS[i] = pos + eY * slot_size.y * i;
344                 }
345         }
346
347         // Make icons blink in case of RUN HERE
348
349         float alpha = 1;
350         if(carrying_keys)
351         {
352                 float blink = 0.6 + sin(2 * M_PI * time) * 0.4; // Oscillate between 0.2 and 1
353                 switch(myteam)
354                 {
355                         case NUM_TEAM_1: if(team1_keys == all_keys) alpha = blink; break;
356                         case NUM_TEAM_2: if(team2_keys == all_keys) alpha = blink; break;
357                         case NUM_TEAM_3: if(team3_keys == all_keys) alpha = blink; break;
358                         case NUM_TEAM_4: if(team4_keys == all_keys) alpha = blink; break;
359                 }
360         }
361
362         // Draw icons
363
364         i = 0;
365
366         while(team1_keys--)
367                 if(myteam == NUM_TEAM_1 && carrying_keys)
368                 {
369                         drawpic_aspect_skin(KH_SLOTS[i++], "kh_red_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
370                         --carrying_keys;
371                 }
372                 else
373                         drawpic_aspect_skin(KH_SLOTS[i++], "kh_red_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
374
375         while(team2_keys--)
376                 if(myteam == NUM_TEAM_2 && carrying_keys)
377                 {
378                         drawpic_aspect_skin(KH_SLOTS[i++], "kh_blue_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
379                         --carrying_keys;
380                 }
381                 else
382                         drawpic_aspect_skin(KH_SLOTS[i++], "kh_blue_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
383
384         while(team3_keys--)
385                 if(myteam == NUM_TEAM_3 && carrying_keys)
386                 {
387                         drawpic_aspect_skin(KH_SLOTS[i++], "kh_yellow_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
388                         --carrying_keys;
389                 }
390                 else
391                         drawpic_aspect_skin(KH_SLOTS[i++], "kh_yellow_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
392
393         while(team4_keys--)
394                 if(myteam == NUM_TEAM_4 && carrying_keys)
395                 {
396                         drawpic_aspect_skin(KH_SLOTS[i++], "kh_pink_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
397                         --carrying_keys;
398                 }
399                 else
400                         drawpic_aspect_skin(KH_SLOTS[i++], "kh_pink_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
401
402         while(dropped_keys--)
403                 drawpic_aspect_skin(KH_SLOTS[i++], "kh_dropped", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
404 }
405
406 // Keepaway HUD mod icon
407 int kaball_prevstatus; // last remembered status
408 float kaball_statuschange_time; // time when the status changed
409
410 // we don't need to reset for keepaway since it immediately
411 // autocorrects prevstatus as to if the player has the ball or not
412
413 void HUD_Mod_Keepaway(vector pos, vector mySize)
414 {
415         mod_active = 1; // keepaway should always show the mod HUD
416
417         float BLINK_FACTOR = 0.15;
418         float BLINK_BASE = 0.85;
419         float BLINK_FREQ = 5;
420         float kaball_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
421
422         int stat_items = STAT(ITEMS);
423         int kaball = (stat_items/IT_KEY1) & 1;
424
425         if(kaball != kaball_prevstatus)
426         {
427                 kaball_statuschange_time = time;
428                 kaball_prevstatus = kaball;
429         }
430
431         vector kaball_pos, kaball_size;
432
433         if(mySize.x > mySize.y) {
434                 kaball_pos = pos + eX * 0.25 * mySize.x;
435                 kaball_size = eX * 0.5 * mySize.x + eY * mySize.y;
436         } else {
437                 kaball_pos = pos + eY * 0.25 * mySize.y;
438                 kaball_size = eY * 0.5 * mySize.y + eX * mySize.x;
439         }
440
441         float kaball_statuschange_elapsedtime = time - kaball_statuschange_time;
442         float f = bound(0, kaball_statuschange_elapsedtime*2, 1);
443
444         if(kaball_prevstatus && f < 1)
445                 drawpic_aspect_skin_expanding(kaball_pos, "keepawayball_carrying", kaball_size, '1 1 1', panel_fg_alpha * kaball_alpha, DRAWFLAG_NORMAL, f);
446
447         if(kaball)
448                 drawpic_aspect_skin(pos, "keepawayball_carrying", eX * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha * kaball_alpha * f, DRAWFLAG_NORMAL);
449 }
450
451
452 // Nexball HUD mod icon
453 void HUD_Mod_NexBall(vector pos, vector mySize)
454 {
455         float nb_pb_starttime, dt, p;
456         int stat_items;
457
458         stat_items = STAT(ITEMS);
459         nb_pb_starttime = STAT(NB_METERSTART);
460
461         if (stat_items & IT_KEY1)
462                 mod_active = 1;
463         else
464                 mod_active = 0;
465
466         //Manage the progress bar if any
467         if (nb_pb_starttime > 0)
468         {
469                 dt = (time - nb_pb_starttime) % nb_pb_period;
470                 // one period of positive triangle
471                 p = 2 * dt / nb_pb_period;
472                 if (p > 1)
473                         p = 2 - p;
474
475                 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", p, (mySize.x <= mySize.y), 0, autocvar_hud_progressbar_nexball_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
476         }
477
478         if (stat_items & IT_KEY1)
479                 drawpic_aspect_skin(pos, "nexball_carrying", eX * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
480 }
481
482 // Race/CTS HUD mod icons
483 float crecordtime_prev; // last remembered crecordtime
484 float crecordtime_change_time; // time when crecordtime last changed
485 float srecordtime_prev; // last remembered srecordtime
486 float srecordtime_change_time; // time when srecordtime last changed
487
488 float race_status_time;
489 int race_status_prev;
490 string race_status_name_prev;
491
492 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
493 int race_CheckName(string net_name)
494 {
495         int i;
496         for (i=RANKINGS_CNT-1;i>=0;--i)
497                 if(grecordholder[i] == net_name)
498                         return i+1;
499         return 0;
500 }
501
502 void race_showTime(string text, vector pos, vector timeText_ofs, float theTime, vector textSize, float f)
503 {
504         drawstring_aspect(pos, text, textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
505         drawstring_aspect(pos + timeText_ofs, TIME_ENCODED_TOSTRING(theTime), textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
506         if (f < 1) {
507                 drawstring_aspect_expanding(pos, text, textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
508                 drawstring_aspect_expanding(pos + timeText_ofs, TIME_ENCODED_TOSTRING(theTime), textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
509         }
510 }
511
512 void HUD_Mod_Race(vector pos, vector mySize)
513 {
514         mod_active = 1; // race should never hide the mod icons panel
515         entity me;
516         me = playerslots[player_localnum];
517         float score;
518         score = me.(scores(ps_primary));
519
520         if(!(scores_flags(ps_primary) & SFL_TIME) || teamplay) // race/cts record display on HUD
521                 return; // no records in the actual race
522
523         // clientside personal record
524         string rr;
525         if(gametype == MAPINFO_TYPE_CTS)
526                 rr = CTS_RECORD;
527         else
528                 rr = RACE_RECORD;
529         float t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
530
531         if(score && (score < t || !t)) {
532                 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
533                 if(autocvar_cl_autodemo_delete_keeprecords)
534                 {
535                         float f = autocvar_cl_autodemo_delete;
536                         f &= ~1;
537                         cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
538                 }
539         }
540
541         if(t != crecordtime_prev) {
542                 crecordtime_prev = t;
543                 crecordtime_change_time = time;
544         }
545
546         vector textPos, medalPos;
547         float squareSize;
548         if(mySize.x > mySize.y) {
549                 // text on left side
550                 squareSize = min(mySize.y, mySize.x/2);
551                 textPos = pos + eX * 0.5 * max(0, mySize.x/2 - squareSize) + eY * 0.5 * (mySize.y - squareSize);
552                 medalPos = pos + eX * 0.5 * max(0, mySize.x/2 - squareSize) + eX * 0.5 * mySize.x + eY * 0.5 * (mySize.y - squareSize);
553         } else {
554                 // text on top
555                 squareSize = min(mySize.x, mySize.y/2);
556                 textPos = pos + eY * 0.5 * max(0, mySize.y/2 - squareSize) + eX * 0.5 * (mySize.x - squareSize);
557                 medalPos = pos + eY * 0.5 * max(0, mySize.y/2 - squareSize) + eY * 0.5 * mySize.y + eX * 0.5 * (mySize.x - squareSize);
558         }
559         vector textSize = eX * squareSize + eY * 0.25 * squareSize;
560
561         race_showTime(_("Personal best"), textPos, eY * 0.25 * squareSize, t, textSize, time - crecordtime_change_time);
562
563         // server record
564         t = race_server_record;
565         if(t != srecordtime_prev) {
566                 srecordtime_prev = t;
567                 srecordtime_change_time = time;
568         }
569
570         textPos += eY * 0.5 * squareSize;
571         race_showTime(_("Server best"), textPos, eY * 0.25 * squareSize, t, textSize, time - srecordtime_change_time);
572
573         if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
574                 race_status_time = time + 5;
575                 race_status_prev = race_status;
576                 if (race_status_name_prev)
577                         strunzone(race_status_name_prev);
578                 race_status_name_prev = strzone(race_status_name);
579         }
580
581         // race "awards"
582         float a;
583         a = bound(0, race_status_time - time, 1);
584
585         string s;
586         s = textShortenToWidth(race_status_name, squareSize, '1 1 0' * 0.1 * squareSize, stringwidth_colors);
587
588         float rank;
589         if(race_status > 0)
590                 rank = race_CheckName(race_status_name);
591         else
592                 rank = 0;
593         string rankname;
594         rankname = count_ordinal(rank);
595
596         vector namepos;
597         namepos = medalPos + '0 0.8 0' * squareSize;
598         vector rankpos;
599         rankpos = medalPos + '0 0.15 0' * squareSize;
600
601         if(race_status == 0)
602                 drawpic_aspect_skin(medalPos, "race_newfail", '1 1 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
603         else if(race_status == 1) {
604                 drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newtime", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
605                 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
606                 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
607         } else if(race_status == 2) {
608                 if(race_status_name == entcs_GetName(player_localnum) || !race_myrank || race_myrank < rank)
609                         drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newrankgreen", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
610                 else
611                         drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newrankyellow", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
612                 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
613                 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
614         } else if(race_status == 3) {
615                 drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newrecordserver", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
616                 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
617                 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
618         }
619
620         if (race_status_time - time <= 0) {
621                 race_status_prev = -1;
622                 race_status = -1;
623                 if(race_status_name)
624                         strunzone(race_status_name);
625                 race_status_name = string_null;
626                 if(race_status_name_prev)
627                         strunzone(race_status_name_prev);
628                 race_status_name_prev = string_null;
629         }
630 }
631
632 void DrawDomItem(vector myPos, vector mySize, float aspect_ratio, int layout, int i)
633 {
634     TC(int, layout); TC(int, i);
635         float stat = -1;
636         string pic = "";
637         vector color = '0 0 0';
638         switch(i)
639         {
640                 case 0: stat = STAT(DOM_PPS_RED); pic = "dom_icon_red"; color = '1 0 0'; break;
641                 case 1: stat = STAT(DOM_PPS_BLUE); pic = "dom_icon_blue"; color = '0 0 1'; break;
642                 case 2: stat = STAT(DOM_PPS_YELLOW); pic = "dom_icon_yellow"; color = '1 1 0'; break;
643                 default:
644                 case 3: stat = STAT(DOM_PPS_PINK); pic = "dom_icon_pink"; color = '1 0 1'; break;
645         }
646         float pps_ratio = 0;
647         if(STAT(DOM_TOTAL_PPS))
648                 pps_ratio = stat / STAT(DOM_TOTAL_PPS);
649
650         if(mySize.x/mySize.y > aspect_ratio)
651         {
652                 i = aspect_ratio * mySize.y;
653                 myPos.x = myPos.x + (mySize.x - i) / 2;
654                 mySize.x = i;
655         }
656         else
657         {
658                 i = 1/aspect_ratio * mySize.x;
659                 myPos.y = myPos.y + (mySize.y - i) / 2;
660                 mySize.y = i;
661         }
662
663         if (layout) // show text too
664         {
665                 //draw the text
666                 color *= 0.5 + pps_ratio * (1 - 0.5); // half saturated color at min, full saturated at max
667                 if (layout == 2) // average pps
668                         drawstring_aspect(myPos + eX * mySize.y, ftos_decimals(stat, 2), eX * (2/3) * mySize.x + eY * mySize.y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
669                 else // percentage of average pps
670                         drawstring_aspect(myPos + eX * mySize.y, strcat( ftos(floor(pps_ratio*100 + 0.5)), "%" ), eX * (2/3) * mySize.x + eY * mySize.y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
671         }
672
673         //draw the icon
674         drawpic_aspect_skin(myPos, pic, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
675         if (stat > 0)
676         {
677                 drawsetcliparea(myPos.x, myPos.y + mySize.y * (1 - pps_ratio), mySize.y, mySize.y * pps_ratio);
678                 drawpic_aspect_skin(myPos, strcat(pic, "-highlighted"), '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
679                 drawresetcliparea();
680         }
681 }
682
683 void HUD_Mod_Dom(vector myPos, vector mySize)
684 {
685         mod_active = 1; // required in each mod function that always shows something
686
687         int layout = autocvar_hud_panel_modicons_dom_layout;
688         int rows, columns;
689         float aspect_ratio;
690         aspect_ratio = (layout) ? 3 : 1;
691         rows = HUD_GetRowCount(team_count, mySize, aspect_ratio);
692         columns = ceil(team_count/rows);
693
694         int i;
695         float row = 0, column = 0;
696         vector pos, itemSize;
697         itemSize = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
698         for(i=0; i<team_count; ++i)
699         {
700                 pos = myPos + eX * column * itemSize.x + eY * row * itemSize.y;
701
702                 DrawDomItem(pos, itemSize, aspect_ratio, layout, i);
703
704                 ++row;
705                 if(row >= rows)
706                 {
707                         row = 0;
708                         ++column;
709                 }
710         }
711 }
712
713 void HUD_ModIcons_SetFunc()
714 {
715         HUD_ModIcons_GameType = gametype.m_modicons;
716 }
717
718 float mod_alpha;
719
720 void HUD_ModIcons()
721 {
722         if(!autocvar__hud_configure)
723         {
724                 if(!autocvar_hud_panel_modicons) return;
725                 if(!HUD_ModIcons_GameType) return;
726         }
727
728         if(mod_active || autocvar__hud_configure)
729                 mod_alpha = min(mod_alpha + frametime * 2, 1);
730         else
731                 mod_alpha = max(mod_alpha - frametime * 2, 0);
732
733         //if(mod_alpha <= 0)
734         //      return;
735         panel_fade_alpha *= mod_alpha;
736         HUD_Panel_LoadCvars();
737
738         draw_beginBoldFont();
739
740         if (autocvar_hud_panel_modicons_dynamichud)
741                 HUD_Scale_Enable();
742         else
743                 HUD_Scale_Disable();
744
745         HUD_Panel_DrawBg();
746
747         if(panel_bg_padding)
748         {
749                 panel_pos += '1 1 0' * panel_bg_padding;
750                 panel_size -= '2 2 0' * panel_bg_padding;
751         }
752
753         if(autocvar__hud_configure)
754                 HUD_Mod_CTF(panel_pos, panel_size);
755         else
756                 HUD_ModIcons_GameType(panel_pos, panel_size);
757
758         draw_endBoldFont();
759 }