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
50string icon_path_from_HUDskin(string theIcon);
51#ifdef MENUQC
52string icon_path_from_menuskin(string theIcon);
53#endif
54
55// NOTE they aren't all registered mutators, e.g. jetpack, low gravity
56// TODO add missing "mutators"
57const int MUT_DODGING = 0;
58const int MUT_INSTAGIB = 1;
59const int MUT_NEW_TOYS = 2;
60const int MUT_NIX = 3;
61const int MUT_ROCKET_FLYING = 4;
62const int MUT_INVINCIBLE_PROJECTILES = 5;
63const int MUT_GRAVITY = 6;
64const int MUT_CLOAKED = 7;
65const int MUT_GRAPPLING_HOOK = 8;
66const int MUT_MIDAIR = 9;
67const int MUT_MELEE_ONLY = 10;
68const int MUT_VAMPIRE = 11;
69const int MUT_PINATA = 12;
70const int MUT_WEAPON_STAY = 13;
71const int MUT_BLOODLOSS = 14;
72const int MUT_JETPACK = 15;
73const int MUT_BUFFS = 16;
74const int MUT_OVERKILL = 17;
75const int MUT_NO_POWERUPS = 18;
76const int MUT_POWERUPS = 19;
77const int MUT_TOUCHEXPLODE = 20;
78const int MUT_WALLJUMP = 21;
79const int MUT_NO_START_WEAPONS = 22;
80const int MUT_NADES = 23;
81const int MUT_OFFHAND_BLASTER = 24;
82
83const int MUT_MAX = 47;
84
85int active_mutators[2];
86bool mut_is_active(int mut);
87string build_mutator_list(string s);
88#endif
89
90// iterative depth-first search, with fields that go "up", "down left" and "right" in a tree
91// for each element, funcPre is called first, then funcPre and funcPost for all its children, and funcPost last
92void depthfirst(entity start, .entity up, .entity downleft, .entity right, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass);
93
94#define TIME_TO_NTHS(t,n) floor((t) * (n) + 0.5)
95
96const int TIME_DECIMALS = 2;
97const float TIME_FACTOR = 100;
98#define TIME_ENCODED_TOSTRING(n, compact) mmssth(n, compact)
99#define RACE_RECORD "/race100record/"
100#define CTS_RECORD "/cts100record/"
101#define CTF_RECORD "/ctf100record/"
102#define TIME_ENCODE(t) TIME_TO_NTHS(t, TIME_FACTOR)
103#define TIME_DECODE(n) ((n) / TIME_FACTOR)
104
105#ifdef GAMEQC
106string ScoreString(float vflags, float value, int rounds_played);
107#endif
108
110float compressShortVector(vector vec);
111
112#ifdef GAMEQC
113float CheckWireframeBox(entity forent, vector v0, vector dvx, vector dvy, vector dvz);
114#endif
115
116string fixPriorityList(string pl, float from, float to, float subtract, float complete);
117string mapPriorityList(string order, string(string) mapfunc);
118string swapInPriorityList(string order, float i, float j);
119
120float cvar_settemp(string pKey, string pValue);
122
123#ifdef GAMEQC
124// modes: 0 = trust q3map2 (_mini images)
125// 1 = trust tracebox (_radar images)
126// in both modes, mapinfo's "size" overrides
127
131void get_mi_min_max(float mode);
132
133vector mi_picmin; // adjusted mins that map to the picture (square)
134vector mi_picmax; // adjusted maxs that map to the picture (square)
135vector mi_pictexcoord0; // texcoords of the image corners (after transforming, these are 2D coords too)
136vector mi_pictexcoord1; // texcoords of the image corners (after transforming, these are 2D coords too)
137vector mi_pictexcoord2; // texcoords of the image corners (after transforming, these are 2D coords too)
138vector mi_pictexcoord3; // texcoords of the image corners (after transforming, these are 2D coords too)
139void get_mi_min_max_texcoords(float mode);
140#endif
141
144float textLengthUpToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw);
145string textShortenToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw);
146float textLengthUpToLength(string theText, int maxLength, textLengthUpToLength_lenFunction_t tw);
147string textShortenToLength(string theText, int maxLength, textLengthUpToLength_lenFunction_t tw);
148
152
153// FIXME can't use Gametype gt because Gitlab compilation unit test fails
154float isGametypeInFilter(entity gt, float tp, float ts, string pattern);
155
156vector solve_shotdirection(vector myorg, vector myvel, vector eorg, vector evel, float spd, float newton_style);
157vector get_shotvelocity(vector myvel, vector mydir, float spd, float newton_style, float mi, float ma);
158
161
162#ifdef SVQC
164string records_reply[10];
165#endif
166
167#ifdef GAMEQC
168vector healtharmor_maxdamage(float h, float a, float armorblock, int deathtype); // returns vector: maxdamage, armorideal, 1 if fully armored
169vector healtharmor_applydamage(float h, float a, float armorblock, int deathtype, float damage); // returns vector: take, save, 0
170#endif
171
172string getcurrentmod();
173
174float matchacl(string acl, string str); // matches str against ACL acl (with entries +foo*, +foo, +*foo, +*foo*, and same with - for forbidding)
175
176void write_String_To_File(int fh, string str, bool alsoprint);
177
178string get_model_datafilename(string mod, float skn, string fil); // skin -1 will return wildcard, mod string_null will also put wildcard there
190const int MAX_AIM_BONES = 4;
195float 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
196
198string translate_key(string key);
199
200// x-encoding (encoding as zero length invisible string)
201// encodes approx. 14 bits into 5 bytes of color code string
202const float XENCODE_MAX = 21295; // 2*22*22*22-1
203const float XENCODE_LEN = 5;
204string xencode(float f);
205float xdecode(string s);
206
207#ifdef GAMEQC
208string strtolower(string s);
209#endif
210
211// generic shutdown handler
212void Shutdown();
213
214#ifdef GAMEQC
217// loops through the tags of model v using counter tagnum
218#define FOR_EACH_TAG(v) float tagnum; Skeleton_SetBones(v); for(tagnum = 0; tagnum < v.skeleton_bones; tagnum++, gettaginfo(v, tagnum))
219#endif
220
221// execute-stuff-next-frame subsystem
222void execute_next_frame();
223void queue_to_execute_next_frame(string s);
224
228
229// expand multiple arguments into one argument by stripping parenthesis
230#define XPD(...) __VA_ARGS__
231
232// Some common varargs functions. Lowercase as they match C.
233#define fprintf(file, ...) fputs(file, sprintf(__VA_ARGS__))
234#define bprintf(...) bprint(sprintf(__VA_ARGS__))
235
236#ifdef GAMEQC
237 #ifdef CSQC
240 #define GENTLE (autocvar_cl_gentle || autocvar_cl_gentle_messages)
241 #else
242 int autocvar_sv_gentle;
243 #define GENTLE autocvar_sv_gentle
244 #endif
245 #define normal_or_gentle(normal, gentle) ((GENTLE && (gentle != "")) ? gentle : normal)
246#endif
247
248#ifdef GAMEQC
250#endif
251
252#ifdef GAMEQC
253const int CNT_NORMAL = 1;
254const int CNT_GAMESTART = 2;
255//const int CNT_IDLE = 3;
256const int CNT_KILL = 4;
257const int CNT_RESPAWN = 5;
258const int CNT_ROUNDSTART = 6;
259entity Announcer_PickNumber(int type, int num);
260#endif
261
262#ifdef GAMEQC
263int Mod_Q1BSP_SuperContentsFromNativeContents(int nativecontents);
264int Mod_Q1BSP_NativeContentsFromSuperContents(int supercontents);
265#endif
266
267#define APPEND_TO_STRING(list,sep,add) ((list) = (((list) != "") ? strcat(list, sep, add) : (add)))
268
269// Returns the correct difference between two always increasing numbers
270#define COMPARE_INCREASING(to,from) (to < from ? from + to + 2 : to - from)
271
272#ifdef SVQC
273void attach_sameorigin(entity e, entity to, string tag);
276
277void SetMovetypeFollow(entity ent, entity e);
280#endif
281
282#ifdef GAMEQC
283string playername(string thename, int teamid, bool team_colorize);
284
285float trace_hits_box_1d(float end, float thmi, float thma);
286
287float trace_hits_box(vector start, vector end, vector thmi, vector thma);
288
289float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma);
290
291float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma);
292#endif
293
294float cvar_or(string cv, float v);
295
296float blink_synced(float base, float range, float freq, float start_time, int start_blink);
297
298float blink(float base, float range, float freq);
299
300string 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:592
string get_model_datafilename(string mod, float skn, string fil)
Definition util.qc:1491
ERASEABLE string translate_key(string key)
Definition util.qc:1622
const int MAX_AIM_BONES
Definition util.qh:190
entity(entity cur, entity near, entity pass) findNextEntityNearFunction_t
Definition util.qh:225
string getWrappedLineLen(float w, textLengthUpToLength_lenFunction_t tw)
void SetMovetypeFollow(entity ent, entity e)
Definition util.qc:2141
string mi_shortname
Definition util.qh:128
string playername(string thename, int teamid, bool team_colorize)
Definition util.qc:2190
void FindConnectedComponent(entity e,.entity fld, findNextEntityNearFunction_t nxt, isConnectedFunction_t iscon, entity pass)
Definition util.qc:1875
string xencode(float f)
void queue_to_execute_next_frame(string s)
Definition util.qc:1865
vector mi_picmin
Definition util.qh:133
void execute_next_frame()
Definition util.qc:1857
void get_mi_min_max_texcoords(float mode)
Definition util.qc:776
const int CNT_NORMAL
Definition util.qh:253
void wordwrap_cb(string s, float l, void(string) callback)
Definition util.qc:338
string maplist_reply
Definition util.qh:163
entity Announcer_PickNumber(int type, int num)
Definition util.qc:1936
float compressShortVector(vector vec)
Definition util.qc:531
string rankings_reply
Definition util.qh:163
int Mod_Q1BSP_SuperContentsFromNativeContents(int nativecontents)
Definition util.qc:2032
float get_model_parameters_weight
Definition util.qh:184
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:193
float xdecode(string s)
Definition util.qc:1792
float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma)
Definition util.qc:2251
string get_model_parameters_sex
Definition util.qh:183
vector healtharmor_maxdamage(float h, float a, float armorblock, int deathtype)
Definition util.qc:1401
vector mi_pictexcoord2
Definition util.qh:137
vector mi_min
Definition util.qh:129
vector decompressShotOrigin(float f)
float textLengthUpToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:894
void depthfirst(entity start,.entity up,.entity downleft,.entity right, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass)
Definition util.qc:404
float skeleton_bones
Definition util.qh:215
float textLengthUpToLength(string theText, int maxLength, textLengthUpToLength_lenFunction_t tw)
Definition util.qc:930
string config_queue[MAX_CONFIG_SETTINGS]
Definition util.qh:29
float cvar_settemp(string pKey, string pValue)
Definition util.qc:819
float matchacl(string acl, string str)
Definition util.qc:1449
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:1245
float get_model_parameters_species
Definition util.qh:182
string find_last_color_code(string s)
Definition util.qc:966
string records_reply[10]
Definition util.qh:164
string fixPriorityList(string pl, float from, float to, float subtract, float complete)
Definition util.qc:610
int Mod_Q1BSP_NativeContentsFromSuperContents(int supercontents)
Definition util.qc:2052
string textShortenToLength(string theText, int maxLength, textLengthUpToLength_lenFunction_t tw)
string getWrappedLine_remaining
Definition util.qh:149
float(entity a, entity b, entity pass) isConnectedFunction_t
Definition util.qh:226
string getcurrentmod()
Definition util.qc:1439
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:192
string getWrappedLine(float w, vector size, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:1143
bool autocvar_cl_gentle
Definition util.qh:238
float compressShotOrigin(vector v)
Definition util.qc:1360
float blink_synced(float base, float range, float freq, float start_time, int start_blink)
Definition util.qc:2274
float get_model_parameters_modelskin
Definition util.qh:180
void get_mi_min_max(float mode)
Definition util.qc:686
string get_model_parameters_name
Definition util.qh:181
const float XENCODE_LEN
Definition util.qh:203
float cvar_settemp_restore()
Definition util.qc:857
string get_model_parameters_bone_weapon
Definition util.qh:189
string strtolower(string s)
vector mi_pictexcoord3
Definition util.qh:138
vector real_origin(entity ent)
Definition util.qc:147
float trace_hits_box_1d(float end, float thmi, float thma)
Definition util.qc:2209
string get_model_parameters_description
Definition util.qh:187
void UnsetMovetypeFollow(entity ent)
Definition util.qc:2161
const int TIME_DECIMALS
Definition util.qh:96
string lsmaps_reply
Definition util.qh:163
vector mi_pictexcoord0
Definition util.qh:135
string textShortenToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:1183
int LostMovetypeFollow(entity ent)
Definition util.qc:2171
bool get_model_parameters_hidden
Definition util.qh:186
vector healtharmor_applydamage(float h, float a, float armorblock, int deathtype, float damage)
Definition util.qc:1425
int autocvar_cl_gentle_messages
Definition util.qh:239
const float TIME_FACTOR
Definition util.qh:97
string get_model_parameters_modelname
Definition util.qh:179
string get_model_parameters_bone_upperbody
Definition util.qh:188
float(string s, vector size) textLengthUpToWidth_widthFunction_t
Definition util.qh:142
string get_model_parameters_bone_aim[MAX_AIM_BONES]
Definition util.qh:191
string ladder_reply
Definition util.qh:163
vector get_shotvelocity(vector myvel, vector mydir, float spd, float newton_style, float mi, float ma)
Definition util.qc:1308
float trace_hits_box(vector start, vector end, vector thmi, vector thma)
Definition util.qc:2231
string swapInPriorityList(string order, float i, float j)
Definition util.qc:663
void attach_sameorigin(entity e, entity to, string tag)
Definition util.qc:2069
vector mi_max
Definition util.qh:130
void Shutdown()
Definition main.qc:162
IntrusiveList g_saved_cvars
Definition util.qh:35
float get_model_parameters_age
Definition util.qh:185
const int CNT_RESPAWN
Definition util.qh:257
vector mi_picmax
Definition util.qh:134
const int MAX_CONFIG_SETTINGS
Definition util.qh:28
float(string s) textLengthUpToLength_lenFunction_t
Definition util.qh:143
const int CNT_KILL
Definition util.qh:256
void Skeleton_SetBones(entity e)
Definition util.qc:1843
void detach_sameorigin(entity e)
Definition util.qc:2109
string wordwrap(string s, float l)
Definition util.qc:169
void follow_sameorigin(entity e, entity to)
Definition util.qc:2122
vector findbetterlocation(vector org, float mindist)
Definition util.qc:116
string mapPriorityList(string order, string(string) mapfunc)
Definition util.qc:652
const int CNT_ROUNDSTART
Definition util.qh:258
void write_String_To_File(int fh, string str, bool alsoprint)
Definition util.qc:1485
string monsterlist_reply
Definition util.qh:163
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:2286
float get_model_parameters(string mod, float skn)
Definition util.qc:1504
vector mi_pictexcoord1
Definition util.qh:136
string get_model_parameters_desc
Definition util.qh:194
vector animfixfps(entity e, vector a, vector b)
Definition util.qc:1917
const int CNT_GAMESTART
Definition util.qh:254
float cvar_or(string cv, float v)
Definition util.qc:2258
void wordwrap_sprint(entity to, string s, float l)
Definition util.qc:191
const float XENCODE_MAX
Definition util.qh:202
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