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