Xonotic
util.qh
Go to the documentation of this file.
1 #pragma once
2 
3 #ifdef SVQC
4 float 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 
6 void traceline_inverted (vector v1, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity);
7 #endif
8 
9 #ifdef GAMEQC
10 /*
11 ==================
12 findbetterlocation
13 
14 Returns a point at least 12 units away from walls
15 (useful for explosion animations, although the blast is performed where it really happened)
16 Ripped from DPMod
17 ==================
18 */
19 vector findbetterlocation (vector org, float mindist);
20 
21 vector real_origin(entity ent);
22 #endif
23 
24 #ifdef SVQC
25 // temporary array used to dump settings for each weapon / turret
26 const int MAX_CONFIG_SETTINGS = 70;
27 string config_queue[MAX_CONFIG_SETTINGS];
28 #endif
29 
30 .string netname;
31 .string message;
32 
34 STATIC_INIT(g_saved_cvars) { g_saved_cvars = IL_NEW(); }
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
38 string wordwrap(string s, float l);
39 #ifdef SVQC
40 void wordwrap_sprint(entity to, string s, float l);
41 #endif
42 void wordwrap_cb(string s, float l, void(string) callback);
43 
44 #ifndef SVQC
46 string draw_UseSkinFor(string pic);
47 #endif
48 
49 // iterative depth-first search, with fields that go "up", "down left" and "right" in a tree
50 // for each element, funcPre is called first, then funcPre and funcPost for all its children, and funcPost last
51 void depthfirst(entity start, .entity up, .entity downleft, .entity right, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass);
52 
53 #define TIME_TO_NTHS(t,n) floor((t) * (n) + 0.5)
54 
55 const int TIME_DECIMALS = 2;
56 const float TIME_FACTOR = 100;
57 #define TIME_ENCODED_TOSTRING(n) mmssth(n)
58 #define RACE_RECORD "/race100record/"
59 #define CTS_RECORD "/cts100record/"
60 #define CTF_RECORD "/ctf100record/"
61 #define TIME_ENCODE(t) TIME_TO_NTHS(t, TIME_FACTOR)
62 #define TIME_DECODE(n) ((n) / TIME_FACTOR)
63 
64 #ifdef GAMEQC
65 string ScoreString(float vflags, float value);
66 #endif
67 
68 vector decompressShortVector(float data);
69 float compressShortVector(vector vec);
70 
71 #ifdef GAMEQC
72 float CheckWireframeBox(entity forent, vector v0, vector dvx, vector dvy, vector dvz);
73 #endif
74 
75 string fixPriorityList(string pl, float from, float to, float subtract, float complete);
76 string mapPriorityList(string order, string(string) mapfunc);
77 string swapInPriorityList(string order, float i, float j);
78 
79 float cvar_settemp(string pKey, string pValue);
80 float cvar_settemp_restore();
81 
82 #ifdef GAMEQC
83 // modes: 0 = trust q3map2 (_mini images)
84 // 1 = trust tracebox (_radar images)
85 // in both modes, mapinfo's "size" overrides
86 
87 string mi_shortname;
88 vector mi_min;
89 vector mi_max;
90 void get_mi_min_max(float mode);
91 
92 vector mi_picmin; // adjusted mins that map to the picture (square)
93 vector mi_picmax; // adjusted maxs that map to the picture (square)
94 vector mi_pictexcoord0; // texcoords of the image corners (after transforming, these are 2D coords too)
95 vector mi_pictexcoord1; // texcoords of the image corners (after transforming, these are 2D coords too)
96 vector mi_pictexcoord2; // texcoords of the image corners (after transforming, these are 2D coords too)
97 vector mi_pictexcoord3; // texcoords of the image corners (after transforming, these are 2D coords too)
98 void get_mi_min_max_texcoords(float mode);
99 #endif
100 
103 float textLengthUpToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw);
104 string textShortenToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw);
105 float textLengthUpToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw);
106 string textShortenToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw);
107 
111 
112 float isGametypeInFilter(entity gt, float tp, float ts, string pattern);
113 
114 vector solve_shotdirection(vector myorg, vector myvel, vector eorg, vector evel, float spd, float newton_style);
115 vector get_shotvelocity(vector myvel, vector mydir, float spd, float newton_style, float mi, float ma);
116 
119 
120 #ifdef SVQC
121 string rankings_reply, ladder_reply, lsmaps_reply, maplist_reply, monsterlist_reply; // cached replies
122 string records_reply[10];
123 #endif
124 
125 #ifdef GAMEQC
126 vector healtharmor_maxdamage(float h, float a, float armorblock, int deathtype); // returns vector: maxdamage, armorideal, 1 if fully armored
127 vector healtharmor_applydamage(float a, float armorblock, int deathtype, float damage); // returns vector: take, save, 0
128 #endif
129 
130 string getcurrentmod();
131 
132 float matchacl(string acl, string str); // matches str against ACL acl (with entries +foo*, +foo, +*foo, +*foo*, and same with - for forbidding)
133 
134 void write_String_To_File(int fh, string str, bool alsoprint);
135 
136 string get_model_datafilename(string mod, float skn, string fil); // skin -1 will return wildcard, mod string_null will also put wildcard there
148 const int MAX_AIM_BONES = 4;
153 float 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
154 
155 ERASEABLE
156 string translate_key(string key);
157 
158 // x-encoding (encoding as zero length invisible string)
159 // encodes approx. 14 bits into 5 bytes of color code string
160 const float XENCODE_MAX = 21295; // 2*22*22*22-1
161 const float XENCODE_LEN = 5;
162 string xencode(float f);
163 float xdecode(string s);
164 
165 #ifdef GAMEQC
166 string strtolower(string s);
167 #endif
168 
169 // generic shutdown handler
170 void Shutdown();
171 
172 #ifdef GAMEQC
173 .float skeleton_bones;
174 void Skeleton_SetBones(entity e);
175 // loops through the tags of model v using counter tagnum
176 #define FOR_EACH_TAG(v) float tagnum; Skeleton_SetBones(v); for(tagnum = 0; tagnum < v.skeleton_bones; tagnum++, gettaginfo(v, tagnum))
177 #endif
178 
179 // execute-stuff-next-frame subsystem
180 void execute_next_frame();
181 void queue_to_execute_next_frame(string s);
182 
186 
187 // expand multiple arguments into one argument by stripping parenthesis
188 #define XPD(...) __VA_ARGS__
189 
190 // Some common varargs functions. Lowercase as they match C.
191 #define fprintf(file, ...) fputs(file, sprintf(__VA_ARGS__))
192 #define bprintf(...) bprint(sprintf(__VA_ARGS__))
193 
194 #ifdef GAMEQC
195  #ifdef CSQC
196  bool autocvar_cl_gentle;
197  int autocvar_cl_gentle_messages;
198  #define GENTLE (autocvar_cl_gentle || autocvar_cl_gentle_messages)
199  #else
200  int autocvar_sv_gentle;
201  #define GENTLE autocvar_sv_gentle
202  #endif
203  #define normal_or_gentle(normal, gentle) ((GENTLE && (gentle != "")) ? gentle : normal)
204 #endif
205 
206 #ifdef GAMEQC
207 vector animfixfps(entity e, vector a, vector b);
208 #endif
209 
210 #ifdef GAMEQC
211 const int CNT_NORMAL = 1;
212 const int CNT_GAMESTART = 2;
213 //const int CNT_IDLE = 3;
214 const int CNT_KILL = 4;
215 const int CNT_RESPAWN = 5;
216 const int CNT_ROUNDSTART = 6;
217 entity Announcer_PickNumber(int type, int num);
218 #endif
219 
220 #ifdef GAMEQC
221 int Mod_Q1BSP_SuperContentsFromNativeContents(int nativecontents);
222 int Mod_Q1BSP_NativeContentsFromSuperContents(int supercontents);
223 #endif
224 
225 #define APPEND_TO_STRING(list,sep,add) ((list) = (((list) != "") ? strcat(list, sep, add) : (add)))
226 
227 // Returns the correct difference between two always increasing numbers
228 #define COMPARE_INCREASING(to,from) (to < from ? from + to + 2 : to - from)
229 
230 #ifdef SVQC
231 void attach_sameorigin(entity e, entity to, string tag);
232 void detach_sameorigin(entity e);
233 void follow_sameorigin(entity e, entity to);
234 
235 void SetMovetypeFollow(entity ent, entity e);
236 void UnsetMovetypeFollow(entity ent);
237 int LostMovetypeFollow(entity ent);
238 #endif
239 
240 #ifdef GAMEQC
241 string playername(string thename, int teamid, bool team_colorize);
242 
243 float trace_hits_box_1d(float end, float thmi, float thma);
244 
245 float trace_hits_box(vector start, vector end, vector thmi, vector thma);
246 
247 float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma);
248 
249 float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma);
250 #endif
251 
252 float cvar_or(string cv, float v);
253 
254 float blink_synced(float base, float range, float freq, float start_time, int start_blink);
255 
256 float blink(float base, float range, float freq);
float get_model_parameters_weight
Definition: util.qh:142
string fixPriorityList(string pl, float from, float to, float subtract, float complete)
Definition: util.qc:485
vector decompressShortVector(float data)
void FindConnectedComponent(entity e,.entity fld, findNextEntityNearFunction_t nxt, isConnectedFunction_t iscon, entity pass)
Definition: util.qc:1630
string getWrappedLineLen(float w, textLengthUpToLength_lenFunction_t tw)
Definition: util.qc:918
string get_model_parameters_desc
Definition: util.qh:152
string getWrappedLine(float w, vector size, textLengthUpToWidth_widthFunction_t tw)
Definition: util.qc:880
string getWrappedLine_remaining
Definition: util.qh:108
ERASEABLE string translate_key(string key)
Definition: util.qc:1376
float textLengthUpToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw)
Definition: util.qc:773
string getcurrentmod()
Definition: util.qc:1191
const float TIME_FACTOR
Definition: util.qh:56
string textShortenToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw)
Definition: util.qc:956
const int MAX_AIM_BONES
Definition: util.qh:148
string draw_UseSkinFor(string pic)
Definition: util.qc:206
float get_model_parameters(string mod, float skn)
Definition: util.qc:1258
float(entity a, entity b, entity pass) isConnectedFunction_t
Definition: util.qh:184
string draw_currentSkin
Definition: util.qh:45
#define IL_NEW()
string get_model_parameters_description
Definition: util.qh:145
STATIC_INIT(g_saved_cvars)
Definition: util.qh:34
entity(entity cur, entity near, entity pass) findNextEntityNearFunction_t
Definition: util.qh:183
entity() spawn
float textLengthUpToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw)
Definition: util.qc:809
entity to
Definition: self.qh:96
limitations: NULL cannot be present elements can only be present once a maximum of IL_MAX lists can e...
float get_model_parameters_fixbone
Definition: util.qh:151
vector size
Definition: csprogsdefs.qc:114
#define ERASEABLE
Definition: _all.inc:35
float cvar_settemp(string pKey, string pValue)
Definition: util.qc:696
vector decompressShotOrigin(float f)
string swapInPriorityList(string order, float i, float j)
Definition: util.qc:540
string get_model_parameters_sex
Definition: util.qh:141
float(string s, vector size) textLengthUpToWidth_widthFunction_t
Definition: util.qh:101
float get_model_parameters_age
Definition: util.qh:143
float get_model_parameters_modelskin
Definition: util.qh:138
float get_model_parameters_species
Definition: util.qh:140
const float XENCODE_MAX
Definition: util.qh:160
string wordwrap(string s, float l)
Definition: util.qc:170
string get_model_parameters_modelname
Definition: util.qh:137
float blink_synced(float base, float range, float freq, float start_time, int start_blink)
Definition: util.qc:2032
const float XENCODE_LEN
Definition: util.qh:161
string message
Definition: util.qh:31
float cvar_or(string cv, float v)
Definition: util.qc:2016
string get_model_parameters_bone_aim[MAX_AIM_BONES]
Definition: util.qh:149
void wordwrap_cb(string s, float l, void(string) callback)
Definition: util.qc:215
float matchacl(string acl, string str)
Definition: util.qc:1203
string get_model_datafilename(string mod, float skn, string fil)
Definition: util.qc:1245
void write_String_To_File(int fh, string str, bool alsoprint)
Definition: util.qc:1239
void execute_next_frame()
Definition: util.qc:1612
float xdecode(string s)
Definition: util.qc:1546
void Shutdown()
Definition: main.qc:152
string textShortenToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw)
Definition: util.qc:964
string get_model_parameters_bone_weapon
Definition: util.qh:147
float isGametypeInFilter(entity gt, float tp, float ts, string pattern)
vector(float skel, float bonenum) _skel_get_boneabs_hidden
string get_model_parameters_bone_upperbody
Definition: util.qh:146
vector get_shotvelocity(vector myvel, vector mydir, float spd, float newton_style, float mi, float ma)
Definition: util.qc:1081
vector v
Definition: ent_cs.qc:116
void queue_to_execute_next_frame(string s)
Definition: util.qc:1620
void depthfirst(entity start,.entity up,.entity downleft,.entity right, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass)
Definition: util.qc:281
float blink(float base, float range, float freq)
Definition: util.qc:2044
IntrusiveList g_saved_cvars
Definition: util.qh:33
float(string s) textLengthUpToLength_lenFunction_t
Definition: util.qh:102
float compressShortVector(vector vec)
Definition: util.qc:406
bool get_model_parameters_hidden
Definition: util.qh:144
float get_model_parameters_bone_aimweight[MAX_AIM_BONES]
Definition: util.qh:150
#define USING(name, T)
Definition: _all.inc:72
float cvar_settemp_restore()
Definition: util.qc:736
#define pass(name, colormin, colormax)
string netname
Definition: util.qh:30
const int TIME_DECIMALS
Definition: util.qh:55
vector solve_shotdirection(vector myorg, vector myvel, vector eorg, vector evel, float spd, float newton_style)
Definition: util.qc:1018
string mapPriorityList(string order, string(string) mapfunc)
Definition: util.qc:527
string xencode(float f)
float compressShotOrigin(vector v)
Definition: util.qc:1121
string get_model_parameters_name
Definition: util.qh:139