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