]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/miscfunctions.qh
Hopefully fix remote compilation
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / miscfunctions.qh
index d20cb168fa39dd00c6e5f22e004094d7102a4e0d..634d3fb647185594e04001b18c1b1790ecf17942 100644 (file)
@@ -1,13 +1,12 @@
-#ifndef MISCFUNCTIONS_H
-#define MISCFUNCTIONS_H
+#pragma once
 
-#include "t_items.qh"
+#include <common/t_items.qh>
 
-#include "mutators/base.qh"
-#include "mutators/gamemode_race.qh"
+#include "mutators/events.qh"
 
-#include "../common/constants.qh"
-#include "../common/mapinfo.qh"
+#include <common/constants.qh>
+#include <common/mapinfo.qh>
+#include <common/turrets/all.qh>
 
 #ifdef RELEASE
 #define cvar_string_normal builtin_cvar_string
@@ -15,7 +14,7 @@
 #else
 string cvar_string_normal(string n)
 {
-       if (!(cvar_type(n) & 1))
+       if (!(cvar_type(n) & CVAR_TYPEFLAG_EXISTS))
                backtrace(strcat("Attempt to access undefined cvar: ", n));
        return builtin_cvar_string(n);
 }
@@ -28,19 +27,36 @@ float cvar_normal(string n)
 #define cvar_set_normal builtin_cvar_set
 
 .vector dropped_origin;
-.void(void) uncustomizeentityforclient;
-.float uncustomizeentityforclient_set;
 .float nottargeted;
 
+entity eliminatedPlayers;
+void EliminatedPlayers_Init(float(entity) isEliminated_func);
+
+string admin_name();
+
+void write_recordmarker(entity pl, float tstart, float dt);
+
+void play2all(string samp);
+
+void play2team(float t, string filename);
+
+void GetCvars_handleFloat(string thisname, float f, .float field, string name);
+
+float spamsound(entity e, float chan, string samp, float vol, float _atten);
+
+void GetCvars_handleString(string thisname, float f, .string field, string name);
+
+void precache_all_playermodels(string pattern);
+
+void soundat(entity e, vector o, float chan, string samp, float vol, float _atten);
+
+void InitializeEntitiesRun();
+
+void stopsoundto(float _dest, entity e, float chan);
+void soundtoat(float _dest, entity e, vector o, float chan, string samp, float vol, float _atten);
 
-float DistributeEvenly_amount;
-float DistributeEvenly_totalweight;
-var void remove(entity e);
 void objerror(string s);
 void droptofloor();
-void() spawnfunc_info_player_deathmatch; // needed for the other spawnpoints
-void() spawnpoint_use;
-void() SUB_Remove;
 
 void attach_sameorigin(entity e, entity to, string tag);
 
@@ -60,7 +76,7 @@ void GameLogInit();
 
 void GameLogClose();
 
-void GetCvars(float f);
+void GetCvars(entity this, float f);
 
 string GetMapname();
 
@@ -68,6 +84,10 @@ float isPushable(entity e);
 
 float LostMovetypeFollow(entity ent);
 
+string uid2name(string myuid);
+
+float MoveToRandomLocationWithinBounds(entity e, vector boundmin, vector boundmax, float goodcontents, float badcontents, float badsurfaceflags, float attempts, float maxaboveground, float minviewdistance);
+
 float MoveToRandomMapLocation(entity e, float goodcontents, float badcontents, float badsurfaceflags, float attempts, float maxaboveground, float minviewdistance);
 
 string NearestLocation(vector p);
@@ -84,8 +104,6 @@ void remove_unsafely(entity e);
 
 void SetMovetypeFollow(entity ent, entity e);
 
-vector shotorg_adjust_values(vector vecs, float y_is_right, float visual, float algn);
-
 void soundto(float dest, entity e, float chan, string samp, float vol, float atten);
 
 void stopsound(entity e, float chan);
