6 #include "../client/sys-pre.qh"
7 #include "../dpdefs/csprogsdefs.qh"
8 #include "../client/sys-post.qh"
9 #include "../client/defs.qh"
10 #include "../dpdefs/keycodes.qh"
11 #include "constants.qh"
13 #include "../warpzonelib/anglestransform.qh"
14 #include "../warpzonelib/mathlib.qh"
15 #include "../warpzonelib/common.qh"
16 #include "../warpzonelib/client.qh"
17 #include "playerstats.qh"
20 #include "util-pre.qh"
21 #include "../menu/sys-pre.qh"
22 #include "../dpdefs/menudefs.qh"
23 #include "../dpdefs/keycodes.qh"
24 #include "../menu/sys-post.qh"
25 #include "../menu/config.qh"
26 #include "../warpzonelib/mathlib.qh"
28 #include "util-pre.qh"
29 #include "../server/sys-pre.qh"
30 #include "../dpdefs/progsdefs.qh"
31 #include "../dpdefs/dpextensions.qh"
32 #include "../server/sys-post.qh"
33 #include "../warpzonelib/anglestransform.qh"
34 #include "../warpzonelib/mathlib.qh"
35 #include "../warpzonelib/common.qh"
36 #include "../warpzonelib/util_server.qh"
37 #include "../warpzonelib/server.qh"
38 #include "constants.qh"
43 #ifdef QCC_SUPPORT_ACCUMULATE
44 # define ACCUMULATE_FUNCTION(func,otherfunc) \
45 [[accumulate]] void func() { otherfunc(); }
46 # define CALL_ACCUMULATED_FUNCTION(func) \
49 #ifdef HAVE_YO_DAWG_CPP
50 // TODO make ascii art pic of xzibit
52 // I HERD YO LIEK MACROS
53 // SO I PUT A MACRO DEFINITION IN YO MACRO DEFINITION
54 // SO YO CAN EXPAND MACROS WHILE YO EXPAND MACROS
55 # define ACCUMULATE_FUNCTION(func,otherfunc) \
57 void __merge__##otherfunc() { func(); otherfunc(); } \
59 #define func __merge__##otherfunc \
61 #define func otherfunc \
63 # define CALL_ACCUMULATED_FUNCTION(func) \
66 # define ACCUMULATE_FUNCTION(func,otherfunc) \
67 .float _ACCUMULATE_##func##__##otherfunc
68 void ACCUMULATE_call(string func)
71 float n = numentityfields();
72 string funcprefix = strcat("_ACCUMULATE_", func, "__");
73 float funcprefixlen = strlen(funcprefix);
74 for(i = 0; i < n; ++i)
76 string name = entityfieldname(i);
77 if(substring(name, 0, funcprefixlen) == funcprefix)
78 callfunction(substring(name, funcprefixlen, -1));
81 # define CALL_ACCUMULATED_FUNCTION(func) \
82 ACCUMULATE_call(#func)
86 // used for simplifying ACCUMULATE_FUNCTIONs
87 #define SET_FIRST_OR_LAST(input,first,count) if(!input) { input = (first + count); }
88 #define SET_FIELD_COUNT(field,first,count) if(!field) { field = (first + count); ++count; }
89 #define CHECK_MAX_COUNT(name,max,count,type) if(count > max) { error(strcat("Maximum ", type, " hit: ", #name, ": ", ftos(count), ".\n")); }
91 // 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
92 // NOTE: s IS allowed to be a tempstring
93 string wordwrap(string s, float l);
96 void wordwrap_sprint(string s, float l);
99 void wordwrap_cb(string s, float l, void(string) callback);
102 string draw_currentSkin;
103 string draw_UseSkinFor(string pic);
106 // iterative depth-first search, with fields that go "up", "down left" and "right" in a tree
107 // for each element, funcPre is called first, then funcPre and funcPost for all its children, and funcPost last
108 void depthfirst(entity start, .entity up, .entity downleft, .entity right, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass);
110 float median(float a, float b, float c);
112 // converts a number to a string with the indicated number of decimals
113 // works for up to 10 decimals!
114 string ftos_decimals(float number, float decimals);
116 bool fexists(string f);
118 vector colormapPaletteColor(float c, float isPants);
120 // unzone the string, and return it as tempstring. Safe to be called on string_null
121 string fstrunzone(string s);
123 // database (NOTE: keys are case sensitive)
124 void db_save(int db, string filename);
125 void db_dump(int db, string pFilename);
127 int db_load(string filename);
128 void db_close(int db);
129 string db_get(int db, string key);
130 void db_put(int db, string key, string value);
132 // stringbuffer loading/saving
133 int buf_load(string filename);
134 void buf_save(int buf, string filename);
136 #define TIME_TO_NTHS(t,n) floor((t) * (n) + 0.4)
137 string format_time(float seconds);
138 string mmsss(float t);
139 string mmssss(float t);
141 const float TIME_DECIMALS = 2;
142 const float TIME_FACTOR = 100;
143 #define TIME_ENCODED_TOSTRING(n) mmssss(n)
144 #define RACE_RECORD "/race100record/"
145 #define CTS_RECORD "/cts100record/"
146 #define TIME_ENCODE(t) TIME_TO_NTHS(t, TIME_FACTOR)
147 #define TIME_DECODE(n) ((n) / TIME_FACTOR)
149 string ScoreString(float vflags, float value);
151 float dotproduct(vector a, vector b);
152 vector cross(vector a, vector b);
154 void compressShortVector_init();
155 vector decompressShortVector(float data);
156 float compressShortVector(vector vec);
159 float CheckWireframeBox(entity forent, vector v0, vector dvx, vector dvy, vector dvz);
162 string fixPriorityList(string pl, float from, float to, float subtract, float complete);
163 string mapPriorityList(string order, string(string) mapfunc);
164 string swapInPriorityList(string order, float i, float j);
166 float cvar_value_issafe(string s);
168 float cvar_settemp(string pKey, string pValue);
169 float cvar_settemp_restore();
172 // modes: 0 = trust q3map2 (_mini images)
173 // 1 = trust tracebox (_radar images)
174 // in both modes, mapinfo's "size" overrides
179 void get_mi_min_max(float mode);
181 vector mi_picmin; // adjusted mins that map to the picture (square)
182 vector mi_picmax; // adjusted maxs that map to the picture (square)
183 vector mi_pictexcoord0; // texcoords of the image corners (after transforming, these are 2D coords too)
184 vector mi_pictexcoord1; // texcoords of the image corners (after transforming, these are 2D coords too)
185 vector mi_pictexcoord2; // texcoords of the image corners (after transforming, these are 2D coords too)
186 vector mi_pictexcoord3; // texcoords of the image corners (after transforming, these are 2D coords too)
187 void get_mi_min_max_texcoords(float mode);
190 float almost_equals(float a, float b);
191 float almost_in_bounds(float a, float b, float c);
193 float power2of(float e);
194 float log2of(float x);
196 const string HEXDIGITS = "0123456789ABCDEF0123456789abcdef";
197 #define HEXDIGIT_TO_DEC_RAW(d) (strstrofs(HEXDIGITS, (d), 0))
198 #define HEXDIGIT_TO_DEC(d) ((HEXDIGIT_TO_DEC_RAW(d) | 0x10) - 0x10)
199 #define DEC_TO_HEXDIGIT(d) (substring(HEXDIGITS, (d), 1))
201 vector rgb_to_hsl(vector rgb);
202 vector hsl_to_rgb(vector hsl);
203 vector rgb_to_hsv(vector rgb);
204 vector hsv_to_rgb(vector hsv);
205 string rgb_to_hexcolor(vector rgb);
207 float boxesoverlap(vector m1, vector m2, vector m3, vector m4);
208 float boxinsidebox(vector smins, vector smaxs, vector bmins, vector bmaxs);
210 typedef float(string s, vector size) textLengthUpToWidth_widthFunction_t;
211 typedef float(string s) textLengthUpToLength_lenFunction_t;
212 float textLengthUpToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw);
213 string textShortenToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw);
214 float textLengthUpToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw);
215 string textShortenToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw);
217 string getWrappedLine_remaining;
218 string getWrappedLine(float w, vector size, textLengthUpToWidth_widthFunction_t tw);
219 string getWrappedLineLen(float w, textLengthUpToLength_lenFunction_t tw);
221 float isGametypeInFilter(float gt, float tp, float ts, string pattern);
223 typedef void(float i1, float i2, entity pass) swapfunc_t; // is only ever called for i1 < i2
224 typedef float(float i1, float i2, entity pass) comparefunc_t; // <0 for <, ==0 for ==, >0 for > (like strcmp)
225 void shuffle(float n, swapfunc_t swap, entity pass);
226 void heapsort(float n, swapfunc_t swap, comparefunc_t cmp, entity pass);
228 string swapwords(string str, float i, float j);
229 string shufflewords(string str);
231 string substring_range(string s, float b, float e);
233 vector solve_quadratic(float a, float b, float c);
236 // z = 1 if a real solution exists, 0 if not
237 // if no real solution exists, x contains the real part and y the imaginary part of the complex solutions x+iy and x-iy
239 vector solve_shotdirection(vector myorg, vector myvel, vector eorg, vector evel, float spd, float newton_style);
240 vector get_shotvelocity(vector myvel, vector mydir, float spd, float newton_style, float mi, float ma);
242 float compressShotOrigin(vector v);
243 vector decompressShotOrigin(float f);
246 string rankings_reply, ladder_reply, lsmaps_reply, maplist_reply, monsterlist_reply; // cached replies
247 string records_reply[10];
250 float RandomSelection_totalweight;
251 float RandomSelection_best_priority;
252 entity RandomSelection_chosen_ent;
253 float RandomSelection_chosen_float;
254 string RandomSelection_chosen_string;
255 void RandomSelection_Init();
256 void RandomSelection_Add(entity e, float f, string s, float weight, float priority);
259 vector healtharmor_maxdamage(float h, float a, float armorblock, float deathtype); // returns vector: maxdamage, armorideal, 1 if fully armored
260 vector healtharmor_applydamage(float a, float armorblock, float deathtype, float damage); // returns vector: take, save, 0
263 string getcurrentmod();
268 vector ReadInt48_t();
269 vector ReadInt72_t();
271 void WriteInt24_t(float dest, float val);
272 void WriteInt48_t(float dest, vector val);
273 void WriteInt72_t(float dest, vector val);
278 #ifdef QCC_SUPPORT_NIL
279 #define func_null nil
280 #define string_null nil
282 var void func_null(void);
285 float float2range11(float f);
286 float float2range01(float f);
288 float gsl_ran_gaussian(float sigma);
290 string car(string s); // returns first word
291 string cdr(string s); // returns all but first word
292 float matchacl(string acl, string str); // matches str against ACL acl (with entries +foo*, +foo, +*foo, +*foo*, and same with - for forbidding)
293 float startsWith(string haystack, string needle);
294 float startsWithNocase(string haystack, string needle);
296 string get_model_datafilename(string mod, float skn, string fil); // skin -1 will return wildcard, mod string_null will also put wildcard there
297 string get_model_parameters_modelname;
298 float get_model_parameters_modelskin;
299 string get_model_parameters_name;
300 float get_model_parameters_species;
301 string get_model_parameters_sex;
302 float get_model_parameters_weight;
303 float get_model_parameters_age;
304 string get_model_parameters_description;
305 string get_model_parameters_bone_upperbody;
306 string get_model_parameters_bone_weapon;
307 const int MAX_AIM_BONES = 4;
308 string get_model_parameters_bone_aim[MAX_AIM_BONES];
309 float get_model_parameters_bone_aimweight[MAX_AIM_BONES];
310 float get_model_parameters_fixbone;
311 string get_model_parameters_desc;
312 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
314 vector vec2(vector v);
317 vector NearestPointOnBox(entity box, vector org);
320 float vercmp(string v1, string v2);
322 float u8_strsize(string s);
324 // translation helpers
325 string prvm_language;
326 string language_filename(string s);
327 string CTX(string s);
328 #define ZCTX(s) strzone(CTX(s))
330 // x-encoding (encoding as zero length invisible string)
331 // encodes approx. 14 bits into 5 bytes of color code string
332 const float XENCODE_MAX = 21295; // 2*22*22*22-1
333 const float XENCODE_LEN = 5;
334 string xencode(float f);
335 float xdecode(string s);
337 // Play all sounds via sound7, for access to the extra channels.
338 // Otherwise, channels 8 to 15 would be blocked for a weird QW feature.
339 #define sound(e,c,s,v,a) sound7(e,c,s,v,a,0,0)
341 float lowestbit(float f);
344 entity ReadCSQCEntity();
348 string strtolower(string s);
351 string MakeConsoleSafe(string input);
354 float InterpretBoolean(string input);
357 // generic shutdown handler
361 .float skeleton_bones;
362 void Skeleton_SetBones(entity e);
363 // loops through the tags of model v using counter tagnum
364 #define FOR_EACH_TAG(v) float tagnum; Skeleton_SetBones(v); for(tagnum = 0; tagnum < v.skeleton_bones; tagnum++, gettaginfo(v, tagnum))
367 void WriteApproxPastTime(float dst, float t);
370 float ReadApproxPastTime();
373 // execute-stuff-next-frame subsystem
374 void execute_next_frame();
375 void queue_to_execute_next_frame(string s);
377 // for marking written-to values as unused where it's a good idea to do this
378 noref float unused_float;
380 // a function f with:
383 // f'(0) = startspeedfactor
384 // f'(1) = endspeedfactor
385 float cubic_speedfunc(float startspeedfactor, float endspeedfactor, float x);
387 // checks whether f'(x) = 0 anywhere from 0 to 1
388 // because if this is the case, the function is not usable for platforms
389 // as it may exceed 0..1 bounds, or go in reverse
390 float cubic_speedfunc_is_sane(float startspeedfactor, float endspeedfactor);
392 typedef entity(entity cur, entity near, entity pass) findNextEntityNearFunction_t;
393 typedef float(entity a, entity b, entity pass) isConnectedFunction_t;
394 void FindConnectedComponent(entity e, .entity fld, findNextEntityNearFunction_t nxt, isConnectedFunction_t iscon, entity pass);
397 vector combine_to_vector(float x, float y, float z);
398 vector get_corner_position(entity box, float corner);
401 // expand multiple arguments into one argument by stripping parenthesis
402 #define XPD(...) __VA_ARGS__
404 // Some common varargs functions. Lowercase as they match C.
405 #define printf(...) print(sprintf(__VA_ARGS__))
406 #define dprintf(...) dprint(sprintf(__VA_ARGS__))
407 #define fprintf(file, ...) fputs(file, sprintf(__VA_ARGS__))
408 #define bprintf(...) bprint(sprintf(__VA_ARGS__))
411 void backtrace(string msg);
414 // color code replace, place inside of sprintf and parse the string... defaults described as constants
415 // foreground/normal colors
416 string autocvar_hud_colorset_foreground_1 = "2"; // F1 - Green // primary priority (important names, etc)
417 string autocvar_hud_colorset_foreground_2 = "3"; // F2 - Yellow // secondary priority (items, locations, numbers, etc)
418 string autocvar_hud_colorset_foreground_3 = "4"; // F3 - Blue // tertiary priority or relatively inconsequential text
419 string autocvar_hud_colorset_foreground_4 = "1"; // F4 - Red // notice/attention grabbing texting
421 string autocvar_hud_colorset_kill_1 = "1"; // K1 - Red // "bad" or "dangerous" text (death messages against you, kill notifications, etc)
422 string autocvar_hud_colorset_kill_2 = "3"; // K2 - Yellow // similar to above, but less important... OR, a highlight out of above message type
423 string autocvar_hud_colorset_kill_3 = "4"; // K3 - Blue // "good" or "beneficial" text (you fragging someone, etc)
425 string autocvar_hud_colorset_background = "7"; // BG - White // neutral/unimportant text
427 string CCR(string input);
431 #define GENTLE (autocvar_cl_gentle || autocvar_cl_gentle_messages)
433 #define GENTLE autocvar_sv_gentle
435 #define normal_or_gentle(normal,gentle) (GENTLE ? ((gentle != "") ? gentle : normal) : normal)
438 // allow writing to also pass through to spectators (like so spectators see the same centerprints as players for example)
439 #define WRITESPECTATABLE_MSG_ONE_VARNAME(varname,statement) entity varname; varname = msg_entity; FOR_EACH_REALCLIENT(msg_entity) if(msg_entity == varname || (msg_entity.classname == STR_SPECTATOR && msg_entity.enemy == varname)) statement msg_entity = varname
440 #define WRITESPECTATABLE_MSG_ONE(statement) WRITESPECTATABLE_MSG_ONE_VARNAME(oldmsg_entity, statement)
441 #define WRITESPECTATABLE(msg,statement) if(msg == MSG_ONE) { WRITESPECTATABLE_MSG_ONE(statement); } else statement float WRITESPECTATABLE_workaround = 0
443 vector vec3(float x, float y, float z);
446 vector animfixfps(entity e, vector a, vector b);
450 void dedicated_print(string input);
453 // todo: better way to do this?
455 #define PROGNAME "MENUQC"
458 #define PROGNAME "SVQC"
460 #define PROGNAME "CSQC"
465 const float CNT_NORMAL = 1;
466 const float CNT_GAMESTART = 2;
467 const float CNT_IDLE = 3;
468 const float CNT_KILL = 4;
469 const float CNT_RESPAWN = 5;
470 const float CNT_ROUNDSTART = 6;
471 float Announcer_PickNumber(float type, float num);
475 int Mod_Q1BSP_SuperContentsFromNativeContents(int nativecontents);
476 int Mod_Q1BSP_NativeContentsFromSuperContents(int supercontents);
479 // Quadratic splines (bezier)
480 vector bezier_quadratic_getpoint(vector a, vector p, vector b, float t);
481 vector bezier_quadratic_getderivative(vector a, vector p, vector b, float t);
483 #define APPEND_TO_STRING(list,sep,add) ((list) = (((list) != "") ? strcat(list, sep, add) : (add)))
485 // Returns the correct difference between two always increasing numbers
486 #define COMPARE_INCREASING(to,from) (to < from ? from + to + 2 : to - from)