]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/modicons.qc
HUD_Mod_Race: cleanup
[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 void race_showTime(string text, vector pos, vector timeText_ofs, float theTime, vector textSize, float f)
489 {
490         drawstring_aspect(pos, text, textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
491         drawstring_aspect(pos + timeText_ofs, TIME_ENCODED_TOSTRING(theTime), textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
492         if (f < 1) {
493                 drawstring_aspect_expanding(pos, text, textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
494                 drawstring_aspect_expanding(pos + timeText_ofs, TIME_ENCODED_TOSTRING(theTime), textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
495         }
496 }
497
498 void HUD_Mod_Race(vector pos, vector mySize)
499 {
500         mod_active = 1; // race should never hide the mod icons panel
501         entity me;
502         me = playerslots[player_localnum];
503         float score;
504         score = me.(scores[ps_primary]);
505
506         if(!(scores_flags[ps_primary] & SFL_TIME) || teamplay) // race/cts record display on HUD
507                 return; // no records in the actual race
508
509         // clientside personal record
510         string rr;
511         if(gametype == MAPINFO_TYPE_CTS)
512                 rr = CTS_RECORD;
513         else
514                 rr = RACE_RECORD;
515         float t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
516
517         if(score && (score < t || !t)) {
518                 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
519                 if(autocvar_cl_autodemo_delete_keeprecords)
520                 {
521                         float f = autocvar_cl_autodemo_delete;
522                         f &= ~1;
523                         cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
524                 }
525         }
526
527         if(t != crecordtime_prev) {
528                 crecordtime_prev = t;
529                 crecordtime_change_time = time;
530         }
531
532         vector textPos, medalPos;
533         float squareSize;
534         if(mySize.x > mySize.y) {
535                 // text on left side
536                 squareSize = min(mySize.y, mySize.x/2);
537                 textPos = pos + eX * 0.5 * max(0, mySize.x/2 - squareSize) + eY * 0.5 * (mySize.y - squareSize);
538                 medalPos = pos + eX * 0.5 * max(0, mySize.x/2 - squareSize) + eX * 0.5 * mySize.x + eY * 0.5 * (mySize.y - squareSize);
539         } else {
540                 // text on top
541                 squareSize = min(mySize.x, mySize.y/2);
542                 textPos = pos + eY * 0.5 * max(0, mySize.y/2 - squareSize) + eX * 0.5 * (mySize.x - squareSize);
543                 medalPos = pos + eY * 0.5 * max(0, mySize.y/2 - squareSize) + eY * 0.5 * mySize.y + eX * 0.5 * (mySize.x - squareSize);
544         }
545         vector textSize = eX * squareSize + eY * 0.25 * squareSize;
546
547         race_showTime(_("Personal best"), textPos, eY * 0.25 * squareSize, t, textSize, time - crecordtime_change_time);
548
549         // server record
550         t = race_server_record;
551         if(t != srecordtime_prev) {
552                 srecordtime_prev = t;
553                 srecordtime_change_time = time;
554         }
555
556         textPos += eY * 0.5 * squareSize;
557         race_showTime(_("Server best"), textPos, eY * 0.25 * squareSize, t, textSize, time - srecordtime_change_time);
558
559         if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
560                 race_status_time = time + 5;
561                 race_status_prev = race_status;
562                 if (race_status_name_prev)
563                         strunzone(race_status_name_prev);
564                 race_status_name_prev = strzone(race_status_name);
565         }
566
567         // race "awards"
568         float a;
569         a = bound(0, race_status_time - time, 1);
570
571         string s;
572         s = textShortenToWidth(race_status_name, squareSize, '1 1 0' * 0.1 * squareSize, stringwidth_colors);
573
574         float rank;
575         if(race_status > 0)
576                 rank = race_CheckName(race_status_name);
577         else
578                 rank = 0;
579         string rankname;
580         rankname = count_ordinal(rank);
581
582         vector namepos;
583         namepos = medalPos + '0 0.8 0' * squareSize;
584         vector rankpos;
585         rankpos = medalPos + '0 0.15 0' * squareSize;
586
587         if(race_status == 0)
588                 drawpic_aspect_skin(medalPos, "race_newfail", '1 1 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
589         else if(race_status == 1) {
590                 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);
591                 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
592                 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
593         } else if(race_status == 2) {
594                 if(race_status_name == entcs_GetName(player_localnum) || !race_myrank || race_myrank < rank)
595                         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);
596                 else
597                         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);
598                 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
599                 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
600         } else if(race_status == 3) {
601                 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);
602                 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
603                 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
604         }
605
606         if (race_status_time - time <= 0) {
607                 race_status_prev = -1;
608                 race_status = -1;
609                 if(race_status_name)
610                         strunzone(race_status_name);
611                 race_status_name = string_null;
612                 if(race_status_name_prev)
613                         strunzone(race_status_name_prev);
614                 race_status_name_prev = string_null;
615         }
616 }
617
618 void DrawDomItem(vector myPos, vector mySize, float aspect_ratio, int layout, int i)
619 {
620         float stat = -1;
621         string pic = "";
622         vector color = '0 0 0';
623         switch(i)
624         {
625                 case 0:
626                         stat = STAT(DOM_PPS_RED);
627                         pic = "dom_icon_red";
628                         color = '1 0 0';
629                         break;
630                 case 1:
631                         stat = STAT(DOM_PPS_BLUE);
632                         pic = "dom_icon_blue";
633                         color = '0 0 1';
634                         break;
635                 case 2:
636                         stat = STAT(DOM_PPS_YELLOW);
637                         pic = "dom_icon_yellow";
638                         color = '1 1 0';
639                         break;
640                 default:
641                 case 3:
642                         stat = STAT(DOM_PPS_PINK);
643                         pic = "dom_icon_pink";
644                         color = '1 0 1';
645                         break;
646         }
647         float pps_ratio = stat / STAT(DOM_TOTAL_PPS);
648
649         if(mySize.x/mySize.y > aspect_ratio)
650         {
651                 i = aspect_ratio * mySize.y;
652                 myPos.x = myPos.x + (mySize.x - i) / 2;
653                 mySize.x = i;
654         }
655         else
656         {
657                 i = 1/aspect_ratio * mySize.x;
658                 myPos.y = myPos.y + (mySize.y - i) / 2;
659                 mySize.y = i;
660         }
661
662         if (layout) // show text too
663         {
664                 //draw the text
665                 color *= 0.5 + pps_ratio * (1 - 0.5); // half saturated color at min, full saturated at max
666                 if (layout == 2) // average pps
667                         drawstring_aspect(myPos + eX * mySize.y, ftos_decimals(stat, 2), eX * (2/3) * mySize.x + eY * mySize.y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
668                 else // percentage of average pps
669                         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);
670         }
671
672         //draw the icon
673         drawpic_aspect_skin(myPos, pic, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
674         if (stat > 0)
675         {
676                 drawsetcliparea(myPos.x, myPos.y + mySize.y * (1 - pps_ratio), mySize.y, mySize.y * pps_ratio);
677                 drawpic_aspect_skin(myPos, strcat(pic, "-highlighted"), '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
678                 drawresetcliparea();
679         }
680 }
681
682 void HUD_Mod_Dom(vector myPos, vector mySize)
683 {
684         mod_active = 1; // required in each mod function that always shows something
685
686         int layout = autocvar_hud_panel_modicons_dom_layout;
687         int rows, columns;
688         float aspect_ratio;
689         aspect_ratio = (layout) ? 3 : 1;
690         rows = HUD_GetRowCount(team_count, mySize, aspect_ratio);
691         columns = ceil(team_count/rows);
692
693         int i;
694         float row = 0, column = 0;
695         vector pos, itemSize;
696         itemSize = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
697         for(i=0; i<team_count; ++i)
698         {
699                 pos = myPos + eX * column * itemSize.x + eY * row * itemSize.y;
700
701                 DrawDomItem(pos, itemSize, aspect_ratio, layout, i);
702
703                 ++row;
704                 if(row >= rows)
705                 {
706                         row = 0;
707                         ++column;
708                 }
709         }
710 }
711
712 void HUD_ModIcons_SetFunc()
713 {
714         switch(gametype)
715         {
716                 case MAPINFO_TYPE_KEYHUNT:              HUD_ModIcons_GameType = HUD_Mod_KH; break;
717                 case MAPINFO_TYPE_CTF:                  HUD_ModIcons_GameType = HUD_Mod_CTF; break;
718                 case MAPINFO_TYPE_NEXBALL:              HUD_ModIcons_GameType = HUD_Mod_NexBall; break;
719                 case MAPINFO_TYPE_CTS:
720                 case MAPINFO_TYPE_RACE:         HUD_ModIcons_GameType = HUD_Mod_Race; break;
721                 case MAPINFO_TYPE_CA:
722                 case MAPINFO_TYPE_FREEZETAG:    HUD_ModIcons_GameType = HUD_Mod_CA; break;
723                 case MAPINFO_TYPE_DOMINATION:   HUD_ModIcons_GameType = HUD_Mod_Dom; break;
724                 case MAPINFO_TYPE_KEEPAWAY:     HUD_ModIcons_GameType = HUD_Mod_Keepaway; break;
725         }
726 }
727
728 int mod_prev; // previous state of mod_active to check for a change
729 float mod_alpha;
730 float mod_change; // "time" when mod_active changed
731
732 void HUD_ModIcons()
733 {
734         if(!autocvar__hud_configure)
735         {
736                 if(!autocvar_hud_panel_modicons) return;
737                 if(!HUD_ModIcons_GameType) return;
738         }
739
740         HUD_Panel_UpdateCvars();
741
742         draw_beginBoldFont();
743
744         if(mod_active != mod_prev) {
745                 mod_change = time;
746                 mod_prev = mod_active;
747         }
748
749         if(mod_active || autocvar__hud_configure)
750                 mod_alpha = bound(0, (time - mod_change) * 2, 1);
751         else
752                 mod_alpha = bound(0, 1 - (time - mod_change) * 2, 1);
753
754         if(mod_alpha)
755                 HUD_Panel_DrawBg(mod_alpha);
756
757         if(panel_bg_padding)
758         {
759                 panel_pos += '1 1 0' * panel_bg_padding;
760                 panel_size -= '2 2 0' * panel_bg_padding;
761         }
762
763         if(autocvar__hud_configure)
764                 HUD_Mod_CTF(panel_pos, panel_size);
765         else
766                 HUD_ModIcons_GameType(panel_pos, panel_size);
767
768         draw_endBoldFont();
769 }