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