1 #include "racetimer.qh"
3 #include <common/mapinfo.qh>
7 // return the string of the onscreen race timer
8 string MakeRaceString(int cp, float mytime, float theirtime, float lapdelta, string theirname)
17 if(theirtime == 0) // goal hit
21 timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
31 timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
37 lapstr = sprintf(_(" (-%dL)"), lapdelta);
42 lapstr = sprintf(_(" (+%dL)"), -lapdelta);
46 else if(theirtime > 0) // anticipation
48 if(mytime >= theirtime)
49 timestr = strcat("+", ftos_decimals(mytime - theirtime, TIME_DECIMALS));
51 timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(theirtime));
61 cpname = _("Start line");
63 cpname = _("Finish line");
65 cpname = sprintf(_("Intermediate %d"), cp);
67 cpname = _("Finish line");
70 return strcat(col, cpname);
71 else if(theirname == "")
72 return strcat(col, sprintf("%s (%s)", cpname, timestr));
74 return strcat(col, sprintf("%s (%s %s)", cpname, timestr, strcat(ColorTranslateRGB(theirname), col, lapstr)));
79 if(!autocvar__hud_configure)
81 if(!autocvar_hud_panel_racetimer) return;
82 if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
83 if(spectatee_status == -1) return;
86 HUD_Panel_LoadCvars();
92 if (autocvar_hud_panel_racetimer_dynamichud)
99 pos += '1 1 0' * panel_bg_padding;
100 mySize -= '2 2 0' * panel_bg_padding;
103 // always force 4:1 aspect
104 vector newSize = '0 0 0';
105 if(mySize.x/mySize.y > 4)
107 newSize.x = 4 * mySize.y;
108 newSize.y = mySize.y;
110 pos.x = pos.x + (mySize.x - newSize.x) / 2;
114 newSize.y = 1/4 * mySize.x;
115 newSize.x = mySize.x;
117 pos.y = pos.y + (mySize.y - newSize.y) / 2;
125 if(autocvar__hud_configure)
128 draw_beginBoldFont();
129 str_pos = pos + eX * 0.5 * (mySize.x - stringwidth(s, false, '1 1 0' * 0.6 * mySize.y));
130 drawstring(str_pos, s, '1 1 0' * 0.6 * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
132 s = _("^1Intermediate 1 (+15.42)");
133 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
134 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha, DRAWFLAG_NORMAL);
135 s = sprintf(_("^1PENALTY: %.1f (%s)"), 2, "missing a checkpoint");
136 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.8 * mySize.y);
137 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha, DRAWFLAG_NORMAL);
139 else if(race_checkpointtime)
141 a = bound(0, 2 - (time - race_checkpointtime), 1);
144 if(a > 0) // just hit a checkpoint?
146 if(race_checkpoint != 254)
148 if(race_time && race_previousbesttime)
149 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
151 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
153 forcetime = TIME_ENCODED_TOSTRING(race_time);
158 if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
160 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
161 if(a > 0) // next one?
162 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
168 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
169 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
174 a = bound(0, 2 - (time - race_penaltyeventtime), 1);
177 s = sprintf(_("^1PENALTY: %.1f (%s)"), race_penaltytime * 0.1, race_penaltyreason);
178 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.8 * mySize.y);
179 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
183 draw_beginBoldFont();
187 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
188 str_pos = pos + eX * 0.5 * (mySize.x - stringwidth(forcetime, false, '1 1 0' * 0.6 * mySize.y));
189 drawstring_expanding(str_pos, forcetime, '1 1 0' * 0.6 * mySize.y, '1 1 1', panel_fg_alpha, 0, a);
194 if(race_laptime && race_checkpoint != 255)
196 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
197 str_pos = pos + eX * 0.5 * (mySize.x - stringwidth(s, false, '0.6 0.6 0' * mySize.y));
198 drawstring(str_pos, s, '0.6 0.6 0' * mySize.y, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
205 if(race_mycheckpointtime)
207 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
208 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -(race_mycheckpointenemy == ""), race_mycheckpointlapsdelta, race_mycheckpointenemy);
209 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
210 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
212 if(race_othercheckpointtime && race_othercheckpointenemy != "")
214 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
215 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -(race_othercheckpointenemy == ""), race_othercheckpointlapsdelta, race_othercheckpointenemy);
216 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
217 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
220 if(race_penaltytime && !race_penaltyaccumulator)
222 t = race_penaltytime * 0.1 + race_penaltyeventtime;
223 a = bound(0, (1 + t - time), 1);
227 s = sprintf(_("^1PENALTY: %.1f (%s)"), (t - time) * 0.1, race_penaltyreason);
229 s = sprintf(_("^2PENALTY: %.1f (%s)"), 0, race_penaltyreason);
230 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
231 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);