]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/racetimer.qc
Rename a macro
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / racetimer.qc
1 #include "racetimer.qh"
2
3 #include "scoreboard.qh"
4 #include <common/mapinfo.qh>
5
6 // Race timer (#6)
7
8 // return the string of the onscreen race timer
9 string MakeRaceString(int cp, float mytime, float theirtime, float lapdelta, string theirname)
10 {
11         TC(int, cp);
12         string col;
13         string timestr;
14         string cpname;
15         string lapstr;
16         lapstr = "";
17
18         if(theirtime == 0) // goal hit
19         {
20                 if(mytime > 0)
21                 {
22                         timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
23                         col = "^1";
24                 }
25                 else if(mytime == 0)
26                 {
27                         timestr = "+0.0";
28                         col = "^3";
29                 }
30                 else
31                 {
32                         timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
33                         col = "^2";
34                 }
35
36                 if(lapdelta > 0)
37                 {
38                         lapstr = sprintf(_(" (-%dL)"), lapdelta);
39                         col = "^2";
40                 }
41                 else if(lapdelta < 0)
42                 {
43                         lapstr = sprintf(_(" (+%dL)"), -lapdelta);
44                         col = "^1";
45                 }
46         }
47         else if(theirtime > 0) // anticipation
48         {
49                 if(mytime >= theirtime)
50                         timestr = strcat("+", ftos_decimals(mytime - theirtime, TIME_DECIMALS));
51                 else
52                         timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(theirtime));
53                 col = "^3";
54         }
55         else
56         {
57                 col = "^7";
58                 timestr = "";
59         }
60
61         if(cp == 254)
62                 cpname = _("Start line");
63         else if(cp == 255)
64                 cpname = _("Finish line");
65         else if(cp)
66                 cpname = sprintf(_("Intermediate %d"), cp);
67         else
68                 cpname = _("Finish line");
69
70         if(theirtime < 0)
71                 return strcat(col, cpname);
72         else if(theirname == "")
73                 return strcat(col, sprintf("%s (%s)", cpname, timestr));
74         else
75                 return strcat(col, sprintf("%s (%s %s)", cpname, timestr, strcat(theirname, col, lapstr)));
76 }
77
78 void HUD_RaceTimer ()
79 {
80         if(!autocvar__hud_configure)
81         {
82                 if(!autocvar_hud_panel_racetimer) return;
83                 if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
84                 if(spectatee_status == -1) return;
85         }
86
87         if(1 - scoreboard_fade_alpha <= 0)
88                 return;
89         HUD_Panel_LoadCvars(1 - scoreboard_fade_alpha);
90
91         vector pos, mySize;
92         pos = panel_pos;
93         mySize = panel_size;
94
95         if (autocvar_hud_panel_racetimer_dynamichud)
96                 HUD_Scale_Enable();
97         else
98                 HUD_Scale_Disable();
99         HUD_Panel_DrawBg();
100         if(panel_bg_padding)
101         {
102                 pos += '1 1 0' * panel_bg_padding;
103                 mySize -= '2 2 0' * panel_bg_padding;
104         }
105
106         // always force 4:1 aspect
107         vector newSize = '0 0 0';
108         if(mySize.x/mySize.y > 4)
109         {
110                 newSize.x = 4 * mySize.y;
111                 newSize.y = mySize.y;
112
113                 pos.x = pos.x + (mySize.x - newSize.x) / 2;
114         }
115         else
116         {
117                 newSize.y = 1/4 * mySize.x;
118                 newSize.x = mySize.x;
119
120                 pos.y = pos.y + (mySize.y - newSize.y) / 2;
121         }
122         mySize = newSize;
123
124         float a, t;
125         string s, forcetime;
126
127         if(autocvar__hud_configure)
128         {
129                 s = "0:13:37";
130                 draw_beginBoldFont();
131                 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);
132                 draw_endBoldFont();
133                 s = _("^1Intermediate 1 (+15.42)");
134                 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);
135                 s = sprintf(_("^1PENALTY: %.1f (%s)"), 2, "missing a checkpoint");
136                 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);
137         }
138         else if(race_checkpointtime)
139         {
140                 a = bound(0, 2 - (time - race_checkpointtime), 1);
141                 s = "";
142                 forcetime = "";
143                 if(a > 0) // just hit a checkpoint?
144                 {
145                         if(race_checkpoint != 254)
146                         {
147                                 if(race_time && race_previousbesttime)
148                                         s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
149                                 else
150                                         s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
151                                 if(race_time)
152                                         forcetime = TIME_ENCODED_TOSTRING(race_time);
153                         }
154                 }
155                 else
156                 {
157                         if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
158                         {
159                                 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
160                                 if(a > 0) // next one?
161                                 {
162                                         s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
163                                 }
164                         }
165                 }
166
167                 if(s != "" && a > 0)
168                 {
169                         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);
170                 }
171
172                 if(race_penaltytime)
173                 {
174                         a = bound(0, 2 - (time - race_penaltyeventtime), 1);
175                         if(a > 0)
176                         {
177                                 s = sprintf(_("^1PENALTY: %.1f (%s)"), race_penaltytime * 0.1, race_penaltyreason);
178                                 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);
179                         }
180                 }
181
182                 draw_beginBoldFont();
183
184                 if(forcetime != "")
185                 {
186                         a = bound(0, (time - race_checkpointtime) / 0.5, 1);
187                         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);
188                 }
189                 else
190                         a = 1;
191
192                 if(race_laptime && race_checkpoint != 255)
193                 {
194                         s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
195                         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);
196                 }
197
198                 draw_endBoldFont();
199         }
200         else
201         {
202                 if(race_mycheckpointtime)
203                 {
204                         a = bound(0, 2 - (time - race_mycheckpointtime), 1);
205                         s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -(race_mycheckpointenemy == ""), race_mycheckpointlapsdelta, race_mycheckpointenemy);
206                         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);
207                 }
208                 if(race_othercheckpointtime && race_othercheckpointenemy != "")
209                 {
210                         a = bound(0, 2 - (time - race_othercheckpointtime), 1);
211                         s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -(race_othercheckpointenemy == ""), race_othercheckpointlapsdelta, race_othercheckpointenemy);
212                         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);
213                 }
214
215                 if(race_penaltytime && !race_penaltyaccumulator)
216                 {
217                         t = race_penaltytime * 0.1 + race_penaltyeventtime;
218                         a = bound(0, (1 + t - time), 1);
219                         if(a > 0)
220                         {
221                                 if(time < t)
222                                         s = sprintf(_("^1PENALTY: %.1f (%s)"), (t - time) * 0.1, race_penaltyreason);
223                                 else
224                                         s = sprintf(_("^2PENALTY: %.1f (%s)"), 0, race_penaltyreason);
225                                 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);
226                         }
227                 }
228         }
229 }