Xonotic
racetimer.qc File Reference
#include "racetimer.qh"
#include <client/draw.qh>
+ Include dependency graph for racetimer.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void HUD_RaceTimer ()
 
void HUD_RaceTimer_Export (int fh)
 
string MakeRaceString (int cp, float mytime, float theirtime, float othertime, float lapdelta, string theirname)
 

Function Documentation

◆ HUD_RaceTimer()

void HUD_RaceTimer ( )

Definition at line 98 of file racetimer.qc.

References autocvar__hud_configure, autocvar_hud_panel_racetimer, autocvar_hud_panel_racetimer_dynamichud, draw_beginBoldFont, draw_endBoldFont, DRAWFLAG_NORMAL, drawstring(), eX, HUD_Panel_DrawBg, HUD_Panel_LoadCvars(), HUD_Scale_Disable(), HUD_Scale_Enable(), MUTATOR_CALLHOOK, panel_bg_padding, panel_fg_alpha, panel_pos, panel_size, spectatee_status, strcat(), stringwidth, and vector().

99 {
101  {
102  if(!autocvar_hud_panel_racetimer) return;
103  if(!MUTATOR_CALLHOOK(ShowRaceTimer)) return;
104  if(spectatee_status == -1) return;
105  }
106 
108 
109  vector pos, mySize;
110  pos = panel_pos;
111  mySize = panel_size;
112 
115  else
118  if(panel_bg_padding)
119  {
120  pos += '1 1 0' * panel_bg_padding;
121  mySize -= '2 2 0' * panel_bg_padding;
122  }
123 
124  // always force 4:1 aspect
125  vector newSize = '0 0 0';
126  if(mySize.x/mySize.y > 4)
127  {
128  newSize.x = 4 * mySize.y;
129  newSize.y = mySize.y;
130 
131  pos.x = pos.x + (mySize.x - newSize.x) / 2;
132  }
133  else
134  {
135  newSize.y = 1/4 * mySize.x;
136  newSize.x = mySize.x;
137 
138  pos.y = pos.y + (mySize.y - newSize.y) / 2;
139  }
140  mySize = newSize;
141 
142  float a, t;
143  string s, forcetime;
144  vector str_pos;
145 
147  {
148  s = "0:13:37";
150  str_pos = pos + eX * 0.5 * (mySize.x - stringwidth(s, false, '1 1 0' * 0.6 * mySize.y));
151  drawstring(str_pos, s, '1 1 0' * 0.6 * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
153  s = strcat("^1", sprintf(_("Intermediate %d"), 1), " (+15.42)");
154  str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
155  drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha, DRAWFLAG_NORMAL);
156  s = sprintf(_("PENALTY: %.1f (%s)"), 2, _("missing a checkpoint"));
157  s = strcat("^1", s);
158  str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.8 * mySize.y);
159  drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha, DRAWFLAG_NORMAL);
160  }
161  else if(race_checkpointtime)
162  {
163  a = bound(0, 2 - (time - race_checkpointtime), 1);
164  s = "";
165  forcetime = "";
166  if(a > 0) // just hit a checkpoint?
167  {
168  if(race_checkpoint != 254)
169  {
172  else
174  if(race_time)
175  forcetime = TIME_ENCODED_TOSTRING(race_time);
176  }
177  }
178  else
179  {
180  if(race_laptime && race_nextcheckpoint != 254)
181  {
183  {
186  if(a > 0) // next one?
188  }
189  }
190  }
191 
192  if(s != "" && a > 0)
193  {
194  str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
195  drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
196  }
197 
198  if(race_penaltytime)
199  {
200  a = bound(0, 2 - (time - race_penaltyeventtime), 1);
201  if(a > 0)
202  {
203  s = sprintf(_("PENALTY: %.1f (%s)"), race_penaltytime * 0.1, race_penaltyreason);
204  s = strcat("^1", s);
205  str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.8 * mySize.y);
206  drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
207  }
208  }
209 
211 
212  if(forcetime != "")
213  {
214  a = bound(0, (time - race_checkpointtime) / 0.5, 1);
215  str_pos = pos + eX * 0.5 * (mySize.x - stringwidth(forcetime, false, '1 1 0' * 0.6 * mySize.y));
216  drawstring_expanding(str_pos, forcetime, '1 1 0' * 0.6 * mySize.y, '1 1 1', panel_fg_alpha, 0, a);
217  }
218  else
219  a = 1;
220 
221  if(race_laptime && race_checkpoint != 255)
222  {
224  str_pos = pos + eX * 0.5 * (mySize.x - stringwidth(s, false, '0.6 0.6 0' * mySize.y));
225  drawstring(str_pos, s, '0.6 0.6 0' * mySize.y, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
226  }
227 
229  }
230  else
231  {
233  {
234  a = bound(0, 2 - (time - race_mycheckpointtime), 1);
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);
238  }
240  {
241  a = bound(0, 2 - (time - race_othercheckpointtime), 1);
243  str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
244  drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
245  }
246 
248  {
250  a = bound(0, (1 + t - time), 1);
251  if(a > 0)
252  {
253  string col;
254  if(time < t)
255  {
256  t = (t - time) * 0.1;
257  col = "^1";
258  }
259  else
260  {
261  t = 0;
262  col = "^2";
263  }
264  s = sprintf(_("PENALTY: %.1f (%s)"), t, race_penaltyreason);
265  s = strcat(col, s);
266  str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
267  drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
268  }
269  }
270  }
271 }
#define draw_endBoldFont()
Definition: draw.qh:5
float panel_fg_alpha
Definition: hud.qh:166
float race_mycheckpointdelta
Definition: racetimer.qh:32
float race_checkpoint
Definition: racetimer.qh:8
bool autocvar__hud_configure
Definition: hud_config.qh:3
#define stringwidth
Definition: csprogsdefs.qh:29
#define draw_beginBoldFont()
Definition: draw.qh:4
vector panel_size
Definition: hud.qh:160
float race_mybesttime
Definition: racetimer.qh:17
float race_othercheckpointdelta
Definition: racetimer.qh:37
void HUD_Scale_Disable()
Definition: hud.qc:83
#define TIME_ENCODED_TOSTRING(n)
Definition: util.qh:57
float race_nextcheckpoint
Definition: racetimer.qh:15
#define TIME_DECODE(n)
Definition: util.qh:62
float race_previousbesttime
Definition: racetimer.qh:12
#define TIME_ENCODE(t)
Definition: util.qh:61
#define HUD_Panel_DrawBg()
Definition: hud.qh:54
float race_nextbesttime
Definition: racetimer.qh:16
void HUD_Scale_Enable()
Definition: hud.qc:90
bool autocvar_hud_panel_racetimer
Definition: racetimer.qh:4
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
string race_nextbestname
Definition: racetimer.qh:18
bool autocvar_hud_panel_racetimer_dynamichud
Definition: racetimer.qh:5
void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
Definition: draw.qc:113
float race_othercheckpointlapsdelta
Definition: racetimer.qh:38
const float DRAWFLAG_NORMAL
Definition: csprogsdefs.qc:317
vector panel_pos
Definition: hud.qh:159
float race_mycheckpointtime
Definition: racetimer.qh:31
float race_time
Definition: racetimer.qh:9
vector(float skel, float bonenum) _skel_get_boneabs_hidden
float race_checkpointtime
Definition: racetimer.qh:11
float spectatee_status
Definition: main.qh:166
const vector eX
Definition: vector.qh:44
float race_penaltytime
Definition: racetimer.qh:21
#define MUTATOR_CALLHOOK(id,...)
Definition: base.qh:140
string race_previousbestname
Definition: racetimer.qh:14
float race_othercheckpoint
Definition: racetimer.qh:35
#define vec2(...)
Definition: vector.qh:90
float race_mycheckpointlapsdelta
Definition: racetimer.qh:33
string race_penaltyreason
Definition: racetimer.qh:22
float race_mycheckpoint
Definition: racetimer.qh:30
string MakeRaceString(int cp, float mytime, float theirtime, float othertime, float lapdelta, string theirname)
Definition: racetimer.qc:13
float race_othercheckpointtime
Definition: racetimer.qh:36
float race_penaltyeventtime
Definition: racetimer.qh:20
float race_mypreviousbesttime
Definition: racetimer.qh:13
float time
Definition: csprogsdefs.qc:16
string race_mycheckpointenemy
Definition: racetimer.qh:34
float race_penaltyaccumulator
Definition: racetimer.qh:19
float race_laptime
Definition: racetimer.qh:10
string race_othercheckpointenemy
Definition: racetimer.qh:39
void HUD_Panel_LoadCvars()
Definition: hud.qc:216
float panel_bg_padding
Definition: hud.qh:171
+ Here is the call graph for this function:

