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