Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
util.qh
Go to the documentation of this file.
1#pragma once
2
3#ifdef SVQC
4float tracebox_inverted (vector v1, vector mi, vector ma, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity); // returns the number of traces done, for benchmarking
5
6void traceline_inverted (vector v1, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity);
7#endif
8
9#ifdef GAMEQC
10#define CENTER_OF_ENT(ent) ((ent).origin + '0 0 0.5' * ((ent).mins.z + (ent).maxs.z))
11
12/*
13==================
14findbetterlocation
15
16Returns a point at least 12 units away from walls
17(useful for explosion animations, although the blast is performed where it really happened)
18Ripped from DPMod
19==================
20*/
21vector findbetterlocation (vector org, float mindist);
22
24#endif
25
26#ifdef SVQC
27// temporary array used to dump settings for each weapon / turret
28const int MAX_CONFIG_SETTINGS = 70;
30#endif
31
32.string netname;
33.string message;
34
37
38// this returns a tempstring containing a copy of s with additional \n newlines added, it also replaces \n in the text with a real newline
39// NOTE: s IS allowed to be a tempstring
40string wordwrap(string s, float l);
41#ifdef SVQC
42void wordwrap_sprint(entity to, string s, float l);
43#endif
44void wordwrap_cb(string s, float l, void(string) callback);
45
46#ifndef SVQC
47string draw_currentSkin;
48string draw_UseSkinFor(string pic);
49#endif
50
51#ifndef SVQC
52string icon_path_from_HUDskin(string theIcon);
53#endif
54#ifdef MENUQC
55string icon_path_from_menuskin(string theIcon);
56#endif
57
58#ifdef CSQC
59// NOTE they aren't all registered mutators, e.g. jetpack, low gravity
60// TODO add missing "mutators"
61const int MUT_DODGING = 0;
62const int MUT_INSTAGIB = 1;
63const int MUT_NEW_TOYS = 2;
64const int MUT_NIX = 3;
65const int MUT_ROCKET_FLYING = 4;
67const int MUT_GRAVITY = 6;
68const int MUT_CLOAKED = 7;
69const int MUT_GRAPPLING_HOOK = 8;
70const int MUT_MIDAIR = 9;
71const int MUT_MELEE_ONLY = 10;
72const int MUT_VAMPIRE = 11;
73const int MUT_PINATA = 12;
74const int MUT_WEAPON_STAY = 13;
75const int MUT_BLOODLOSS = 14;
76const int MUT_JETPACK = 15;
77const int MUT_OVERKILL = 16;
78const int MUT_BUFFS = 17;
79const int MUT_NO_POWERUPS = 18;
80const int MUT_POWERUPS = 19;
82const int MUT_TOUCHEXPLODE = 21;
83const int MUT_WALLJUMP = 22;
84const int MUT_NO_START_WEAPONS = 23;
85const int MUT_NADES = 24;
86const int MUT_OFFHAND_BLASTER = 25;
87
88const int MUT_MAX = 47;
89
91bool mut_is_active(int mut);
92string build_mutator_list(string s);
93#endif
94
95// iterative depth-first search, with fields that go "up", "down left" and "right" in a tree
96// for each element, funcPre is called first, then funcPre and funcPost for all its children, and funcPost last
97void depthfirst(entity start, .entity up, .entity downleft, .entity right, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass);
98
99#define TIME_TO_NTHS(t,n) floor((t) * (n) + 0.5)
100
101const int TIME_DECIMALS = 2;
102const float TIME_FACTOR = 100;
103#define TIME_ENCODED_TOSTRING(n, compact) mmssth(n, compact)
104#define RACE_RECORD "/race100record/"
105#define CTS_RECORD "/cts100record/"
106#define CTF_RECORD "/ctf100record/"
107#define TIME_ENCODE(t) TIME_TO_NTHS(t, TIME_FACTOR)
108#define TIME_DECODE(n) ((n) / TIME_FACTOR)
109
110#ifdef GAMEQC
111string ScoreString(float vflags, float value, int rounds_played);
112#endif
113
115float compressShortVector(vector vec);
116
117#ifdef GAMEQC
118float CheckWireframeBox(entity forent, vector v0, vector dvx, vector dvy, vector dvz);
119#endif
120
121string fixPriorityList(string pl, float from, float to, float subtract, float complete);
122string mapPriorityList(string order, string(string) mapfunc);
123string swapInPriorityList(string order, float i, float j);
124
125float cvar_settemp(string pKey, string pValue);
127
128#ifdef GAMEQC
129// modes: 0 = trust q3map2 (_mini images)
130// 1 = trust tracebox (_radar images)
131// in both modes, mapinfo's "size" overrides
132
136void get_mi_min_max(float mode);
137
138vector mi_picmin; // adjusted mins that map to the picture (square)
139vector mi_picmax; // adjusted maxs that map to the picture (square)
140vector mi_pictexcoord0; // texcoords of the image corners (after transforming, these are 2D coords too)
141vector mi_pictexcoord1; // texcoords of the image corners (after transforming, these are 2D coords too)
142vector mi_pictexcoord2; // texcoords of the image corners (after transforming, these are 2D coords too)
143vector mi_pictexcoord3; // texcoords of the image corners (after transforming, these are 2D coords too)
144void get_mi_min_max_texcoords(float mode);
145#endif
146
149float textLengthUpToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw);
150string textShortenToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw);
151float textLengthUpToLength(string theText, int maxLength, textLengthUpToLength_lenFunction_t tw);
152string textShortenToLength(string theText, int maxLength, textLengthUpToLength_lenFunction_t tw);
153
157
158// FIXME can't use Gametype gt because Gitlab compilation unit test fails
159float isGametypeInFilter(entity gt, float tp, float ts, string pattern);
160
161vector solve_shotdirection(vector myorg, vector myvel, vector eorg, vector evel, float spd, float newton_style);
162vector get_shotvelocity(vector myvel, vector mydir, float spd, float newton_style, float mi, float ma);
163
166
167#ifdef SVQC
169string records_reply[10];
170#endif
171
172#ifdef GAMEQC
173vector healtharmor_maxdamage(float h, float a, float armorblock, int deathtype); // returns vector: maxdamage, armorideal, 1 if fully armored
174vector healtharmor_applydamage(float h, float a, float armorblock, int deathtype, float damage); // returns vector: take, save, 0
175#endif
176
177string getcurrentmod();
178
179float matchacl(string acl, string str); // matches str against ACL acl (with entries +foo*, +foo, +*foo, +*foo*, and same with - for forbidding)
180
181void write_String_To_File(int fh, string str, bool alsoprint);
182
183string get_model_datafilename(string mod, float skn, string fil); // skin -1 will return wildcard, mod string_null will also put wildcard there
195const int MAX_AIM_BONES = 4;
200float get_model_parameters(string mod, float skn); // call with string_null to clear; skin -1 means mod is the filename of the txt file and is to be split
201
203string translate_key(string key);
204
205// x-encoding (encoding as zero length invisible string)
206// encodes approx. 14 bits into 5 bytes of color code string
207const float XENCODE_MAX = 21295; // 2*22*22*22-1
208const float XENCODE_LEN = 5;
209string xencode(float f);
210float xdecode(string s);
211
212#ifdef GAMEQC
213string strtolower(string s);
214#endif
215
216// generic shutdown handler
217void Shutdown();
218
219#ifdef GAMEQC
222// loops through the tags of model v using counter tagnum
223#define FOR_EACH_TAG(v) float tagnum; Skeleton_SetBones(v); for(tagnum = 0; tagnum < v.skeleton_bones; tagnum++, gettaginfo(v, tagnum))
224#endif
225
226// execute-stuff-next-frame subsystem
227void execute_next_frame();
228void queue_to_execute_next_frame(string s);
229
233
234// expand multiple arguments into one argument by stripping parenthesis
235#define XPD(...) __VA_ARGS__
236
237// Some common varargs functions. Lowercase as they match C.
238#define fprintf(file, ...) fputs(file, sprintf(__VA_ARGS__))
239#define bprintf(...) bprint(sprintf(__VA_ARGS__))
240
241#ifdef GAMEQC
242 #ifdef CSQC
245 #define GENTLE (autocvar_cl_gentle || autocvar_cl_gentle_messages)
246 #else
247 int autocvar_sv_gentle;
248 #define GENTLE autocvar_sv_gentle
249 #endif
250 #define normal_or_gentle(normal, gentle) ((GENTLE && (gentle != "")) ? gentle : normal)
251#endif
252
253#ifdef GAMEQC
255#endif
256
257#ifdef GAMEQC
258const int CNT_NORMAL = 1;
259const int CNT_GAMESTART = 2;
260//const int CNT_IDLE = 3;
261const int CNT_KILL = 4;
262const int CNT_RESPAWN = 5;
263const int CNT_ROUNDSTART = 6;
264entity Announcer_PickNumber(int type, int num);
265#endif
266
267#ifdef GAMEQC
268int Mod_Q1BSP_SuperContentsFromNativeContents(int nativecontents);
269int Mod_Q1BSP_NativeContentsFromSuperContents(int supercontents);
270#endif
271
272#define APPEND_TO_STRING(list,sep,add) ((list) = (((list) != "") ? strcat(list, sep, add) : (add)))
273
274// Returns the correct difference between two always increasing numbers
275#define COMPARE_INCREASING(to,from) (to < from ? from + to + 2 : to - from)
276
277#ifdef SVQC
278void attach_sameorigin(entity e, entity to, string tag);
281
282void SetMovetypeFollow(entity ent, entity e);
285#endif
286
287#ifdef GAMEQC
288string playername(string thename, int teamid, bool team_colorize);
289
290float trace_hits_box_1d(float end, float thmi, float thma);
291
292float trace_hits_box(vector start, vector end, vector thmi, vector thma);
293
294float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma);
295
296float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma);
297#endif
298
299float cvar_or(string cv, float v);
300
301float blink_synced(float base, float range, float freq, float start_time, int start_blink);
302
303float blink(float base, float range, float freq);
304
305string find_last_color_code(string s);
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
limitations: NULL cannot be present elements can only be present once a maximum of IL_MAX lists can e...
string netname
Definition powerups.qc:20
string message
Definition powerups.qc:19
int rounds_played
Definition stats.qh:379
float CheckWireframeBox(entity forent, vector v0, vector dvx, vector dvy, vector dvz)
Definition util.qc:582
string get_model_datafilename(string mod, float skn, string fil)
Definition util.qc:1481
ERASEABLE string translate_key(string key)
Definition util.qc:1612
const int MAX_AIM_BONES
Definition util.qh:195
entity(entity cur, entity near, entity pass) findNextEntityNearFunction_t
Definition util.qh:230
string getWrappedLineLen(float w, textLengthUpToLength_lenFunction_t tw)
bool mut_is_active(int mut)
Definition util.qc:263
void SetMovetypeFollow(entity ent, entity e)
Definition util.qc:2131
string mi_shortname
Definition util.qh:133
string playername(string thename, int teamid, bool team_colorize)
Definition util.qc:2180
void FindConnectedComponent(entity e,.entity fld, findNextEntityNearFunction_t nxt, isConnectedFunction_t iscon, entity pass)
Definition util.qc:1865
string xencode(float f)
void queue_to_execute_next_frame(string s)
Definition util.qc:1855
vector mi_picmin
Definition util.qh:138
void execute_next_frame()
Definition util.qc:1847
void get_mi_min_max_texcoords(float mode)
Definition util.qc:766
const int CNT_NORMAL
Definition util.qh:258
void wordwrap_cb(string s, float l, void(string) callback)
Definition util.qc:328
string maplist_reply
Definition util.qh:168
entity Announcer_PickNumber(int type, int num)
Definition util.qc:1926
float compressShortVector(vector vec)
Definition util.qc:521
const int MUT_MAX
Definition util.qh:88
const int MUT_WEAPON_STAY
Definition util.qh:74
string rankings_reply
Definition util.qh:168
int Mod_Q1BSP_SuperContentsFromNativeContents(int nativecontents)
Definition util.qc:2022
float get_model_parameters_weight
Definition util.qh:189
const int MUT_VAMPIRE
Definition util.qh:72
float tracebox_inverted(vector v1, vector mi, vector ma, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity)
Definition util.qc:23
const int MUT_GRAPPLING_HOOK
Definition util.qh:69
float get_model_parameters_fixbone
Definition util.qh:198
float xdecode(string s)
Definition util.qc:1782
float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma)
Definition util.qc:2241
string get_model_parameters_sex
Definition util.qh:188
vector healtharmor_maxdamage(float h, float a, float armorblock, int deathtype)
Definition util.qc:1391
vector mi_pictexcoord2
Definition util.qh:142
vector mi_min
Definition util.qh:134
vector decompressShotOrigin(float f)
float textLengthUpToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:884
const int MUT_TOUCHEXPLODE
Definition util.qh:82
void depthfirst(entity start,.entity up,.entity downleft,.entity right, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass)
Definition util.qc:394
const int MUT_JETPACK
Definition util.qh:76
float skeleton_bones
Definition util.qh:220
const int MUT_INVINCIBLE_PROJECTILES
Definition util.qh:66
float textLengthUpToLength(string theText, int maxLength, textLengthUpToLength_lenFunction_t tw)
Definition util.qc:920
const int MUT_NO_START_WEAPONS
Definition util.qh:84
string config_queue[MAX_CONFIG_SETTINGS]
Definition util.qh:29
float cvar_settemp(string pKey, string pValue)
Definition util.qc:809
float matchacl(string acl, string str)
Definition util.qc:1439
string ScoreString(float vflags, float value, int rounds_played)
vector solve_shotdirection(vector myorg, vector myvel, vector eorg, vector evel, float spd, float newton_style)
Definition util.qc:1235
string build_mutator_list(string s)
Definition util.qc:272
const int MUT_NEW_TOYS
Definition util.qh:63
float get_model_parameters_species
Definition util.qh:187
const int MUT_ROCKET_FLYING
Definition util.qh:65
string find_last_color_code(string s)
Definition util.qc:956
string records_reply[10]
Definition util.qh:169
string fixPriorityList(string pl, float from, float to, float subtract, float complete)
Definition util.qc:600
const int MUT_DODGING
Definition util.qh:61
int Mod_Q1BSP_NativeContentsFromSuperContents(int supercontents)
Definition util.qc:2042
const int MUT_INSTAGIB
Definition util.qh:62
string textShortenToLength(string theText, int maxLength, textLengthUpToLength_lenFunction_t tw)
string getWrappedLine_remaining
Definition util.qh:154
float(entity a, entity b, entity pass) isConnectedFunction_t
Definition util.qh:231
string getcurrentmod()
Definition util.qc:1429
float isGametypeInFilter(entity gt, float tp, float ts, string pattern)
vector decompressShortVector(float data)
float get_model_parameters_bone_aimweight[MAX_AIM_BONES]
Definition util.qh:197
string getWrappedLine(float w, vector size, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:1133
string icon_path_from_menuskin(string theIcon)
Returns icon path from the current menu skin (MENU only).
Definition util.qc:239
bool autocvar_cl_gentle
Definition util.qh:243
int active_mutators[2]
Definition util.qh:90
float compressShotOrigin(vector v)
Definition util.qc:1350
float blink_synced(float base, float range, float freq, float start_time, int start_blink)
Definition util.qc:2264
float get_model_parameters_modelskin
Definition util.qh:185
void get_mi_min_max(float mode)
Definition util.qc:676
string get_model_parameters_name
Definition util.qh:186
const float XENCODE_LEN
Definition util.qh:208
float cvar_settemp_restore()
Definition util.qc:847
string get_model_parameters_bone_weapon
Definition util.qh:194
const int MUT_GRAVITY
Definition util.qh:67
string strtolower(string s)
vector mi_pictexcoord3
Definition util.qh:143
vector real_origin(entity ent)
Definition util.qc:147
float trace_hits_box_1d(float end, float thmi, float thma)
Definition util.qc:2199
const int MUT_BLOODLOSS
Definition util.qh:75
string get_model_parameters_description
Definition util.qh:192
void UnsetMovetypeFollow(entity ent)
Definition util.qc:2151
const int TIME_DECIMALS
Definition util.qh:101
string lsmaps_reply
Definition util.qh:168
const int MUT_MELEE_ONLY
Definition util.qh:71
const int MUT_CLOAKED
Definition util.qh:68
vector mi_pictexcoord0
Definition util.qh:140
string textShortenToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:1173
int LostMovetypeFollow(entity ent)
Definition util.qc:2161
const int MUT_MIDAIR
Definition util.qh:70
bool get_model_parameters_hidden
Definition util.qh:191
vector healtharmor_applydamage(float h, float a, float armorblock, int deathtype, float damage)
Definition util.qc:1415
int autocvar_cl_gentle_messages
Definition util.qh:244
const float TIME_FACTOR
Definition util.qh:102
string get_model_parameters_modelname
Definition util.qh:184
string get_model_parameters_bone_upperbody
Definition util.qh:193
float(string s, vector size) textLengthUpToWidth_widthFunction_t
Definition util.qh:147
const int MUT_OVERKILL
Definition util.qh:77
string get_model_parameters_bone_aim[MAX_AIM_BONES]
Definition util.qh:196
string ladder_reply
Definition util.qh:168
const int MUT_NIX
Definition util.qh:64
vector get_shotvelocity(vector myvel, vector mydir, float spd, float newton_style, float mi, float ma)
Definition util.qc:1298
const int MUT_NO_POWERUPS
Definition util.qh:79
float trace_hits_box(vector start, vector end, vector thmi, vector thma)
Definition util.qc:2221
string swapInPriorityList(string order, float i, float j)
Definition util.qc:653
void attach_sameorigin(entity e, entity to, string tag)
Definition util.qc:2059
vector mi_max
Definition util.qh:135
void Shutdown()
Definition main.qc:163
IntrusiveList g_saved_cvars
Definition util.qh:35
float get_model_parameters_age
Definition util.qh:190
const int CNT_RESPAWN
Definition util.qh:262
vector mi_picmax
Definition util.qh:139
const int MAX_CONFIG_SETTINGS
Definition util.qh:28
float(string s) textLengthUpToLength_lenFunction_t
Definition util.qh:148
const int CNT_KILL
Definition util.qh:261
void Skeleton_SetBones(entity e)
Definition util.qc:1833
void detach_sameorigin(entity e)
Definition util.qc:2099
string wordwrap(string s, float l)
Definition util.qc:169
void follow_sameorigin(entity e, entity to)
Definition util.qc:2112
const int MUT_PINATA
Definition util.qh:73
const int MUT_POWERUPS
Definition util.qh:80
vector findbetterlocation(vector org, float mindist)
Definition util.qc:116
string mapPriorityList(string order, string(string) mapfunc)
Definition util.qc:642
const int CNT_ROUNDSTART
Definition util.qh:263
const int MUT_OFFHAND_BLASTER
Definition util.qh:86
void write_String_To_File(int fh, string str, bool alsoprint)
Definition util.qc:1475
string monsterlist_reply
Definition util.qh:168
const int MUT_BUFFS_REPLACE_POWERUPS
Definition util.qh:81
void traceline_inverted(vector v1, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity)
Definition util.qc:100
float blink(float base, float range, float freq)
Definition util.qc:2276
float get_model_parameters(string mod, float skn)
Definition util.qc:1494
vector mi_pictexcoord1
Definition util.qh:141
const int MUT_WALLJUMP
Definition util.qh:83
string get_model_parameters_desc
Definition util.qh:199
vector animfixfps(entity e, vector a, vector b)
Definition util.qc:1907
const int MUT_NADES
Definition util.qh:85
const int CNT_GAMESTART
Definition util.qh:259
float cvar_or(string cv, float v)
Definition util.qc:2248
void wordwrap_sprint(entity to, string s, float l)
Definition util.qc:191
const float XENCODE_MAX
Definition util.qh:207
const int MUT_BUFFS
Definition util.qh:78
vector size
entity() spawn
#define pass(name, colormin, colormax)
#define base
#define IL_NEW()
#define ERASEABLE
Definition _all.inc:37
#define USING(name, T)
Definition _all.inc:72
float mod(float val, float m)
float freq
Definition pendulum.qc:3
vector
Definition self.qh:96
vector org
Definition self.qh:96
#define STATIC_INIT(func)
during worldspawn
Definition static.qh:33