Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
extra.qc File Reference
Include dependency graph for extra.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SLICKDETECT_STEPS_EPSILON   0.00001

Functions

void StrafeHUD_DrawJumpHeight (entity e, bool onground, bool swimming, float text_offset_top, float text_offset_bottom)
float StrafeHUD_DrawSlickDetector (entity e, bool already_detected)
void StrafeHUD_DrawStartSpeed (float speed, float text_offset_top, float text_offset_bottom)
void StrafeHUD_DrawStrafeEfficiency (float strafe_ratio, float text_offset_top, float text_offset_bottom)
void StrafeHUD_DrawVerticalAngle (entity e, float text_offset_top, float text_offset_bottom)
void StrafeHUD_Sonar (float strafe_ratio, string sonarsound)
string StrafeHUD_UpdateSonarSound ()

Macro Definition Documentation

◆ SLICKDETECT_STEPS_EPSILON

#define SLICKDETECT_STEPS_EPSILON   0.00001

Definition at line 18 of file extra.qc.

Referenced by StrafeHUD_DrawSlickDetector().

Function Documentation

◆ StrafeHUD_DrawJumpHeight()

void StrafeHUD_DrawJumpHeight ( entity e,
bool onground,
bool swimming,
float text_offset_top,
float text_offset_bottom )

Definition at line 127 of file extra.qc.

128{
129 float length_conversion_factor = StrafeHUD_GetLengthUnitFactor(autocvar_hud_speed_unit);
130 static float jumpheight = 0, jumptime = 0; // displayed value and timestamp for fade out
131
132 // tries to catch kill and spectate but those are not reliable
133 if ((e.velocity.z <= 0) || onground || swimming || IS_DEAD(e) || !IS_PLAYER(e))
134 jumpheight_min = jumpheight_max = e.origin.z;
135 else if(e.origin.z > jumpheight_max)
136 {
137 jumpheight_max = e.origin.z;
138 float jumpheight_new = jumpheight_max - jumpheight_min;
139
140 if ((jumpheight_new * length_conversion_factor) > max(autocvar_hud_panel_strafehud_jumpheight_min, 0))
141 {
142 jumpheight = jumpheight_new;
143 jumptime = time;
144 }
145 }
146
148 return;
149
150 // use more decimals when displaying km or miles
151 int length_decimals = autocvar_hud_speed_unit >= 3 && autocvar_hud_speed_unit <= 5 ? 6 : 2;
152
153 float jumpheight_height = autocvar_hud_panel_strafehud_jumpheight_size * panel_size.y;
154 string jumpheight_text = ftos_decimals(jumpheight * length_conversion_factor, length_decimals);
156 jumpheight_text = strcat(jumpheight_text, StrafeHUD_GetLengthUnit(autocvar_hud_speed_unit));
157
159 jumpheight_text, jumpheight_height,
163 text_offset_top, text_offset_bottom);
164}
void StrafeHUD_DrawTextIndicator(string text, float height, vector color, float fadetime, float lasttime, vector pos, float offset_top, float offset_bottom)
Definition draw.qc:308
float StrafeHUD_GetLengthUnitFactor(int length_unit)
Definition util.qc:82
string StrafeHUD_GetLengthUnit(int length_unit)
Definition util.qc:95
#define IS_DEAD(s)
Definition player.qh:245
#define IS_PLAYER(s)
Definition player.qh:243
float time
float jumpheight_min
Definition extra.qh:4
float jumpheight_max
Definition extra.qh:4
vector panel_size
Definition hud.qh:163
int autocvar_hud_speed_unit
Definition hud.qh:207
float max(float f,...)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
float autocvar_hud_panel_strafehud_jumpheight_fade
Definition strafehud.qh:88
vector autocvar_hud_panel_strafehud_jumpheight_color
Definition strafehud.qh:90
bool autocvar_hud_panel_strafehud_unit_show
Definition strafehud.qh:12
bool autocvar_hud_panel_strafehud_jumpheight
Definition strafehud.qh:87
float autocvar_hud_panel_strafehud_jumpheight_min
Definition strafehud.qh:89
vector autocvar_hud_panel_strafehud_jumpheight_pos
Definition strafehud.qh:91
float autocvar_hud_panel_strafehud_jumpheight_size
Definition strafehud.qh:92
ERASEABLE string ftos_decimals(float number, int decimals)
converts a number to a string with the indicated number of decimals
Definition string.qh:469

