Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
checkpoints.qc
Go to the documentation of this file.
1#include "checkpoints.qh"
2#include "racetimer.qh"
3#include "physics.qh"
4
6#include <client/draw.qh>
7#include <common/ent_cs.qh>
8
9// Checkpoints (#27)
10
12{
13 // allow saving cvars that aesthetically change the panel into hud skin files
14 HUD_Write_Cvar("hud_panel_checkpoints_align");
15 HUD_Write_Cvar("hud_panel_checkpoints_flip");
16 HUD_Write_Cvar("hud_panel_checkpoints_fontscale");
17}
18
19const float CHECKPOINTS_SPACING = 0.25;
20const float CHECKPOINTS_BASE_SIZE = 0.75;
21
22string demolines[10];
23
24vector Checkpoints_drawstring(string s, vector pos, vector sz, float a, vector fontsize)
25{
27 const float align = bound(0, autocvar_hud_panel_checkpoints_align, 1);
28 float offset = 0;
30 {
31 const string s_original = s;
32 do
33 {
34 s = getWrappedLine(sz.x - offset, fontsize, stringwidth_colors);
36 offset = (sz.x - stringwidth_colors(s, fontsize) - offset) * align;
37 pos.y -= fontsize.y;
38 offset = fontsize.x;
39 }
41
42 getWrappedLine_remaining = s_original;
43 offset = 0;
44 }
45 const float old_pos_y = pos.y;
46
47 do
48 {
49 s = getWrappedLine(sz.x - offset, fontsize, stringwidth_colors);
51 offset = (sz.x - stringwidth_colors(s, fontsize) - offset) * align;
52 drawcolorcodedstring(pos + eX * offset, s, fontsize, a, DRAWFLAG_NORMAL);
53 pos.y += fontsize.y;
54 offset = fontsize.x;
55 }
57
59 {
60 pos.y = old_pos_y;
61 pos.y -= CHECKPOINTS_SPACING * fontsize.y;
62 }
63 else
64 pos.y += CHECKPOINTS_SPACING * fontsize.y;
65
66 return pos;
67}
68
69vector Checkpoints_Draw(int end, vector pos, vector fontsize, vector rs_fontsize)
70{
71 string s;
72 for (int j = end; j >= 0; --j)
73 {
75 if (s == "")
76 continue;
77 pos = Checkpoints_drawstring(s, pos, panel_size, panel_fg_alpha, fontsize);
78 if (autocvar_hud_panel_checkpoints_flip) // now check if the next line can be shown (fit)
79 {
80 if (pos.y < panel_pos.y)
81 break;
82 }
83 else
84 {
85 if (pos.y > panel_pos.y + panel_size.y - rs_fontsize.y)
86 break;
87 }
88 }
89 return pos;
90}
91
93{
95 return;
96
98
101 else
104
106 {
107 panel_pos += '1 1 0' * panel_bg_padding;
108 panel_size -= '2 2 0' * panel_bg_padding;
109 }
110
111 vector pos = panel_pos;
113 pos.y += panel_size.y;
114
115 const vector rs_fontsize = hud_fontsize * CHECKPOINTS_BASE_SIZE;
116 const vector fontsize = autocvar_hud_panel_checkpoints_fontscale > 0.125 ? rs_fontsize * autocvar_hud_panel_checkpoints_fontscale : rs_fontsize;
117
118 int i;
120 {
121 // show up to race_nextcheckpoint (not including) or everything if you are before start (0 or 254)
122 // (except race_laptime != 0 for race, means next is start+finish so don't show previous lap finish)
123 if (race_checkpoint != 0 && race_checkpoint != 254) // middle of run/race
124 i = race_checkpoint;
125 else if (ISGAMETYPE(RACE) && race_nextcheckpoint == 0) // before start, but on race, so don't keep old finish visible
126 i = 253;
127 else // before start, not on race (cts), keep old run cps visible
128 i = 255;
129 }
130 else
131 {
132 const string units_text = autocvar_cl_race_cptimes_showspeed_unit ? GetSpeedUnit(autocvar_hud_speed_unit) : "";
133 const float speed_conv_f = GetSpeedUnitFactor(autocvar_hud_speed_unit);
134 for (i = 0; i < 4; ++i)
135 {
136 string timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(18.7 + i * 5.33), false);
137 string time_split = i == 0 ? "+0.39" : i == 1 ? "+0.0" : i == 2 ? "-0.14" : "-0.08";
138 string col = i == 0 ? "^1" : i == 1 ? "^3" : "^2";
139 float speed_split = speed_conv_f * (1086 + i * 51);
140 float speed_diff = speed_conv_f * (i == 0 ? -34 : i == 1 ? 86 : i == 2 ? 25 : 0);
142 if (i == 3)
143 speed_color = "^3";
144 demolines[i] = sprintf(strcat("%s %s", _("Checkpoint %d"), " (%s) ^7%d%s %s"), timestr, col, i+1, time_split, speed_split, units_text, sprintf("%s(%+d%s)", speed_color, speed_diff, units_text));
145 }
146 for (; i < 10; ++i) // iust draw 10 for configuring the HUD
147 demolines[i] = sprintf(strcat("%s ^7", _("Checkpoint %d"), " ^7%d%s"), TIME_ENCODED_TOSTRING(TIME_ENCODE(i*9.37), false), i+1, (1100 + i*63) * speed_conv_f, units_text);
148 --i;
149 }
150
151 pos = Checkpoints_Draw(i, pos, fontsize, rs_fontsize);
152}
void HUD_Checkpoints_Export(int fh)
vector Checkpoints_Draw(int end, vector pos, vector fontsize, vector rs_fontsize)
vector Checkpoints_drawstring(string s, vector pos, vector sz, float a, vector fontsize)
const float CHECKPOINTS_SPACING
string demolines[10]
const float CHECKPOINTS_BASE_SIZE
void HUD_Checkpoints()
bool autocvar_hud_panel_checkpoints_flip
Definition checkpoints.qh:6
bool autocvar_hud_panel_checkpoints_dynamichud
Definition checkpoints.qh:5
bool autocvar_hud_panel_checkpoints_align
Definition checkpoints.qh:7
bool autocvar_hud_panel_checkpoints
Definition checkpoints.qh:4
float autocvar_hud_panel_checkpoints_fontscale
Definition checkpoints.qh:8
#define drawcolorcodedstring(position, text, scale, alpha, flag)
Definition draw.qh:30
vector autocvar_hud_progressbar_acceleration_neg_color
Definition physics.qh:30
vector autocvar_hud_progressbar_acceleration_color
Definition physics.qh:29
string GetSpeedUnit(int speed_unit)
Definition main.qc:1122
float GetSpeedUnitFactor(int speed_unit)
Definition main.qc:1109
vector hud_fontsize
Definition main.qh:77
#define ISGAMETYPE(NAME)
Definition main.qh:46
ERASEABLE string rgb_to_hexcolor(vector rgb)
Definition color.qh:183
string getWrappedLine(float maxWidth, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:995
string getWrappedLine_remaining
Definition util.qh:147
#define TIME_ENCODE(t)
Definition util.qh:100
#define TIME_ENCODED_TOSTRING(n, compact)
Definition util.qh:96
const float DRAWFLAG_NORMAL
void HUD_Panel_LoadCvars()
Definition hud.qc:215
void HUD_Scale_Enable()
Definition hud.qc:91
void HUD_Scale_Disable()
Definition hud.qc:84
vector panel_size
Definition hud.qh:163
float panel_fg_alpha
Definition hud.qh:169
float panel_bg_padding
Definition hud.qh:174
int autocvar_hud_speed_unit
Definition hud.qh:207
#define HUD_Panel_DrawBg()
Definition hud.qh:55
vector panel_pos
Definition hud.qh:162
#define HUD_Write_Cvar(cvar)
Definition hud_config.qh:40
bool autocvar__hud_configure
Definition hud_config.qh:3
float bound(float min, float value, float max)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
float race_nextcheckpoint
Definition racetimer.qh:19
float race_checkpoint
Definition racetimer.qh:8
string race_checkpoint_splits[256]
Definition racetimer.qh:14
vector
Definition self.qh:92
float stringwidth_colors(string s, vector theSize)
Definition string.qh:30
const vector eX
Definition vector.qh:44