]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/weapons/selection.qc
Merge branch 'master' into TimePath/universal_weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / selection.qc
index f7f3cde51230e2af87ee885741e67be068b7473d..f145799c1ac416cdda140db0626685dbb572431b 100644 (file)
@@ -1,3 +1,12 @@
+#include "selection.qh"
+#include "../_all.qh"
+
+#include "weaponsystem.qh"
+#include "../t_items.qh"
+#include "../../common/constants.qh"
+#include "../../common/util.qh"
+#include "../../common/weapons/all.qh"
+
 // switch between weapons
 void Send_WeaponComplain(entity e, float wpn, float type)
 {
@@ -9,16 +18,15 @@ void Send_WeaponComplain(entity e, float wpn, float type)
 }
 
 float client_hasweapon(entity cl, float wpn, float andammo, float complain)
-{
+{SELFPARAM();
        float f;
-       entity oldself;
 
        if(time < self.hasweapon_complain_spam)
                complain = 0;
 
-       if(wpn == WEP_HOOK && !g_grappling_hook && autocvar_g_nades && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(wpn)))
+       if(wpn == WEP_HOOK.m_id && !g_grappling_hook && autocvar_g_nades && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(wpn)))
                complain = 0;
-               
+
        if(complain)
                self.hasweapon_complain_spam = time + 0.2;
 
@@ -26,7 +34,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
        {
                if (complain)
                        sprint(self, "Invalid weapon\n");
-               return FALSE;
+               return false;
        }
        if (cl.weapons & WepSet_FromWeapon(wpn))
        {
@@ -38,31 +46,30 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
                        }
                        else
                        {
-                               oldself = self;
-                               self = cl;
-                               f = WEP_ACTION(wpn, WR_CHECKAMMO1);
-                               f = f + WEP_ACTION(wpn, WR_CHECKAMMO2);
+                               setself(cl);
+                               f = _WEP_ACTION(wpn, WR_CHECKAMMO1);
+                               f = f + _WEP_ACTION(wpn, WR_CHECKAMMO2);
 
                                // always allow selecting the Mine Layer if we placed mines, so that we can detonate them
                                entity mine;
-                               if(wpn == WEP_MINE_LAYER)
+                               if(wpn == WEP_MINE_LAYER.m_id)
                                for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
                                        f = 1;
 
-                               self = oldself;
+                               setself(this);
                        }
                        if (!f)
                        {
                                if (complain)
                                if(IS_REAL_CLIENT(cl))
                                {
-                                       play2(cl, "weapons/unavailable.wav");
+                                       play2(cl, SND(UNAVAILABLE));
                                        Send_WeaponComplain (cl, wpn, 0);
                                }
-                               return FALSE;
+                               return false;
                        }
                }
-               return TRUE;
+               return true;
        }
        if (complain)
        {
@@ -82,15 +89,16 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
                                                continue;
                                        if(!(e.flags & FL_ITEM))
                                                continue;
-                                       WaypointSprite_Spawn(
-                                               (get_weaponinfo(wpn)).wpmodel,
+                                       entity wp = WaypointSprite_Spawn(
+                                               WP_Weapon,
                                                1, 0,
-                                               world, e.origin + ('0 0 1' * e.maxs_z) * 1.2,
+                                               world, e.origin + ('0 0 1' * e.maxs.z) * 1.2,
                                                self, 0,
                                                world, enemy,
                                                0,
-                                               RADARICON_NONE, '0 0 0'
+                                               RADARICON_NONE
                                        );
+                                       wp.wp_extra = wpn;
                                }
                        }
                }
@@ -99,17 +107,16 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
                        Send_WeaponComplain (cl, wpn, 2);
                }
 
-               play2(cl, "weapons/unavailable.wav");
+               play2(cl, SND(UNAVAILABLE));
        }
-       return FALSE;
+       return false;
 }
 
 float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain, float skipmissing)
