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