]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/weapons/selection.qc
Fix #2850 "xonotic crashes when pressing restart level after match end in campaign"
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / selection.qc
index f1866eab089311a0ce2c2a052d6b9b3fbaf00031..1af0881c3400b7df6758b7e275405769a5c1669e 100644 (file)
@@ -1,16 +1,18 @@
 #include "selection.qh"
 
-#include "weaponsystem.qh"
-#include <common/t_items.qh>
-#include <server/items.qh>
 #include <common/constants.qh>
+#include <common/items/item.qh>
+#include <common/mapobjects/triggers.qh>
+#include <common/mutators/mutator/waypoints/waypointsprites.qh>
 #include <common/net_linked.qh>
+#include <common/replicate.qh>
+#include <common/state.qh>
 #include <common/util.qh>
-#include <common/items/item.qh>
 #include <common/weapons/_all.qh>
-#include <common/state.qh>
-#include <common/mutators/mutator/waypoints/waypointsprites.qh>
 #include <common/wepent.qh>
+#include <server/items/items.qh>
+#include <server/items/spawning.qh>
+#include <server/weapons/weaponsystem.qh>
 
 // switch between weapons
 void Send_WeaponComplain(entity e, float wpn, float type)
@@ -26,7 +28,7 @@ void Weapon_whereis(Weapon this, entity cl)
        if (!autocvar_g_showweaponspawns) return;
        IL_EACH(g_items, it.weapon == this.m_id && (!it.team || (it.ItemStatus & ITS_AVAILABLE)),
        {
-               if (Item_IsLoot(it) && (autocvar_g_showweaponspawns < 2))
+               if (ITEM_IS_LOOT(it) && (autocvar_g_showweaponspawns < 2))
                {
                        continue;
                }
@@ -100,6 +102,7 @@ bool client_hasweapon(entity this, Weapon wpn, .entity weaponentity, float andam
                return true;
        }
        if (complain)
+       if(IS_REAL_CLIENT(this))
        {
                // DRESK - 3/16/07
                // Report Proper Weapon Status / Modified Weapon Ownership Message
@@ -151,7 +154,7 @@ float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, fl
        while(rest != "")
        {
                weaponwant = stof(car(rest)); rest = cdr(rest);
-               wep = Weapons_from(weaponwant);
+               wep = REGISTRY_GET(Weapons, weaponwant);
                wepset = wep.m_wepset;
                if(imp >= 0)
                if(wep.impulse != imp)
@@ -207,7 +210,7 @@ float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, fl
                while(rest != "")
                {
                        weaponwant = stof(car(rest)); rest = cdr(rest);
-                       wep = Weapons_from(weaponwant);
+                       wep = REGISTRY_GET(Weapons, weaponwant);
                        wepset = wep.m_wepset;
                        if(imp >= 0)
                                if(wep.impulse != imp)
@@ -241,9 +244,10 @@ float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, fl
 void W_SwitchWeapon_Force(Player this, Weapon wep, .entity weaponentity)
 {
        TC(Weapon, wep);
-       this.(weaponentity).cnt = this.(weaponentity).m_switchweapon.m_id;
-       this.(weaponentity).m_switchweapon = wep;
-       this.(weaponentity).selectweapon = wep.m_id;
+       entity w_ent = this.(weaponentity);
+       w_ent.cnt = w_ent.m_switchweapon.m_id;
+       w_ent.m_switchweapon = wep;
+       w_ent.selectweapon = wep.m_id;
 }
 
 // perform weapon to attack (weaponstate and attack_finished check is here)
@@ -281,7 +285,7 @@ bool W_SwitchWeapon(entity this, Weapon w, .entity weaponentity)
                        return false;
                }
        }
-       else if(!weaponLocked(this) && CS(this).cvar_cl_weapon_switch_reload)
+       else if(!weaponLocked(this) && CS_CVAR(this).cvar_cl_weapon_switch_reload)
        {
                entity actor = this;
                w.wr_reload(w, actor, weaponentity);
@@ -292,7 +296,7 @@ bool W_SwitchWeapon(entity this, Weapon w, .entity weaponentity)
 
 void W_SwitchWeapon_TryOthers(entity this, Weapon w, .entity weaponentity)
 {
-       if(!W_SwitchWeapon(this, w, weaponentity) && CS(this).cvar_cl_weapon_switch_fallback_to_impulse)
+       if(!W_SwitchWeapon(this, w, weaponentity) && CS_CVAR(this).cvar_cl_weapon_switch_fallback_to_impulse)
                W_NextWeaponOnImpulse(this, w.impulse, weaponentity);
 }
 
@@ -301,15 +305,15 @@ void W_CycleWeapon(entity this, string weaponorder, float dir, .entity weaponent
        float w;
        w = W_GetCycleWeapon(this, weaponorder, dir, -1, 1, true, weaponentity);
        if(w > 0)
-               W_SwitchWeapon(this, Weapons_from(w), weaponentity);
+               W_SwitchWeapon(this, REGISTRY_GET(Weapons, w), weaponentity);
 }
 
 void W_NextWeaponOnImpulse(entity this, float imp, .entity weaponentity)
 {
        float w;
-       w = W_GetCycleWeapon(this, CS(this).cvar_cl_weaponpriority, +1, imp, 1, (CS(this).cvar_cl_weaponimpulsemode == 0), weaponentity);
+       w = W_GetCycleWeapon(this, CS_CVAR(this).cvar_cl_weaponpriority, +1, imp, 1, (CS_CVAR(this).cvar_cl_weaponimpulsemode == 0), weaponentity);
        if(w > 0)
-               W_SwitchWeapon(this, Weapons_from(w), weaponentity);
+               W_SwitchWeapon(this, REGISTRY_GET(Weapons, w), weaponentity);
 }
 
 // next weapon
@@ -318,9 +322,9 @@ void W_NextWeapon(entity this, int list, .entity weaponentity)
        if(list == 0)
                W_CycleWeapon(this, weaponorder_byid, -1, weaponentity);
        else if(list == 1)
-               W_CycleWeapon(this, CS(this).weaponorder_byimpulse, -1, weaponentity);
+               W_CycleWeapon(this, CS_CVAR(this).weaponorder_byimpulse, -1, weaponentity);
        else if(list == 2)
-               W_CycleWeapon(this, CS(this).cvar_cl_weaponpriority, -1, weaponentity);
+               W_CycleWeapon(this, CS_CVAR(this).cvar_cl_weaponpriority, -1, weaponentity);
 }
 
 // prev weapon
@@ -329,17 +333,27 @@ void W_PreviousWeapon(entity this, float list, .entity weaponentity)
        if(list == 0)
                W_CycleWeapon(this, weaponorder_byid, +1, weaponentity);
        else if(list == 1)
-               W_CycleWeapon(this, CS(this).weaponorder_byimpulse, +1, weaponentity);
+               W_CycleWeapon(this, CS_CVAR(this).weaponorder_byimpulse, +1, weaponentity);
        else if(list == 2)
-               W_CycleWeapon(this, CS(this).cvar_cl_weaponpriority, +1, weaponentity);
+               W_CycleWeapon(this, CS_CVAR(this).cvar_cl_weaponpriority, +1, weaponentity);
 }
 
 // previously used if exists and has ammo, (second) best otherwise
 void W_LastWeapon(entity this, .entity weaponentity)
 {
-       Weapon wep = Weapons_from(this.(weaponentity).cnt);
+       Weapon wep = REGISTRY_GET(Weapons, this.(weaponentity).cnt);
        if (client_hasweapon(this, wep, weaponentity, true, false))
                W_SwitchWeapon(this, wep, weaponentity);
        else
                W_SwitchToOtherWeapon(this, weaponentity);
 }
+
+// fix switchweapon (needed when spectating is disabled, as PutClientInServer comes too early)
+REPLICATE_APPLYCHANGE("cl_weaponpriority",
+       for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+       {
+               .entity weaponentity = weaponentities[slot];
+               if (this.(weaponentity) && (this.(weaponentity).m_weapon != WEP_Null || slot == 0))
+                       this.(weaponentity).m_switchweapon = w_getbestweapon(this, weaponentity);
+       }
+);