]> de.git.xonotic.org Git - voretournament/voretournament.git/blob - data/qcsrc/common/util.qh
ec704494393eebf68662fd5f5a2e287391a31884
[voretournament/voretournament.git] / data / qcsrc / common / util.qh
1 #define ACCUMULATE_FUNCTION(func,otherfunc) \\r
2         #ifdef func \\r
3         void __merge__##otherfunc() { func(); otherfunc(); } \\r
4         #undef func \\r
5         #define func __merge__##otherfunc \\r
6         #else \\r
7         #define func otherfunc \\r
8         #endif\r
9 \r
10 // 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\r
11 // NOTE: s IS allowed to be a tempstring\r
12 string wordwrap(string s, float l);\r
13 #ifndef MENUQC\r
14 #ifndef CSQC\r
15 void wordwrap_sprint(string s, float l);\r
16 #endif\r
17 #endif\r
18 void wordwrap_cb(string s, float l, void(string) callback)\r
19 \r
20 #ifndef SVQC\r
21 string draw_currentSkin;\r
22 string draw_UseSkinFor(string pic);\r
23 #endif\r
24 \r
25 float GameCommand_Generic(string cmd);\r
26 // returns TRUE if handled, FALSE otherwise\r
27 // uses tokenize on its argument!\r
28 \r
29 // iterative depth-first search, with fields that go "up", "down left" and "right" in a tree\r
30 // for each element, funcPre is called first, then funcPre and funcPost for all its children, and funcPost last\r
31 void depthfirst(entity start, .entity up, .entity downleft, .entity right, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass);\r
32 \r
33 float median(float a, float b, float c);\r
34 \r
35 // converts a number to a string with the indicated number of decimals\r
36 // works for up to 10 decimals!\r
37 string ftos_decimals(float number, float decimals);\r
38 \r
39 vector colormapPaletteColor(float c, float isPants);\r
40 \r
41 // unzone the string, and return it as tempstring. Safe to be called on string_null\r
42 string fstrunzone(string s);\r
43 \r
44 // database (NOTE: keys are case sensitive)\r
45 void db_save(float db, string filename);\r
46 void db_dump(float db, string pFilename);\r
47 float db_create();\r
48 float db_load(string filename);\r
49 void db_close(float db);\r
50 string db_get(float db, string key);\r
51 void db_put(float db, string key, string value);\r
52 \r
53 // stringbuffer loading/saving\r
54 float buf_load(string filename);\r
55 void buf_save(float buf, string filename);\r
56 \r
57 // modulo function\r
58 #ifndef MENUQC\r
59 float mod(float a, float b) { return a - (floor(a / b) * b); }   \r
60 #endif\r
61 \r
62 string GametypeNameFromType(float g);\r
63 #define TIME_TO_NTHS(t,n) floor((t) * (n) + 0.4)\r
64 string mmsss(float t);\r
65 string mmssss(float t);\r
66 \r
67 #define TIME_DECIMALS 2\r
68 #define TIME_FACTOR 100\r
69 #define TIME_ENCODED_TOSTRING(n) mmssss(n)\r
70 #define RACE_RECORD "/race100record/"\r
71 #define CTS_RECORD "/cts100record/"\r
72 #define TIME_ENCODE(t) TIME_TO_NTHS(t, TIME_FACTOR)\r
73 #define TIME_DECODE(n) ((n) / TIME_FACTOR)\r
74 \r
75 string ScoreString(float vflags, float value);\r
76 \r
77 vector cross(vector a, vector b);\r
78 \r
79 void compressShortVector_init();\r
80 vector decompressShortVector(float data);\r
81 float compressShortVector(vector vec);\r
82 \r
83 #ifndef MENUQC\r
84 float CheckWireframeBox(entity forent, vector v0, vector dvx, vector dvy, vector dvz);\r
85 #endif\r
86 \r
87 string fixPriorityList(string pl, float from, float to, float subtract, float complete);\r
88 string swapInPriorityList(string order, float i, float j);\r
89 \r
90 float cvar_value_issafe(string s);\r
91 \r
92 void cvar_settemp(string pKey, string pValue);\r
93 void cvar_settemp_restore();\r
94 \r
95 #ifndef MENUQC\r
96 // modes: 0 = trust q3map2 (_mini images)\r
97 //        1 = trust tracebox (_radar images)\r
98 // in both modes, mapinfo's "size" overrides\r
99 \r
100 string mi_shortname;\r
101 vector mi_min;\r
102 vector mi_max;\r
103 void get_mi_min_max(float mode);\r
104 \r
105 vector mi_picmin; // adjusted mins that map to the picture (square)\r
106 vector mi_picmax; // adjusted maxs that map to the picture (square)\r
107 vector mi_pictexcoord0; // texcoords of the image corners (after transforming, these are 2D coords too)\r
108 vector mi_pictexcoord1; // texcoords of the image corners (after transforming, these are 2D coords too)\r
109 vector mi_pictexcoord2; // texcoords of the image corners (after transforming, these are 2D coords too)\r
110 vector mi_pictexcoord3; // texcoords of the image corners (after transforming, these are 2D coords too)\r
111 void get_mi_min_max_texcoords(float mode);\r
112 #endif\r
113 \r
114 #define FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(x) void reference_##x() { x = x; }\r
115 \r
116 float almost_equals(float a, float b);\r
117 float almost_in_bounds(float a, float b, float c);\r
118 \r
119 float power2of(float e);\r
120 float log2of(float x);\r
121 \r
122 string HEXDIGITS = "0123456789ABCDEF0123456789abcdef";\r
123 #define HEXDIGIT_TO_DEC_RAW(d) (strstrofs(HEXDIGITS, (d), 0))\r
124 #define HEXDIGIT_TO_DEC(d) ((HEXDIGIT_TO_DEC_RAW(d) | 0x10) - 0x10)\r
125 #define DEC_TO_HEXDIGIT(d) (substring(HEXDIGITS, (d), 1))\r
126 \r
127 vector rgb_to_hsl(vector rgb);\r
128 vector hsl_to_rgb(vector hsl);\r
129 vector rgb_to_hsv(vector rgb);\r
130 vector hsv_to_rgb(vector hsv);\r
131 string rgb_to_hexcolor(vector rgb);\r
132 \r
133 float boxesoverlap(vector m1, vector m2, vector m3, vector m4);\r
134 float boxinsidebox(vector smins, vector smaxs, vector bmins, vector bmaxs);\r
135 \r
136 typedef float(string s, vector size) textLengthUpToWidth_widthFunction_t;\r
137 typedef float(string s) textLengthUpToLength_lenFunction_t;\r
138 float textLengthUpToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw);\r
139 string textShortenToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw);\r
140 float textLengthUpToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw);\r
141 string textShortenToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw);\r
142 \r
143 string getWrappedLine_remaining;\r
144 string getWrappedLine(float w, vector size, textLengthUpToWidth_widthFunction_t tw);\r
145 string getWrappedLineLen(float w, textLengthUpToLength_lenFunction_t tw);\r
146 \r
147 float isGametypeInFilter(float gt, float tp, string pattern);\r
148 \r
149 typedef void(float i1, float i2, entity pass) swapfunc_t; // is only ever called for i1 < i2\r
150 typedef float(float i1, float i2, entity pass) comparefunc_t; // <0 for <, ==0 for ==, >0 for > (like strcmp)\r
151 void shuffle(float n, swapfunc_t swap, entity pass);\r
152 void heapsort(float n, swapfunc_t swap, comparefunc_t cmp, entity pass);\r
153 \r
154 string swapwords(string str, float i, float j);\r
155 string shufflewords(string str);\r
156 \r
157 string substring_range(string s, float b, float e);\r
158 \r
159 vector solve_quadratic(float a, float b, float c);\r
160 // solution 1 -> x\r
161 // solution 2 -> y\r
162 // z = 1 if a real solution exists, 0 if not\r
163 // if no real solution exists, x contains the real part and y the imaginary part of the complex solutions x+iy and x-iy\r
164 \r
165 void check_unacceptable_compiler_bugs();\r
166 \r
167 float compressShotOrigin(vector v);\r
168 vector decompressShotOrigin(float f);\r
169 \r
170 string rankings_reply, lsmaps_reply, lsnewmaps_reply, maplist_reply; // cached replies\r
171 string records_reply[10];\r
172 \r
173 float RandomSelection_totalweight;\r
174 float RandomSelection_best_priority;\r
175 entity RandomSelection_chosen_ent;\r
176 float RandomSelection_chosen_float;\r
177 string RandomSelection_chosen_string;\r
178 void RandomSelection_Init();\r
179 void RandomSelection_Add(entity e, float f, string s, float weight, float priority);\r
180 \r
181 vector healtharmor_maxdamage(float h, float a, float armorblock); // returns vector: maxdamage, armorideal, 1 if fully armored\r
182 vector healtharmor_applydamage(float a, float armorblock, float damage); // returns vector: take, save, 0\r
183 \r
184 string getcurrentmod();\r
185 \r
186 #ifndef MENUQC\r
187 #ifdef CSQC\r
188 float ReadInt24_t();\r
189 #else\r
190 void WriteInt24_t(float dest, float val);\r
191 #endif\r
192 #endif\r
193 \r
194 // the NULL function\r
195 const var void func_null(void); FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(func_null)\r
196 const var string string_null;\r
197 float float2range11(float f);\r
198 float float2range01(float f);\r
199 \r
200 float gsl_ran_gaussian(float sigma);\r
201 \r
202 string car(string s); // returns first word\r
203 string cdr(string s); // returns all but first word\r
204 float matchacl(string acl, string str); // matches str against ACL acl (with entries +foo*, +foo, +*foo, +*foo*, and same with - for forbidding)\r
205 float startsWith(string haystack, string needle);\r
206 float startsWithNocase(string haystack, string needle);\r