References autocvar_hud_panel_strafehud_jumpheight, autocvar_hud_panel_strafehud_jumpheight_color, autocvar_hud_panel_strafehud_jumpheight_fade, autocvar_hud_panel_strafehud_jumpheight_min, autocvar_hud_panel_strafehud_jumpheight_pos, autocvar_hud_panel_strafehud_jumpheight_size, autocvar_hud_panel_strafehud_unit_show, autocvar_hud_speed_unit, entity(), ftos_decimals(), IS_DEAD, IS_PLAYER, jumpheight_max, jumpheight_min, max(), panel_size, StrafeHUD_DrawTextIndicator(), StrafeHUD_GetLengthUnit(), StrafeHUD_GetLengthUnitFactor(), strcat(), and time.

Referenced by HUD_StrafeHUD().

◆ StrafeHUD_DrawSlickDetector()

float StrafeHUD_DrawSlickDetector ( entity e,
bool already_detected )

Definition at line 23 of file extra.qc.

24{
25 float slickdetector_height = bound(0, autocvar_hud_panel_strafehud_slickdetector_height, 1);
26 slickdetector_height *= panel_size.y;
30 && slickdetector_height > 0
31 && panel_size.x > 0)
32 {
34 bool allslick = PHYS_FRICTION(e) == 0;
35 bool slickdetected = false;
36
37 slicksteps = 90 * DEG2RAD / 2 ** slicksteps;
38
39 // don't need to traceline if already touching slick
40 slickdetected = already_detected;
41
42 // coordinates at the bottom center of the player bbox
43 vector traceorigin = e.origin + eZ * e.mins.z;
44
45 // traceline downwards into every direction
47 for (float f = 0; f < 90 * DEG2RAD - SLICKDETECT_STEPS_EPSILON && !slickdetected; f += slicksteps)
48 {
49 vector slickoffset;
50 float slickrotate;
51
52 // creates a vector angled 'f' degrees relative to the Z vector
53 // negative cosine value to face downwards
56
57 for (float j = 0; j < 360 * DEG2RAD - SLICKDETECT_STEPS_EPSILON && !slickdetected; j += slicksteps)
58 {
59 // adjusts the vector so that it rotates 'j' degrees around the Z vector
60 slickoffset.x = sin(j) * slickrotate;
61 slickoffset.y = cos(j) * slickrotate;
62
63 // trace a line, we hit slick if:
64 // - it hits something and surface friction is disabled
65 // - the slick surface flag got set
66 // note: it is not guaranteed that the detected surface is actually
67 // a zero friction surface if PHYS_FRICTION_SLICK() does not equal zero
68 traceline(traceorigin, traceorigin + slickoffset, MOVE_NOMONSTERS, e);
69 if ((allslick && trace_fraction < 1)
71 {
72 slickdetected = true;
73 }
74
75 // rotation does nothing when we are perpendicular to the ground, hence only one iteration
76 if (f == 0)
77 break;
78 }
79 }
80
81 // if a traceline hit a slick surface
82 if (slickdetected)
83 {
84 vector slickdetector_size = panel_size;
85 slickdetector_size.y = slickdetector_height;
86
87 // horizontal lines
88 for (int i = 0; i <= 1; ++i)
89 {
90 float y_offset = (i == 0)
91 ? -slickdetector_size.y // top
92 : panel_size.y; // bottom
94 panel_pos + eY * y_offset,
98 }
99 }
100
101 return slickdetector_height;
102 }
103
104 return 0;
105}
#define drawfill(position, size, rgb, alpha, flag)
Definition draw.qh:36
#define PHYS_FRICTION(s)
Definition player.qh:114
const float DRAWFLAG_NORMAL
const float MOVE_NOMONSTERS
float DEG2RAD
float Q3SURFACEFLAG_SLICK
float trace_dphitq3surfaceflags
float trace_fraction
v y
Definition ent_cs.qc:121
#define SLICKDETECT_STEPS_EPSILON
Definition extra.qc:18
float panel_fg_alpha
Definition hud.qh:169
vector panel_pos
Definition hud.qh:162
float bound(float min, float value, float max)
float cos(float f)
float sin(float f)
vector
Definition self.qh:92
float autocvar_hud_panel_strafehud_slickdetector_range
Definition strafehud.qh:76
float autocvar_hud_panel_strafehud_slickdetector_height
Definition strafehud.qh:80
float autocvar_hud_panel_strafehud_slickdetector_alpha
Definition strafehud.qh:79
int autocvar_hud_panel_strafehud_slickdetector_granularity
Definition strafehud.qh:77
vector autocvar_hud_panel_strafehud_slickdetector_color
Definition strafehud.qh:78
bool autocvar_hud_panel_strafehud_slickdetector
Definition strafehud.qh:75
const vector eY
Definition vector.qh:45
const vector eZ
Definition vector.qh:46

