]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/miscfunctions.qh
4cc3bc3de955482fb70b40988b8a7c586ab463c4
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / miscfunctions.qh
1 #pragma once
2
3 #include <common/t_items.qh>
4
5 #include "mutators/events.qh"
6
7 #include <common/constants.qh>
8 #include <common/mapinfo.qh>
9 #include <common/turrets/all.qh>
10
11 #ifdef RELEASE
12 #define cvar_string_normal builtin_cvar_string
13 #define cvar_normal builtin_cvar
14 #else
15 string cvar_string_normal(string n)
16 {
17         if (!(cvar_type(n) & CVAR_TYPEFLAG_EXISTS))
18                 backtrace(strcat("Attempt to access undefined cvar: ", n));
19         return builtin_cvar_string(n);
20 }
21
22 float cvar_normal(string n)
23 {
24         return stof(cvar_string_normal(n));
25 }
26 #endif
27 #define cvar_set_normal builtin_cvar_set
28
29 .vector dropped_origin;
30 .float nottargeted;
31
32 entity eliminatedPlayers;
33 void EliminatedPlayers_Init(float(entity) isEliminated_func);
34
35 void write_recordmarker(entity pl, float tstart, float dt);
36
37 void play2all(string samp);
38
39 void play2team(float t, string filename);
40
41 void GetCvars_handleFloat(entity this, string thisname, float f, .float field, string name);
42
43 float spamsound(entity e, float chan, string samp, float vol, float _atten);
44
45 void GetCvars_handleString(entity this, string thisname, float f, .string field, string name);
46
47 void precache_all_playermodels(string pattern);
48
49 void soundat(entity e, vector o, float chan, string samp, float vol, float _atten);
50
51 void InitializeEntitiesRun();
52
53 void stopsoundto(float _dest, entity e, float chan);
54 void soundtoat(float _dest, entity e, vector o, float chan, string samp, float vol, float _atten);
55
56 void droptofloor(entity this);
57
58 void attach_sameorigin(entity e, entity to, string tag);
59
60 void crosshair_trace(entity pl);
61
62 void crosshair_trace_plusvisibletriggers(entity pl);
63
64 void detach_sameorigin(entity e);
65
66 void follow_sameorigin(entity e, entity to);
67
68 string formatmessage(entity this, string msg);
69
70 void GameLogEcho(string s);
71
72 void GameLogInit();
73
74 void GameLogClose();
75
76 void GetCvars(entity this, float f);
77
78 string GetMapname();
79
80 float isPushable(entity e);
81
82 float LostMovetypeFollow(entity ent);
83
84 string uid2name(string myuid);
85
86 float MoveToRandomLocationWithinBounds(entity e, vector boundmin, vector boundmax, float goodcontents, float badcontents, float badsurfaceflags, float attempts, float maxaboveground, float minviewdistance);
87
88 float MoveToRandomMapLocation(entity e, float goodcontents, float badcontents, float badsurfaceflags, float attempts, float maxaboveground, float minviewdistance);
89
90 string NearestLocation(vector p);
91
92 void play2(entity e, string filename);
93
94 string playername(entity p, bool team_colorize);
95
96 void precache();
97
98 void remove_safely(entity e);
99
100 void remove_unsafely(entity e);
101
102 void SetMovetypeFollow(entity ent, entity e);
103
104 void soundto(float dest, entity e, float chan, string samp, float vol, float atten);
105
106 void stopsound(entity e, float chan);
107
108 float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma);
109
110 void traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag);
111
112 void WarpZone_crosshair_trace(entity pl);
113
114 void WarpZone_traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag);
115
116 #define IS_DEAD(s) ((s).deadflag != DEAD_NO)
117
118
119 #define ITEM_TOUCH_NEEDKILL() (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY))
120 #define ITEM_DAMAGE_NEEDKILL(dt) (((dt) == DEATH_HURTTRIGGER.m_id) || ((dt) == DEATH_SLIME.m_id) || ((dt) == DEATH_LAVA.m_id) || ((dt) == DEATH_SWAMP.m_id))
121
122 #define PROJECTILE_TOUCH(e,t) MACRO_BEGIN if (WarpZone_Projectile_Touch(e,t)) return; MACRO_END
123
124 #define CENTER_OR_VIEWOFS(ent) (ent.origin + (IS_PLAYER(ent) ? ent.view_ofs : ((ent.mins + ent.maxs) * 0.5)))
125
126 // copies a string to a tempstring (so one can strunzone it)
127 string strcat1(string s) = #115; // FRIK_FILE
128
129 float logfile_open;
130 float logfile;
131
132 /*
133 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
134 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
135 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
136 // BE CONSTANT OR strzoneD!
137 float strstrofs(string haystack, string needle, float offset)
138 {
139         float len, endpos;
140         string found;
141         len = strlen(needle);
142         endpos = strlen(haystack) - len;
143         while(offset <= endpos)
144         {
145                 found = substring(haystack, offset, len);
146                 if(found == needle)
147                         return offset;
148                 offset = offset + 1;
149         }
150         return -1;
151 }
152 */
153
154 const float NUM_NEAREST_ENTITIES = 4;
155 entity nearest_entity[NUM_NEAREST_ENTITIES];
156 float nearest_length[NUM_NEAREST_ENTITIES];
157
158
159 //#NO AUTOCVARS START
160
161 float g_pickup_shells_max;
162 float g_pickup_nails_max;
163 float g_pickup_rockets_max;
164 float g_pickup_cells_max;
165 float g_pickup_plasma_max;
166 float g_pickup_fuel_max;
167 float g_pickup_weapons_anyway;
168 float g_weaponarena;
169 WepSet g_weaponarena_weapons;
170 float g_weaponarena_random;
171 float g_weaponarena_random_with_blaster;
172 string g_weaponarena_list;
173 float g_weaponspeedfactor;
174 float g_weaponratefactor;
175 float g_weapondamagefactor;
176 float g_weaponforcefactor;
177 float g_weaponspreadfactor;
178
179 WepSet start_weapons;
180 WepSet start_weapons_default;
181 WepSet start_weapons_defaultmask;
182 int start_items;
183 float start_ammo_shells;
184 float start_ammo_nails;
185 float start_ammo_rockets;
186 float start_ammo_cells;
187 float start_ammo_plasma;
188 float start_ammo_fuel;
189 float start_health;
190 float start_armorvalue;
191 WepSet warmup_start_weapons;
192 WepSet warmup_start_weapons_default;
193 WepSet warmup_start_weapons_defaultmask;
194 #define WARMUP_START_WEAPONS ((g_warmup_allguns == 1) ? (warmup_start_weapons & (weaponsInMap | start_weapons)) : warmup_start_weapons)
195 float warmup_start_ammo_shells;
196 float warmup_start_ammo_nails;
197 float warmup_start_ammo_rockets;
198 float warmup_start_ammo_cells;
199 float warmup_start_ammo_plasma;
200 float warmup_start_ammo_fuel;
201 float warmup_start_health;
202 float warmup_start_armorvalue;
203 float g_weapon_stay;
204
205 float want_weapon(entity weaponinfo, float allguns); // WEAPONTODO: what still needs done?
206 void readplayerstartcvars();
207
208 float sv_autotaunt;
209 float sv_taunt;
210
211 string GetGametype(); // g_world.qc
212 void readlevelcvars()
213 {
214         if(cvar("sv_allow_fullbright"))
215                 serverflags |= SERVERFLAG_ALLOW_FULLBRIGHT;
216
217         g_instagib = cvar("g_instagib");
218
219         sv_clones = cvar("sv_clones");
220         sv_foginterval = cvar("sv_foginterval");
221         g_footsteps = cvar("g_footsteps");
222         g_jetpack = cvar("g_jetpack");
223         sv_maxidle = cvar("sv_maxidle");
224         sv_maxidle_spectatorsareidle = cvar("sv_maxidle_spectatorsareidle");
225         sv_maxidle_slots = cvar("sv_maxidle_slots");
226         sv_maxidle_slots_countbots = cvar("sv_maxidle_slots_countbots");
227         sv_autotaunt = cvar("sv_autotaunt");
228         sv_taunt = cvar("sv_taunt");
229
230         warmup_stage = cvar("g_warmup");
231         warmup_limit = cvar("g_warmup_limit");
232         g_warmup_allguns = cvar("g_warmup_allguns");
233         g_warmup_allow_timeout = cvar("g_warmup_allow_timeout");
234
235         if(cvar("g_campaign"))
236                 warmup_stage = 0; // no warmup during campaign
237
238         g_pickup_respawntime_weapon = cvar("g_pickup_respawntime_weapon");
239         g_pickup_respawntime_superweapon = cvar("g_pickup_respawntime_superweapon");
240         g_pickup_respawntime_ammo = cvar("g_pickup_respawntime_ammo");
241         g_pickup_respawntime_short = cvar("g_pickup_respawntime_short");
242         g_pickup_respawntime_medium = cvar("g_pickup_respawntime_medium");
243         g_pickup_respawntime_long = cvar("g_pickup_respawntime_long");
244         g_pickup_respawntime_powerup = cvar("g_pickup_respawntime_powerup");
245         g_pickup_respawntimejitter_weapon = cvar("g_pickup_respawntimejitter_weapon");
246         g_pickup_respawntimejitter_superweapon = cvar("g_pickup_respawntimejitter_superweapon");
247         g_pickup_respawntimejitter_ammo = cvar("g_pickup_respawntimejitter_ammo");
248         g_pickup_respawntimejitter_short = cvar("g_pickup_respawntimejitter_short");
249         g_pickup_respawntimejitter_medium = cvar("g_pickup_respawntimejitter_medium");
250         g_pickup_respawntimejitter_long = cvar("g_pickup_respawntimejitter_long");
251         g_pickup_respawntimejitter_powerup = cvar("g_pickup_respawntimejitter_powerup");
252
253         g_weaponspeedfactor = cvar("g_weaponspeedfactor");
254         g_weaponratefactor = cvar("g_weaponratefactor");
255         g_weapondamagefactor = cvar("g_weapondamagefactor");
256         g_weaponforcefactor = cvar("g_weaponforcefactor");
257         g_weaponspreadfactor = cvar("g_weaponspreadfactor");
258
259         g_pickup_shells = cvar("g_pickup_shells");
260         g_pickup_shells_max = cvar("g_pickup_shells_max");
261         g_pickup_nails = cvar("g_pickup_nails");
262         g_pickup_nails_max = cvar("g_pickup_nails_max");
263         g_pickup_rockets = cvar("g_pickup_rockets");
264         g_pickup_rockets_max = cvar("g_pickup_rockets_max");
265         g_pickup_cells = cvar("g_pickup_cells");
266         g_pickup_cells_max = cvar("g_pickup_cells_max");
267         g_pickup_plasma = cvar("g_pickup_plasma");
268         g_pickup_plasma_max = cvar("g_pickup_plasma_max");
269         g_pickup_fuel = cvar("g_pickup_fuel");
270         g_pickup_fuel_jetpack = cvar("g_pickup_fuel_jetpack");
271         g_pickup_fuel_max = cvar("g_pickup_fuel_max");
272         g_pickup_armorsmall = cvar("g_pickup_armorsmall");
273         g_pickup_armorsmall_max = cvar("g_pickup_armorsmall_max");
274         g_pickup_armorsmall_anyway = cvar("g_pickup_armorsmall_anyway");
275         g_pickup_armormedium = cvar("g_pickup_armormedium");
276         g_pickup_armormedium_max = cvar("g_pickup_armormedium_max");
277         g_pickup_armormedium_anyway = cvar("g_pickup_armormedium_anyway");
278         g_pickup_armorbig = cvar("g_pickup_armorbig");
279         g_pickup_armorbig_max = cvar("g_pickup_armorbig_max");
280         g_pickup_armorbig_anyway = cvar("g_pickup_armorbig_anyway");
281         g_pickup_armormega = cvar("g_pickup_armormega");
282         g_pickup_armormega_max = cvar("g_pickup_armormega_max");
283         g_pickup_armormega_anyway = cvar("g_pickup_armormega_anyway");
284         g_pickup_healthsmall = cvar("g_pickup_healthsmall");
285         g_pickup_healthsmall_max = cvar("g_pickup_healthsmall_max");
286         g_pickup_healthsmall_anyway = cvar("g_pickup_healthsmall_anyway");
287         g_pickup_healthmedium = cvar("g_pickup_healthmedium");
288         g_pickup_healthmedium_max = cvar("g_pickup_healthmedium_max");
289         g_pickup_healthmedium_anyway = cvar("g_pickup_healthmedium_anyway");
290         g_pickup_healthbig = cvar("g_pickup_healthbig");
291         g_pickup_healthbig_max = cvar("g_pickup_healthbig_max");
292         g_pickup_healthbig_anyway = cvar("g_pickup_healthbig_anyway");
293         g_pickup_healthmega = cvar("g_pickup_healthmega");
294         g_pickup_healthmega_max = cvar("g_pickup_healthmega_max");
295         g_pickup_healthmega_anyway = cvar("g_pickup_healthmega_anyway");
296
297         g_pickup_ammo_anyway = cvar("g_pickup_ammo_anyway");
298         g_pickup_weapons_anyway = cvar("g_pickup_weapons_anyway");
299
300     g_weapon_stay = cvar(strcat("g_", GetGametype(), "_weapon_stay"));
301     if(!g_weapon_stay)
302         g_weapon_stay = cvar("g_weapon_stay");
303
304     MUTATOR_CALLHOOK(ReadLevelCvars);
305
306         if (!warmup_stage)
307                 game_starttime = time + cvar("g_start_delay");
308
309         FOREACH(Weapons, it != WEP_Null, LAMBDA(it.wr_init(it)));
310
311         readplayerstartcvars();
312 }
313
314 //#NO AUTOCVARS END
315
316 const float INITPRIO_FIRST                              = 0;
317 const float INITPRIO_GAMETYPE                   = 0;
318 const float INITPRIO_GAMETYPE_FALLBACK  = 1;
319 const float INITPRIO_FINDTARGET                 = 10;
320 const float INITPRIO_DROPTOFLOOR                = 20;
321 const float INITPRIO_SETLOCATION                = 90;
322 const float INITPRIO_LINKDOORS                  = 91;
323 const float INITPRIO_LAST                               = 99;
324
325 .void(entity this) initialize_entity;
326 .float initialize_entity_order;
327 .entity initialize_entity_next;
328 entity initialize_entity_first;
329
330
331
332
333
334 float sound_allowed(float dest, entity e);
335 void InitializeEntity(entity e, void(entity this) func, float order);