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