]> de.git.xonotic.org Git - voretournament/voretournament.git/blob - data/qcsrc/common/util.qh
Get VoreTournament code to compile with gmqcc. To be compiled with the same parameter...
[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 #ifndef GMQCC\r
115 #define FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(x) void reference_##x() { x = x; }\r
116 #else\r
117 #define FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(x)\r
118 #endif\r
119 \r
120 float almost_equals(float a, float b);\r
121 float almost_in_bounds(float a, float b, float c);\r
122 \r
123 float power2of(float e);\r
124 float log2of(float x);\r
125 \r
126 string HEXDIGITS = "0123456789ABCDEF0123456789abcdef";\r
127 #define HEXDIGIT_TO_DEC_RAW(d) (strstrofs(HEXDIGITS, (d), 0))\r
128 #define HEXDIGIT_TO_DEC(d) ((HEXDIGIT_TO_DEC_RAW(d) | 0x10) - 0x10)\r
129 #define DEC_TO_HEXDIGIT(d) (substring(HEXDIGITS, (d), 1))\r
130 \r
131 vector rgb_to_hsl(vector rgb);\r
132 vector hsl_to_rgb(vector hsl);\r
133 vector rgb_to_hsv(vector rgb);\r
134 vector hsv_to_rgb(vector hsv);\r
135 string rgb_to_hexcolor(vector rgb);\r
136 \r
137 float boxesoverlap(vector m1, vector m2, vector m3, vector m4);\r
138 float boxinsidebox(vector smins, vector smaxs, vector bmins, vector bmaxs);\r
139 \r
140 typedef float(string s, vector size) textLengthUpToWidth_widthFunction_t;\r
141 typedef float(string s) textLengthUpToLength_lenFunction_t;\r
142 float textLengthUpToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw);\r
143 string textShortenToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw);\r
144 float textLengthUpToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw);\r
145 string textShortenToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw);\r
146 \r
147 string getWrappedLine_remaining;\r
148 string getWrappedLine(float w, vector size, textLengthUpToWidth_widthFunction_t tw);\r
149 string getWrappedLineLen(float w, textLengthUpToLength_lenFunction_t tw);\r
150 \r
151 float isGametypeInFilter(float gt, float tp, string pattern);\r
152 \r
153 typedef void(float i1, float i2, entity pass) swapfunc_t; // is only ever called for i1 < i2\r
154 typedef float(float i1, float i2, entity pass) comparefunc_t; // <0 for <, ==0 for ==, >0 for > (like strcmp)\r
155 void shuffle(float n, swapfunc_t swap, entity pass);\r
156 void heapsort(float n, swapfunc_t swap, comparefunc_t cmp, entity pass);\r
157 \r
158 string swapwords(string str, float i, float j);\r
159 string shufflewords(string str);\r
160 \r
161 string substring_range(string s, float b, float e);\r
162 \r
163 vector solve_quadratic(float a, float b, float c);\r
164 // solution 1 -> x\r
165 // solution 2 -> y\r
166 // z = 1 if a real solution exists, 0 if not\r
167 // 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
168 \r
169 void check_unacceptable_compiler_bugs();\r
170 \r
171 float compressShotOrigin(vector v);\r
172 vector decompressShotOrigin(float f);\r
173 \r
174 string rankings_reply, lsmaps_reply, lsnewmaps_reply, maplist_reply; // cached replies\r
175 string records_reply[10];\r
176 \r
177 float RandomSelection_totalweight;\r
178 float RandomSelection_best_priority;\r
179 entity RandomSelection_chosen_ent;\r
180 float RandomSelection_chosen_float;\r
181 string RandomSelection_chosen_string;\r
182 void RandomSelection_Init();\r
183 void RandomSelection_Add(entity e, float f, string s, float weight, float priority);\r
184 \r
185 vector healtharmor_maxdamage(float h, float a, float armorblock); // returns vector: maxdamage, armorideal, 1 if fully armored\r
186 vector healtharmor_applydamage(float a, float armorblock, float damage); // returns vector: take, save, 0\r
187 \r
188 string getcurrentmod();\r
189 \r
190 #ifndef MENUQC\r
191 #ifdef CSQC\r
192 float ReadInt24_t();\r
193 #else\r
194 void WriteInt24_t(float dest, float val);\r
195 #endif\r
196 #endif\r
197 \r
198 // the NULL function\r
199 #ifdef GMQCC\r
200 #define null nil\r
201 #define func_null nil\r
202 #define string_null nil\r
203 #else\r
204 #define null SUB_null\r
205 var void func_null(void);\r
206 var string string_null;\r
207 #endif\r
208 float float2range11(float f);\r
209 float float2range01(float f);\r
210 \r
211 float gsl_ran_gaussian(float sigma);\r
212 \r
213 string car(string s); // returns first word\r
214 string cdr(string s); // returns all but first word\r
215 float matchacl(string acl, string str); // matches str against ACL acl (with entries +foo*, +foo, +*foo, +*foo*, and same with - for forbidding)\r
216 float startsWith(string haystack, string needle);\r
217 float startsWithNocase(string haystack, string needle);\r