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/*
11==================
12findbetterlocation
13
14Returns a point at least 12 units away from walls
15(useful for explosion animations, although the blast is performed where it really happened)
16Ripped from DPMod
17==================
18*/
19vector findbetterlocation (vector org, float mindist);
20
22#endif
23
24#ifdef SVQC
25// temporary array used to dump settings for each weapon / turret
26const int MAX_CONFIG_SETTINGS = 70;
28#endif
29
30.string netname;
31.string message;
32
35
36// 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
37// NOTE: s IS allowed to be a tempstring
38string wordwrap(string s, float l);
39#ifdef SVQC
40void wordwrap_sprint(entity to, string s, float l);
41#endif
42void wordwrap_cb(string s, float l, void(string) callback);
43
44#ifndef SVQC
45string draw_currentSkin;
46string draw_UseSkinFor(string pic);
47
48string icon_path_from_HUDskin(string theIcon);
49#ifdef MENUQC
50string icon_path_from_menuskin(string theIcon);
51#endif
52
53// NOTE they aren't all registered mutators, e.g. jetpack, low gravity
54// TODO add missing "mutators"
55const int MUT_DODGING = 0;
56const int MUT_INSTAGIB = 1;
57const int MUT_NEW_TOYS = 2;
58const int MUT_NIX = 3;
59const int MUT_ROCKET_FLYING = 4;
60const int MUT_INVINCIBLE_PROJECTILES = 5;
61const int MUT_GRAVITY = 6;
62const int MUT_CLOAKED = 7;
63const int MUT_GRAPPLING_HOOK = 8;
64const int MUT_MIDAIR = 9;
65const int MUT_MELEE_ONLY = 10;
66const int MUT_VAMPIRE = 11;
67const int MUT_PINATA = 12;
68const int MUT_WEAPON_STAY = 13;
69const int MUT_BLOODLOSS = 14;
70const int MUT_JETPACK = 15;
71const int MUT_BUFFS = 16;
72const int MUT_OVERKILL = 17;
73const int MUT_NO_POWERUPS = 18;
74const int MUT_POWERUPS = 19;
75const int MUT_TOUCHEXPLODE = 20;
76const int MUT_WALLJUMP = 21;
77const int MUT_NO_START_WEAPONS = 22;
78const int MUT_NADES = 23;
79const int MUT_OFFHAND_BLASTER = 24;
80
81const int MUT_MAX = 47;
82
83int active_mutators[2];
84bool mut_is_active(int mut);
85string build_mutator_list(string s);
86#endif
87
88// iterative depth-first search, with fields that go "up", "down left" and "right" in a tree
89// for each element, funcPre is called first, then funcPre and funcPost for all its children, and funcPost last
90void depthfirst(entity start, .entity up, .entity downleft, .entity right, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass);
91
92#define TIME_TO_NTHS(t,n) floor((t) * (n) + 0.5)
93
94const int TIME_DECIMALS = 2;
95const float TIME_FACTOR = 100;
96#define TIME_ENCODED_TOSTRING(n, compact) mmssth(n, compact)
97#define RACE_RECORD "/race100record/"
98#define CTS_RECORD "/cts100record/"
99#define CTF_RECORD "/ctf100record/"
100#define TIME_ENCODE(t) TIME_TO_NTHS(t, TIME_FACTOR)
101#define TIME_DECODE(n) ((n) / TIME_FACTOR)
102
103#ifdef GAMEQC
104string ScoreString(float vflags, float value, int rounds_played);
105#endif
106
108float compressShortVector(vector vec);
109
110#ifdef GAMEQC
111float CheckWireframeBox(entity forent, vector v0, vector dvx, vector dvy, vector dvz);
112#endif
113
114string fixPriorityList(string pl, float from, float to, float subtract, float complete);
115string mapPriorityList(string order, string(string) mapfunc);
116string swapInPriorityList(string order, float i, float j);
117
118float cvar_settemp(string pKey, string pValue);
120
121#ifdef GAMEQC
122// modes: 0 = trust q3map2 (_mini images)
123// 1 = trust tracebox (_radar images)
124// in both modes, mapinfo's "size" overrides
125
129void get_mi_min_max(float mode);
130
131vector mi_picmin; // adjusted mins that map to the picture (square)
132vector mi_picmax; // adjusted maxs that map to the picture (square)
133vector mi_pictexcoord0; // texcoords of the image corners (after transforming, these are 2D coords too)
134vector mi_pictexcoord1; // texcoords of the image corners (after transforming, these are 2D coords too)
135vector mi_pictexcoord2; // texcoords of the image corners (after transforming, these are 2D coords too)
136vector mi_pictexcoord3; // texcoords of the image corners (after transforming, these are 2D coords too)
137void get_mi_min_max_texcoords(float mode);
138#endif
139
142float textLengthUpToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw);
143string textShortenToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw);
144float textLengthUpToLength(string theText, int maxLength, textLengthUpToLength_lenFunction_t tw);
145string textShortenToLength(string theText, int maxLength, textLengthUpToLength_lenFunction_t tw);
146
150
151// FIXME can't use Gametype gt because Gitlab compilation unit test fails
152float isGametypeInFilter(entity gt, float tp, float ts, string pattern);
153
154vector solve_shotdirection(vector myorg, vector myvel, vector eorg, vector evel, float spd, float newton_style);
155vector get_shotvelocity(vector myvel, vector mydir, float spd, float newton_style, float mi, float ma);
156
159
160#ifdef SVQC
162string records_reply[10];
163#endif
164
165#ifdef GAMEQC
166vector healtharmor_maxdamage(float h, float a, float armorblock, int deathtype); // returns vector: maxdamage, armorideal, 1 if fully armored
167vector healtharmor_applydamage(float a, float armorblock, int deathtype, float damage); // returns vector: take, save, 0
168#endif
169
170string getcurrentmod();
171
172float matchacl(string acl, string str); // matches str against ACL acl (with entries +foo*, +foo, +*foo, +*foo*, and same with - for forbidding)
173
174void write_String_To_File(int fh, string str, bool alsoprint);
175
176string get_model_datafilename(string mod, float skn, string fil); // skin -1 will return wildcard, mod string_null will also put wildcard there
188const int MAX_AIM_BONES = 4;
193float 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
194
196string translate_key(string key);
197
198// x-encoding (encoding as zero length invisible string)
199// encodes approx. 14 bits into 5 bytes of color code string
200const float XENCODE_MAX = 21295; // 2*22*22*22-1
201const float XENCODE_LEN = 5;
202string xencode(float f);
203float xdecode(string s);
204
205#ifdef GAMEQC
206string strtolower(string s);
207#endif
208
209// generic shutdown handler
210void Shutdown();
211
212#ifdef GAMEQC
215// loops through the tags of model v using counter tagnum
216#define FOR_EACH_TAG(v) float tagnum; Skeleton_SetBones(v); for(tagnum = 0; tagnum < v.skeleton_bones; tagnum++, gettaginfo(v, tagnum))
217#endif
218
219// execute-stuff-next-frame subsystem
220void execute_next_frame();
221void queue_to_execute_next_frame(string s);
222
226
227// expand multiple arguments into one argument by stripping parenthesis
228#define XPD(...) __VA_ARGS__
229
230// Some common varargs functions. Lowercase as they match C.
231#define fprintf(file, ...) fputs(file, sprintf(__VA_ARGS__))
232#define bprintf(...) bprint(sprintf(__VA_ARGS__))
233
234#ifdef GAMEQC
235 #ifdef CSQC
238 #define GENTLE (autocvar_cl_gentle || autocvar_cl_gentle_messages)
239 #else
240 int autocvar_sv_gentle;
241 #define GENTLE autocvar_sv_gentle
242 #endif
243 #define normal_or_gentle(normal, gentle) ((GENTLE && (gentle != "")) ? gentle : normal)
244#endif
245
246#ifdef GAMEQC
248#endif
249
250#ifdef GAMEQC
251const int CNT_NORMAL = 1;
252const int CNT_GAMESTART = 2;
253//const int CNT_IDLE = 3;
254const int CNT_KILL = 4;
255const int CNT_RESPAWN = 5;
256const int CNT_ROUNDSTART = 6;
257entity Announcer_PickNumber(int type, int num);
258#endif
259
260#ifdef GAMEQC
261int Mod_Q1BSP_SuperContentsFromNativeContents(int nativecontents);
262int Mod_Q1BSP_NativeContentsFromSuperContents(int supercontents);
263#endif
264
265#define APPEND_TO_STRING(list,sep,add) ((list) = (((list) != "") ? strcat(list, sep, add) : (add)))
266
267// Returns the correct difference between two always increasing numbers
268#define COMPARE_INCREASING(to,from) (to < from ? from + to + 2 : to - from)
269
270#ifdef SVQC
271void attach_sameorigin(entity e, entity to, string tag);
274
275void SetMovetypeFollow(entity ent, entity e);
278#endif
279
280#ifdef GAMEQC
281string playername(string thename, int teamid, bool team_colorize);
282
283float trace_hits_box_1d(float end, float thmi, float thma);
284
285float trace_hits_box(vector start, vector end, vector thmi, vector thma);
286
287float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma);
288
289float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma);
290#endif
291
292float cvar_or(string cv, float v);
293
294float blink_synced(float base, float range, float freq, float start_time, int start_blink);
295
296float blink(float base, float range, float freq);
297
298string 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:377
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:1381
ERASEABLE string translate_key(string key)
Definition util.qc:1512
const int MAX_AIM_BONES
Definition util.qh:188
string getWrappedLineLen(float w, textLengthUpToLength_lenFunction_t tw)
void SetMovetypeFollow(entity ent, entity e)
Definition util.qc:2033
string mi_shortname
Definition util.qh:126
string playername(string thename, int teamid, bool team_colorize)
Definition util.qc:2082
void FindConnectedComponent(entity e,.entity fld, findNextEntityNearFunction_t nxt, isConnectedFunction_t iscon, entity pass)
Definition util.qc:1766
float(string s) textLengthUpToLength_lenFunction_t
Definition util.qh:141
string xencode(float f)
void queue_to_execute_next_frame(string s)
Definition util.qc:1756
vector mi_picmin
Definition util.qh:131
void execute_next_frame()
Definition util.qc:1748
void get_mi_min_max_texcoords(float mode)
Definition util.qc:768
const int CNT_NORMAL
Definition util.qh:251
void wordwrap_cb(string s, float l, void(string) callback)
Definition util.qc:327
string maplist_reply
Definition util.qh:161
entity Announcer_PickNumber(int type, int num)
Definition util.qc:1827
float compressShortVector(vector vec)
Definition util.qc:521
string rankings_reply
Definition util.qh:161
int Mod_Q1BSP_SuperContentsFromNativeContents(int nativecontents)
Definition util.qc:1923
float get_model_parameters_weight
Definition util.qh:182
float tracebox_inverted(vector v1, vector mi, vector ma, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity)
Definition util.qc:23
float get_model_parameters_fixbone
Definition util.qh:191
float xdecode(string s)
Definition util.qc:1682
float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma)
Definition util.qc:2143
string get_model_parameters_sex
Definition util.qh:181
vector healtharmor_maxdamage(float h, float a, float armorblock, int deathtype)
Definition util.qc:1289
vector mi_pictexcoord2
Definition util.qh:135
vector mi_min
Definition util.qh:127
vector decompressShotOrigin(float f)
float textLengthUpToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:888
void depthfirst(entity start,.entity up,.entity downleft,.entity right, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass)
Definition util.qc:393
float skeleton_bones
Definition util.qh:213
float textLengthUpToLength(string theText, int maxLength, textLengthUpToLength_lenFunction_t tw)
Definition util.qc:924
vector healtharmor_applydamage(float a, float armorblock, int deathtype, float damage)
Definition util.qc:1313
string config_queue[MAX_CONFIG_SETTINGS]
Definition util.qh:27
float cvar_settemp(string pKey, string pValue)
Definition util.qc:811
float matchacl(string acl, string str)
Definition util.qc:1339
float(entity a, entity b, entity pass) isConnectedFunction_t
Definition util.qh:224
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:1133
float get_model_parameters_species
Definition util.qh:180
string find_last_color_code(string s)
Definition util.qc:960
string records_reply[10]
Definition util.qh:162
string fixPriorityList(string pl, float from, float to, float subtract, float complete)
Definition util.qc:600
int Mod_Q1BSP_NativeContentsFromSuperContents(int supercontents)
Definition util.qc:1943
string textShortenToLength(string theText, int maxLength, textLengthUpToLength_lenFunction_t tw)
string getWrappedLine_remaining
Definition util.qh:147
string getcurrentmod()
Definition util.qc:1327
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:190
string getWrappedLine(float w, vector size, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:995
bool autocvar_cl_gentle
Definition util.qh:236
float compressShotOrigin(vector v)
Definition util.qc:1248
float blink_synced(float base, float range, float freq, float start_time, int start_blink)
Definition util.qc:2166
float get_model_parameters_modelskin
Definition util.qh:178
void get_mi_min_max(float mode)
Definition util.qc:678
string get_model_parameters_name
Definition util.qh:179
const float XENCODE_LEN
Definition util.qh:201
float cvar_settemp_restore()
Definition util.qc:851
string get_model_parameters_bone_weapon
Definition util.qh:187
string strtolower(string s)
vector mi_pictexcoord3
Definition util.qh:136
vector real_origin(entity ent)
Definition util.qc:148
float trace_hits_box_1d(float end, float thmi, float thma)
Definition util.qc:2101
string get_model_parameters_description
Definition util.qh:185
void UnsetMovetypeFollow(entity ent)
Definition util.qc:2053
const int TIME_DECIMALS
Definition util.qh:94
string lsmaps_reply
Definition util.qh:161
vector mi_pictexcoord0
Definition util.qh:133
string textShortenToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:1071
int LostMovetypeFollow(entity ent)
Definition util.qc:2063
bool get_model_parameters_hidden
Definition util.qh:184
int autocvar_cl_gentle_messages
Definition util.qh:237
const float TIME_FACTOR
Definition util.qh:95
string get_model_parameters_modelname
Definition util.qh:177
string get_model_parameters_bone_upperbody
Definition util.qh:186
entity(entity cur, entity near, entity pass) findNextEntityNearFunction_t
Definition util.qh:223
string get_model_parameters_bone_aim[MAX_AIM_BONES]
Definition util.qh:189
string ladder_reply
Definition util.qh:161
vector get_shotvelocity(vector myvel, vector mydir, float spd, float newton_style, float mi, float ma)
Definition util.qc:1196
float(string s, vector size) textLengthUpToWidth_widthFunction_t
Definition util.qh:140
float trace_hits_box(vector start, vector end, vector thmi, vector thma)
Definition util.qc:2123
string swapInPriorityList(string order, float i, float j)
Definition util.qc:655
void attach_sameorigin(entity e, entity to, string tag)
Definition util.qc:1960
vector mi_max
Definition util.qh:128
void Shutdown()
Definition main.qc:162
IntrusiveList g_saved_cvars
Definition util.qh:33
float get_model_parameters_age
Definition util.qh:183
const int CNT_RESPAWN
Definition util.qh:255
vector mi_picmax
Definition util.qh:132
const int MAX_CONFIG_SETTINGS
Definition util.qh:26
const int CNT_KILL
Definition util.qh:254
void Skeleton_SetBones(entity e)
Definition util.qc:1733
void detach_sameorigin(entity e)
Definition util.qc:2000
string wordwrap(string s, float l)
Definition util.qc:170
void follow_sameorigin(entity e, entity to)
Definition util.qc:2014
vector findbetterlocation(vector org, float mindist)
Definition util.qc:117
string mapPriorityList(string order, string(string) mapfunc)
Definition util.qc:642
const int CNT_ROUNDSTART
Definition util.qh:256
void write_String_To_File(int fh, string str, bool alsoprint)
Definition util.qc:1375
string monsterlist_reply
Definition util.qh:161
void traceline_inverted(vector v1, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity)
Definition util.qc:101
float blink(float base, float range, float freq)
Definition util.qc:2178
float get_model_parameters(string mod, float skn)
Definition util.qc:1394
vector mi_pictexcoord1
Definition util.qh:134
string get_model_parameters_desc
Definition util.qh:192
vector animfixfps(entity e, vector a, vector b)
Definition util.qc:1808
const int CNT_GAMESTART
Definition util.qh:252
float cvar_or(string cv, float v)
Definition util.qc:2150
void wordwrap_sprint(entity to, string s, float l)
Definition util.qc:192
const float XENCODE_MAX
Definition util.qh:200
vector size
entity() spawn
#define pass(name, colormin, colormax)
#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:92
vector org
Definition self.qh:92
#define STATIC_INIT(func)
during worldspawn
Definition static.qh:32