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