]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/util.qh
Merge branch 'master' into Mario/stats_eloranking
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / util.qh
1 #pragma once
2
3 #ifdef SVQC
4         #include <server/autocvars.qh>
5 #endif
6
7 #ifdef SVQC
8 float tracebox_inverted (vector v1, vector mi, vector ma, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity); // returns the number of traces done, for benchmarking
9
10 void traceline_inverted (vector v1, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity);
11 #endif
12
13 #ifdef GAMEQC
14 /*
15 ==================
16 findbetterlocation
17
18 Returns a point at least 12 units away from walls
19 (useful for explosion animations, although the blast is performed where it really happened)
20 Ripped from DPMod
21 ==================
22 */
23 vector findbetterlocation (vector org, float mindist);
24
25 vector real_origin(entity ent);
26 #endif
27
28 #ifdef SVQC
29 // temporary array used to dump weapon and turret settings
30 const int MAX_CONFIG_SETTINGS = 256;
31 string config_queue[MAX_CONFIG_SETTINGS];
32 #endif
33
34 .string netname;
35 .string message;
36
37 IntrusiveList g_saved_cvars;
38 STATIC_INIT(g_saved_cvars) { g_saved_cvars = IL_NEW(); }
39
40 // 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
41 // NOTE: s IS allowed to be a tempstring
42 string wordwrap(string s, float l);
43 #ifdef SVQC
44 void wordwrap_sprint(entity to, string s, float l);
45 #endif
46 void wordwrap_cb(string s, float l, void(string) callback);
47
48 #ifndef SVQC
49 string draw_currentSkin;
50 string draw_UseSkinFor(string pic);
51 #endif
52
53 // iterative depth-first search, with fields that go "up", "down left" and "right" in a tree
54 // for each element, funcPre is called first, then funcPre and funcPost for all its children, and funcPost last
55 void depthfirst(entity start, .entity up, .entity downleft, .entity right, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass);
56
57 #define TIME_TO_NTHS(t,n) floor((t) * (n) + 0.5)
58
59 const int TIME_DECIMALS = 2;
60 const float TIME_FACTOR = 100;
61 #define TIME_ENCODED_TOSTRING(n) mmssss(n)
62 #define RACE_RECORD "/race100record/"
63 #define CTS_RECORD "/cts100record/"
64 #define CTF_RECORD "/ctf100record/"
65 #define TIME_ENCODE(t) TIME_TO_NTHS(t, TIME_FACTOR)
66 #define TIME_DECODE(n) ((n) / TIME_FACTOR)
67
68 #ifdef GAMEQC
69 string ScoreString(float vflags, float value);
70 #endif
71
72 vector decompressShortVector(float data);
73 float compressShortVector(vector vec);
74
75 #ifdef GAMEQC
76 float CheckWireframeBox(entity forent, vector v0, vector dvx, vector dvy, vector dvz);
77 #endif
78
79 string fixPriorityList(string pl, float from, float to, float subtract, float complete);
80 string mapPriorityList(string order, string(string) mapfunc);
81 string swapInPriorityList(string order, float i, float j);
82
83 float cvar_settemp(string pKey, string pValue);
84 float cvar_settemp_restore();
85
86 #ifdef GAMEQC
87 // modes: 0 = trust q3map2 (_mini images)
88 //        1 = trust tracebox (_radar images)
89 // in both modes, mapinfo's "size" overrides
90
91 string mi_shortname;
92 vector mi_min;
93 vector mi_max;
94 void get_mi_min_max(float mode);
95
96 vector mi_picmin; // adjusted mins that map to the picture (square)
97 vector mi_picmax; // adjusted maxs that map to the picture (square)
98 vector mi_pictexcoord0; // texcoords of the image corners (after transforming, these are 2D coords too)
99 vector mi_pictexcoord1; // texcoords of the image corners (after transforming, these are 2D coords too)
100 vector mi_pictexcoord2; // texcoords of the image corners (after transforming, these are 2D coords too)
101 vector mi_pictexcoord3; // texcoords of the image corners (after transforming, these are 2D coords too)
102 void get_mi_min_max_texcoords(float mode);
103 #endif
104
105 USING(textLengthUpToWidth_widthFunction_t, float(string s, vector size));
106 USING(textLengthUpToLength_lenFunction_t, float(string s));
107 float textLengthUpToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw);
108 string textShortenToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw);
109 float textLengthUpToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw);
110 string textShortenToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw);
111
112 string getWrappedLine_remaining;
113 string getWrappedLine(float w, vector size, textLengthUpToWidth_widthFunction_t tw);
114 string getWrappedLineLen(float w, textLengthUpToLength_lenFunction_t tw);
115
116 float isGametypeInFilter(entity gt, float tp, float ts, string pattern);
117
118 vector solve_shotdirection(vector myorg, vector myvel, vector eorg, vector evel, float spd, float newton_style);
119 vector get_shotvelocity(vector myvel, vector mydir, float spd, float newton_style, float mi, float ma);
120
121 float compressShotOrigin(vector v);
122 vector decompressShotOrigin(float f);
123
124 #ifdef SVQC
125 string rankings_reply, ladder_reply, lsmaps_reply, maplist_reply, monsterlist_reply; // cached replies
126 string records_reply[10];
127 #endif
128
129 #ifdef GAMEQC
130 vector healtharmor_maxdamage(float h, float a, float armorblock, int deathtype); // returns vector: maxdamage, armorideal, 1 if fully armored
131 vector healtharmor_applydamage(float a, float armorblock, int deathtype, float damage); // returns vector: take, save, 0
132 #endif
133
134 string getcurrentmod();
135
136 float matchacl(string acl, string str); // matches str against ACL acl (with entries +foo*, +foo, +*foo, +*foo*, and same with - for forbidding)
137
138 string get_model_datafilename(string mod, float skn, string fil); // skin -1 will return wildcard, mod string_null will also put wildcard there
139 string get_model_parameters_modelname;
140 float get_model_parameters_modelskin;
141 string get_model_parameters_name;
142 float get_model_parameters_species;
143 string get_model_parameters_sex;
144 float get_model_parameters_weight;
145 float get_model_parameters_age;
146 bool get_model_parameters_hidden;
147 string get_model_parameters_description;
148 string get_model_parameters_bone_upperbody;
149 string get_model_parameters_bone_weapon;
150 const int MAX_AIM_BONES = 4;
151 string get_model_parameters_bone_aim[MAX_AIM_BONES];
152 float get_model_parameters_bone_aimweight[MAX_AIM_BONES];
153 float get_model_parameters_fixbone;
154 string get_model_parameters_desc;
155 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
156
157 // x-encoding (encoding as zero length invisible string)
158 // encodes approx. 14 bits into 5 bytes of color code string
159 const float XENCODE_MAX = 21295; // 2*22*22*22-1
160 const float XENCODE_LEN = 5;
161 string xencode(float f);
162 float xdecode(string s);
163
164 #ifdef GAMEQC
165 string strtolower(string s);
166 #endif
167
168 // generic shutdown handler
169 void Shutdown();
170
171 #ifdef GAMEQC
172 .float skeleton_bones;
173 void Skeleton_SetBones(entity e);
174 // loops through the tags of model v using counter tagnum
175 #define FOR_EACH_TAG(v) float tagnum; Skeleton_SetBones(v); for(tagnum = 0; tagnum < v.skeleton_bones; tagnum++, gettaginfo(v, tagnum))
176 #endif
177
178 // execute-stuff-next-frame subsystem
179 void execute_next_frame();
180 void queue_to_execute_next_frame(string s);
181
182 USING(findNextEntityNearFunction_t, entity(entity cur, entity near, entity pass));
183 USING(isConnectedFunction_t, float(entity a, entity b, entity pass));
184 void FindConnectedComponent(entity e, .entity fld, findNextEntityNearFunction_t nxt, isConnectedFunction_t iscon, entity pass);
185
186 // expand multiple arguments into one argument by stripping parenthesis
187 #define XPD(...) __VA_ARGS__
188
189 // Some common varargs functions. Lowercase as they match C.
190 #define fprintf(file, ...) fputs(file, sprintf(__VA_ARGS__))
191 #define bprintf(...) bprint(sprintf(__VA_ARGS__))
192
193 #ifdef GAMEQC
194         #ifdef CSQC
195                 #define GENTLE (autocvar_cl_gentle || autocvar_cl_gentle_messages)
196         #else
197                 #define GENTLE autocvar_sv_gentle
198         #endif
199         #define normal_or_gentle(normal, gentle) (GENTLE ? ((gentle != "") ? gentle : normal) : normal)
200 #endif
201
202 #ifdef GAMEQC
203 vector animfixfps(entity e, vector a, vector b);
204 #endif
205
206 #ifdef GAMEQC
207 const int CNT_NORMAL = 1;
208 const int CNT_GAMESTART = 2;
209 const int CNT_IDLE = 3;
210 const int CNT_KILL = 4;
211 const int CNT_RESPAWN = 5;
212 const int CNT_ROUNDSTART = 6;
213 entity Announcer_PickNumber(int type, int num);
214 #endif
215
216 #ifdef GAMEQC
217 int Mod_Q1BSP_SuperContentsFromNativeContents(int nativecontents);
218 int Mod_Q1BSP_NativeContentsFromSuperContents(int supercontents);
219 #endif
220
221 #define APPEND_TO_STRING(list,sep,add) ((list) = (((list) != "") ? strcat(list, sep, add) : (add)))
222
223 // Returns the correct difference between two always increasing numbers
224 #define COMPARE_INCREASING(to,from) (to < from ? from + to + 2 : to - from)