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