]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/miscfunctions.qh
f19f53fd0b3010d021308c2a29235f195097d1d1
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / miscfunctions.qh
1 #ifndef MISCFUNCTIONS_H
2 #define MISCFUNCTIONS_H
3
4 #include "t_items.qh"
5
6 #include "mutators/base.qh"
7 #include "mutators/gamemode_race.qh"
8
9 #include "../common/constants.qh"
10 #include "../common/mapinfo.qh"
11
12 #ifdef RELEASE
13 #define cvar_string_normal builtin_cvar_string
14 #define cvar_normal builtin_cvar
15 #else
16 string cvar_string_normal(string n)
17 {
18         if (!(cvar_type(n) & 1))
19                 backtrace(strcat("Attempt to access undefined cvar: ", n));
20         return builtin_cvar_string(n);
21 }
22
23 float cvar_normal(string n)
24 {
25         return stof(cvar_string_normal(n));
26 }
27 #endif
28 #define cvar_set_normal builtin_cvar_set
29
30 .vector dropped_origin;
31 .void(void) uncustomizeentityforclient;
32 .float uncustomizeentityforclient_set;
33 .float nottargeted;
34
35
36 float DistributeEvenly_amount;
37 float DistributeEvenly_totalweight;
38 var void remove(entity e);
39 void objerror(string s);
40 void droptofloor();
41 void() spawnfunc_info_player_deathmatch; // needed for the other spawnpoints
42 void() spawnpoint_use;
43 void() SUB_Remove;
44
45 void attach_sameorigin(entity e, entity to, string tag);
46
47 void crosshair_trace(entity pl);
48
49 void crosshair_trace_plusvisibletriggers(entity pl);
50
51 void detach_sameorigin(entity e);
52
53 void follow_sameorigin(entity e, entity to);
54
55 string formatmessage(string msg);
56
57 void GameLogEcho(string s);
58
59 void GameLogInit();
60
61 void GameLogClose();
62
63 void GetCvars(float f);
64
65 string GetMapname();
66
67 float isPushable(entity e);
68
69 float LostMovetypeFollow(entity ent);
70
71 float MoveToRandomMapLocation(entity e, float goodcontents, float badcontents, float badsurfaceflags, float attempts, float maxaboveground, float minviewdistance);
72
73 string NearestLocation(vector p);
74
75 void play2(entity e, string filename);
76
77 string playername(entity p);
78
79 void precache();
80
81 void remove_safely(entity e);
82
83 void remove_unsafely(entity e);
84
85 void SetMovetypeFollow(entity ent, entity e);
86
87 vector shotorg_adjust_values(vector vecs, float y_is_right, float visual, float algn);
88
89 void soundto(float dest, entity e, float chan, string samp, float vol, float atten);
90
91 void stopsound(entity e, float chan);
92
93 float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma);
94
95 void traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag);
96
97 void WarpZone_crosshair_trace(entity pl);
98
99 void WarpZone_traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag);
100
101
102 #define IFTARGETED if(!self.nottargeted && self.targetname != "")
103
104 #define ITEM_TOUCH_NEEDKILL() (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY))
105 #define ITEM_DAMAGE_NEEDKILL(dt) (((dt) == DEATH_HURTTRIGGER) || ((dt) == DEATH_SLIME) || ((dt) == DEATH_LAVA) || ((dt) == DEATH_SWAMP))
106
107 #define PROJECTILE_TOUCH if(WarpZone_Projectile_Touch()) return
108
109 #define move_out_of_solid(e) WarpZoneLib_MoveOutOfSolid(e)
110
111 const string STR_PLAYER = "player";
112 const string STR_SPECTATOR = "spectator";
113 const string STR_OBSERVER = "observer";
114
115 #define IS_PLAYER(v)                    (v.classname == STR_PLAYER)
116 #define IS_SPEC(v)                              (v.classname == STR_SPECTATOR)
117 #define IS_OBSERVER(v)                  (v.classname == STR_OBSERVER)
118 #define IS_CLIENT(v)                    (v.flags & FL_CLIENT)
119 #define IS_BOT_CLIENT(v)                (clienttype(v) == CLIENTTYPE_BOT)
120 #define IS_REAL_CLIENT(v)               (clienttype(v) == CLIENTTYPE_REAL)
121 #define IS_NOT_A_CLIENT(v)              (clienttype(v) == CLIENTTYPE_NOTACLIENT)
122
123 #define FOR_EACH_CLIENTSLOT(v) for(v = world; (v = nextent(v)) && (num_for_edict(v) <= maxclients); )
124 #define FOR_EACH_CLIENT(v) FOR_EACH_CLIENTSLOT(v) if(IS_CLIENT(v))
125 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(IS_REAL_CLIENT(v))
126
127 #define FOR_EACH_PLAYER(v) FOR_EACH_CLIENT(v) if(IS_PLAYER(v))
128 #define FOR_EACH_SPEC(v) FOR_EACH_CLIENT(v) if (!IS_PLAYER(v)) // Samual: shouldn't this be IS_SPEC(v)? and rather create a separate macro to include observers too
129 #define FOR_EACH_REALPLAYER(v) FOR_EACH_REALCLIENT(v) if(IS_PLAYER(v))
130
131 #define FOR_EACH_MONSTER(v) for(v = world; (v = findflags(v, flags, FL_MONSTER)) != world; )
132
133 #define CENTER_OR_VIEWOFS(ent) (ent.origin + (IS_PLAYER(ent) ? ent.view_ofs : ((ent.mins + ent.maxs) * 0.5)))
134
135 // copies a string to a tempstring (so one can strunzone it)
136 string strcat1(string s) = #115; // FRIK_FILE
137
138 float logfile_open;
139 float logfile;
140
141 #define strstr strstrofs
142 /*
143 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
144 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
145 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
146 // BE CONSTANT OR strzoneD!
147 float strstr(string haystack, string needle, float offset)
148 {
149         float len, endpos;
150         string found;
151         len = strlen(needle);
152         endpos = strlen(haystack) - len;
153         while(offset <= endpos)
154         {
155                 found = substring(haystack, offset, len);
156                 if(found == needle)
157                         return offset;
158                 offset = offset + 1;
159         }
160         return -1;
161 }
162 */
163
164 const float NUM_NEAREST_ENTITIES = 4;
165 entity nearest_entity[NUM_NEAREST_ENTITIES];
166 float nearest_length[NUM_NEAREST_ENTITIES];
167
168
169 //#NO AUTOCVARS START
170
171 float g_pickup_shells;
172 float g_pickup_shells_max;
173 float g_pickup_nails;
174 float g_pickup_nails_max;
175 float g_pickup_rockets;
176 float g_pickup_rockets_max;
177 float g_pickup_cells;
178 float g_pickup_cells_max;
179 float g_pickup_plasma;
180 float g_pickup_plasma_max;
181 float g_pickup_fuel;
182 float g_pickup_fuel_jetpack;
183 float g_pickup_fuel_max;
184 float g_pickup_armorsmall;
185 float g_pickup_armorsmall_max;
186 float g_pickup_armorsmall_anyway;
187 float g_pickup_armormedium;
188 float g_pickup_armormedium_max;
189 float g_pickup_armormedium_anyway;
190 float g_pickup_armorbig;
191 float g_pickup_armorbig_max;
192 float g_pickup_armorbig_anyway;
193 float g_pickup_armorlarge;
194 float g_pickup_armorlarge_max;
195 float g_pickup_armorlarge_anyway;
196 float g_pickup_healthsmall;
197 float g_pickup_healthsmall_max;
198 float g_pickup_healthsmall_anyway;
199 float g_pickup_healthmedium;
200 float g_pickup_healthmedium_max;
201 float g_pickup_healthmedium_anyway;
202 float g_pickup_healthlarge;
203 float g_pickup_healthlarge_max;
204 float g_pickup_healthlarge_anyway;
205 float g_pickup_healthmega;
206 float g_pickup_healthmega_max;
207 float g_pickup_healthmega_anyway;
208 float g_pickup_ammo_anyway;
209 float g_pickup_weapons_anyway;
210 float g_weaponarena;
211 WepSet g_weaponarena_weapons;
212 float g_weaponarena_random;
213 float g_weaponarena_random_with_blaster;
214 string g_weaponarena_list;
215 float g_weaponspeedfactor;
216 float g_weaponratefactor;
217 float g_weapondamagefactor;
218 float g_weaponforcefactor;
219 float g_weaponspreadfactor;
220
221 WepSet start_weapons;
222 WepSet start_weapons_default;
223 WepSet start_weapons_defaultmask;
224 int start_items;
225 float start_ammo_shells;
226 float start_ammo_nails;
227 float start_ammo_rockets;
228 float start_ammo_cells;
229 float start_ammo_plasma;
230 float start_ammo_fuel;
231 float start_health;
232 float start_armorvalue;
233 WepSet warmup_start_weapons;
234 WepSet warmup_start_weapons_default;
235 WepSet warmup_start_weapons_defaultmask;
236 #define WARMUP_START_WEAPONS ((g_warmup_allguns == 1) ? (warmup_start_weapons & (weaponsInMap | start_weapons)) : warmup_start_weapons)
237 float warmup_start_ammo_shells;
238 float warmup_start_ammo_nails;
239 float warmup_start_ammo_rockets;
240 float warmup_start_ammo_cells;
241 float warmup_start_ammo_plasma;
242 float warmup_start_ammo_fuel;
243 float warmup_start_health;
244 float warmup_start_armorvalue;
245 float g_weapon_stay;
246
247 float want_weapon(entity weaponinfo, float allguns); // WEAPONTODO: what still needs done?
248 void readplayerstartcvars();
249
250 float g_bugrigs;
251 float g_bugrigs_planar_movement;
252 float g_bugrigs_planar_movement_car_jumping;
253 float g_bugrigs_reverse_spinning;
254 float g_bugrigs_reverse_speeding;
255 float g_bugrigs_reverse_stopping;
256 float g_bugrigs_air_steering;
257 float g_bugrigs_angle_smoothing;
258 float g_bugrigs_friction_floor;
259 float g_bugrigs_friction_brake;
260 float g_bugrigs_friction_air;
261 float g_bugrigs_accel;
262 float g_bugrigs_speed_ref;
263 float g_bugrigs_speed_pow;
264 float g_bugrigs_steer;
265
266 float sv_autotaunt;
267 float sv_taunt;
268
269 string GetGametype(); // g_world.qc
270 void mutators_add(); // mutators.qc
271 void readlevelcvars(void)
272 {
273         // load mutators
274         mutators_add();
275
276         if(cvar("sv_allow_fullbright"))
277                 serverflags |= SERVERFLAG_ALLOW_FULLBRIGHT;
278
279     g_bugrigs = cvar("g_bugrigs");
280     g_bugrigs_planar_movement = cvar("g_bugrigs_planar_movement");
281     g_bugrigs_planar_movement_car_jumping = cvar("g_bugrigs_planar_movement_car_jumping");
282     g_bugrigs_reverse_spinning = cvar("g_bugrigs_reverse_spinning");
283     g_bugrigs_reverse_speeding = cvar("g_bugrigs_reverse_speeding");
284     g_bugrigs_reverse_stopping = cvar("g_bugrigs_reverse_stopping");
285     g_bugrigs_air_steering = cvar("g_bugrigs_air_steering");
286     g_bugrigs_angle_smoothing = cvar("g_bugrigs_angle_smoothing");
287     g_bugrigs_friction_floor = cvar("g_bugrigs_friction_floor");
288     g_bugrigs_friction_brake = cvar("g_bugrigs_friction_brake");
289     g_bugrigs_friction_air = cvar("g_bugrigs_friction_air");
290     g_bugrigs_accel = cvar("g_bugrigs_accel");
291     g_bugrigs_speed_ref = cvar("g_bugrigs_speed_ref");
292     g_bugrigs_speed_pow = cvar("g_bugrigs_speed_pow");
293     g_bugrigs_steer = cvar("g_bugrigs_steer");
294
295         g_instagib = cvar("g_instagib");
296
297         sv_clones = cvar("sv_clones");
298         sv_foginterval = cvar("sv_foginterval");
299         g_cloaked = cvar("g_cloaked");
300         g_footsteps = cvar("g_footsteps");
301         g_grappling_hook = cvar("g_grappling_hook");
302         g_jetpack = cvar("g_jetpack");
303         sv_maxidle = cvar("sv_maxidle");
304         sv_maxidle_spectatorsareidle = cvar("sv_maxidle_spectatorsareidle");
305         sv_autotaunt = cvar("sv_autotaunt");
306         sv_taunt = cvar("sv_taunt");
307
308         warmup_stage = cvar("g_warmup");
309         g_warmup_limit = cvar("g_warmup_limit");
310         g_warmup_allguns = cvar("g_warmup_allguns");
311         g_warmup_allow_timeout = cvar("g_warmup_allow_timeout");
312
313         if ((g_race && g_race_qualifying == 2) || g_assault || cvar("g_campaign"))
314                 warmup_stage = 0; // these modes cannot work together, sorry
315
316         g_pickup_respawntime_weapon = cvar("g_pickup_respawntime_weapon");
317         g_pickup_respawntime_superweapon = cvar("g_pickup_respawntime_superweapon");
318         g_pickup_respawntime_ammo = cvar("g_pickup_respawntime_ammo");
319         g_pickup_respawntime_short = cvar("g_pickup_respawntime_short");
320         g_pickup_respawntime_medium = cvar("g_pickup_respawntime_medium");
321         g_pickup_respawntime_long = cvar("g_pickup_respawntime_long");
322         g_pickup_respawntime_powerup = cvar("g_pickup_respawntime_powerup");
323         g_pickup_respawntimejitter_weapon = cvar("g_pickup_respawntimejitter_weapon");
324         g_pickup_respawntimejitter_superweapon = cvar("g_pickup_respawntimejitter_superweapon");
325         g_pickup_respawntimejitter_ammo = cvar("g_pickup_respawntimejitter_ammo");
326         g_pickup_respawntimejitter_short = cvar("g_pickup_respawntimejitter_short");
327         g_pickup_respawntimejitter_medium = cvar("g_pickup_respawntimejitter_medium");
328         g_pickup_respawntimejitter_long = cvar("g_pickup_respawntimejitter_long");
329         g_pickup_respawntimejitter_powerup = cvar("g_pickup_respawntimejitter_powerup");
330
331         g_weaponspeedfactor = cvar("g_weaponspeedfactor");
332         g_weaponratefactor = cvar("g_weaponratefactor");
333         g_weapondamagefactor = cvar("g_weapondamagefactor");
334         g_weaponforcefactor = cvar("g_weaponforcefactor");
335         g_weaponspreadfactor = cvar("g_weaponspreadfactor");
336
337         g_pickup_shells = cvar("g_pickup_shells");
338         g_pickup_shells_max = cvar("g_pickup_shells_max");
339         g_pickup_nails = cvar("g_pickup_nails");
340         g_pickup_nails_max = cvar("g_pickup_nails_max");
341         g_pickup_rockets = cvar("g_pickup_rockets");
342         g_pickup_rockets_max = cvar("g_pickup_rockets_max");
343         g_pickup_cells = cvar("g_pickup_cells");
344         g_pickup_cells_max = cvar("g_pickup_cells_max");
345         g_pickup_plasma = cvar("g_pickup_plasma");
346         g_pickup_plasma_max = cvar("g_pickup_plasma_max");
347         g_pickup_fuel = cvar("g_pickup_fuel");
348         g_pickup_fuel_jetpack = cvar("g_pickup_fuel_jetpack");
349         g_pickup_fuel_max = cvar("g_pickup_fuel_max");
350         g_pickup_armorsmall = cvar("g_pickup_armorsmall");
351         g_pickup_armorsmall_max = cvar("g_pickup_armorsmall_max");
352         g_pickup_armorsmall_anyway = cvar("g_pickup_armorsmall_anyway");
353         g_pickup_armormedium = cvar("g_pickup_armormedium");
354         g_pickup_armormedium_max = cvar("g_pickup_armormedium_max");
355         g_pickup_armormedium_anyway = cvar("g_pickup_armormedium_anyway");
356         g_pickup_armorbig = cvar("g_pickup_armorbig");
357         g_pickup_armorbig_max = cvar("g_pickup_armorbig_max");
358         g_pickup_armorbig_anyway = cvar("g_pickup_armorbig_anyway");
359         g_pickup_armorlarge = cvar("g_pickup_armorlarge");
360         g_pickup_armorlarge_max = cvar("g_pickup_armorlarge_max");
361         g_pickup_armorlarge_anyway = cvar("g_pickup_armorlarge_anyway");
362         g_pickup_healthsmall = cvar("g_pickup_healthsmall");
363         g_pickup_healthsmall_max = cvar("g_pickup_healthsmall_max");
364         g_pickup_healthsmall_anyway = cvar("g_pickup_healthsmall_anyway");
365         g_pickup_healthmedium = cvar("g_pickup_healthmedium");
366         g_pickup_healthmedium_max = cvar("g_pickup_healthmedium_max");
367         g_pickup_healthmedium_anyway = cvar("g_pickup_healthmedium_anyway");
368         g_pickup_healthlarge = cvar("g_pickup_healthlarge");
369         g_pickup_healthlarge_max = cvar("g_pickup_healthlarge_max");
370         g_pickup_healthlarge_anyway = cvar("g_pickup_healthlarge_anyway");
371         g_pickup_healthmega = cvar("g_pickup_healthmega");
372         g_pickup_healthmega_max = cvar("g_pickup_healthmega_max");
373         g_pickup_healthmega_anyway = cvar("g_pickup_healthmega_anyway");
374
375         g_pickup_ammo_anyway = cvar("g_pickup_ammo_anyway");
376         g_pickup_weapons_anyway = cvar("g_pickup_weapons_anyway");
377
378     g_weapon_stay = cvar(strcat("g_", GetGametype(), "_weapon_stay"));
379     if(!g_weapon_stay)
380         g_weapon_stay = cvar("g_weapon_stay");
381
382         if (!warmup_stage)
383                 game_starttime = time + cvar("g_start_delay");
384
385         for(int i = WEP_FIRST; i <= WEP_LAST; ++i)
386                 WEP_ACTION(i, WR_INIT);
387
388         readplayerstartcvars();
389 }
390
391 //#NO AUTOCVARS END
392
393
394 // Sound functions
395 //string precache_sound (string s) = #19;
396 // hack
397 float precache_sound_index (string s) = #19;
398
399 const float SND_VOLUME = 1;
400 const float SND_ATTENUATION = 2;
401 const float SND_LARGEENTITY = 8;
402 const float SND_LARGESOUND = 16;
403
404 // WARNING: this kills the trace globals
405 #define EXACTTRIGGER_TOUCH if(WarpZoneLib_ExactTrigger_Touch()) return
406 #define EXACTTRIGGER_INIT  WarpZoneLib_ExactTrigger_Init()
407
408 const float INITPRIO_FIRST                              = 0;
409 const float INITPRIO_GAMETYPE                   = 0;
410 const float INITPRIO_GAMETYPE_FALLBACK  = 1;
411 const float INITPRIO_FINDTARGET                 = 10;
412 const float INITPRIO_DROPTOFLOOR                = 20;
413 const float INITPRIO_SETLOCATION                = 90;
414 const float INITPRIO_LINKDOORS                  = 91;
415 const float INITPRIO_LAST                               = 99;
416
417 .void(void) initialize_entity;
418 .float initialize_entity_order;
419 .entity initialize_entity_next;
420 entity initialize_entity_first;
421
422
423
424
425
426 float sound_allowed(float dest, entity e);
427 void InitializeEntity(entity e, void(void) func, float order);
428 void SetCustomizer(entity e, float(void) customizer, void(void) uncustomizer);
429 void Net_LinkEntity(entity e, float docull, float dt, float(entity, float) sendfunc);
430
431 #endif