@@ -98,38 +116,14 @@ void WarpZone_crosshair_trace(entity pl);
 
 void WarpZone_traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag);
 
+#define IS_DEAD(s) ((s).deadflag != DEAD_NO)
 
-#define IFTARGETED if(!self.nottargeted && self.targetname != "")
 
 #define ITEM_TOUCH_NEEDKILL() (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY))
-#define ITEM_DAMAGE_NEEDKILL(dt) (((dt) == DEATH_HURTTRIGGER) || ((dt) == DEATH_SLIME) || ((dt) == DEATH_LAVA) || ((dt) == DEATH_SWAMP))
+#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))
 
 #define PROJECTILE_TOUCH if(WarpZone_Projectile_Touch()) return
 
-#define move_out_of_solid(e) WarpZoneLib_MoveOutOfSolid(e)
-
-const string STR_PLAYER = "player";
-const string STR_SPECTATOR = "spectator";
-const string STR_OBSERVER = "observer";
-
-#define IS_PLAYER(v)                   (v.classname == STR_PLAYER)
-#define IS_SPEC(v)                             (v.classname == STR_SPECTATOR)
-#define IS_OBSERVER(v)                         (v.classname == STR_OBSERVER)
-#define IS_CLIENT(v)                   (v.flags & FL_CLIENT)
-#define IS_BOT_CLIENT(v)               (clienttype(v) == CLIENTTYPE_BOT)
-#define IS_REAL_CLIENT(v)              (clienttype(v) == CLIENTTYPE_REAL)
-#define IS_NOT_A_CLIENT(v)             (clienttype(v) == CLIENTTYPE_NOTACLIENT)
-
-#define FOR_EACH_CLIENTSLOT(v) for(v = world; (v = nextent(v)) && (num_for_edict(v) <= maxclients); )
-#define FOR_EACH_CLIENT(v) FOR_EACH_CLIENTSLOT(v) if(IS_CLIENT(v))
-#define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(IS_REAL_CLIENT(v))
-
-#define FOR_EACH_PLAYER(v) FOR_EACH_CLIENT(v) if(IS_PLAYER(v))
-#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
-#define FOR_EACH_REALPLAYER(v) FOR_EACH_REALCLIENT(v) if(IS_PLAYER(v))
-
-#define FOR_EACH_MONSTER(v) for(v = world; (v = findflags(v, flags, FL_MONSTER)) != world; )
-
 #define CENTER_OR_VIEWOFS(ent) (ent.origin + (IS_PLAYER(ent) ? ent.view_ofs : ((ent.mins + ent.maxs) * 0.5)))
 
 // copies a string to a tempstring (so one can strunzone it)
@@ -138,13 +132,12 @@ string strcat1(string s) = #115; // FRIK_FILE
 float logfile_open;
 float logfile;
 
