1 // a dummy macro that prevents the "hanging ;" warning
2 #define ENDS_WITH_CURLY_BRACE
4 // return the actual code name of a var as a string
5 #define VAR_TO_TEXT(var) #var
7 #ifdef HAVE_YO_DAWG_CPP
8 // TODO make ascii art pic of xzibit
10 // I HERD YO LIEK MACROS
11 // SO I PUT A MACRO DEFINITION IN YO MACRO DEFINITION
12 // SO YO CAN EXPAND MACROS WHILE YO EXPAND MACROS
13 # define ACCUMULATE_FUNCTION(func,otherfunc) \
15 void __merge__##otherfunc() { func(); otherfunc(); } \
17 #define func __merge__##otherfunc \
19 #define func otherfunc \
21 # define CALL_ACCUMULATED_FUNCTION(func) \
24 # define ACCUMULATE_FUNCTION(func,otherfunc) \
25 .void _ACCUMULATE_##func##__##otherfunc;
26 void ACCUMULATE_call(string func)
29 float n = numentityfields();
30 string funcprefix = strcat("_ACCUMULATE_", func, "__");
31 float funcprefixlen = strlen(funcprefix);
32 for(i = 0; i < n; ++i)
34 string name = entityfieldname(i);
35 if(substring(name, 0, funcprefixlen) == funcprefix)
36 callfunction(substring(name, funcprefixlen, -1));
39 # define CALL_ACCUMULATED_FUNCTION(func) \
40 ACCUMULATE_call(#func)
43 // used for simplifying ACCUMULATE_FUNCTIONs
44 #define SET_FIRST_OR_LAST(input,first,count) if(!input) { input = (first + count); }
45 #define SET_FIELD_COUNT(field,first,count) if(!field) { field = (first + count); ++count; }
46 #define CHECK_MAX_COUNT(name,max,count,type) if(count == max) { error(strcat("Maximum ", type, " hit: ", VAR_TO_TEXT(name), ": ", ftos(count), ".\n")); }
48 // 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
49 // NOTE: s IS allowed to be a tempstring
50 string wordwrap(string s, float l);
53 void wordwrap_sprint(string s, float l);
56 void wordwrap_cb(string s, float l, void(string) callback);
59 string draw_currentSkin;
60 string draw_UseSkinFor(string pic);
63 // iterative depth-first search, with fields that go "up", "down left" and "right" in a tree
64 // for each element, funcPre is called first, then funcPre and funcPost for all its children, and funcPost last
65 void depthfirst(entity start, .entity up, .entity downleft, .entity right, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass);
67 float median(float a, float b, float c);
69 // converts a number to a string with the indicated number of decimals
70 // works for up to 10 decimals!
71 string ftos_decimals(float number, float decimals);
73 float fexists(string f);
75 vector colormapPaletteColor(float c, float isPants);
77 // unzone the string, and return it as tempstring. Safe to be called on string_null
78 string fstrunzone(string s);
80 // database (NOTE: keys are case sensitive)
81 void db_save(float db, string filename);
82 void db_dump(float db, string pFilename);
84 float db_load(string filename);
85 void db_close(float db);
86 string db_get(float db, string key);
87 void db_put(float db, string key, string value);
89 // stringbuffer loading/saving
90 float buf_load(string filename);
91 void buf_save(float buf, string filename);
95 float mod(float a, float b) { return a - (floor(a / b) * b); }
98 #define TIME_TO_NTHS(t,n) floor((t) * (n) + 0.4)
99 string mmsss(float t);
100 string mmssss(float t);
102 #define TIME_DECIMALS 2
103 #define TIME_FACTOR 100
104 #define TIME_ENCODED_TOSTRING(n) mmssss(n)
105 #define RACE_RECORD "/race100record/"
106 #define CTS_RECORD "/cts100record/"
107 #define TIME_ENCODE(t) TIME_TO_NTHS(t, TIME_FACTOR)
108 #define TIME_DECODE(n) ((n) / TIME_FACTOR)
110 string ScoreString(float vflags, float value);
112 float dotproduct(vector a, vector b);
113 vector cross(vector a, vector b);
115 void compressShortVector_init();
116 vector decompressShortVector(float data);
117 float compressShortVector(vector vec);
120 float CheckWireframeBox(entity forent, vector v0, vector dvx, vector dvy, vector dvz);
123 string fixPriorityList(string pl, float from, float to, float subtract, float complete);
124 string mapPriorityList(string order, string(string) mapfunc);
125 string swapInPriorityList(string order, float i, float j);
127 float cvar_value_issafe(string s);
129 float cvar_settemp(string pKey, string pValue);
130 float cvar_settemp_restore();
133 // modes: 0 = trust q3map2 (_mini images)
134 // 1 = trust tracebox (_radar images)
135 // in both modes, mapinfo's "size" overrides
140 void get_mi_min_max(float mode);
142 vector mi_picmin; // adjusted mins that map to the picture (square)
143 vector mi_picmax; // adjusted maxs that map to the picture (square)
144 vector mi_pictexcoord0; // texcoords of the image corners (after transforming, these are 2D coords too)
145 vector mi_pictexcoord1; // texcoords of the image corners (after transforming, these are 2D coords too)
146 vector mi_pictexcoord2; // texcoords of the image corners (after transforming, these are 2D coords too)
147 vector mi_pictexcoord3; // texcoords of the image corners (after transforming, these are 2D coords too)
148 void get_mi_min_max_texcoords(float mode);
151 float almost_equals(float a, float b);
152 float almost_in_bounds(float a, float b, float c);
154 float power2of(float e);
155 float log2of(float x);
157 string HEXDIGITS = "0123456789ABCDEF0123456789abcdef";
158 #define HEXDIGIT_TO_DEC_RAW(d) (strstrofs(HEXDIGITS, (d), 0))
159 #define HEXDIGIT_TO_DEC(d) ((HEXDIGIT_TO_DEC_RAW(d) | 0x10) - 0x10)
160 #define DEC_TO_HEXDIGIT(d) (substring(HEXDIGITS, (d), 1))
162 vector rgb_to_hsl(vector rgb);
163 vector hsl_to_rgb(vector hsl);
164 vector rgb_to_hsv(vector rgb);
165 vector hsv_to_rgb(vector hsv);
166 string rgb_to_hexcolor(vector rgb);
168 float boxesoverlap(vector m1, vector m2, vector m3, vector m4);
169 float boxinsidebox(vector smins, vector smaxs, vector bmins, vector bmaxs);
171 typedef float(string s, vector size) textLengthUpToWidth_widthFunction_t;
172 typedef float(string s) textLengthUpToLength_lenFunction_t;
173 float textLengthUpToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw);
174 string textShortenToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw);
175 float textLengthUpToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw);
176 string textShortenToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw);
178 string getWrappedLine_remaining;
179 string getWrappedLine(float w, vector size, textLengthUpToWidth_widthFunction_t tw);
180 string getWrappedLineLen(float w, textLengthUpToLength_lenFunction_t tw);
182 float isGametypeInFilter(float gt, float tp, float ts, string pattern);
184 typedef void(float i1, float i2, entity pass) swapfunc_t; // is only ever called for i1 < i2
185 typedef float(float i1, float i2, entity pass) comparefunc_t; // <0 for <, ==0 for ==, >0 for > (like strcmp)
186 void shuffle(float n, swapfunc_t swap, entity pass);
187 void heapsort(float n, swapfunc_t swap, comparefunc_t cmp, entity pass);
189 string swapwords(string str, float i, float j);
190 string shufflewords(string str);
192 string substring_range(string s, float b, float e);
194 vector solve_quadratic(float a, float b, float c);
197 // z = 1 if a real solution exists, 0 if not
198 // if no real solution exists, x contains the real part and y the imaginary part of the complex solutions x+iy and x-iy
200 vector solve_shotdirection(vector myorg, vector myvel, vector eorg, vector evel, float spd, float newton_style);
201 vector get_shotvelocity(vector myvel, vector mydir, float spd, float newton_style, float mi, float ma);
203 void check_unacceptable_compiler_bugs();
205 float compressShotOrigin(vector v);
206 vector decompressShotOrigin(float f);
209 string rankings_reply, ladder_reply, lsmaps_reply, lsnewmaps_reply, maplist_reply; // cached replies
210 string records_reply[10];
213 float RandomSelection_totalweight;
214 float RandomSelection_best_priority;
215 entity RandomSelection_chosen_ent;
216 float RandomSelection_chosen_float;
217 string RandomSelection_chosen_string;
218 void RandomSelection_Init();
219 void RandomSelection_Add(entity e, float f, string s, float weight, float priority);
221 vector healtharmor_maxdamage(float h, float a, float armorblock); // returns vector: maxdamage, armorideal, 1 if fully armored
222 vector healtharmor_applydamage(float a, float armorblock, float damage); // returns vector: take, save, 0
224 string getcurrentmod();
230 void WriteInt24_t(float dest, float val);
236 #define func_null nil
237 #define string_null nil
239 var void func_null(void);
240 var string string_null;
242 float float2range11(float f);
243 float float2range01(float f);
245 float gsl_ran_gaussian(float sigma);
247 string car(string s); // returns first word
248 string cdr(string s); // returns all but first word
249 float matchacl(string acl, string str); // matches str against ACL acl (with entries +foo*, +foo, +*foo, +*foo*, and same with - for forbidding)
250 float startsWith(string haystack, string needle);
251 float startsWithNocase(string haystack, string needle);
253 string get_model_datafilename(string mod, float skn, string fil); // skin -1 will return wildcard, mod string_null will also put wildcard there
254 string get_model_parameters_modelname;
255 float get_model_parameters_modelskin;
256 string get_model_parameters_name;
257 float get_model_parameters_species;
258 string get_model_parameters_sex;
259 float get_model_parameters_weight;
260 float get_model_parameters_age;
261 string get_model_parameters_bone_upperbody;
262 string get_model_parameters_bone_weapon;
263 #define MAX_AIM_BONES 4
264 string get_model_parameters_bone_aim[MAX_AIM_BONES];
265 float get_model_parameters_bone_aimweight[MAX_AIM_BONES];
266 float get_model_parameters_fixbone;
267 string get_model_parameters_desc;
268 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
270 // stupid stupid stupid FTEQCC has a max limit on macro sizes, let's work around by splitting the macro into two macros! :(
271 #define HUD_Panel_GetName_Part2(id) \
273 case HUD_PANEL_ENGINEINFO: panel_name = HUD_PANELNAME_ENGINEINFO; break; \
274 case HUD_PANEL_INFOMESSAGES: panel_name = HUD_PANELNAME_INFOMESSAGES; break; \
275 case HUD_PANEL_PHYSICS: panel_name = HUD_PANELNAME_PHYSICS; break; \
276 case HUD_PANEL_CENTERPRINT: panel_name = HUD_PANELNAME_CENTERPRINT; break; \
277 } ENDS_WITH_CURLY_BRACE
279 // Get name of specified panel id
280 #define HUD_Panel_GetName(id) \
282 case HUD_PANEL_WEAPONS: panel_name = HUD_PANELNAME_WEAPONS; break; \
283 case HUD_PANEL_AMMO: panel_name = HUD_PANELNAME_AMMO; break; \
284 case HUD_PANEL_POWERUPS: panel_name = HUD_PANELNAME_POWERUPS; break; \
285 case HUD_PANEL_HEALTHARMOR: panel_name = HUD_PANELNAME_HEALTHARMOR; break; \
286 case HUD_PANEL_NOTIFY: panel_name = HUD_PANELNAME_NOTIFY; break; \
287 case HUD_PANEL_TIMER: panel_name = HUD_PANELNAME_TIMER; break; \
288 case HUD_PANEL_RADAR: panel_name = HUD_PANELNAME_RADAR; break; \
289 case HUD_PANEL_SCORE: panel_name = HUD_PANELNAME_SCORE; break; \
290 case HUD_PANEL_RACETIMER: panel_name = HUD_PANELNAME_RACETIMER; break; \
291 case HUD_PANEL_VOTE: panel_name = HUD_PANELNAME_VOTE; break; \
292 case HUD_PANEL_MODICONS: panel_name = HUD_PANELNAME_MODICONS; break; \
293 case HUD_PANEL_PRESSEDKEYS: panel_name = HUD_PANELNAME_PRESSEDKEYS; break; \
294 case HUD_PANEL_CHAT: panel_name = HUD_PANELNAME_CHAT; break; \
295 default: HUD_Panel_GetName_Part2(id)\
298 vector vec2(vector v);
301 vector NearestPointOnBox(entity box, vector org);
304 float vercmp(string v1, string v2);
306 float u8_strsize(string s);
308 // translation helpers
309 string prvm_language;
310 string language_filename(string s);
311 string CTX(string s);
312 #define ZCTX(s) strzone(CTX(s))
314 // x-encoding (encoding as zero length invisible string)
315 // encodes approx. 14 bits into 5 bytes of color code string
316 const float XENCODE_MAX = 21295; // 2*22*22*22-1
317 const float XENCODE_LEN = 5;
318 string xencode(float f);
319 float xdecode(string s);
321 #ifndef COMPAT_XON010_CHANNELS
322 #define sound(e,c,s,v,a) sound7(e,c,s,v,a,0,0)
325 float lowestbit(float f);
328 entity ReadCSQCEntity();
332 string strtolower(string s);
335 string MakeConsoleSafe(string input);
338 float InterpretBoolean(string input);
341 // generic shutdown handler
345 .float skeleton_bones;
346 void Skeleton_SetBones(entity e);
347 // loops through the tags of model v using counter tagnum
348 #define FOR_EACH_TAG(v) float tagnum; Skeleton_SetBones(v); for(tagnum = 0; tagnum < v.skeleton_bones; tagnum++, gettaginfo(v, tagnum))
351 void WriteApproxPastTime(float dst, float t);
354 float ReadApproxPastTime();
357 // execute-stuff-next-frame subsystem
358 void execute_next_frame();
359 void queue_to_execute_next_frame(string s);
361 // for marking written-to values as unused where it's a good idea to do this
362 noref float unused_float;
364 // a function f with:
367 // f'(0) = startspeedfactor
368 // f'(1) = endspeedfactor
369 float cubic_speedfunc(float startspeedfactor, float endspeedfactor, float x);
371 // checks whether f'(x) = 0 anywhere from 0 to 1
372 // because if this is the case, the function is not usable for platforms
373 // as it may exceed 0..1 bounds, or go in reverse
374 float cubic_speedfunc_is_sane(float startspeedfactor, float endspeedfactor);
376 typedef entity(entity cur, entity near, entity pass) findNextEntityNearFunction_t;
377 typedef float(entity a, entity b, entity pass) isConnectedFunction_t;
378 void FindConnectedComponent(entity e, .entity fld, findNextEntityNearFunction_t nxt, isConnectedFunction_t iscon, entity pass);
380 // expand multiple arguments into one argument by stripping parenthesis
381 #define XPD(...) __VA_ARGS__
383 float Count_Proper_Strings(string improper, string...count);
384 float Count_Proper_Floats(float improper, float...count);
387 void backtrace(string msg);
390 // color code replace, place inside of sprintf and parse the string... defaults described as constants
391 // foreground/normal colors
392 var string autocvar_hud_colorset_foreground_1 = "2"; // F1 - Green // primary priority (important names, etc)
393 var string autocvar_hud_colorset_foreground_2 = "3"; // F2 - Yellow // secondary priority (items, locations, numbers, etc)
394 var string autocvar_hud_colorset_foreground_3 = "4"; // F3 - Blue // tertiary priority or relatively inconsequential text
395 var string autocvar_hud_colorset_foreground_4 = "1"; // F4 - Red // notice/attention grabbing texting
397 var string autocvar_hud_colorset_kill_1 = "1"; // K1 - Red // "bad" or "dangerous" text (death messages against you, kill notifications, etc)
398 var string autocvar_hud_colorset_kill_2 = "3"; // K2 - Yellow // similar to above, but less important... OR, a highlight out of above message type
399 var string autocvar_hud_colorset_kill_3 = "4"; // K3 - Blue // "good" or "beneficial" text (you fragging someone, etc)
401 var string autocvar_hud_colorset_background = "7"; // BG - White // neutral/unimportant text
403 string CCR(string input);
407 #define GENTLE (autocvar_cl_gentle || autocvar_cl_gentle_messages)
409 #define GENTLE autocvar_sv_gentle
411 #define normal_or_gentle(normal,gentle) (GENTLE ? ((gentle != "") ? gentle : normal) : normal)
414 // allow writing to also pass through to spectators (like so spectators see the same centerprints as players for example)
415 #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
416 #define WRITESPECTATABLE_MSG_ONE(statement) WRITESPECTATABLE_MSG_ONE_VARNAME(oldmsg_entity, statement)
417 #define WRITESPECTATABLE(msg,statement) if(msg == MSG_ONE) { WRITESPECTATABLE_MSG_ONE(statement); } else statement float WRITESPECTATABLE_workaround = 0
419 vector vec3(float x, float y, float z);
422 vector animfixfps(entity e, vector a, vector b);
425 #define count_minutes_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s minutes")), ftos_decimals(time, decs))
427 #define count_minutes(time) count_fill(time, \
428 ZCTX(_("CI_ZER^%d minutes")), /* zeroth */ \
429 ZCTX(_("CI_FIR^%d minute")), /* first */ \
430 ZCTX(_("CI_SEC^%d minutes")), /* minute */ \
431 ZCTX(_("CI_THI^%d minutes")), /* third */ \
432 ZCTX(_("CI_MUL^%d minutes"))) /* multi */
434 #define count_seconds_decs(time,decs) sprintf(ZCTX(_("CI_DEC^%s seconds")), ftos_decimals(time, decs))
436 #define count_seconds(time) count_fill(time, \
437 ZCTX(_("CI_ZER^%d seconds")), /* zeroth */ \
438 ZCTX(_("CI_FIR^%d second")), /* first */ \
439 ZCTX(_("CI_SEC^%d seconds")), /* second */ \
440 ZCTX(_("CI_THI^%d seconds")), /* third */ \
441 ZCTX(_("CI_MUL^%d seconds"))) /* multi */
443 string count_ordinal(float interval);
445 string count_fill(float interval, string zeroth, string first, string second, string third, string multi);
447 string process_time(string fields, float seconds);
450 void dedicated_print(string input);