]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/util.qh
Merge branch 'martin-t/seta' into 'master'
[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 settings for each weapon / turret
30 const int MAX_CONFIG_SETTINGS = 70;
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 void write_String_To_File(int fh, string str, bool alsoprint);
139
140 string get_model_datafilename(string mod, float skn, string fil); // skin -1 will return wildcard, mod string_null will also put wildcard there
141 string get_model_parameters_modelname;
142 float get_model_parameters_modelskin;
143 string get_model_parameters_name;
144 float get_model_parameters_species;
145 string get_model_parameters_sex;
146 float get_model_parameters_weight;
147 float get_model_parameters_age;
148 bool get_model_parameters_hidden;
149 string get_model_parameters_description;
150 string get_model_parameters_bone_upperbody;
151 string get_model_parameters_bone_weapon;
152 const int MAX_AIM_BONES = 4;
153 string get_model_parameters_bone_aim[MAX_AIM_BONES];
154 float get_model_parameters_bone_aimweight[MAX_AIM_BONES];
155 float get_model_parameters_fixbone;
156 string get_model_parameters_desc;
157 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
158
159 ERASEABLE
160 string translate_key(string key);
161
162 // x-encoding (encoding as zero length invisible string)
163 // encodes approx. 14 bits into 5 bytes of color code string
164 const float XENCODE_MAX = 21295; // 2*22*22*22-1
165 const float XENCODE_LEN = 5;
166 string xencode(float f);
167 float xdecode(string s);
168
169 #ifdef GAMEQC
170 string strtolower(string s);
171 #endif
172
173 // generic shutdown handler
174 void Shutdown();
175
176 #ifdef GAMEQC
177 .float skeleton_bones;
178 void Skeleton_SetBones(entity e);
179 // loops through the tags of model v using counter tagnum
180 #define FOR_EACH_TAG(v) float tagnum; Skeleton_SetBones(v); for(tagnum = 0; tagnum < v.skeleton_bones; tagnum++, gettaginfo(v, tagnum))
181 #endif
182
183 // execute-stuff-next-frame subsystem
184 void execute_next_frame();
185 void queue_to_execute_next_frame(string s);
186
187 USING(findNextEntityNearFunction_t, entity(entity cur, entity near, entity pass));
188 USING(isConnectedFunction_t, float(entity a, entity b, entity pass));
189 void FindConnectedComponent(entity e, .entity fld, findNextEntityNearFunction_t nxt, isConnectedFunction_t iscon, entity pass);
190
191 // expand multiple arguments into one argument by stripping parenthesis
192 #define XPD(...) __VA_ARGS__
193
194 // Some common varargs functions. Lowercase as they match C.
195 #define fprintf(file, ...) fputs(file, sprintf(__VA_ARGS__))
196 #define bprintf(...) bprint(sprintf(__VA_ARGS__))
197
198 #ifdef GAMEQC
199         #ifdef CSQC
200                 #define GENTLE (autocvar_cl_gentle || autocvar_cl_gentle_messages)
201         #else
202                 #define GENTLE autocvar_sv_gentle
203         #endif
204         #define normal_or_gentle(normal, gentle) ((GENTLE && (gentle != "")) ? gentle : normal)
205 #endif
206
207 #ifdef GAMEQC
208 vector animfixfps(entity e, vector a, vector b);
209 #endif
210
211 #ifdef GAMEQC
212 const int CNT_NORMAL = 1;
213 const int CNT_GAMESTART = 2;
214 const int CNT_IDLE = 3;
215 const int CNT_KILL = 4;
216 const int CNT_RESPAWN = 5;
217 const int CNT_ROUNDSTART = 6;
218 entity Announcer_PickNumber(int type, int num);
219 #endif
220
221 #ifdef GAMEQC
222 int Mod_Q1BSP_SuperContentsFromNativeContents(int nativecontents);
223 int Mod_Q1BSP_NativeContentsFromSuperContents(int supercontents);
224 #endif
225
226 #define APPEND_TO_STRING(list,sep,add) ((list) = (((list) != "") ? strcat(list, sep, add) : (add)))
227
228 // Returns the correct difference between two always increasing numbers
229 #define COMPARE_INCREASING(to,from) (to < from ? from + to + 2 : to - from)