]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/util.qh
s/#ifndef MENUQC/#ifdef GAMEQC/g
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / util.qh
1 #pragma once
2
3 #ifdef GAMEQC
4
5 vector real_origin(entity ent);
6 #endif
7
8 // 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
9 // NOTE: s IS allowed to be a tempstring
10 string wordwrap(string s, float l);
11 #ifdef SVQC
12 void wordwrap_sprint(entity to, string s, float l);
13 #endif
14 void wordwrap_cb(string s, float l, void(string) callback);
15
16 #ifndef SVQC
17 string draw_currentSkin;
18 string draw_UseSkinFor(string pic);
19 #endif
20
21 // iterative depth-first search, with fields that go "up", "down left" and "right" in a tree
22 // for each element, funcPre is called first, then funcPre and funcPost for all its children, and funcPost last
23 void depthfirst(entity start, .entity up, .entity downleft, .entity right, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass);
24
25 float median(float a, float b, float c);
26
27 // converts a number to a string with the indicated number of decimals
28 string ftos_decimals(float number, float decimals);
29 string ftos_mindecimals(float number);
30
31 bool fexists(string f);
32
33 // unzone the string, and return it as tempstring. Safe to be called on string_null
34 string fstrunzone(string s);
35
36 // database (NOTE: keys are case sensitive)
37 void db_save(int db, string filename);
38 void db_dump(int db, string pFilename);
39 int db_create();
40 int db_load(string filename);
41 void db_close(int db);
42 string db_get(int db, string key);
43 void db_put(int db, string key, string value);
44
45 // stringbuffer loading/saving
46 int buf_load(string filename);
47 void buf_save(int buf, string filename);
48
49 #define TIME_TO_NTHS(t,n) floor((t) * (n) + 0.4)
50 string format_time(float seconds);
51 string mmsss(float t);
52 string mmssss(float t);
53
54 const float TIME_DECIMALS = 2;
55 const float TIME_FACTOR = 100;
56 #define TIME_ENCODED_TOSTRING(n) mmssss(n)
57 #define RACE_RECORD "/race100record/"
58 #define CTS_RECORD "/cts100record/"
59 #define TIME_ENCODE(t) TIME_TO_NTHS(t, TIME_FACTOR)
60 #define TIME_DECODE(n) ((n) / TIME_FACTOR)
61
62 string ScoreString(float vflags, float value);
63
64 vector decompressShortVector(float data);
65 float compressShortVector(vector vec);
66
67 #ifdef GAMEQC
68 float CheckWireframeBox(entity forent, vector v0, vector dvx, vector dvy, vector dvz);
69 #endif
70
71 string fixPriorityList(string pl, float from, float to, float subtract, float complete);
72 string mapPriorityList(string order, string(string) mapfunc);
73 string swapInPriorityList(string order, float i, float j);
74
75 float cvar_value_issafe(string s);
76
77 float cvar_settemp(string pKey, string pValue);
78 float cvar_settemp_restore();
79
80 #ifdef GAMEQC
81 // modes: 0 = trust q3map2 (_mini images)
82 //        1 = trust tracebox (_radar images)
83 // in both modes, mapinfo's "size" overrides
84
85 string mi_shortname;
86 vector mi_min;
87 vector mi_max;
88 void get_mi_min_max(float mode);
89
90 vector mi_picmin; // adjusted mins that map to the picture (square)
91 vector mi_picmax; // adjusted maxs that map to the picture (square)
92 vector mi_pictexcoord0; // texcoords of the image corners (after transforming, these are 2D coords too)
93 vector mi_pictexcoord1; // texcoords of the image corners (after transforming, these are 2D coords too)
94 vector mi_pictexcoord2; // texcoords of the image corners (after transforming, these are 2D coords too)
95 vector mi_pictexcoord3; // texcoords of the image corners (after transforming, these are 2D coords too)
96 void get_mi_min_max_texcoords(float mode);
97 #endif
98
99 float almost_equals(float a, float b);
100 float almost_in_bounds(float a, float b, float c);
101
102 float power2of(float e);
103 float log2of(float x);
104
105 vector rgb_to_hsl(vector rgb);
106 vector hsl_to_rgb(vector hsl);
107 vector rgb_to_hsv(vector rgb);
108 vector hsv_to_rgb(vector hsv);
109 string rgb_to_hexcolor(vector rgb);
110
111 float boxesoverlap(vector m1, vector m2, vector m3, vector m4);
112 float boxinsidebox(vector smins, vector smaxs, vector bmins, vector bmaxs);
113
114 USING(textLengthUpToWidth_widthFunction_t, float(string s, vector size));
115 USING(textLengthUpToLength_lenFunction_t, float(string s));
116 float textLengthUpToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw);
117 string textShortenToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw);
118 float textLengthUpToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw);
119 string textShortenToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw);
120
121 string getWrappedLine_remaining;
122 string getWrappedLine(float w, vector size, textLengthUpToWidth_widthFunction_t tw);
123 string getWrappedLineLen(float w, textLengthUpToLength_lenFunction_t tw);
124
125 float isGametypeInFilter(entity gt, float tp, float ts, string pattern);
126
127 string swapwords(string str, float i, float j);
128 string shufflewords(string str);
129
130 string substring_range(string s, float b, float e);
131
132 vector solve_quadratic(float a, float b, float c);
133 // solution 1 -> x
134 // solution 2 -> y
135 // z = 1 if a real solution exists, 0 if not
136 // if no real solution exists, x contains the real part and y the imaginary part of the complex solutions x+iy and x-iy
137
138 vector solve_shotdirection(vector myorg, vector myvel, vector eorg, vector evel, float spd, float newton_style);
139 vector get_shotvelocity(vector myvel, vector mydir, float spd, float newton_style, float mi, float ma);
140
141 float compressShotOrigin(vector v);
142 vector decompressShotOrigin(float f);
143
144 #ifdef SVQC
145 string rankings_reply, ladder_reply, lsmaps_reply, maplist_reply, monsterlist_reply; // cached replies
146 string records_reply[10];
147 #endif
148
149 #ifdef GAMEQC
150 vector healtharmor_maxdamage(float h, float a, float armorblock, int deathtype); // returns vector: maxdamage, armorideal, 1 if fully armored
151 vector healtharmor_applydamage(float a, float armorblock, int deathtype, float damage); // returns vector: take, save, 0
152 #endif
153
154 string getcurrentmod();
155
156 #ifdef GAMEQC
157 #ifdef CSQC
158 int ReadInt24_t();
159 #else
160 void WriteInt24_t(float dest, float val);
161 void WriteInt48_t(float dest, vector val);
162 void WriteInt72_t(float dest, vector val);
163 #endif
164 #endif
165
166 float float2range11(float f);
167 float float2range01(float f);
168
169 float gsl_ran_gaussian(float sigma);
170
171 float matchacl(string acl, string str); // matches str against ACL acl (with entries +foo*, +foo, +*foo, +*foo*, and same with - for forbidding)
172
173 string get_model_datafilename(string mod, float skn, string fil); // skin -1 will return wildcard, mod string_null will also put wildcard there
174 string get_model_parameters_modelname;
175 float get_model_parameters_modelskin;
176 string get_model_parameters_name;
177 float get_model_parameters_species;
178 string get_model_parameters_sex;
179 float get_model_parameters_weight;
180 float get_model_parameters_age;
181 string get_model_parameters_description;
182 string get_model_parameters_bone_upperbody;
183 string get_model_parameters_bone_weapon;
184 const int MAX_AIM_BONES = 4;
185 string get_model_parameters_bone_aim[MAX_AIM_BONES];
186 float get_model_parameters_bone_aimweight[MAX_AIM_BONES];
187 float get_model_parameters_fixbone;
188 string get_model_parameters_desc;
189 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
190
191 #ifdef GAMEQC
192 vector NearestPointOnBox(entity box, vector org);
193 #endif
194
195 float vercmp(string v1, string v2);
196
197 float u8_strsize(string s);
198
199 // x-encoding (encoding as zero length invisible string)
200 // encodes approx. 14 bits into 5 bytes of color code string
201 const float XENCODE_MAX = 21295; // 2*22*22*22-1
202 const float XENCODE_LEN = 5;
203 string xencode(float f);
204 float xdecode(string s);
205
206 #ifdef GAMEQC
207 string strtolower(string s);
208 #endif
209
210 string MakeConsoleSafe(string input);
211
212 // generic shutdown handler
213 void Shutdown();
214
215 #ifdef GAMEQC
216 .float skeleton_bones;
217 void Skeleton_SetBones(entity e);
218 // loops through the tags of model v using counter tagnum
219 #define FOR_EACH_TAG(v) float tagnum; Skeleton_SetBones(v); for(tagnum = 0; tagnum < v.skeleton_bones; tagnum++, gettaginfo(v, tagnum))
220 #endif
221 #ifdef SVQC
222 void WriteApproxPastTime(float dst, float t);
223 #endif
224 #ifdef CSQC
225 float ReadApproxPastTime();
226 #endif
227
228 // execute-stuff-next-frame subsystem
229 void execute_next_frame();
230 void queue_to_execute_next_frame(string s);
231
232 // a function f with:
233 // f(0) = 0
234 // f(1) = 1
235 // f'(0) = startspeedfactor
236 // f'(1) = endspeedfactor
237 float cubic_speedfunc(float startspeedfactor, float endspeedfactor, float x);
238
239 // checks whether f'(x) = 0 anywhere from 0 to 1
240 // because if this is the case, the function is not usable for platforms
241 // as it may exceed 0..1 bounds, or go in reverse
242 float cubic_speedfunc_is_sane(float startspeedfactor, float endspeedfactor);
243
244 USING(findNextEntityNearFunction_t, entity(entity cur, entity near, entity pass));
245 USING(isConnectedFunction_t, float(entity a, entity b, entity pass));
246 void FindConnectedComponent(entity e, .entity fld, findNextEntityNearFunction_t nxt, isConnectedFunction_t iscon, entity pass);
247
248 // expand multiple arguments into one argument by stripping parenthesis
249 #define XPD(...) __VA_ARGS__
250
251 // Some common varargs functions. Lowercase as they match C.
252 #define fprintf(file, ...) fputs(file, sprintf(__VA_ARGS__))
253 #define bprintf(...) bprint(sprintf(__VA_ARGS__))
254
255 string CCR(string input);
256
257 #ifdef GAMEQC
258         #ifdef CSQC
259                 #define GENTLE (autocvar_cl_gentle || autocvar_cl_gentle_messages)
260         #else
261                 #define GENTLE autocvar_sv_gentle
262         #endif
263         #define normal_or_gentle(normal, gentle) (GENTLE ? ((gentle != "") ? gentle : normal) : normal)
264 #endif
265
266 #ifdef GAMEQC
267 vector animfixfps(entity e, vector a, vector b);
268 #endif
269
270 #ifdef GAMEQC
271 const float CNT_NORMAL = 1;
272 const float CNT_GAMESTART = 2;
273 const float CNT_IDLE = 3;
274 const float CNT_KILL = 4;
275 const float CNT_RESPAWN = 5;
276 const float CNT_ROUNDSTART = 6;
277 entity Announcer_PickNumber(float type, float num);
278 #endif
279
280 #ifdef GAMEQC
281 int Mod_Q1BSP_SuperContentsFromNativeContents(int nativecontents);
282 int Mod_Q1BSP_NativeContentsFromSuperContents(int supercontents);
283 #endif
284
285 // Quadratic splines (bezier)
286 vector bezier_quadratic_getpoint(vector a, vector p, vector b, float t);
287 vector bezier_quadratic_getderivative(vector a, vector p, vector b, float t);
288
289 #define APPEND_TO_STRING(list,sep,add) ((list) = (((list) != "") ? strcat(list, sep, add) : (add)))
290
291 // Returns the correct difference between two always increasing numbers
292 #define COMPARE_INCREASING(to,from) (to < from ? from + to + 2 : to - from)