References autocvar_hud_panel_strafehud_slickdetector, autocvar_hud_panel_strafehud_slickdetector_alpha, autocvar_hud_panel_strafehud_slickdetector_color, autocvar_hud_panel_strafehud_slickdetector_granularity, autocvar_hud_panel_strafehud_slickdetector_height, autocvar_hud_panel_strafehud_slickdetector_range, bound(), cos(), DEG2RAD, drawfill, DRAWFLAG_NORMAL, entity(), eY, eZ, MOVE_NOMONSTERS, panel_fg_alpha, panel_pos, panel_size, PHYS_FRICTION, Q3SURFACEFLAG_SLICK, sin(), SLICKDETECT_STEPS_EPSILON, trace_dphitq3surfaceflags, trace_fraction, and vector.

Referenced by HUD_StrafeHUD().

◆ StrafeHUD_DrawStartSpeed()

void StrafeHUD_DrawStartSpeed ( float speed,
float text_offset_top,
float text_offset_bottom )

Definition at line 186 of file extra.qc.

187{
188 static float startspeed = 0, starttime = 0; // displayed value and timestamp for fade out
189
190 // check if the start trigger was hit (will also trigger if the finish trigger was hit if those have the same ID)
191 if (race_nextcheckpoint == 1 || (race_checkpoint == 254 && race_nextcheckpoint == 255))
192 if (race_checkpointtime > 0 && starttime != race_checkpointtime)
193 {
194 starttime = race_checkpointtime;
195 startspeed = speed;
196 }
197
199 return;
200
201 float speed_conversion_factor = GetSpeedUnitFactor(autocvar_hud_speed_unit);
202 float startspeed_height = autocvar_hud_panel_strafehud_startspeed_size * panel_size.y;
203 string startspeed_text = ftos_decimals(startspeed * speed_conversion_factor, 2);
205 startspeed_text = strcat(startspeed_text, GetSpeedUnit(autocvar_hud_speed_unit));
206
208 startspeed_text, startspeed_height,
212 text_offset_top, text_offset_bottom);
213}
string GetSpeedUnit(int speed_unit)
Definition main.qc:1122
float GetSpeedUnitFactor(int speed_unit)
Definition main.qc:1109
float speed
Definition dynlight.qc:9
float race_nextcheckpoint
Definition racetimer.qh:19
float race_checkpoint
Definition racetimer.qh:8
float race_checkpointtime
Definition racetimer.qh:13
vector autocvar_hud_panel_strafehud_startspeed_pos
Definition strafehud.qh:85
bool autocvar_hud_panel_strafehud_startspeed
Definition strafehud.qh:82
float autocvar_hud_panel_strafehud_startspeed_size
Definition strafehud.qh:86
float autocvar_hud_panel_strafehud_startspeed_fade
Definition strafehud.qh:83
vector autocvar_hud_panel_strafehud_startspeed_color
Definition strafehud.qh:84

