]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/weapons/selection.qc
Merge branch 'master' into Mario/wepent_experimental
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / selection.qc
index da663109444111c49fbf3fcf5637f37ace75d3cf..7abe976ae2bc0d6c19f4732e2f05859e8cac96eb 100644 (file)
@@ -3,11 +3,13 @@
 #include "weaponsystem.qh"
 #include <common/t_items.qh>
 #include <common/constants.qh>
+#include <common/net_linked.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>
 
 // switch between weapons
 void Send_WeaponComplain(entity e, float wpn, float type)
@@ -21,7 +23,7 @@ void Send_WeaponComplain(entity e, float wpn, float type)
 void Weapon_whereis(Weapon this, entity cl)
 {
        if (!autocvar_g_showweaponspawns) return;
-       IL_EACH(g_items, it.weapon == this.m_id,
+       IL_EACH(g_items, it.weapon == this.m_id && (it.ItemStatus & ITS_AVAILABLE),
        {
                if (it.classname == "droppedweapon" && autocvar_g_showweaponspawns < 2)
                        continue;
@@ -38,7 +40,7 @@ void Weapon_whereis(Weapon this, entity cl)
        });
 }
 
-bool client_hasweapon(entity this, Weapon wpn, float andammo, bool complain)
+bool client_hasweapon(entity this, Weapon wpn, .entity weaponentity, float andammo, bool complain)
 {
        float f = 0;
 
@@ -69,11 +71,11 @@ bool client_hasweapon(entity this, Weapon wpn, float andammo, bool complain)
                        }
                        else
                        {
-                               f = wpn.wr_checkammo1(wpn, this) + wpn.wr_checkammo2(wpn, this);
+                               f = wpn.wr_checkammo1(wpn, this, weaponentity) + wpn.wr_checkammo2(wpn, this, weaponentity);
 
                                // always allow selecting the Mine Layer if we placed mines, so that we can detonate them
                                if(wpn == WEP_MINE_LAYER)
-                                       IL_EACH(g_mines, it.owner == this,
+                                       IL_EACH(g_mines, it.owner == this && it.weaponentity_fld == weaponentity,
                                        {
                                                f = 1;
                                                break; // no need to continue
@@ -166,7 +168,7 @@ float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, fl
 
                ++c;
 
-               if(!skipmissing || client_hasweapon(this, wep, true, false))
+               if(!skipmissing || client_hasweapon(this, wep, weaponentity, true, false))
                {
                        if(switchtonext)
                                return weaponwant;
@@ -223,7 +225,7 @@ float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, fl
                        --c;
                        if(c == 0)
                        {
-                               client_hasweapon(this, wep, true, true);
+                               client_hasweapon(this, wep, weaponentity, true, true);
                                break;
                        }
                }
@@ -248,12 +250,12 @@ void W_SwitchToOtherWeapon(entity this, .entity weaponentity)
        if (this.weapons & set)
        {
                this.weapons &= ~set;
-               ww = w_getbestweapon(this);
+               ww = w_getbestweapon(this, weaponentity);
                this.weapons |= set;
        }
        else
        {
-               ww = w_getbestweapon(this);
+               ww = w_getbestweapon(this, weaponentity);
        }
        if (ww == WEP_Null) return;
        W_SwitchWeapon_Force(this, ww, weaponentity);
@@ -263,7 +265,7 @@ void W_SwitchWeapon(entity this, Weapon w, .entity weaponentity)
 {
        if(this.(weaponentity).m_switchweapon != w)
        {
-               if(client_hasweapon(this, w, true, true))
+               if(client_hasweapon(this, w, weaponentity, true, true))
                        W_SwitchWeapon_Force(this, w, weaponentity);
                else
                        this.(weaponentity).selectweapon = w.m_id; // update selectweapon anyway
@@ -316,8 +318,8 @@ void W_PreviousWeapon(entity this, float list, .entity weaponentity)
 // previously used if exists and has ammo, (second) best otherwise
 void W_LastWeapon(entity this, .entity weaponentity)
 {
-       Weapon wep = Weapons_from(this.cnt);
-       if (client_hasweapon(this, wep, true, false))
+       Weapon wep = Weapons_from(this.(weaponentity).cnt);
+       if (client_hasweapon(this, wep, weaponentity, true, false))
                W_SwitchWeapon(this, wep, weaponentity);
        else
                W_SwitchToOtherWeapon(this, weaponentity);