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/all.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;
34 entity eliminatedPlayers;
35 void EliminatedPlayers_Init(float(entity) isEliminated_func);
37 string admin_name(void);
39 void write_recordmarker(entity pl, float tstart, float dt);
41 void play2all(string samp);
43 void DistributeEvenly_Init(float amount, float totalweight);
44 float DistributeEvenly_Get(float weight);
46 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);
48 void shockwave_spawn(string m, vector org, float sz, float t1, float t2);
50 void play2team(float t, string filename);
52 void GetCvars_handleFloat(string thisname, float f, .float field, string name);
54 float spamsound(entity e, float chan, string samp, float vol, float _atten);
56 void GetCvars_handleString(string thisname, float f, .string field, string name);
58 void precache_all_playermodels(string pattern);
60 void soundat(entity e, vector o, float chan, string samp, float vol, float _atten);
62 void InitializeEntitiesRun();
64 void stopsoundto(float _dest, entity e, float chan);
65 void soundtoat(float _dest, entity e, vector o, float chan, string samp, float vol, float _atten);
66 float ExponentialFalloff(float mindist, float maxdist, float halflifedist, float d);
68 vector shotorg_adjust(vector vecs, float y_is_right, float visual);
70 float DistributeEvenly_amount;
71 float DistributeEvenly_totalweight;
72 void objerror(string s);
76 void attach_sameorigin(entity e, entity to, string tag);
78 void crosshair_trace(entity pl);
80 void crosshair_trace_plusvisibletriggers(entity pl);
82 void detach_sameorigin(entity e);
84 void follow_sameorigin(entity e, entity to);
86 string formatmessage(string msg);
88 void GameLogEcho(string s);
94 void GetCvars(float f);
98 float isPushable(entity e);
100 float LostMovetypeFollow(entity ent);
102 string uid2name(string myuid);
104 float MoveToRandomLocationWithinBounds(entity e, vector boundmin, vector boundmax, float goodcontents, float badcontents, float badsurfaceflags, float attempts, float maxaboveground, float minviewdistance);
106 float MoveToRandomMapLocation(entity e, float goodcontents, float badcontents, float badsurfaceflags, float attempts, float maxaboveground, float minviewdistance);
108 string NearestLocation(vector p);
110 void play2(entity e, string filename);
112 string playername(entity p);
116 void remove_safely(entity e);
118 void remove_unsafely(entity e);
120 void SetMovetypeFollow(entity ent, entity e);
122 vector shotorg_adjust_values(vector vecs, float y_is_right, float visual, float algn);
124 void soundto(float dest, entity e, float chan, string samp, float vol, float atten);
126 void stopsound(entity e, float chan);
128 float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma);
130 void traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag);
132 void WarpZone_crosshair_trace(entity pl);
134 void WarpZone_traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag);
137 #define ITEM_TOUCH_NEEDKILL() (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY))
138 #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))
140 #define PROJECTILE_TOUCH if(WarpZone_Projectile_Touch()) return
142 const string STR_PLAYER = "player";
143 const string STR_SPECTATOR = "spectator";
144 const string STR_OBSERVER = "observer";
146 #define IS_PLAYER(v) (v.classname == STR_PLAYER)
147 #define IS_SPEC(v) (v.classname == STR_SPECTATOR)
148 #define IS_OBSERVER(v) (v.classname == STR_OBSERVER)
149 #define IS_CLIENT(v) (v.flags & FL_CLIENT)
150 #define IS_BOT_CLIENT(v) (clienttype(v) == CLIENTTYPE_BOT)
151 #define IS_REAL_CLIENT(v) (clienttype(v) == CLIENTTYPE_REAL)
152 #define IS_NOT_A_CLIENT(v) (clienttype(v) == CLIENTTYPE_NOTACLIENT)
154 #define IS_MONSTER(v) (v.flags & FL_MONSTER)
155 #define IS_VEHICLE(v) (v.vehicle_flags & VHF_ISVEHICLE)
156 #define IS_TURRET(v) (v.turret_flags & TUR_FLAG_ISTURRET)
158 #define FOR_EACH_CLIENTSLOT(v) for(v = world; (v = nextent(v)) && (num_for_edict(v) <= maxclients); )
159 #define FOR_EACH_CLIENT(v) FOR_EACH_CLIENTSLOT(v) if(IS_CLIENT(v))
160 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(IS_REAL_CLIENT(v))
162 #define FOR_EACH_PLAYER(v) FOR_EACH_CLIENT(v) if(IS_PLAYER(v))
163 #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
164 #define FOR_EACH_REALPLAYER(v) FOR_EACH_REALCLIENT(v) if(IS_PLAYER(v))
166 #define FOR_EACH_MONSTER(v) for(v = world; (v = findflags(v, flags, FL_MONSTER)) != world; )
168 #define CENTER_OR_VIEWOFS(ent) (ent.origin + (IS_PLAYER(ent) ? ent.view_ofs : ((ent.mins + ent.maxs) * 0.5)))
170 // copies a string to a tempstring (so one can strunzone it)
171 string strcat1(string s) = #115; // FRIK_FILE
176 #define strstr strstrofs
178 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
179 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
180 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
181 // BE CONSTANT OR strzoneD!
182 float strstr(string haystack, string needle, float offset)
186 len = strlen(needle);
187 endpos = strlen(haystack) - len;
188 while(offset <= endpos)
190 found = substring(haystack, offset, len);
199 const float NUM_NEAREST_ENTITIES = 4;
200 entity nearest_entity[NUM_NEAREST_ENTITIES];
201 float nearest_length[NUM_NEAREST_ENTITIES];
204 //#NO AUTOCVARS START
206 float g_pickup_shells;
207 float g_pickup_shells_max;
208 float g_pickup_nails;
209 float g_pickup_nails_max;
210 float g_pickup_rockets;
211 float g_pickup_rockets_max;
212 float g_pickup_cells;
213 float g_pickup_cells_max;
214 float g_pickup_plasma;
215 float g_pickup_plasma_max;
217 float g_pickup_fuel_jetpack;
218 float g_pickup_fuel_max;
219 float g_pickup_armorsmall;
220 float g_pickup_armorsmall_max;
221 float g_pickup_armorsmall_anyway;
222 float g_pickup_armormedium;
223 float g_pickup_armormedium_max;
224 float g_pickup_armormedium_anyway;
225 float g_pickup_armorbig;
226 float g_pickup_armorbig_max;
227 float g_pickup_armorbig_anyway;
228 float g_pickup_armorlarge;
229 float g_pickup_armorlarge_max;
230 float g_pickup_armorlarge_anyway;
231 float g_pickup_healthsmall;
232 float g_pickup_healthsmall_max;
233 float g_pickup_healthsmall_anyway;
234 float g_pickup_healthmedium;
235 float g_pickup_healthmedium_max;
236 float g_pickup_healthmedium_anyway;
237 float g_pickup_healthlarge;
238 float g_pickup_healthlarge_max;
239 float g_pickup_healthlarge_anyway;
240 float g_pickup_healthmega;
241 float g_pickup_healthmega_max;
242 float g_pickup_healthmega_anyway;
243 float g_pickup_ammo_anyway;
244 float g_pickup_weapons_anyway;
246 WepSet g_weaponarena_weapons;
247 float g_weaponarena_random;
248 float g_weaponarena_random_with_blaster;
249 string g_weaponarena_list;
250 float g_weaponspeedfactor;
251 float g_weaponratefactor;
252 float g_weapondamagefactor;
253 float g_weaponforcefactor;
254 float g_weaponspreadfactor;
256 WepSet start_weapons;
257 WepSet start_weapons_default;
258 WepSet start_weapons_defaultmask;
260 float start_ammo_shells;
261 float start_ammo_nails;
262 float start_ammo_rockets;
263 float start_ammo_cells;
264 float start_ammo_plasma;
265 float start_ammo_fuel;
267 float start_armorvalue;
268 WepSet warmup_start_weapons;
269 WepSet warmup_start_weapons_default;
270 WepSet warmup_start_weapons_defaultmask;
271 #define WARMUP_START_WEAPONS ((g_warmup_allguns == 1) ? (warmup_start_weapons & (weaponsInMap | start_weapons)) : warmup_start_weapons)
272 float warmup_start_ammo_shells;
273 float warmup_start_ammo_nails;
274 float warmup_start_ammo_rockets;
275 float warmup_start_ammo_cells;
276 float warmup_start_ammo_plasma;
277 float warmup_start_ammo_fuel;
278 float warmup_start_health;
279 float warmup_start_armorvalue;
282 float want_weapon(entity weaponinfo, float allguns); // WEAPONTODO: what still needs done?
283 void readplayerstartcvars();
286 float g_bugrigs_planar_movement;
287 float g_bugrigs_planar_movement_car_jumping;
288 float g_bugrigs_reverse_spinning;
289 float g_bugrigs_reverse_speeding;
290 float g_bugrigs_reverse_stopping;
291 float g_bugrigs_air_steering;
292 float g_bugrigs_angle_smoothing;
293 float g_bugrigs_friction_floor;
294 float g_bugrigs_friction_brake;
295 float g_bugrigs_friction_air;
296 float g_bugrigs_accel;
297 float g_bugrigs_speed_ref;
298 float g_bugrigs_speed_pow;
299 float g_bugrigs_steer;
304 string GetGametype(); // g_world.qc
305 void readlevelcvars(void)
307 if(cvar("sv_allow_fullbright"))
308 serverflags |= SERVERFLAG_ALLOW_FULLBRIGHT;
310 g_bugrigs = cvar("g_bugrigs");
311 g_bugrigs_planar_movement = cvar("g_bugrigs_planar_movement");
312 g_bugrigs_planar_movement_car_jumping = cvar("g_bugrigs_planar_movement_car_jumping");
313 g_bugrigs_reverse_spinning = cvar("g_bugrigs_reverse_spinning");
314 g_bugrigs_reverse_speeding = cvar("g_bugrigs_reverse_speeding");
315 g_bugrigs_reverse_stopping = cvar("g_bugrigs_reverse_stopping");
316 g_bugrigs_air_steering = cvar("g_bugrigs_air_steering");
317 g_bugrigs_angle_smoothing = cvar("g_bugrigs_angle_smoothing");
318 g_bugrigs_friction_floor = cvar("g_bugrigs_friction_floor");
319 g_bugrigs_friction_brake = cvar("g_bugrigs_friction_brake");
320 g_bugrigs_friction_air = cvar("g_bugrigs_friction_air");
321 g_bugrigs_accel = cvar("g_bugrigs_accel");
322 g_bugrigs_speed_ref = cvar("g_bugrigs_speed_ref");
323 g_bugrigs_speed_pow = cvar("g_bugrigs_speed_pow");
324 g_bugrigs_steer = cvar("g_bugrigs_steer");
326 g_instagib = cvar("g_instagib");
328 sv_clones = cvar("sv_clones");
329 sv_foginterval = cvar("sv_foginterval");
330 g_cloaked = cvar("g_cloaked");
331 g_footsteps = cvar("g_footsteps");
332 g_jetpack = cvar("g_jetpack");
333 sv_maxidle = cvar("sv_maxidle");
334 sv_maxidle_spectatorsareidle = cvar("sv_maxidle_spectatorsareidle");
335 sv_autotaunt = cvar("sv_autotaunt");
336 sv_taunt = cvar("sv_taunt");
338 warmup_stage = cvar("g_warmup");
339 g_warmup_limit = cvar("g_warmup_limit");
340 g_warmup_allguns = cvar("g_warmup_allguns");
341 g_warmup_allow_timeout = cvar("g_warmup_allow_timeout");
343 if ((g_race && g_race_qualifying == 2) || g_assault || cvar("g_campaign"))
344 warmup_stage = 0; // these modes cannot work together, sorry
346 g_pickup_respawntime_weapon = cvar("g_pickup_respawntime_weapon");
347 g_pickup_respawntime_superweapon = cvar("g_pickup_respawntime_superweapon");
348 g_pickup_respawntime_ammo = cvar("g_pickup_respawntime_ammo");
349 g_pickup_respawntime_short = cvar("g_pickup_respawntime_short");
350 g_pickup_respawntime_medium = cvar("g_pickup_respawntime_medium");
351 g_pickup_respawntime_long = cvar("g_pickup_respawntime_long");
352 g_pickup_respawntime_powerup = cvar("g_pickup_respawntime_powerup");
353 g_pickup_respawntimejitter_weapon = cvar("g_pickup_respawntimejitter_weapon");
354 g_pickup_respawntimejitter_superweapon = cvar("g_pickup_respawntimejitter_superweapon");
355 g_pickup_respawntimejitter_ammo = cvar("g_pickup_respawntimejitter_ammo");
356 g_pickup_respawntimejitter_short = cvar("g_pickup_respawntimejitter_short");
357 g_pickup_respawntimejitter_medium = cvar("g_pickup_respawntimejitter_medium");
358 g_pickup_respawntimejitter_long = cvar("g_pickup_respawntimejitter_long");
359 g_pickup_respawntimejitter_powerup = cvar("g_pickup_respawntimejitter_powerup");
361 g_weaponspeedfactor = cvar("g_weaponspeedfactor");
362 g_weaponratefactor = cvar("g_weaponratefactor");
363 g_weapondamagefactor = cvar("g_weapondamagefactor");
364 g_weaponforcefactor = cvar("g_weaponforcefactor");
365 g_weaponspreadfactor = cvar("g_weaponspreadfactor");
367 g_pickup_shells = cvar("g_pickup_shells");
368 g_pickup_shells_max = cvar("g_pickup_shells_max");
369 g_pickup_nails = cvar("g_pickup_nails");
370 g_pickup_nails_max = cvar("g_pickup_nails_max");
371 g_pickup_rockets = cvar("g_pickup_rockets");
372 g_pickup_rockets_max = cvar("g_pickup_rockets_max");
373 g_pickup_cells = cvar("g_pickup_cells");
374 g_pickup_cells_max = cvar("g_pickup_cells_max");
375 g_pickup_plasma = cvar("g_pickup_plasma");
376 g_pickup_plasma_max = cvar("g_pickup_plasma_max");
377 g_pickup_fuel = cvar("g_pickup_fuel");
378 g_pickup_fuel_jetpack = cvar("g_pickup_fuel_jetpack");
379 g_pickup_fuel_max = cvar("g_pickup_fuel_max");
380 g_pickup_armorsmall = cvar("g_pickup_armorsmall");
381 g_pickup_armorsmall_max = cvar("g_pickup_armorsmall_max");
382 g_pickup_armorsmall_anyway = cvar("g_pickup_armorsmall_anyway");
383 g_pickup_armormedium = cvar("g_pickup_armormedium");
384 g_pickup_armormedium_max = cvar("g_pickup_armormedium_max");
385 g_pickup_armormedium_anyway = cvar("g_pickup_armormedium_anyway");
386 g_pickup_armorbig = cvar("g_pickup_armorbig");
387 g_pickup_armorbig_max = cvar("g_pickup_armorbig_max");
388 g_pickup_armorbig_anyway = cvar("g_pickup_armorbig_anyway");
389 g_pickup_armorlarge = cvar("g_pickup_armorlarge");
390 g_pickup_armorlarge_max = cvar("g_pickup_armorlarge_max");
391 g_pickup_armorlarge_anyway = cvar("g_pickup_armorlarge_anyway");
392 g_pickup_healthsmall = cvar("g_pickup_healthsmall");
393 g_pickup_healthsmall_max = cvar("g_pickup_healthsmall_max");
394 g_pickup_healthsmall_anyway = cvar("g_pickup_healthsmall_anyway");
395 g_pickup_healthmedium = cvar("g_pickup_healthmedium");
396 g_pickup_healthmedium_max = cvar("g_pickup_healthmedium_max");
397 g_pickup_healthmedium_anyway = cvar("g_pickup_healthmedium_anyway");
398 g_pickup_healthlarge = cvar("g_pickup_healthlarge");
399 g_pickup_healthlarge_max = cvar("g_pickup_healthlarge_max");
400 g_pickup_healthlarge_anyway = cvar("g_pickup_healthlarge_anyway");
401 g_pickup_healthmega = cvar("g_pickup_healthmega");
402 g_pickup_healthmega_max = cvar("g_pickup_healthmega_max");
403 g_pickup_healthmega_anyway = cvar("g_pickup_healthmega_anyway");
405 g_pickup_ammo_anyway = cvar("g_pickup_ammo_anyway");
406 g_pickup_weapons_anyway = cvar("g_pickup_weapons_anyway");
408 g_weapon_stay = cvar(strcat("g_", GetGametype(), "_weapon_stay"));
410 g_weapon_stay = cvar("g_weapon_stay");
413 game_starttime = time + cvar("g_start_delay");
415 for(int i = WEP_FIRST; i <= WEP_LAST; ++i) {
416 Weapon w = get_weaponinfo(i);
420 readplayerstartcvars();
427 //string precache_sound (string s) = #19;
429 float precache_sound_index (string s) = #19;
431 const float SND_VOLUME = 1;
432 const float SND_ATTENUATION = 2;
433 const float SND_LARGEENTITY = 8;
434 const float SND_LARGESOUND = 16;
436 const float INITPRIO_FIRST = 0;
437 const float INITPRIO_GAMETYPE = 0;
438 const float INITPRIO_GAMETYPE_FALLBACK = 1;
439 const float INITPRIO_FINDTARGET = 10;
440 const float INITPRIO_DROPTOFLOOR = 20;
441 const float INITPRIO_SETLOCATION = 90;
442 const float INITPRIO_LINKDOORS = 91;
443 const float INITPRIO_LAST = 99;
445 .void(void) initialize_entity;
446 .float initialize_entity_order;
447 .entity initialize_entity_next;
448 entity initialize_entity_first;
454 float sound_allowed(float dest, entity e);
455 void InitializeEntity(entity e, void(void) func, float order);
456 void SetCustomizer(entity e, float(void) customizer, void(void) uncustomizer);