References autocvar_hud_panel_strafehud_startspeed, autocvar_hud_panel_strafehud_startspeed_color, autocvar_hud_panel_strafehud_startspeed_fade, autocvar_hud_panel_strafehud_startspeed_pos, autocvar_hud_panel_strafehud_startspeed_size, autocvar_hud_panel_strafehud_unit_show, autocvar_hud_speed_unit, ftos_decimals(), GetSpeedUnit(), GetSpeedUnitFactor(), panel_size, race_checkpoint, race_checkpointtime, race_nextcheckpoint, speed, StrafeHUD_DrawTextIndicator(), and strcat().

Referenced by HUD_StrafeHUD().

◆ StrafeHUD_DrawStrafeEfficiency()

void StrafeHUD_DrawStrafeEfficiency ( float strafe_ratio,
float text_offset_top,
float text_offset_bottom )

Definition at line 168 of file extra.qc.

169{
171 return;
172
174 string strafeeff_text = strcat(ftos_decimals(strafe_ratio * 100, 2), "%");
175 vector strafeeff_color = StrafeHUD_MixColors('1 1 1', (strafe_ratio > 0 ? '0 1 0' : '1 0 0'), fabs(strafe_ratio));
176
178 strafeeff_text, strafeeff_height,
179 strafeeff_color, 1,
181 text_offset_top, text_offset_bottom);
182}
vector StrafeHUD_MixColors(vector color1, vector color2, float ratio)
Definition util.qc:351
float fabs(float f)
float autocvar_hud_panel_strafehud_strafeefficiency_size
Definition strafehud.qh:99
bool autocvar_hud_panel_strafehud_strafeefficiency
Definition strafehud.qh:97
vector autocvar_hud_panel_strafehud_strafeefficiency_pos
Definition strafehud.qh:98

References autocvar_hud_panel_strafehud_strafeefficiency, autocvar_hud_panel_strafehud_strafeefficiency_pos, autocvar_hud_panel_strafehud_strafeefficiency_size, fabs(), ftos_decimals(), panel_size, StrafeHUD_DrawTextIndicator(), StrafeHUD_MixColors(), strcat(), time, and vector.

Referenced by HUD_StrafeHUD().

◆ StrafeHUD_DrawVerticalAngle()

void StrafeHUD_DrawVerticalAngle ( entity e,
float text_offset_top,
float text_offset_bottom )

Definition at line 108 of file extra.qc.

109{
111 return;
112
113 float vangle = -PHYS_INPUT_ANGLES(e).x;
115 string vangle_text = sprintf(_("%s°"), ftos_decimals(vangle, 2));
116
118 vangle_text, vangle_height,
121 text_offset_top, text_offset_bottom);
122}
#define PHYS_INPUT_ANGLES(s)
Definition player.qh:250
float autocvar_hud_panel_strafehud_vangle_size
Definition strafehud.qh:96
vector autocvar_hud_panel_strafehud_vangle_pos
Definition strafehud.qh:95
vector autocvar_hud_panel_strafehud_vangle_color
Definition strafehud.qh:94
bool autocvar_hud_panel_strafehud_vangle
Definition strafehud.qh:93

References autocvar_hud_panel_strafehud_vangle, autocvar_hud_panel_strafehud_vangle_color, autocvar_hud_panel_strafehud_vangle_pos, autocvar_hud_panel_strafehud_vangle_size, entity(), ftos_decimals(), panel_size, PHYS_INPUT_ANGLES, StrafeHUD_DrawTextIndicator(), and time.

Referenced by HUD_StrafeHUD().

◆ StrafeHUD_Sonar()

void StrafeHUD_Sonar ( float strafe_ratio,
string sonarsound )

Definition at line 216 of file extra.qc.

