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