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