-#define strstr strstrofs
 /*
 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
 // BE CONSTANT OR strzoneD!
-float strstr(string haystack, string needle, float offset)
+float strstrofs(string haystack, string needle, float offset)
 {
        float len, endpos;
        string found;
@@ -244,319 +237,23 @@ float warmup_start_health;
 float warmup_start_armorvalue;
 float g_weapon_stay;
 
-float want_weapon(entity weaponinfo, float allguns) // WEAPONTODO: what still needs done?
-{
-       int i = weaponinfo.weapon;
-       int d = 0;
-
-       if (!i)
-               return 0;
-
-       if (g_lms || g_ca || allguns)
-       {
-               if(weaponinfo.spawnflags & WEP_FLAG_NORMAL)
-                       d = true;
-               else
-                       d = false;
-       }
-       else if (g_cts)
-               d = (i == WEP_SHOTGUN);
-       else if (g_nexball)
-               d = 0; // weapon is set a few lines later
-       else
-               d = !(!weaponinfo.weaponstart);
-
-       if(g_grappling_hook) // if possible, redirect off-hand hook to on-hand hook
-               d |= (i == WEP_HOOK);
-       if(!g_cts && (weaponinfo.spawnflags & WEP_FLAG_MUTATORBLOCKED)) // never default mutator blocked guns
-               d = 0;
-
-       float t = weaponinfo.weaponstartoverride;
-
-       //print(strcat("want_weapon: ", weaponinfo.netname, " - d: ", ftos(d), ", t: ", ftos(t), ". \n"));
-
-       // bit order in t:
-       // 1: want or not
-       // 2: is default?
-       // 4: is set by default?
-       if(t < 0)
-               t = 4 | (3 * d);
-       else
-               t |= (2 * d);
-
-       return t;
-}
-
-void readplayerstartcvars()
-{
-       entity e;
-       float i, j, t;
-       string s;
-
-       // initialize starting values for players
-       start_weapons = '0 0 0';
-       start_weapons_default = '0 0 0';
-       start_weapons_defaultmask = '0 0 0';
-       start_items = 0;
-       start_ammo_shells = 0;
-       start_ammo_nails = 0;
-       start_ammo_rockets = 0;
-       start_ammo_cells = 0;
-       start_ammo_plasma = 0;
-       start_health = cvar("g_balance_health_start");
-       start_armorvalue = cvar("g_balance_armor_start");
-
-       g_weaponarena = 0;
-       g_weaponarena_weapons = '0 0 0';
-
-       s = cvar_string("g_weaponarena");
-       if (s == "0" || s == "")
-       {
-               if(g_ca)
-                       s = "most";
-       }
-
-       if (s == "0" || s == "")
-       {
-               // no arena
-       }
-       else if (s == "off")
-       {
-               // forcibly turn off weaponarena
-       }
-       else if (s == "all" || s == "1")
-       {
-               g_weaponarena = 1;
-               g_weaponarena_list = "All Weapons";
-               for (j = WEP_FIRST; j <= WEP_LAST; ++j)
-               {
-                       e = get_weaponinfo(j);
-                       if (!(e.spawnflags & WEP_FLAG_MUTATORBLOCKED))
-                               g_weaponarena_weapons |= WepSet_FromWeapon(j);
-               }
-       }
-       else if (s == "most")
-       {
-               g_weaponarena = 1;
-               g_weaponarena_list = "Most Weapons";
-               for (j = WEP_FIRST; j <= WEP_LAST; ++j)
-               {
-                       e = get_weaponinfo(j);
-                       if (!(e.spawnflags & WEP_FLAG_MUTATORBLOCKED))
-                               if (e.spawnflags & WEP_FLAG_NORMAL)
-                                       g_weaponarena_weapons |= WepSet_FromWeapon(j);
-               }
-       }
-       else if (s == "none")
-       {
-               g_weaponarena = 1;
-               g_weaponarena_list = "No Weapons";
-       }
-       else
-       {
-               g_weaponarena = 1;
-               t = tokenize_console(s);
-               g_weaponarena_list = "";
-               for (i = 0; i < t; ++i)
-               {
-                       s = argv(i);
-                       for (j = WEP_FIRST; j <= WEP_LAST; ++j)
-                       {
-                               e = get_weaponinfo(j);
-                               if (e.netname == s)
-                               {
-                                       g_weaponarena_weapons |= WepSet_FromWeapon(j);
-                                       g_weaponarena_list = strcat(g_weaponarena_list, e.message, " & ");
-                                       break;
-                               }
-                       }
-                       if (j > WEP_LAST)
-                       {
-                               print("The weapon mutator list contains an unknown weapon ", s, ". Skipped.\n");
-                       }
-               }
-               g_weaponarena_list = strzone(substring(g_weaponarena_list, 0, strlen(g_weaponarena_list) - 3));
-       }
-
-       if(g_weaponarena)
-               g_weaponarena_random = cvar("g_weaponarena_random");
-       else
-               g_weaponarena_random = 0;
-       g_weaponarena_random_with_blaster = cvar("g_weaponarena_random_with_blaster");
-
-       if (g_weaponarena)
-       {
-               g_weapon_stay = 0; // incompatible
-               start_weapons = g_weaponarena_weapons;
-               start_items |= IT_UNLIMITED_AMMO;
-       }
-       else
-       {
-               for (i = WEP_FIRST; i <= WEP_LAST; ++i)
-               {
-                       e = get_weaponinfo(i);
-                       int w = want_weapon(e, false);
-                       if(w & 1)
-                               start_weapons |= WepSet_FromWeapon(i);
-                       if(w & 2)
-                               start_weapons_default |= WepSet_FromWeapon(i);
-                       if(w & 4)
-                               start_weapons_defaultmask |= WepSet_FromWeapon(i);
-               }
-       }
-
-       if(!cvar("g_use_ammunition"))
-               start_items |= IT_UNLIMITED_AMMO;
-
-       if(start_items & IT_UNLIMITED_WEAPON_AMMO)
-       {
-               start_ammo_shells = 999;
-               start_ammo_nails = 999;
-               start_ammo_rockets = 999;
-               start_ammo_cells = 999;
-               start_ammo_plasma = 999;
-               start_ammo_fuel = 999;
-       }
-       else
-       {
-               start_ammo_shells = cvar("g_start_ammo_shells");
-               start_ammo_nails = cvar("g_start_ammo_nails");
-               start_ammo_rockets = cvar("g_start_ammo_rockets");
-               start_ammo_cells = cvar("g_start_ammo_cells");
-               start_ammo_plasma = cvar("g_start_ammo_plasma");
-               start_ammo_fuel = cvar("g_start_ammo_fuel");
-       }
-
-       if (warmup_stage)
-       {
-               warmup_start_ammo_shells = start_ammo_shells;
-               warmup_start_ammo_nails = start_ammo_nails;
-               warmup_start_ammo_rockets = start_ammo_rockets;
-               warmup_start_ammo_cells = start_ammo_cells;
-               warmup_start_ammo_plasma = start_ammo_plasma;
-               warmup_start_ammo_fuel = start_ammo_fuel;
-               warmup_start_health = start_health;
-               warmup_start_armorvalue = start_armorvalue;
-               warmup_start_weapons = start_weapons;
-               warmup_start_weapons_default = start_weapons_default;
-               warmup_start_weapons_defaultmask = start_weapons_defaultmask;
-
-               if (!g_weaponarena && !g_ca)
-               {
-                       warmup_start_ammo_shells = cvar("g_warmup_start_ammo_shells");
-                       warmup_start_ammo_nails = cvar("g_warmup_start_ammo_nails");
-                       warmup_start_ammo_rockets = cvar("g_warmup_start_ammo_rockets");
-                       warmup_start_ammo_cells = cvar("g_warmup_start_ammo_cells");
-                       warmup_start_ammo_plasma = cvar("g_warmup_start_ammo_plasma");
-                       warmup_start_ammo_fuel = cvar("g_warmup_start_ammo_fuel");
-                       warmup_start_health = cvar("g_warmup_start_health");
-                       warmup_start_armorvalue = cvar("g_warmup_start_armor");
-                       warmup_start_weapons = '0 0 0';
-                       warmup_start_weapons_default = '0 0 0';
-                       warmup_start_weapons_defaultmask = '0 0 0';
-                       for (i = WEP_FIRST; i <= WEP_LAST; ++i)
-                       {
-                               e = get_weaponinfo(i);
-                               int w = want_weapon(e, g_warmup_allguns);
-                               if(w & 1)
-                                       warmup_start_weapons |= WepSet_FromWeapon(i);
-                               if(w & 2)
-                                       warmup_start_weapons_default |= WepSet_FromWeapon(i);
-                               if(w & 4)
-                                       warmup_start_weapons_defaultmask |= WepSet_FromWeapon(i);
-                       }
-               }
-       }
-
-       if (g_jetpack)
-               start_items |= IT_JETPACK;
-
-       MUTATOR_CALLHOOK(SetStartItems);
-
-       if ((start_items & IT_JETPACK) || (g_grappling_hook && (start_weapons & WEPSET_HOOK)))
-       {
-               start_items |= IT_FUEL_REGEN;
-               start_ammo_fuel = max(start_ammo_fuel, cvar("g_balance_fuel_rotstable"));
-               warmup_start_ammo_fuel = max(warmup_start_ammo_fuel, cvar("g_balance_fuel_rotstable"));
-       }
-
-       WepSet precache_weapons = start_weapons;
-       if (g_warmup_allguns != 1)
-               precache_weapons |= warmup_start_weapons;
-       for (i = WEP_FIRST; i <= WEP_LAST; ++i)
-       {
-               e = get_weaponinfo(i);
-               if(precache_weapons & WepSet_FromWeapon(i))
-                       WEP_ACTION(i, WR_INIT);
-       }
-
-       start_ammo_shells = max(0, start_ammo_shells);
-       start_ammo_nails = max(0, start_ammo_nails);
-       start_ammo_rockets = max(0, start_ammo_rockets);
-       start_ammo_cells = max(0, start_ammo_cells);
-       start_ammo_plasma = max(0, start_ammo_plasma);
-       start_ammo_fuel = max(0, start_ammo_fuel);
-
-       warmup_start_ammo_shells = max(0, warmup_start_ammo_shells);
-       warmup_start_ammo_nails = max(0, warmup_start_ammo_nails);
-       warmup_start_ammo_rockets = max(0, warmup_start_ammo_rockets);
-       warmup_start_ammo_cells = max(0, warmup_start_ammo_cells);
-       warmup_start_ammo_plasma = max(0, warmup_start_ammo_plasma);
-       warmup_start_ammo_fuel = max(0, warmup_start_ammo_fuel);
-}
-
-float g_bugrigs;
-float g_bugrigs_planar_movement;
-float g_bugrigs_planar_movement_car_jumping;
-float g_bugrigs_reverse_spinning;
-float g_bugrigs_reverse_speeding;
-float g_bugrigs_reverse_stopping;
-float g_bugrigs_air_steering;
-float g_bugrigs_angle_smoothing;
-float g_bugrigs_friction_floor;
-float g_bugrigs_friction_brake;
-float g_bugrigs_friction_air;
-float g_bugrigs_accel;
-float g_bugrigs_speed_ref;
-float g_bugrigs_speed_pow;
-float g_bugrigs_steer;
+float want_weapon(entity weaponinfo, float allguns); // WEAPONTODO: what still needs done?
+void readplayerstartcvars();
 
 float sv_autotaunt;
 float sv_taunt;
 
 string GetGametype(); // g_world.qc
-void mutators_add(); // mutators.qc
-void readlevelcvars(void)
+void readlevelcvars()
 {
-       // load mutators
-       mutators_add();
-
        if(cvar("sv_allow_fullbright"))
                serverflags |= SERVERFLAG_ALLOW_FULLBRIGHT;
 
-    g_bugrigs = cvar("g_bugrigs");
-    g_bugrigs_planar_movement = cvar("g_bugrigs_planar_movement");
-    g_bugrigs_planar_movement_car_jumping = cvar("g_bugrigs_planar_movement_car_jumping");
-    g_bugrigs_reverse_spinning = cvar("g_bugrigs_reverse_spinning");
-    g_bugrigs_reverse_speeding = cvar("g_bugrigs_reverse_speeding");
-    g_bugrigs_reverse_stopping = cvar("g_bugrigs_reverse_stopping");
-    g_bugrigs_air_steering = cvar("g_bugrigs_air_steering");
-    g_bugrigs_angle_smoothing = cvar("g_bugrigs_angle_smoothing");
-    g_bugrigs_friction_floor = cvar("g_bugrigs_friction_floor");
-    g_bugrigs_friction_brake = cvar("g_bugrigs_friction_brake");
-    g_bugrigs_friction_air = cvar("g_bugrigs_friction_air");
-    g_bugrigs_accel = cvar("g_bugrigs_accel");
-    g_bugrigs_speed_ref = cvar("g_bugrigs_speed_ref");
-    g_bugrigs_speed_pow = cvar("g_bugrigs_speed_pow");
-    g_bugrigs_steer = cvar("g_bugrigs_steer");
-
        g_instagib = cvar("g_instagib");
 
        sv_clones = cvar("sv_clones");
        sv_foginterval = cvar("sv_foginterval");
-       g_cloaked = cvar("g_cloaked");
        g_footsteps = cvar("g_footsteps");
-       g_grappling_hook = cvar("g_grappling_hook");
        g_jetpack = cvar("g_jetpack");
        sv_maxidle = cvar("sv_maxidle");
        sv_maxidle_spectatorsareidle = cvar("sv_maxidle_spectatorsareidle");
@@ -564,12 +261,12 @@ void readlevelcvars(void)
        sv_taunt = cvar("sv_taunt");
 
        warmup_stage = cvar("g_warmup");
-       g_warmup_limit = cvar("g_warmup_limit");
+       warmup_limit = cvar("g_warmup_limit");
        g_warmup_allguns = cvar("g_warmup_allguns");
        g_warmup_allow_timeout = cvar("g_warmup_allow_timeout");
 
-       if ((g_race && g_race_qualifying == 2) || g_assault || cvar("g_campaign"))
-               warmup_stage = 0; // these modes cannot work together, sorry
+       if(cvar("g_campaign"))
+               warmup_stage = 0; // no warmup during campaign
 
        g_pickup_respawntime_weapon = cvar("g_pickup_respawntime_weapon");
        g_pickup_respawntime_superweapon = cvar("g_pickup_respawntime_superweapon");
@@ -637,29 +334,18 @@ void readlevelcvars(void)
     if(!g_weapon_stay)
         g_weapon_stay = cvar("g_weapon_stay");
 
+    MUTATOR_CALLHOOK(ReadLevelCvars);
+
        if (!warmup_stage)
                game_starttime = time + cvar("g_start_delay");
 
+       FOREACH(Weapons, it != WEP_Null, LAMBDA(it.wr_init(it)));
+
        readplayerstartcvars();
 }
 
 //#NO AUTOCVARS END
 
-
-// Sound functions
-//string precache_sound (string s) = #19;
-// hack
-float precache_sound_index (string s) = #19;
-
-const float SND_VOLUME = 1;
-const float SND_ATTENUATION = 2;
-const float SND_LARGEENTITY = 8;
-const float SND_LARGESOUND = 16;
-
-// WARNING: this kills the trace globals
-#define EXACTTRIGGER_TOUCH if(WarpZoneLib_ExactTrigger_Touch()) return
-#define EXACTTRIGGER_INIT  WarpZoneLib_ExactTrigger_Init()
-
 const float INITPRIO_FIRST                             = 0;
 const float INITPRIO_GAMETYPE                  = 0;
 const float INITPRIO_GAMETYPE_FALLBACK         = 1;
@@ -669,7 +355,7 @@ const float INITPRIO_SETLOCATION            = 90;
 const float INITPRIO_LINKDOORS                         = 91;
 const float INITPRIO_LAST                              = 99;
 
-.void(void) initialize_entity;
+.void(entity this) initialize_entity;
 .float initialize_entity_order;
 .entity initialize_entity_next;
 entity initialize_entity_first;
@@ -679,8 +365,5 @@ entity initialize_entity_first;
 
 
 float sound_allowed(float dest, entity e);
-void InitializeEntity(entity e, void(void) func, float order);
-void SetCustomizer(entity e, float(void) customizer, void(void) uncustomizer);
-void Net_LinkEntity(entity e, float docull, float dt, float(entity, float) sendfunc);
-
-#endif
+void InitializeEntity(entity e, void(entity this) func, float order);
+void SetCustomizer(entity e, float() customizer, void() uncustomizer);