1 #include "racetimer.qh"
3 #include <client/autocvars.qh>
4 #include <client/defs.qh>
5 #include <client/miscfunctions.qh>
6 #include <common/mapinfo.qh>
10 // return the string of the onscreen race timer
11 string MakeRaceString(int cp, float mytime, float theirtime, float othertime, float lapdelta, string theirname)
14 string cpname, lapstr = "", timestr = "", col = "^7", othercol = "^7", othertimestr = "";
15 if(theirname == "" || !autocvar_cl_race_cptimes_showself)
16 othertime = 0; // don't count personal time
18 if(theirtime == 0) // goal hit
22 timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
32 timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
38 othertimestr = strcat("+", ftos_decimals(+othertime, TIME_DECIMALS));
41 else if(othertime == 0)
43 othertimestr = "+0.0";
48 othertimestr = strcat("-", ftos_decimals(-othertime, TIME_DECIMALS));
54 lapstr = sprintf(_(" (-%dL)"), lapdelta);
59 lapstr = sprintf(_(" (+%dL)"), -lapdelta);
63 else if(theirtime > 0) // anticipation
65 if(mytime >= theirtime)
66 timestr = strcat("+", ftos_decimals(mytime - theirtime, TIME_DECIMALS));
68 timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(theirtime));
70 if(mytime >= othertime)
71 othertimestr = strcat("+", ftos_decimals(mytime - othertime, TIME_DECIMALS));
73 othertimestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(othertime));
78 cpname = _("Start line");
80 cpname = _("Finish line");
82 cpname = sprintf(_("Intermediate %d"), cp);
84 cpname = _("Finish line");
87 return strcat(col, cpname);
88 else if(theirname == "")
89 return strcat(col, sprintf("%s (%s)", cpname, timestr));
91 return strcat(col, sprintf("%s %s(%s)%s (%s %s)", cpname, othercol, othertimestr, col, timestr, strcat(ColorTranslateRGB(theirname), col, lapstr)));
93 return strcat(col, sprintf("%s (%s %s)", cpname, timestr, strcat(ColorTranslateRGB(theirname), col, lapstr)));
98 if(!autocvar__hud_configure)
100 if(!autocvar_hud_panel_racetimer) return;
101 if(!(ISGAMETYPE(RACE) || ISGAMETYPE(CTS))) return;
102 if(spectatee_status == -1) return;
105 HUD_Panel_LoadCvars();
111 if (autocvar_hud_panel_racetimer_dynamichud)
118 pos += '1 1 0' * panel_bg_padding;
119 mySize -= '2 2 0' * panel_bg_padding;
122 // always force 4:1 aspect
123 vector newSize = '0 0 0';
124 if(mySize.x/mySize.y > 4)
126 newSize.x = 4 * mySize.y;
127 newSize.y = mySize.y;
129 pos.x = pos.x + (mySize.x - newSize.x) / 2;
133 newSize.y = 1/4 * mySize.x;
134 newSize.x = mySize.x;
136 pos.y = pos.y + (mySize.y - newSize.y) / 2;
144 if(autocvar__hud_configure)
147 draw_beginBoldFont();
148 str_pos = pos + eX * 0.5 * (mySize.x - stringwidth(s, false, '1 1 0' * 0.6 * mySize.y));
149 drawstring(str_pos, s, '1 1 0' * 0.6 * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
151 s = _("^1Intermediate 1 (+15.42)");
152 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
153 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha, DRAWFLAG_NORMAL);
154 s = sprintf(_("^1PENALTY: %.1f (%s)"), 2, "missing a checkpoint");
155 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.8 * mySize.y);
156 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha, DRAWFLAG_NORMAL);
158 else if(race_checkpointtime)
160 a = bound(0, 2 - (time - race_checkpointtime), 1);
163 if(a > 0) // just hit a checkpoint?
165 if(race_checkpoint != 254)
167 if(race_time && race_previousbesttime)
168 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, ((race_mypreviousbesttime) ? TIME_DECODE(race_time) - TIME_DECODE(race_mypreviousbesttime) : 0), 0, race_previousbestname);
170 s = MakeRaceString(race_checkpoint, 0, -1, 0, 0, race_previousbestname);
172 forcetime = TIME_ENCODED_TOSTRING(race_time);
177 if(race_laptime && race_nextcheckpoint != 254)
179 if(race_nextbesttime)
181 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
182 float a2 = ((race_mybesttime) ? bound(0, 2 - ((race_laptime + TIME_DECODE(race_mybesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1) : 0);
183 if(a > 0) // next one?
184 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), ((a2 > 0) ? TIME_DECODE(race_mybesttime) : 0), 0, race_nextbestname);
191 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
192 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
197 a = bound(0, 2 - (time - race_penaltyeventtime), 1);
200 s = sprintf(_("^1PENALTY: %.1f (%s)"), race_penaltytime * 0.1, race_penaltyreason);
201 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.8 * mySize.y);
202 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
206 draw_beginBoldFont();
210 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
211 str_pos = pos + eX * 0.5 * (mySize.x - stringwidth(forcetime, false, '1 1 0' * 0.6 * mySize.y));
212 drawstring_expanding(str_pos, forcetime, '1 1 0' * 0.6 * mySize.y, '1 1 1', panel_fg_alpha, 0, a);
217 if(race_laptime && race_checkpoint != 255)
219 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
220 str_pos = pos + eX * 0.5 * (mySize.x - stringwidth(s, false, '0.6 0.6 0' * mySize.y));
221 drawstring(str_pos, s, '0.6 0.6 0' * mySize.y, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
228 if(race_mycheckpointtime)
230 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
231 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -(race_mycheckpointenemy == ""), 0, race_mycheckpointlapsdelta, race_mycheckpointenemy);
232 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
233 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
235 if(race_othercheckpointtime && race_othercheckpointenemy != "")
237 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
238 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -(race_othercheckpointenemy == ""), 0, race_othercheckpointlapsdelta, race_othercheckpointenemy);
239 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
240 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
243 if(race_penaltytime && !race_penaltyaccumulator)
245 t = race_penaltytime * 0.1 + race_penaltyeventtime;
246 a = bound(0, (1 + t - time), 1);
250 s = sprintf(_("^1PENALTY: %.1f (%s)"), (t - time) * 0.1, race_penaltyreason);
252 s = sprintf(_("^2PENALTY: %.1f (%s)"), 0, race_penaltyreason);
253 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
254 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);