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