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 othertime, float lapdelta, string theirname)
11 string cpname, lapstr = "", timestr = "", col = "^7", othercol = "^7", othertimestr = "";
12 if(theirname == "" || !autocvar_cl_race_cptimes_showself)
13 othertime = 0; // don't count personal time
15 if(theirtime == 0) // goal hit
19 timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
29 timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
35 othertimestr = strcat("+", ftos_decimals(+othertime, TIME_DECIMALS));
38 else if(othertime == 0)
40 othertimestr = "+0.0";
45 othertimestr = strcat("-", ftos_decimals(-othertime, TIME_DECIMALS));
51 lapstr = sprintf(_(" (-%dL)"), lapdelta);
56 lapstr = sprintf(_(" (+%dL)"), -lapdelta);
60 else if(theirtime > 0) // anticipation
62 if(mytime >= theirtime)
63 timestr = strcat("+", ftos_decimals(mytime - theirtime, TIME_DECIMALS));
65 timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(theirtime));
67 if(mytime >= othertime)
68 othertimestr = strcat("+", ftos_decimals(mytime - othertime, TIME_DECIMALS));
70 othertimestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(othertime));
75 cpname = _("Start line");
77 cpname = _("Finish line");
79 cpname = sprintf(_("Intermediate %d"), cp);
81 cpname = _("Finish line");
84 return strcat(col, cpname);
85 else if(theirname == "")
86 return strcat(col, sprintf("%s (%s)", cpname, timestr));
88 return strcat(col, sprintf("%s %s(%s)%s (%s %s)", cpname, othercol, othertimestr, col, timestr, strcat(ColorTranslateRGB(theirname), col, lapstr)));
90 return strcat(col, sprintf("%s (%s %s)", cpname, timestr, strcat(ColorTranslateRGB(theirname), col, lapstr)));
95 if(!autocvar__hud_configure)
97 if(!autocvar_hud_panel_racetimer) return;
98 if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
99 if(spectatee_status == -1) return;
102 HUD_Panel_LoadCvars();
108 if (autocvar_hud_panel_racetimer_dynamichud)
115 pos += '1 1 0' * panel_bg_padding;
116 mySize -= '2 2 0' * panel_bg_padding;
119 // always force 4:1 aspect
120 vector newSize = '0 0 0';
121 if(mySize.x/mySize.y > 4)
123 newSize.x = 4 * mySize.y;
124 newSize.y = mySize.y;
126 pos.x = pos.x + (mySize.x - newSize.x) / 2;
130 newSize.y = 1/4 * mySize.x;
131 newSize.x = mySize.x;
133 pos.y = pos.y + (mySize.y - newSize.y) / 2;
141 if(autocvar__hud_configure)
144 draw_beginBoldFont();
145 str_pos = pos + eX * 0.5 * (mySize.x - stringwidth(s, false, '1 1 0' * 0.6 * mySize.y));
146 drawstring(str_pos, s, '1 1 0' * 0.6 * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
148 s = _("^1Intermediate 1 (+15.42)");
149 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
150 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha, DRAWFLAG_NORMAL);
151 s = sprintf(_("^1PENALTY: %.1f (%s)"), 2, "missing a checkpoint");
152 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.8 * mySize.y);
153 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha, DRAWFLAG_NORMAL);
155 else if(race_checkpointtime)
157 a = bound(0, 2 - (time - race_checkpointtime), 1);
160 if(a > 0) // just hit a checkpoint?
162 if(race_checkpoint != 254)
164 if(race_time && race_previousbesttime)
165 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);
167 s = MakeRaceString(race_checkpoint, 0, -1, 0, 0, race_previousbestname);
169 forcetime = TIME_ENCODED_TOSTRING(race_time);
174 if(race_laptime && race_nextcheckpoint != 254)
176 if(race_nextbesttime)
178 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
179 float a2 = ((race_mybesttime) ? bound(0, 2 - ((race_laptime + TIME_DECODE(race_mybesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1) : 0);
180 if(a > 0) // next one?
181 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);
188 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
189 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
194 a = bound(0, 2 - (time - race_penaltyeventtime), 1);
197 s = sprintf(_("^1PENALTY: %.1f (%s)"), race_penaltytime * 0.1, race_penaltyreason);
198 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.8 * mySize.y);
199 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
203 draw_beginBoldFont();
207 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
208 str_pos = pos + eX * 0.5 * (mySize.x - stringwidth(forcetime, false, '1 1 0' * 0.6 * mySize.y));
209 drawstring_expanding(str_pos, forcetime, '1 1 0' * 0.6 * mySize.y, '1 1 1', panel_fg_alpha, 0, a);
214 if(race_laptime && race_checkpoint != 255)
216 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
217 str_pos = pos + eX * 0.5 * (mySize.x - stringwidth(s, false, '0.6 0.6 0' * mySize.y));
218 drawstring(str_pos, s, '0.6 0.6 0' * mySize.y, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
225 if(race_mycheckpointtime)
227 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
228 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -(race_mycheckpointenemy == ""), 0, race_mycheckpointlapsdelta, race_mycheckpointenemy);
229 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
230 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
232 if(race_othercheckpointtime && race_othercheckpointenemy != "")
234 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
235 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -(race_othercheckpointenemy == ""), 0, race_othercheckpointlapsdelta, race_othercheckpointenemy);
236 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
237 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
240 if(race_penaltytime && !race_penaltyaccumulator)
242 t = race_penaltytime * 0.1 + race_penaltyeventtime;
243 a = bound(0, (1 + t - time), 1);
247 s = sprintf(_("^1PENALTY: %.1f (%s)"), (t - time) * 0.1, race_penaltyreason);
249 s = sprintf(_("^2PENALTY: %.1f (%s)"), 0, race_penaltyreason);
250 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
251 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);