-{
+{SELFPARAM();
        // We cannot tokenize in this function, as GiveItems calls this
        // function. Thus we must use car/cdr.
-       float weaponwant, first_valid, prev_valid, switchtonext, switchtolast, c;
-       string rest;
+       float weaponwant, first_valid, prev_valid, switchtonext, switchtolast;
        WepSet wepset = '0 0 0';
        switchtonext = switchtolast = 0;
        first_valid = prev_valid = 0;
@@ -124,9 +131,9 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa
        if(dir == 0)
                switchtonext = 1;
 
-       c = 0;
+       int c = 0;
 
-       rest = weaponorder;
+       string rest = weaponorder;
        while(rest != "")
        {
                weaponwant = stof(car(rest)); rest = cdr(rest);
@@ -136,13 +143,13 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa
                if(wep.impulse != imp)
                        continue;
 
-               float i, have_other = FALSE;
+               float i, have_other = false;
                for(i = WEP_FIRST; i <= WEP_LAST; ++i)
                {
                        if(i != weaponwant)
                        if((get_weaponinfo(i)).impulse == imp || imp < 0)
                        if((pl.weapons & WepSet_FromWeapon(i)) || (weaponsInMap & WepSet_FromWeapon(i)))
-                               have_other = TRUE;
+                               have_other = true;
                }
 
                // skip weapons we don't own that aren't normal and aren't in the map
@@ -153,7 +160,7 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa
 
                ++c;
 
-               if(!skipmissing || client_hasweapon(pl, weaponwant, TRUE, FALSE))
+               if(!skipmissing || client_hasweapon(pl, weaponwant, true, false))
                {
                        if(switchtonext)
                                return weaponwant;
@@ -193,13 +200,13 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa
                                if(wep.impulse != imp)
                                        continue;
 
-                       float i, have_other = FALSE;
+                       float i, have_other = false;
                        for(i = WEP_FIRST; i <= WEP_LAST; ++i)
                        {
                                if(i != weaponwant)
                                if((get_weaponinfo(i)).impulse == imp || imp < 0)
                                if((pl.weapons & WepSet_FromWeapon(i)) || (weaponsInMap & WepSet_FromWeapon(i)))
-                                       have_other = TRUE;
+                                       have_other = true;
                        }
 
                        // skip weapons we don't own that aren't normal and aren't in the map
@@ -211,7 +218,7 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa
                        --c;
                        if(c == 0)
                        {
-                               client_hasweapon(pl, weaponwant, TRUE, TRUE);
+                               client_hasweapon(pl, weaponwant, true, true);
                                break;
                        }
                }
@@ -245,27 +252,27 @@ void W_SwitchToOtherWeapon(entity pl)
 }
 
 void W_SwitchWeapon(float imp)
-{
+{SELFPARAM();
        if (self.switchweapon != imp)
        {
-               if (client_hasweapon(self, imp, TRUE, TRUE))
+               if (client_hasweapon(self, imp, true, true))
                        W_SwitchWeapon_Force(self, imp);
                else
                        self.selectweapon = imp; // update selectweapon ANYWAY
        }
-       else if(!forbidWeaponUse()) { WEP_ACTION(self.weapon, WR_RELOAD); }
+       else if(!forbidWeaponUse(self)) { _WEP_ACTION(self.weapon, WR_RELOAD); }
 }
 
 void W_CycleWeapon(string weaponorder, float dir)
-{
+{SELFPARAM();
        float w;
-       w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1, TRUE);
+       w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1, true);
        if(w > 0)
                W_SwitchWeapon(w);
 }
 
 void W_NextWeaponOnImpulse(float imp)
-{
+{SELFPARAM();
        float w;
        w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1, (self.cvar_cl_weaponimpulsemode == 0));
        if(w > 0)
@@ -274,7 +281,7 @@ void W_NextWeaponOnImpulse(float imp)
 
 // next weapon
 void W_NextWeapon(float list)
-{
+{SELFPARAM();
        if(list == 0)
                W_CycleWeapon(weaponorder_byid, -1);
        else if(list == 1)
@@ -285,7 +292,7 @@ void W_NextWeapon(float list)
 
 // prev weapon
 void W_PreviousWeapon(float list)
-{
+{SELFPARAM();
        if(list == 0)
                W_CycleWeapon(weaponorder_byid, +1);
        else if(list == 1)
@@ -296,8 +303,8 @@ void W_PreviousWeapon(float list)
 
 // previously used if exists and has ammo, (second) best otherwise
 void W_LastWeapon(void)
-{
-       if(client_hasweapon(self, self.cnt, TRUE, FALSE))
+{SELFPARAM();
+       if(client_hasweapon(self, self.cnt, true, false))
                W_SwitchWeapon(self.cnt);
        else
                W_SwitchToOtherWeapon(self);