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