217{
218 static float sonar_time = 0;
219
220 float sonar_start = bound(0, autocvar_hud_panel_strafehud_sonar_start, 1);
221 float sonar_ratio = strafe_ratio - sonar_start;
222 if (sonar_start != 1)
223 sonar_ratio /= 1 - sonar_start;
224 else
225 sonar_ratio = 1;
226
229 bool sonar_ready = (sonar_time == 0) || ((time - sonar_time) >= sonar_interval);
230 if (autocvar_hud_panel_strafehud_sonar && sonar_ready && (strafe_ratio >= sonar_start))
231 {
232 sonar_time = time;
233
234 float sonar_volume = bound(0, autocvar_hud_panel_strafehud_sonar_volume_start, 1);
236
239
240 if (sonarsound && (sonar_volume > 0))
241 sound7(csqcplayer, CH_INFO, sonarsound, bound(0, sonar_volume, 1) * VOL_BASE, ATTN_NONE, max(0.000001, sonar_pitch * 100), 0);
242 }
243}
entity csqcplayer
Definition cl_player.qh:26
const float ATTN_NONE
const float VOL_BASE
Definition sound.qh:36
const int CH_INFO
Definition sound.qh:6
float autocvar_hud_panel_strafehud_sonar_interval_start
Definition strafehud.qh:105
float autocvar_hud_panel_strafehud_sonar_volume_exponent
Definition strafehud.qh:110
float autocvar_hud_panel_strafehud_sonar_pitch_start
Definition strafehud.qh:111
float autocvar_hud_panel_strafehud_sonar_interval_exponent
Definition strafehud.qh:107
float autocvar_hud_panel_strafehud_sonar_pitch_exponent
Definition strafehud.qh:113
float autocvar_hud_panel_strafehud_sonar_interval_range
Definition strafehud.qh:106
float autocvar_hud_panel_strafehud_sonar_volume_range
Definition strafehud.qh:109
float autocvar_hud_panel_strafehud_sonar_start
Definition strafehud.qh:104
float autocvar_hud_panel_strafehud_sonar_pitch_range
Definition strafehud.qh:112
bool autocvar_hud_panel_strafehud_sonar
Definition strafehud.qh:102
float autocvar_hud_panel_strafehud_sonar_volume_start
Definition strafehud.qh:108

References ATTN_NONE, autocvar_hud_panel_strafehud_sonar, autocvar_hud_panel_strafehud_sonar_interval_exponent, autocvar_hud_panel_strafehud_sonar_interval_range, autocvar_hud_panel_strafehud_sonar_interval_start, autocvar_hud_panel_strafehud_sonar_pitch_exponent, autocvar_hud_panel_strafehud_sonar_pitch_range, autocvar_hud_panel_strafehud_sonar_pitch_start, autocvar_hud_panel_strafehud_sonar_start, autocvar_hud_panel_strafehud_sonar_volume_exponent, autocvar_hud_panel_strafehud_sonar_volume_range, autocvar_hud_panel_strafehud_sonar_volume_start, bound(), CH_INFO, csqcplayer, max(), time, and VOL_BASE.

Referenced by HUD_StrafeHUD().

◆ StrafeHUD_UpdateSonarSound()

string StrafeHUD_UpdateSonarSound ( )

Definition at line 246 of file extra.qc.

247{
249 static string cursound = string_null;
250 static string sonarsound = string_null;
251 if (newsound == "")
252 {
253 strfree(cursound);
254 strfree(sonarsound);
255 cursound = sonarsound = string_null;
256 }
257 else if (newsound != cursound)
258 {
259 strfree(cursound);
260 cursound = strzone(newsound);
261
262 strfree(sonarsound);
263 sonarsound = _Sound_fixpath(newsound);
264 if (sonarsound)
265 {
266 sonarsound = strzone(sonarsound);
267 precache_sound(sonarsound);
268 }
269 }
270
271 return sonarsound;
272}
string precache_sound(string sample)
string strzone(string s)
string string_null
Definition nil.qh:9
string _Sound_fixpath(string base)
Definition sound.qh:94
string autocvar_hud_panel_strafehud_sonar_audio
Definition strafehud.qh:103
#define strfree(this)
Definition string.qh:59

References _Sound_fixpath(), autocvar_hud_panel_strafehud_sonar_audio, precache_sound(), strfree, string_null, and strzone().

Referenced by HUD_StrafeHUD().