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