1 #ifndef MISCFUNCTIONS_H
2 #define MISCFUNCTIONS_H
6 #include "mutators/events.qh"
8 #include "../common/constants.qh"
9 #include "../common/mapinfo.qh"
10 #include "../common/turrets/all.qh"
13 #define cvar_string_normal builtin_cvar_string
14 #define cvar_normal builtin_cvar
16 string cvar_string_normal(string n)
18 if (!(cvar_type(n) & CVAR_TYPEFLAG_EXISTS))
19 backtrace(strcat("Attempt to access undefined cvar: ", n));
20 return builtin_cvar_string(n);
23 float cvar_normal(string n)
25 return stof(cvar_string_normal(n));
28 #define cvar_set_normal builtin_cvar_set
30 .vector dropped_origin;
33 entity eliminatedPlayers;
34 void EliminatedPlayers_Init(float(entity) isEliminated_func);
38 void write_recordmarker(entity pl, float tstart, float dt);
40 void play2all(string samp);
42 void play2team(float t, string filename);
44 void GetCvars_handleFloat(string thisname, float f, .float field, string name);
46 float spamsound(entity e, float chan, string samp, float vol, float _atten);
48 void GetCvars_handleString(string thisname, float f, .string field, string name);
50 void precache_all_playermodels(string pattern);
52 void soundat(entity e, vector o, float chan, string samp, float vol, float _atten);
54 void InitializeEntitiesRun();
56 void stopsoundto(float _dest, entity e, float chan);
57 void soundtoat(float _dest, entity e, vector o, float chan, string samp, float vol, float _atten);
59 void objerror(string s);
63 void attach_sameorigin(entity e, entity to, string tag);
65 void crosshair_trace(entity pl);
67 void crosshair_trace_plusvisibletriggers(entity pl);
69 void detach_sameorigin(entity e);
71 void follow_sameorigin(entity e, entity to);
73 string formatmessage(string msg);
75 void GameLogEcho(string s);
81 void GetCvars(float f);
85 float isPushable(entity e);
87 float LostMovetypeFollow(entity ent);
89 string uid2name(string myuid);
91 float MoveToRandomLocationWithinBounds(entity e, vector boundmin, vector boundmax, float goodcontents, float badcontents, float badsurfaceflags, float attempts, float maxaboveground, float minviewdistance);
93 float MoveToRandomMapLocation(entity e, float goodcontents, float badcontents, float badsurfaceflags, float attempts, float maxaboveground, float minviewdistance);
95 string NearestLocation(vector p);
97 void play2(entity e, string filename);
99 string playername(entity p);
103 void remove_safely(entity e);
105 void remove_unsafely(entity e);
107 void SetMovetypeFollow(entity ent, entity e);
109 void soundto(float dest, entity e, float chan, string samp, float vol, float atten);
111 void stopsound(entity e, float chan);
113 float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma);
115 void traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag);
117 void WarpZone_crosshair_trace(entity pl);
119 void WarpZone_traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag);
122 #define ITEM_TOUCH_NEEDKILL() (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY))
123 #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))
125 #define PROJECTILE_TOUCH if(WarpZone_Projectile_Touch()) return
127 const string STR_PLAYER = "player";
128 const string STR_SPECTATOR = "spectator";
129 const string STR_OBSERVER = "observer";
131 #define IS_PLAYER(v) ((v).classname == STR_PLAYER)
132 #define IS_SPEC(v) ((v).classname == STR_SPECTATOR)
133 #define IS_OBSERVER(v) ((v).classname == STR_OBSERVER)
134 #define IS_CLIENT(v) (v.flags & FL_CLIENT)
135 #define IS_BOT_CLIENT(v) (clienttype(v) == CLIENTTYPE_BOT)
136 #define IS_REAL_CLIENT(v) (clienttype(v) == CLIENTTYPE_REAL)
137 #define IS_NOT_A_CLIENT(v) (clienttype(v) == CLIENTTYPE_NOTACLIENT)
139 #define IS_MONSTER(v) (v.flags & FL_MONSTER)
140 #define IS_VEHICLE(v) (v.vehicle_flags & VHF_ISVEHICLE)
141 #define IS_TURRET(v) (v.turret_flags & TUR_FLAG_ISTURRET)
143 #define FOR_EACH_CLIENTSLOT(v) for(v = world; (v = nextent(v)) && (num_for_edict(v) <= maxclients); )
144 #define FOR_EACH_CLIENT(v) FOR_EACH_CLIENTSLOT(v) if(IS_CLIENT(v))
145 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(IS_REAL_CLIENT(v))
147 #define FOR_EACH_PLAYER(v) FOR_EACH_CLIENT(v) if(IS_PLAYER(v))
148 #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
149 #define FOR_EACH_REALPLAYER(v) FOR_EACH_REALCLIENT(v) if(IS_PLAYER(v))
151 #define FOR_EACH_MONSTER(v) for(v = world; (v = findflags(v, flags, FL_MONSTER)) != world; )
153 #define CENTER_OR_VIEWOFS(ent) (ent.origin + (IS_PLAYER(ent) ? ent.view_ofs : ((ent.mins + ent.maxs) * 0.5)))
155 // copies a string to a tempstring (so one can strunzone it)
156 string strcat1(string s) = #115; // FRIK_FILE
161 #define strstr strstrofs
163 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
164 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
165 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
166 // BE CONSTANT OR strzoneD!
167 float strstr(string haystack, string needle, float offset)
171 len = strlen(needle);
172 endpos = strlen(haystack) - len;
173 while(offset <= endpos)
175 found = substring(haystack, offset, len);
184 const float NUM_NEAREST_ENTITIES = 4;
185 entity nearest_entity[NUM_NEAREST_ENTITIES];
186 float nearest_length[NUM_NEAREST_ENTITIES];
189 //#NO AUTOCVARS START
191 float g_pickup_shells;
192 float g_pickup_shells_max;
193 float g_pickup_nails;
194 float g_pickup_nails_max;
195 float g_pickup_rockets;
196 float g_pickup_rockets_max;
197 float g_pickup_cells;
198 float g_pickup_cells_max;
199 float g_pickup_plasma;
200 float g_pickup_plasma_max;
202 float g_pickup_fuel_jetpack;
203 float g_pickup_fuel_max;
204 float g_pickup_armorsmall;
205 float g_pickup_armorsmall_max;
206 float g_pickup_armorsmall_anyway;
207 float g_pickup_armormedium;
208 float g_pickup_armormedium_max;
209 float g_pickup_armormedium_anyway;
210 float g_pickup_armorbig;
211 float g_pickup_armorbig_max;
212 float g_pickup_armorbig_anyway;
213 float g_pickup_armorlarge;
214 float g_pickup_armorlarge_max;
215 float g_pickup_armorlarge_anyway;
216 float g_pickup_healthsmall;
217 float g_pickup_healthsmall_max;
218 float g_pickup_healthsmall_anyway;
219 float g_pickup_healthmedium;
220 float g_pickup_healthmedium_max;
221 float g_pickup_healthmedium_anyway;
222 float g_pickup_healthlarge;
223 float g_pickup_healthlarge_max;
224 float g_pickup_healthlarge_anyway;
225 float g_pickup_healthmega;
226 float g_pickup_healthmega_max;
227 float g_pickup_healthmega_anyway;
228 float g_pickup_ammo_anyway;
229 float g_pickup_weapons_anyway;
231 WepSet g_weaponarena_weapons;
232 float g_weaponarena_random;
233 float g_weaponarena_random_with_blaster;
234 string g_weaponarena_list;
235 float g_weaponspeedfactor;
236 float g_weaponratefactor;
237 float g_weapondamagefactor;
238 float g_weaponforcefactor;
239 float g_weaponspreadfactor;
241 WepSet start_weapons;
242 WepSet start_weapons_default;
243 WepSet start_weapons_defaultmask;
245 float start_ammo_shells;
246 float start_ammo_nails;
247 float start_ammo_rockets;
248 float start_ammo_cells;
249 float start_ammo_plasma;
250 float start_ammo_fuel;
252 float start_armorvalue;
253 WepSet warmup_start_weapons;
254 WepSet warmup_start_weapons_default;
255 WepSet warmup_start_weapons_defaultmask;
256 #define WARMUP_START_WEAPONS ((g_warmup_allguns == 1) ? (warmup_start_weapons & (weaponsInMap | start_weapons)) : warmup_start_weapons)
257 float warmup_start_ammo_shells;
258 float warmup_start_ammo_nails;
259 float warmup_start_ammo_rockets;
260 float warmup_start_ammo_cells;
261 float warmup_start_ammo_plasma;
262 float warmup_start_ammo_fuel;
263 float warmup_start_health;
264 float warmup_start_armorvalue;
267 float want_weapon(entity weaponinfo, float allguns); // WEAPONTODO: what still needs done?
268 void readplayerstartcvars();
271 float g_bugrigs_planar_movement;
272 float g_bugrigs_planar_movement_car_jumping;
273 float g_bugrigs_reverse_spinning;
274 float g_bugrigs_reverse_speeding;
275 float g_bugrigs_reverse_stopping;
276 float g_bugrigs_air_steering;
277 float g_bugrigs_angle_smoothing;
278 float g_bugrigs_friction_floor;
279 float g_bugrigs_friction_brake;
280 float g_bugrigs_friction_air;
281 float g_bugrigs_accel;
282 float g_bugrigs_speed_ref;
283 float g_bugrigs_speed_pow;
284 float g_bugrigs_steer;
289 string GetGametype(); // g_world.qc
290 void readlevelcvars()
292 if(cvar("sv_allow_fullbright"))
293 serverflags |= SERVERFLAG_ALLOW_FULLBRIGHT;
295 g_bugrigs = cvar("g_bugrigs");
296 g_bugrigs_planar_movement = cvar("g_bugrigs_planar_movement");
297 g_bugrigs_planar_movement_car_jumping = cvar("g_bugrigs_planar_movement_car_jumping");
298 g_bugrigs_reverse_spinning = cvar("g_bugrigs_reverse_spinning");
299 g_bugrigs_reverse_speeding = cvar("g_bugrigs_reverse_speeding");
300 g_bugrigs_reverse_stopping = cvar("g_bugrigs_reverse_stopping");
301 g_bugrigs_air_steering = cvar("g_bugrigs_air_steering");
302 g_bugrigs_angle_smoothing = cvar("g_bugrigs_angle_smoothing");
303 g_bugrigs_friction_floor = cvar("g_bugrigs_friction_floor");
304 g_bugrigs_friction_brake = cvar("g_bugrigs_friction_brake");
305 g_bugrigs_friction_air = cvar("g_bugrigs_friction_air");
306 g_bugrigs_accel = cvar("g_bugrigs_accel");
307 g_bugrigs_speed_ref = cvar("g_bugrigs_speed_ref");
308 g_bugrigs_speed_pow = cvar("g_bugrigs_speed_pow");
309 g_bugrigs_steer = cvar("g_bugrigs_steer");
311 g_instagib = cvar("g_instagib");
313 sv_clones = cvar("sv_clones");
314 sv_foginterval = cvar("sv_foginterval");
315 g_footsteps = cvar("g_footsteps");
316 g_jetpack = cvar("g_jetpack");
317 sv_maxidle = cvar("sv_maxidle");
318 sv_maxidle_spectatorsareidle = cvar("sv_maxidle_spectatorsareidle");
319 sv_autotaunt = cvar("sv_autotaunt");
320 sv_taunt = cvar("sv_taunt");
322 warmup_stage = cvar("g_warmup");
323 g_warmup_limit = cvar("g_warmup_limit");
324 g_warmup_allguns = cvar("g_warmup_allguns");
325 g_warmup_allow_timeout = cvar("g_warmup_allow_timeout");
327 if(cvar("g_campaign"))
328 warmup_stage = 0; // no warmup during campaign
330 g_pickup_respawntime_weapon = cvar("g_pickup_respawntime_weapon");
331 g_pickup_respawntime_superweapon = cvar("g_pickup_respawntime_superweapon");
332 g_pickup_respawntime_ammo = cvar("g_pickup_respawntime_ammo");
333 g_pickup_respawntime_short = cvar("g_pickup_respawntime_short");
334 g_pickup_respawntime_medium = cvar("g_pickup_respawntime_medium");
335 g_pickup_respawntime_long = cvar("g_pickup_respawntime_long");
336 g_pickup_respawntime_powerup = cvar("g_pickup_respawntime_powerup");
337 g_pickup_respawntimejitter_weapon = cvar("g_pickup_respawntimejitter_weapon");
338 g_pickup_respawntimejitter_superweapon = cvar("g_pickup_respawntimejitter_superweapon");
339 g_pickup_respawntimejitter_ammo = cvar("g_pickup_respawntimejitter_ammo");
340 g_pickup_respawntimejitter_short = cvar("g_pickup_respawntimejitter_short");
341 g_pickup_respawntimejitter_medium = cvar("g_pickup_respawntimejitter_medium");
342 g_pickup_respawntimejitter_long = cvar("g_pickup_respawntimejitter_long");
343 g_pickup_respawntimejitter_powerup = cvar("g_pickup_respawntimejitter_powerup");
345 g_weaponspeedfactor = cvar("g_weaponspeedfactor");
346 g_weaponratefactor = cvar("g_weaponratefactor");
347 g_weapondamagefactor = cvar("g_weapondamagefactor");
348 g_weaponforcefactor = cvar("g_weaponforcefactor");
349 g_weaponspreadfactor = cvar("g_weaponspreadfactor");
351 g_pickup_shells = cvar("g_pickup_shells");
352 g_pickup_shells_max = cvar("g_pickup_shells_max");
353 g_pickup_nails = cvar("g_pickup_nails");
354 g_pickup_nails_max = cvar("g_pickup_nails_max");
355 g_pickup_rockets = cvar("g_pickup_rockets");
356 g_pickup_rockets_max = cvar("g_pickup_rockets_max");
357 g_pickup_cells = cvar("g_pickup_cells");
358 g_pickup_cells_max = cvar("g_pickup_cells_max");
359 g_pickup_plasma = cvar("g_pickup_plasma");
360 g_pickup_plasma_max = cvar("g_pickup_plasma_max");
361 g_pickup_fuel = cvar("g_pickup_fuel");
362 g_pickup_fuel_jetpack = cvar("g_pickup_fuel_jetpack");
363 g_pickup_fuel_max = cvar("g_pickup_fuel_max");
364 g_pickup_armorsmall = cvar("g_pickup_armorsmall");
365 g_pickup_armorsmall_max = cvar("g_pickup_armorsmall_max");
366 g_pickup_armorsmall_anyway = cvar("g_pickup_armorsmall_anyway");
367 g_pickup_armormedium = cvar("g_pickup_armormedium");
368 g_pickup_armormedium_max = cvar("g_pickup_armormedium_max");
369 g_pickup_armormedium_anyway = cvar("g_pickup_armormedium_anyway");
370 g_pickup_armorbig = cvar("g_pickup_armorbig");
371 g_pickup_armorbig_max = cvar("g_pickup_armorbig_max");
372 g_pickup_armorbig_anyway = cvar("g_pickup_armorbig_anyway");
373 g_pickup_armorlarge = cvar("g_pickup_armorlarge");
374 g_pickup_armorlarge_max = cvar("g_pickup_armorlarge_max");
375 g_pickup_armorlarge_anyway = cvar("g_pickup_armorlarge_anyway");
376 g_pickup_healthsmall = cvar("g_pickup_healthsmall");
377 g_pickup_healthsmall_max = cvar("g_pickup_healthsmall_max");
378 g_pickup_healthsmall_anyway = cvar("g_pickup_healthsmall_anyway");
379 g_pickup_healthmedium = cvar("g_pickup_healthmedium");
380 g_pickup_healthmedium_max = cvar("g_pickup_healthmedium_max");
381 g_pickup_healthmedium_anyway = cvar("g_pickup_healthmedium_anyway");
382 g_pickup_healthlarge = cvar("g_pickup_healthlarge");
383 g_pickup_healthlarge_max = cvar("g_pickup_healthlarge_max");
384 g_pickup_healthlarge_anyway = cvar("g_pickup_healthlarge_anyway");
385 g_pickup_healthmega = cvar("g_pickup_healthmega");
386 g_pickup_healthmega_max = cvar("g_pickup_healthmega_max");
387 g_pickup_healthmega_anyway = cvar("g_pickup_healthmega_anyway");
389 g_pickup_ammo_anyway = cvar("g_pickup_ammo_anyway");
390 g_pickup_weapons_anyway = cvar("g_pickup_weapons_anyway");
392 g_weapon_stay = cvar(strcat("g_", GetGametype(), "_weapon_stay"));
394 g_weapon_stay = cvar("g_weapon_stay");
396 MUTATOR_CALLHOOK(ReadLevelCvars);
399 game_starttime = time + cvar("g_start_delay");
401 for(int i = WEP_FIRST; i <= WEP_LAST; ++i) {
402 Weapon w = get_weaponinfo(i);
406 readplayerstartcvars();
413 //string precache_sound (string s) = #19;
415 float precache_sound_index (string s) = #19;
417 const float SND_VOLUME = BIT(0);
418 const float SND_ATTENUATION = BIT(1);
419 const float SND_LARGEENTITY = BIT(3);
420 const float SND_LARGESOUND = BIT(4);
422 const float INITPRIO_FIRST = 0;
423 const float INITPRIO_GAMETYPE = 0;
424 const float INITPRIO_GAMETYPE_FALLBACK = 1;
425 const float INITPRIO_FINDTARGET = 10;
426 const float INITPRIO_DROPTOFLOOR = 20;
427 const float INITPRIO_SETLOCATION = 90;
428 const float INITPRIO_LINKDOORS = 91;
429 const float INITPRIO_LAST = 99;
431 .void() initialize_entity;
432 .float initialize_entity_order;
433 .entity initialize_entity_next;
434 entity initialize_entity_first;
440 float sound_allowed(float dest, entity e);
441 void InitializeEntity(entity e, void() func, float order);
442 void SetCustomizer(entity e, float() customizer, void() uncustomizer);