]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/racetimer.qc
client: pass compilation units test
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / racetimer.qc
1 #include "racetimer.qh"
2
3 #include <common/mapinfo.qh>
4
5 /** Race timer (#8) */
6 void HUD_RaceTimer ()
7 {
8         if(!autocvar__hud_configure)
9         {
10                 if(!autocvar_hud_panel_racetimer) return;
11                 if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
12                 if(spectatee_status == -1) return;
13         }
14
15         HUD_Panel_UpdateCvars();
16
17         vector pos, mySize;
18         pos = panel_pos;
19         mySize = panel_size;
20
21         HUD_Panel_DrawBg(1);
22         if(panel_bg_padding)
23         {
24                 pos += '1 1 0' * panel_bg_padding;
25                 mySize -= '2 2 0' * panel_bg_padding;
26         }
27
28         // always force 4:1 aspect
29         vector newSize = '0 0 0';
30         if(mySize.x/mySize.y > 4)
31         {
32                 newSize.x = 4 * mySize.y;
33                 newSize.y = mySize.y;
34
35                 pos.x = pos.x + (mySize.x - newSize.x) / 2;
36         }
37         else
38         {
39                 newSize.y = 1/4 * mySize.x;
40                 newSize.x = mySize.x;
41
42                 pos.y = pos.y + (mySize.y - newSize.y) / 2;
43         }
44         mySize = newSize;
45
46         float a, t;
47         string s, forcetime;
48
49         if(autocvar__hud_configure)
50         {
51                 s = "0:13:37";
52                 draw_beginBoldFont();
53                 drawstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, false, '0.60 0.60 0' * mySize.y), s, '0.60 0.60 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
54                 draw_endBoldFont();
55                 s = _("^1Intermediate 1 (+15.42)");
56                 drawcolorcodedstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, true, '1 1 0' * 0.20 * mySize.y) + eY * 0.60 * mySize.y, s, '1 1 0' * 0.20 * mySize.y, panel_fg_alpha, DRAWFLAG_NORMAL);
57                 s = sprintf(_("^1PENALTY: %.1f (%s)"), 2, "missing a checkpoint");
58                 drawcolorcodedstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, true, '1 1 0' * 0.20 * mySize.y) + eY * 0.80 * mySize.y, s, '1 1 0' * 0.20 * mySize.y, panel_fg_alpha, DRAWFLAG_NORMAL);
59         }
60         else if(race_checkpointtime)
61         {
62                 a = bound(0, 2 - (time - race_checkpointtime), 1);
63                 s = "";
64                 forcetime = "";
65                 if(a > 0) // just hit a checkpoint?
66                 {
67                         if(race_checkpoint != 254)
68                         {
69                                 if(race_time && race_previousbesttime)
70                                         s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
71                                 else
72                                         s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
73                                 if(race_time)
74                                         forcetime = TIME_ENCODED_TOSTRING(race_time);
75                         }
76                 }
77                 else
78                 {
79                         if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
80                         {
81                                 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
82                                 if(a > 0) // next one?
83                                 {
84                                         s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
85                                 }
86                         }
87                 }
88
89                 if(s != "" && a > 0)
90                 {
91                         drawcolorcodedstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, true, '1 1 0' * 0.2 * mySize.y) + eY * 0.6 * mySize.y, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
92                 }
93
94                 if(race_penaltytime)
95                 {
96                         a = bound(0, 2 - (time - race_penaltyeventtime), 1);
97                         if(a > 0)
98                         {
99                                 s = sprintf(_("^1PENALTY: %.1f (%s)"), race_penaltytime * 0.1, race_penaltyreason);
100                                 drawcolorcodedstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, true, '1 1 0' * 0.2 * mySize.y) + eY * 0.8 * mySize.y, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
101                         }
102                 }
103
104                 draw_beginBoldFont();
105
106                 if(forcetime != "")
107                 {
108                         a = bound(0, (time - race_checkpointtime) / 0.5, 1);
109                         drawstring_expanding(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(forcetime, false, '1 1 0' * 0.6 * mySize.y), forcetime, '1 1 0' * 0.6 * mySize.y, '1 1 1', panel_fg_alpha, 0, a);
110                 }
111                 else
112                         a = 1;
113
114                 if(race_laptime && race_checkpoint != 255)
115                 {
116                         s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
117                         drawstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, false, '0.6 0.6 0' * mySize.y), s, '0.6 0.6 0' * mySize.y, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
118                 }
119
120                 draw_endBoldFont();
121         }
122         else
123         {
124                 if(race_mycheckpointtime)
125                 {
126                         a = bound(0, 2 - (time - race_mycheckpointtime), 1);
127                         s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -(race_mycheckpointenemy == ""), race_mycheckpointlapsdelta, race_mycheckpointenemy);
128                         drawcolorcodedstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, true, '1 1 0' * 0.2 * mySize.y) + eY * 0.6 * mySize.y, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
129                 }
130                 if(race_othercheckpointtime && race_othercheckpointenemy != "")
131                 {
132                         a = bound(0, 2 - (time - race_othercheckpointtime), 1);
133                         s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -(race_othercheckpointenemy == ""), race_othercheckpointlapsdelta, race_othercheckpointenemy);
134                         drawcolorcodedstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, true, '1 1 0' * 0.2 * mySize.y) + eY * 0.6 * mySize.y, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
135                 }
136
137                 if(race_penaltytime && !race_penaltyaccumulator)
138                 {
139                         t = race_penaltytime * 0.1 + race_penaltyeventtime;
140                         a = bound(0, (1 + t - time), 1);
141                         if(a > 0)
142                         {
143                                 if(time < t)
144                                         s = sprintf(_("^1PENALTY: %.1f (%s)"), (t - time) * 0.1, race_penaltyreason);
145                                 else
146                                         s = sprintf(_("^2PENALTY: %.1f (%s)"), 0, race_penaltyreason);
147                                 drawcolorcodedstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, true, '1 1 0' * 0.2 * mySize.y) + eY * 0.6 * mySize.y, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
148                         }
149                 }
150         }
151 }