◆ HUD_RaceTimer_Export()

void HUD_RaceTimer_Export ( int  fh)

Definition at line 7 of file racetimer.qc.

8 {
9  // allow saving cvars that aesthetically change the panel into hud skin files
10 }

◆ MakeRaceString()

string MakeRaceString ( int  cp,
float  mytime,
float  theirtime,
float  othertime,
float  lapdelta,
string  theirname 
)

Definition at line 13 of file racetimer.qc.

References autocvar_cl_race_cptimes_showself, ftos_decimals(), strcat(), TC, and TIME_DECIMALS.

14 {
15  TC(int, cp);
16  string cpname, lapstr = "", timestr = "", col = "^7", othercol = "^7", othertimestr = "";
17  if(theirname == "" || !autocvar_cl_race_cptimes_showself)
18  othertime = 0; // don't count personal time
19 
20  if(theirtime == 0) // goal hit
21  {
22  if(mytime > 0)
23  {
24  timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
25  col = "^1";
26  }
27  else if(mytime == 0)
28  {
29  timestr = "+0.0";
30  col = "^3";
31  }
32  else
33  {
34  timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
35  col = "^2";
36  }
37 
38  if(othertime > 0)
39  {
40  othertimestr = strcat("+", ftos_decimals(+othertime, TIME_DECIMALS));
41  othercol = "^1";
42  }
43  else if(othertime == 0)
44  {
45  othertimestr = "+0.0";
46  othercol = "^3";
47  }
48  else
49  {
50  othertimestr = strcat("-", ftos_decimals(-othertime, TIME_DECIMALS));
51  othercol = "^2";
52  }
53 
54  if(lapdelta > 0)
55  {
56  lapstr = sprintf(_(" (-%dL)"), lapdelta);
57  col = "^2";
58  }
59  else if(lapdelta < 0)
60  {
61  lapstr = sprintf(_(" (+%dL)"), -lapdelta);
62  col = "^1";
63  }
64  }
65  else if(theirtime > 0) // anticipation
66  {
67  if(mytime >= theirtime)
68  timestr = strcat("+", ftos_decimals(mytime - theirtime, TIME_DECIMALS));
69  else
70  timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(theirtime));
71  col = "^3";
72  if(mytime >= othertime)
73  othertimestr = strcat("+", ftos_decimals(mytime - othertime, TIME_DECIMALS));
74  else
75  othertimestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(othertime));
76  othercol = "^7";
77  }
78 
79  if(cp == 254)
80  cpname = _("Start line");
81  else if(cp == 255)
82  cpname = _("Finish line");
83  else if(cp)
84  cpname = sprintf(_("Intermediate %d"), cp);
85  else
86  cpname = _("Finish line");
87 
88  if(theirtime < 0)
89  return strcat(col, cpname);
90  else if(theirname == "")
91  return strcat(col, sprintf("%s (%s)", cpname, timestr));
92  else if(othertime)
93  return strcat(col, sprintf("%s %s(%s)%s (%s %s)", cpname, othercol, othertimestr, col, timestr, strcat(ColorTranslateRGB(theirname), col, lapstr)));
94  else
95  return strcat(col, sprintf("%s (%s %s)", cpname, timestr, strcat(ColorTranslateRGB(theirname), col, lapstr)));
96 }
ERASEABLE string ftos_decimals(float number, int decimals)
converts a number to a string with the indicated number of decimals
Definition: string.qh:450
#define TIME_ENCODED_TOSTRING(n)
Definition: util.qh:57
#define TIME_ENCODE(t)
Definition: util.qh:61
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
ERASEABLE string ColorTranslateRGB(string s)
Definition: string.qh:177
#define TC(T, sym)
Definition: _all.inc:82
const int TIME_DECIMALS
Definition: util.qh:55
bool autocvar_cl_race_cptimes_showself
Definition: main.qh:21
+ Here is the call graph for this function: