]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/miscfunctions.qc
rename teams_matter to teamplay everywhere
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / miscfunctions.qc
index cb74c8d3a8a926148704766a302c6ab9004284b1..c16608821abf47ee661137a9ce5203b023b39486 100644 (file)
@@ -21,8 +21,8 @@ string ColoredTeamName(float t);
 
 string admin_name(void)
 {
-       if(cvar_string("sv_adminnick") != "")
-               return cvar_string("sv_adminnick");
+       if(autocvar_sv_adminnick != "")
+               return autocvar_sv_adminnick;
        else
                return "SERVER ADMIN";
 }
@@ -92,16 +92,16 @@ string GetAdvancedDeathReports(entity enPlayer) // Extra fragmessage information
        else
                strPlayerPingColor = "^2";
 
-       if((cvar("sv_fragmessage_information_stats")) && (enPlayer.health >= 1))
+       if((autocvar_sv_fragmessage_information_stats) && (enPlayer.health >= 1))
                strMessage = strcat(strMessage, "\n^7(Health ^1", ftos(nPlayerHealth), "^7 / Armor ^2", ftos(nPlayerArmor), "^7)");
 
-       if(cvar("sv_fragmessage_information_ping")) {
+       if(autocvar_sv_fragmessage_information_ping) {
                if(clienttype(enPlayer) == CLIENTTYPE_BOT) // Bots have no ping
                        strMessage = strcat(strMessage, " ^7(^2Bot");
                else
                        strMessage = strcat(strMessage, " ^7(Ping ", strPlayerPingColor, ftos(nPlayerPing), "ms");
-               if(cvar("sv_fragmessage_information_handicap"))
-                       if(cvar("sv_fragmessage_information_handicap") == 2)
+               if(autocvar_sv_fragmessage_information_handicap)
+                       if(autocvar_sv_fragmessage_information_handicap == 2)
                                if(nPlayerHandicap <= 1)
                                        strMessage = strcat(strMessage, "^7 / Handicap ^2Off^7)");
                                else
@@ -110,8 +110,8 @@ string GetAdvancedDeathReports(entity enPlayer) // Extra fragmessage information
                                strMessage = strcat(strMessage, "^7 / Handicap ^2", ftos(nPlayerHandicap), "^7)");
                else
                        strMessage = strcat(strMessage, "^7)");
-       } else if(cvar("sv_fragmessage_information_handicap")) {
-               if(cvar("sv_fragmessage_information_handicap") == 2)
+       } else if(autocvar_sv_fragmessage_information_handicap) {
+               if(autocvar_sv_fragmessage_information_handicap == 2)
                        if(nPlayerHandicap <= 1)
                                strMessage = strcat(strMessage, "\n^7(Handicap ^2Off^7)");
                        else
@@ -135,29 +135,29 @@ void GameLogEcho(string s)
     string fn;
     float matches;
 
-    if (cvar("sv_eventlog_files"))
+    if (autocvar_sv_eventlog_files)
     {
         if (!logfile_open)
         {
             logfile_open = TRUE;
-            matches = cvar("sv_eventlog_files_counter") + 1;
+            matches = autocvar_sv_eventlog_files_counter + 1;
             cvar_set("sv_eventlog_files_counter", ftos(matches));
             fn = ftos(matches);
             if (strlen(fn) < 8)
                 fn = strcat(substring("00000000", 0, 8 - strlen(fn)), fn);
-            fn = strcat(cvar_string("sv_eventlog_files_nameprefix"), fn, cvar_string("sv_eventlog_files_namesuffix"));
+            fn = strcat(autocvar_sv_eventlog_files_nameprefix, fn, autocvar_sv_eventlog_files_namesuffix);
             logfile = fopen(fn, FILE_APPEND);
             fputs(logfile, ":logversion:3\n");
         }
         if (logfile >= 0)
         {
-            if (cvar("sv_eventlog_files_timestamps"))
+            if (autocvar_sv_eventlog_files_timestamps)
                 fputs(logfile, strcat(":time:", strftime(TRUE, "%Y-%m-%d %H:%M:%S", "\n", s, "\n")));
             else
                 fputs(logfile, strcat(s, "\n"));
         }
     }
-    if (cvar("sv_eventlog_console"))
+    if (autocvar_sv_eventlog_console)
     {
         print(s, "\n");
     }
@@ -189,13 +189,13 @@ vector PL_CROUCH_MAX;
 float spawnpoint_nag;
 void relocate_spawnpoint()
 {
-    PL_VIEW_OFS                             = stov(cvar_string("sv_player_viewoffset"));
-    PL_MIN                                  = stov(cvar_string("sv_player_mins"));
-    PL_MAX                                  = stov(cvar_string("sv_player_maxs"));
-    PL_HEAD                                 = stov(cvar_string("sv_player_headsize"));
-    PL_CROUCH_VIEW_OFS                      = stov(cvar_string("sv_player_crouch_viewoffset"));
-    PL_CROUCH_MIN                           = stov(cvar_string("sv_player_crouch_mins"));
-    PL_CROUCH_MAX                           = stov(cvar_string("sv_player_crouch_maxs"));
+    PL_VIEW_OFS                             = stov(autocvar_sv_player_viewoffset);
+    PL_MIN                                  = stov(autocvar_sv_player_mins);
+    PL_MAX                                  = stov(autocvar_sv_player_maxs);
+    PL_HEAD                                 = stov(autocvar_sv_player_headsize);
+    PL_CROUCH_VIEW_OFS                      = stov(autocvar_sv_player_crouch_viewoffset);
+    PL_CROUCH_MIN                           = stov(autocvar_sv_player_crouch_mins);
+    PL_CROUCH_MAX                           = stov(autocvar_sv_player_crouch_maxs);
 
     // nudge off the floor
     setorigin(self, self.origin + '0 0 1');
@@ -213,7 +213,7 @@ void relocate_spawnpoint()
         print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
         print(" ", ftos(self.origin_y - o_y));
         print(" ", ftos(self.origin_z - o_z), "'\n");
-        if (cvar("g_spawnpoints_auto_move_out_of_solid"))
+        if (autocvar_g_spawnpoints_auto_move_out_of_solid)
         {
             if (!spawnpoint_nag)
                 print("\{1}^1NOTE: this map needs FIXING (it contains spawnpoints in solid, see server log)\n");
@@ -236,8 +236,9 @@ void relocate_spawnpoint()
     if (have_team_spawns != 0)
         if (self.team)
             have_team_spawns = 1;
+    have_team_spawns_forteam[self.team] = 1;
 
-    if (cvar("r_showbboxes"))
+    if (autocvar_r_showbboxes)
     {
         // show where spawnpoints point at too
         makevectors(self.angles);
@@ -459,11 +460,6 @@ string formatmessage(string msg)
                        replacement = cursor_ent.netname;
                        if (!replacement || !cursor_ent)
                                replacement = "nothing";
-               } else if (escape == "p") {
-                       if (self.last_selected_player)
-                               replacement = self.last_selected_player.netname;
-                       else
-                               replacement = "(nobody)";
                } else if (escape == "s")
                        replacement = ftos(vlen(self.velocity - self.velocity_z * '0 0 1'));
                else if (escape == "S")
@@ -584,7 +580,6 @@ void GetCvars(float f)
        GetCvars_handleFloat(s, f, autoswitch, "cl_autoswitch");
        GetCvars_handleFloat(s, f, cvar_cl_playerdetailreduction, "cl_playerdetailreduction");
        GetCvars_handleFloat(s, f, cvar_scr_centertime, "scr_centertime");
-       GetCvars_handleFloat(s, f, cvar_cl_shownames, "cl_shownames");
        GetCvars_handleString(s, f, cvar_g_xonoticversion, "g_xonoticversion");
        GetCvars_handleFloat(s, f, cvar_cl_handicap, "cl_handicap");
        GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriority, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete_AndBuildImpulseList);
@@ -603,7 +598,6 @@ void GetCvars(float f)
        GetCvars_handleFloat(s, f, cvar_cl_noantilag, "cl_noantilag");
        GetCvars_handleFloat(s, f, cvar_cl_voice_directional, "cl_voice_directional");
        GetCvars_handleFloat(s, f, cvar_cl_voice_directional_taunt_attenuation, "cl_voice_directional_taunt_attenuation");
-       GetCvars_handleFloat(s, f, cvar_cl_hitsound, "cl_hitsound");
        GetCvars_handleFloat(s, f, cvar_cl_accuracy_data_share, "cl_accuracy_data_share");
        GetCvars_handleFloat(s, f, cvar_cl_accuracy_data_receive, "cl_accuracy_data_receive");
 
@@ -616,30 +610,23 @@ void GetCvars(float f)
 #endif
        GetCvars_handleFloatOnce(s, f, cvar_cl_gunalign, "cl_gunalign");
        GetCvars_handleFloat(s, f, cvar_cl_allow_uid2name, "cl_allow_uid2name");
+       GetCvars_handleFloat(s, f, cvar_cl_allow_uidtracking, "cl_allow_uidtracking");
 
        // fixup of switchweapon (needed for LMS or when spectating is disabled, as PutClientInServer comes too early)
        if (f > 0)
        {
                if (s == "cl_weaponpriority")
                        self.switchweapon = w_getbestweapon(self);
+               if (s == "cl_allow_uidtracking")
+                       PlayerStats_AddPlayer(self);
        }
 }
 
-float fexists(string f)
-{
-    float fh;
-    fh = fopen(f, FILE_READ);
-    if (fh < 0)
-        return FALSE;
-    fclose(fh);
-    return TRUE;
-}
-
 void backtrace(string msg)
 {
     float dev, war;
-    dev = cvar("developer");
-    war = cvar("prvm_backtraceforwarnings");
+    dev = autocvar_developer;
+    war = autocvar_prvm_backtraceforwarnings;
     cvar_set("developer", "1");
     cvar_set("prvm_backtraceforwarnings", "1");
     print("\n");
@@ -775,7 +762,7 @@ void centerprint(entity e, string s)
 string playername(entity p)
 {
     string t;
-    if (teams_matter && !intermission_running && p.classname == "player")
+    if (teamplay && !intermission_running && p.classname == "player")
     {
         t = Team_ColorCode(p.team);
         return strcat(t, strdecolorize(p.netname));
@@ -794,6 +781,8 @@ vector randompos(vector m1, vector m2)
     return  v;
 };
 
+//#NO AUTOCVARS START
+
 float g_pickup_shells;
 float g_pickup_shells_max;
 float g_pickup_nails;
@@ -878,8 +867,8 @@ float want_weapon(string cvarprefix, entity weaponinfo, float allguns)
                        t = (weaponinfo.spawnflags & WEP_FLAG_NORMAL);
                else if(t < -1)
                        t = 0;
-               else if (g_race || g_cts)
-                       t = (i == WEP_LASER);
+               else if (g_cts)
+                       t = (i == WEP_SHOTGUN);
                else if (g_nexball)
                        t = 0; // weapon is set a few lines later
                else
@@ -913,8 +902,19 @@ void readplayerstartcvars()
 
        g_weaponarena = 0;
        s = cvar_string("g_weaponarena");
-       if (s == "0")
+       if (s == "0" || s == "")
        {
+               if(g_lms || g_ca)
+                       s = "most";
+       }
+
+       if (s == "0" || s == "")
+       {
+               // no arena
+       }
+       else if (s == "off")
+       {
+               // forcibly turn off weaponarena
        }
        else if (s == "all")
        {
@@ -979,17 +979,8 @@ void readplayerstartcvars()
        if (g_weaponarena)
        {
                start_weapons = g_weaponarena;
-               if (g_weaponarena & (WEPBIT_GRENADE_LAUNCHER | WEPBIT_MINE_LAYER | WEPBIT_HAGAR | WEPBIT_ROCKET_LAUNCHER))
-                       start_ammo_rockets = 999;
-               if (g_weaponarena & WEPBIT_SHOTGUN)
-                       start_ammo_shells = 999;
-               if (g_weaponarena & (WEPBIT_ELECTRO | WEPBIT_CRYLINK | WEPBIT_NEX | WEPBIT_MINSTANEX | WEPBIT_HLAC | WEPBIT_HOOK))
-                       start_ammo_cells = 999;
-               if (g_weaponarena & (WEPBIT_UZI | WEPBIT_CAMPINGRIFLE))
-                       start_ammo_nails = 999;
-               if (g_weaponarena & WEPBIT_HOOK)
-                       start_ammo_fuel = 999;
-               start_items |= IT_UNLIMITED_AMMO;
+               if(!(g_lms || g_ca))
+                       start_items |= IT_UNLIMITED_AMMO;
        }
        else if (g_minstagib)
        {
@@ -997,24 +988,46 @@ void readplayerstartcvars()
                start_armorvalue = 0;
                start_weapons = WEPBIT_MINSTANEX;
                weapon_action(WEP_MINSTANEX, WR_PRECACHE);
-               start_ammo_cells = cvar("g_minstagib_ammo_start");
                g_minstagib_invis_alpha = cvar("g_minstagib_invis_alpha");
-               start_ammo_fuel = cvar("g_start_ammo_fuel");
 
                if (g_minstagib_invis_alpha <= 0)
                        g_minstagib_invis_alpha = -1;
        }
        else
        {
-               if (g_lms || g_ca)
+               for (i = WEP_FIRST; i <= WEP_LAST; ++i)
+               {
+                       e = get_weaponinfo(i);
+                       if(want_weapon("g_start_weapon_", e, FALSE))
+                               start_weapons |= e.weapons;
+               }
+       }
+
+       if(!cvar("g_use_ammunition"))
+               start_items |= IT_UNLIMITED_AMMO;
+
+       if(g_minstagib)
+       {
+               start_ammo_cells = cvar("g_minstagib_ammo_start");
+               start_ammo_fuel = cvar("g_start_ammo_fuel");
+       }
+       else if(start_items & IT_UNLIMITED_WEAPON_AMMO)
+       {
+               start_ammo_rockets = 999;
+               start_ammo_shells = 999;
+               start_ammo_cells = 999;
+               start_ammo_nails = 999;
+               start_ammo_fuel = 999;
+       }
+       else
+       {
+               if(g_lms || g_ca)
                {
                        start_ammo_shells = cvar("g_lms_start_ammo_shells");
                        start_ammo_nails = cvar("g_lms_start_ammo_nails");
                        start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
                        start_ammo_cells = cvar("g_lms_start_ammo_cells");
                        start_ammo_fuel = cvar("g_lms_start_ammo_fuel");
-                       start_health = cvar("g_lms_start_health");
-                       start_armorvalue = cvar("g_lms_start_armor");
                }
                else
                {
@@ -1024,13 +1037,12 @@ void readplayerstartcvars()
                        start_ammo_cells = cvar("g_start_ammo_cells");
                        start_ammo_fuel = cvar("g_start_ammo_fuel");
                }
+       }
 
-               for (i = WEP_FIRST; i <= WEP_LAST; ++i)
-               {
-                       e = get_weaponinfo(i);
-                       if(want_weapon("g_start_weapon_", e, FALSE))
-                               start_weapons |= e.weapons;
-               }
+       if (g_lms || g_ca)
+       {
+               start_health = cvar("g_lms_start_health");
+               start_armorvalue = cvar("g_lms_start_armor");
        }
 
        if (inWarmupStage)
@@ -1071,22 +1083,6 @@ void readplayerstartcvars()
                warmup_start_ammo_fuel = max(warmup_start_ammo_fuel, cvar("g_balance_fuel_rotstable"));
        }
 
-       if(!cvar("g_use_ammunition"))
-       {
-               start_ammo_shells = cvar("g_pickup_shells_max");
-               start_ammo_nails = cvar("g_pickup_nails_max");
-               start_ammo_rockets = cvar("g_pickup_rockets_max");
-               start_ammo_cells = cvar("g_pickup_cells_max");
-               start_ammo_fuel = cvar("g_pickup_fuel_max");
-               start_items |= IT_UNLIMITED_AMMO;
-               warmup_start_ammo_shells = cvar("g_pickup_shells_max");
-               warmup_start_ammo_nails = cvar("g_pickup_nails_max");
-               warmup_start_ammo_rockets = cvar("g_pickup_rockets_max");
-               warmup_start_ammo_cells = cvar("g_pickup_cells_max");
-               warmup_start_ammo_fuel = cvar("g_pickup_fuel_max");
-               //warmup_start_items |= IT_UNLIMITED_AMMO;
-       }
-
        if (g_jetpack)
                start_items |= IT_JETPACK;
 
@@ -1155,8 +1151,7 @@ float sv_pitch_min;
 float sv_pitch_max;
 float sv_pitch_fixyaw;
 
-float sv_accuracy_data_share;
-
+string GetGametype(); // g_world.qc
 void readlevelcvars(void)
 {
        // first load all the mutators
@@ -1169,7 +1164,6 @@ void readlevelcvars(void)
        if(cvar("g_vampire"))
                MUTATOR_ADD(mutator_vampire);
 
-       serverflags = 0;
        if(cvar("sv_allow_fullbright"))
                serverflags |= SERVERFLAG_ALLOW_FULLBRIGHT;
 
@@ -1208,6 +1202,8 @@ void readlevelcvars(void)
        sv_gentle = cvar("sv_gentle");
        sv_foginterval = cvar("sv_foginterval");
        g_cloaked = cvar("g_cloaked");
+    if(g_cts)
+        g_cloaked = 1; // always enable cloak in CTS
        g_jump_grunt = cvar("g_jump_grunt");
        g_footsteps = cvar("g_footsteps");
        g_grappling_hook = cvar("g_grappling_hook");
@@ -1291,7 +1287,9 @@ void readlevelcvars(void)
 
        g_pinata = cvar("g_pinata");
 
-       g_weapon_stay = cvar("g_weapon_stay");
+    g_weapon_stay = cvar(strcat("g_", GetGametype(), "_weapon_stay"));
+    if(!g_weapon_stay)
+        g_weapon_stay = cvar("g_weapon_stay");
 
        if (!g_weapon_stay && (cvar("deathmatch") == 2))
                g_weapon_stay = 1;
@@ -1308,30 +1306,10 @@ void readlevelcvars(void)
        sv_pitch_max = cvar("sv_pitch_max");
        sv_pitch_fixyaw = cvar("sv_pitch_fixyaw");
 
-       sv_accuracy_data_share = boolean(cvar("sv_accuracy_data_share"));
-
        readplayerstartcvars();
 }
 
-/*
-// TODO sound pack system
-string soundpack;
-
-string precache_sound_builtin (string s) = #19;
-void(entity e, float chan, string samp, float vol, float atten) sound_builtin = #8;
-string precache_sound(string s)
-{
-       return precache_sound_builtin(strcat(soundpack, s));
-}
-void play2(entity e, string filename)
-{
-       stuffcmd(e, strcat("play2 ", soundpack, filename, "\n"));
-}
-void sound(entity e, float chan, string samp, float vol, float atten)
-{
-       sound_builtin(e, chan, strcat(soundpack, samp), vol, atten);
-}
-*/
+//#NO AUTOCVARS END
 
 // Sound functions
 string precache_sound (string s) = #19;
@@ -1360,7 +1338,7 @@ float sound_allowed(float dest, entity e)
         if (e == msg_entity)
             return TRUE;
     // sounds by players can be removed
-    if (cvar("bot_sound_monopoly"))
+    if (autocvar_bot_sound_monopoly)
         if (clienttype(e) == CLIENTTYPE_REAL)
             return FALSE;
     // anything else may pass
@@ -1506,7 +1484,7 @@ void play2team(float t, string filename)
 {
     local entity head;
 
-    if (cvar("bot_sound_monopoly"))
+    if (autocvar_bot_sound_monopoly)
         return;
 
     FOR_EACH_REALPLAYER(head)
@@ -1518,7 +1496,7 @@ void play2team(float t, string filename)
 
 void play2all(string samp)
 {
-    if (cvar("bot_sound_monopoly"))
+    if (autocvar_bot_sound_monopoly)
         return;
 
     sound(world, CHAN_AUTO, samp, VOL_BASE, ATTN_NONE);
@@ -1537,8 +1515,12 @@ void precache_playermodel(string m)
        precache_model(m);
        if(sv_loddistance1)
        {
-               precache_model(strcat(substring(m, 0, -5), "_lod1", substring(m, -4, -1)));
-               precache_model(strcat(substring(m, 0, -5), "_lod2", substring(m, -4, -1)));
+               f = strcat(substring(m, 0, -5), "_lod1", substring(m, -4, -1));
+               if(fexists(f))
+                       precache_model(f);
+               f = strcat(substring(m, 0, -5), "_lod2", substring(m, -4, -1));
+               if(fexists(f))
+                       precache_model(f);
        }
 
        globhandle = search_begin(strcat(m, "_*.sounds"), TRUE, FALSE);
@@ -1575,7 +1557,6 @@ void precache()
 {
     // gamemode related things
     precache_model ("models/misc/chatbubble.spr");
-    precache_model ("models/misc/teambubble.spr");
     if (g_runematch)
     {
         precache_model ("models/runematch/curse.mdl");
@@ -1583,12 +1564,12 @@ void precache()
     }
 
 #ifdef TTURRETS_ENABLED
-    if (cvar("g_turrets"))
+    if (autocvar_g_turrets)
         turrets_precash();
 #endif
 
     // Precache all player models if desired
-    if (cvar("sv_precacheplayermodels"))
+    if (autocvar_sv_precacheplayermodels)
     {
         PrecachePlayerSounds("sound/player/default.sounds");
         precache_all_playermodels("models/player/*.zym");
@@ -1598,22 +1579,22 @@ void precache()
         precache_all_playermodels("models/player/*.iqm");
     }
 
-    if (cvar("sv_defaultcharacter"))
+    if (autocvar_sv_defaultcharacter)
     {
         string s;
-        s = cvar_string("sv_defaultplayermodel_red");
+        s = autocvar_sv_defaultplayermodel_red;
         if (s != "")
             precache_playermodel(s);
-        s = cvar_string("sv_defaultplayermodel_blue");
+        s = autocvar_sv_defaultplayermodel_blue;
         if (s != "")
             precache_playermodel(s);
-        s = cvar_string("sv_defaultplayermodel_yellow");
+        s = autocvar_sv_defaultplayermodel_yellow;
         if (s != "")
             precache_playermodel(s);
-        s = cvar_string("sv_defaultplayermodel_pink");
+        s = autocvar_sv_defaultplayermodel_pink;
         if (s != "")
             precache_playermodel(s);
-        s = cvar_string("sv_defaultplayermodel");
+        s = autocvar_sv_defaultplayermodel;
         if (s != "")
             precache_playermodel(s);
     }
@@ -1635,8 +1616,6 @@ void precache()
     precache_sound ("misc/gib_splat02.wav");
     precache_sound ("misc/gib_splat03.wav");
     precache_sound ("misc/gib_splat04.wav");
-    precache_sound ("misc/hit.wav");
-       precache_sound ("misc/typehit.wav");
     PrecacheGlobalSound((globalsound_fall = "misc/hitground 4"));
     PrecacheGlobalSound((globalsound_metalfall = "misc/metalhitground 4"));
     precache_sound ("misc/null.wav");
@@ -1663,6 +1642,7 @@ void precache()
     precache_model ("models/sprites/10.spr32");
 
     // common weapon precaches
+       precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound here
     precache_sound ("weapons/weapon_switch.wav");
     precache_sound ("weapons/weaponpickup.wav");
     precache_sound ("weapons/unavailable.wav");
@@ -1673,7 +1653,7 @@ void precache()
         precache_sound ("weapons/hook_impact.wav"); // hook
     }
 
-    if(cvar("sv_precacheweapons"))
+    if(autocvar_sv_precacheweapons)
     {
         //precache weapon models/sounds
         local float wep;
@@ -1764,6 +1744,14 @@ void objerror(string s)
     objerror_builtin(s);
 }
 
+.float remove_except_protected_forbidden;
+void remove_except_protected(entity e)
+{
+       if(e.remove_except_protected_forbidden)
+               error("not allowed to remove this at this point");
+       remove_builtin(e);
+}
+
 void remove_unsafely(entity e)
 {
     remove_builtin(e);
@@ -1814,6 +1802,11 @@ void InitializeEntitiesRun()
     entity startoflist;
     startoflist = initialize_entity_first;
     initialize_entity_first = world;
+    remove = remove_except_protected;
+    for (self = startoflist; self; self = self.initialize_entity_next)
+    {
+       self.remove_except_protected_forbidden = 1;
+    }
     for (self = startoflist; self; )
     {
         entity e;
@@ -1823,6 +1816,7 @@ void InitializeEntitiesRun()
         self.initialize_entity_order = 0;
         self.initialize_entity = func_null;
         self.initialize_entity_next = world;
+       self.remove_except_protected_forbidden = 0;
         if (self.classname == "initialize_entity")
         {
             entity e_old;
@@ -1831,9 +1825,16 @@ void InitializeEntitiesRun()
             self = e_old;
         }
         //dprint("Delayed initialization: ", self.classname, "\n");
-        func();
+        if(func != func_null)
+            func();
+        else
+        {
+            eprint(self);
+            backtrace(strcat("Null function in: ", self.classname, "\n"));
+        }
         self = e;
     }
+    remove = remove_unsafely;
 }
 
 .float uncustomizeentityforclient_set;
@@ -1985,7 +1986,8 @@ float SUB_NoImpactCheck()
        // these stop the projectile from moving, so...
        if(trace_dphitcontents == 0)
        {
-               dprint("A hit happened with zero hit contents... DEBUG THIS, this should never happen for projectiles! Projectile will self-destruct.\n");
+               //dprint("A hit happened with zero hit contents... DEBUG THIS, this should never happen for projectiles! Projectile will self-destruct.\n");
+               dprint(sprintf(_("A hit from a projectile happened with no hit contents! DEBUG THIS, this should never happen for projectiles! Profectile will self-destruct. (edict: %d, classname: %s, origin: %s)\n"), num_for_edict(self), self.classname, vtos(self.origin)));
                checkclient();
        }
     if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
@@ -2529,10 +2531,7 @@ float MoveToRandomMapLocation(entity e, float goodcontents, float badcontents, f
 
         // rule 6: we must not end up in trigger_hurt
         if (tracebox_hits_trigger_hurt(start, e.mins, e.maxs, enddown))
-        {
-            dprint("trigger_hurt! ouch! and nothing else could find it!\n");
             continue;
-        }
 
         break;
     }
@@ -2609,7 +2608,6 @@ void zcurveparticles_from_tracetoss(float effectno, vector start, vector end, ve
        zcurveparticles(effectno, start, end, end_dz, vlen(vel));
 }
 
-string GetGametype(); // g_world.qc
 void write_recordmarker(entity pl, float tstart, float dt)
 {
     GameLogEcho(strcat(":recordset:", ftos(pl.playerid), ":", ftos(dt)));
@@ -2625,15 +2623,15 @@ vector shotorg_adjustfromclient(vector vecs, float y_is_right, float allowcenter
 {
        switch(algn)
        {
-               case 1: // right
+               default:
+               case 3: // right
                        break;
 
-               case 2: // left
+               case 4: // left
                        vecs_y = -vecs_y;
                        break;
 
-               default:
-               case 3:
+               case 1:
                        if(allowcenter) // 2: allow center handedness
                        {
                                // center
@@ -2646,7 +2644,7 @@ vector shotorg_adjustfromclient(vector vecs, float y_is_right, float allowcenter
                        }
                        break;
 
-               case 4:
+               case 2:
                        if(allowcenter) // 2: allow center handedness
                        {
                                // center
@@ -2668,11 +2666,12 @@ vector shotorg_adjust_values(vector vecs, float y_is_right, float visual, float
        string s;
        vector v;
 
-       if (cvar("g_shootfromeye"))
+       if (autocvar_g_shootfromeye)
        {
                if (visual)
                {
-                       vecs = shotorg_adjustfromclient(vecs, y_is_right, TRUE, algn);
+                       vecs_y = 0;
+                       vecs_z -= 2;
                }
                else
                {
@@ -2680,19 +2679,12 @@ vector shotorg_adjust_values(vector vecs, float y_is_right, float visual, float
                        vecs_z = 0;
                }
        }
-       else if (cvar("g_shootfromcenter"))
+       else if (autocvar_g_shootfromcenter)
        {
-               if (visual)
-               {
-                       vecs = shotorg_adjustfromclient(vecs, y_is_right, TRUE, algn);
-               }
-               else
-               {
-                       vecs_y = 0;
-                       vecs_z -= 2;
-               }
+               vecs_y = 0;
+               vecs_z -= 2;
        }
-       else if ((s = cvar_string("g_shootfromfixedorigin")) != "")
+       else if ((s = autocvar_g_shootfromfixedorigin) != "")
        {
                v = stov(s);
                if (y_is_right)
@@ -2702,9 +2694,9 @@ vector shotorg_adjust_values(vector vecs, float y_is_right, float visual, float
                vecs_y = v_y;
                vecs_z = v_z;
        }
-       else if (cvar("g_shootfromclient"))
+       else if (autocvar_g_shootfromclient)
        {
-               vecs = shotorg_adjustfromclient(vecs, y_is_right, (cvar("g_shootfromclient") >= 2), algn);
+               vecs = shotorg_adjustfromclient(vecs, y_is_right, (autocvar_g_shootfromclient >= 2), algn);
        }
        return vecs;
 }
@@ -2842,65 +2834,65 @@ void SoundEntity_Detach(entity pl)
 float ParseCommandPlayerSlotTarget_firsttoken;
 entity GetCommandPlayerSlotTargetFromTokenizedCommand(float tokens, float idx) // idx = start index
 {
-    string s;
-    entity e, head;
-    float n;
+       string s;
+       entity e, head;
+       float n;
 
-    s = string_null;
+       s = string_null;
 
-    ParseCommandPlayerSlotTarget_firsttoken = -1;
+       ParseCommandPlayerSlotTarget_firsttoken = -1;
 
-    if (tokens > idx)
-    {
-        if (substring(argv(idx), 0, 1) == "#")
-        {
-            s = substring(argv(idx), 1, -1);
-            ++idx;
-            if (s == "")
-                if (tokens > idx)
-                {
-                    s = argv(idx);
-                    ++idx;
-                }
+       if (tokens > idx)
+       {
+               if (substring(argv(idx), 0, 1) == "#")
+               {
+                       s = substring(argv(idx), 1, -1);
+                       ++idx;
+                       if (s == "") if (tokens > idx)
+                       {
+                               s = argv(idx);
+                               ++idx;
+                       }
                        ParseCommandPlayerSlotTarget_firsttoken = idx;
-            if (s == ftos(stof(s)))
-            {
-                e = edict_num(stof(s));
-                if (e.flags & FL_CLIENT)
-                    return e;
-            }
-        }
-        else
-        {
-            // it must be a nick name
-            s = argv(idx);
-            ++idx;
+                       n = stof(s);
+                       if (s == ftos(n) && n > 0 && n <= maxclients)
+                       {
+                               e = edict_num(n);
+                               if (e.flags & FL_CLIENT)
+                                       return e;
+                       }
+               }
+               else
+               {
+                       // it must be a nick name
+                       s = argv(idx);
+                       ++idx;
                        ParseCommandPlayerSlotTarget_firsttoken = idx;
 
-            n = 0;
-            FOR_EACH_CLIENT(head)
-            if (head.netname == s)
-            {
-                e = head;
-                ++n;
-            }
-            if (n == 1)
-                return e;
+                       n = 0;
+                       FOR_EACH_CLIENT(head)
+                               if (head.netname == s)
+                               {
+                                       e = head;
+                                       ++n;
+                               }
+                       if (n == 1)
+                               return e;
 
-            s = strdecolorize(s);
-            n = 0;
-            FOR_EACH_CLIENT(head)
-            if (strdecolorize(head.netname) == s)
-            {
-                e = head;
-                ++n;
-            }
-            if (n == 1)
-                return e;
-        }
-    }
+                       s = strdecolorize(s);
+                       n = 0;
+                       FOR_EACH_CLIENT(head)
+                               if (strdecolorize(head.netname) == s)
+                               {
+                                       e = head;
+                                       ++n;
+                               }
+                       if (n == 1)
+                               return e;
+               }
+       }
 
-    return world;
+       return world;
 }
 
 .float scale2;