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