]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/weapons/selection.qc
Declare more ints as ints
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / selection.qc
index c232795919afc01e45aeb2c39903740f6127d417..5ea0a5d9d842c8690cdf979cd7a9c717e5439477 100644 (file)
@@ -1,11 +1,25 @@
+#if defined(CSQC)
+#elif defined(MENUQC)
+#elif defined(SVQC)
+       #include "../../dpdefs/progsdefs.qh"
+    #include "../../dpdefs/dpextensions.qh"
+    #include "../../common/constants.qh"
+    #include "../../common/util.qh"
+    #include "../../common/weapons/weapons.qh"
+    #include "selection.qh"
+    #include "weaponsystem.qh"
+    #include "../t_items.qh"
+    #include "../autocvars.qh"
+    #include "../defs.qh"
+#endif
+
 // switch between weapons
-void Send_WeaponComplain(entity e, float wpn, string wpnname, float type)
+void Send_WeaponComplain(entity e, float wpn, float type)
 {
        msg_entity = e;
        WriteByte(MSG_ONE, SVC_TEMPENTITY);
        WriteByte(MSG_ONE, TE_CSQC_WEAPONCOMPLAIN);
        WriteByte(MSG_ONE, wpn);
-       WriteString(MSG_ONE, wpnname);
        WriteByte(MSG_ONE, type);
 }
 
@@ -19,7 +33,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
 
        if(wpn == WEP_HOOK && !g_grappling_hook && autocvar_g_nades && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(wpn)))
                complain = 0;
-               
+
        if(complain)
                self.hasweapon_complain_spam = time + 0.2;
 
@@ -27,7 +41,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))
        {
@@ -58,12 +72,12 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
                                if(IS_REAL_CLIENT(cl))
                                {
                                        play2(cl, "weapons/unavailable.wav");
-                                       Send_WeaponComplain (cl, wpn, W_Name(wpn), 0);
+                                       Send_WeaponComplain (cl, wpn, 0);
                                }
-                               return FALSE;
+                               return false;
                        }
                }
-               return TRUE;
+               return true;
        }
        if (complain)
        {
@@ -71,26 +85,22 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
                // Report Proper Weapon Status / Modified Weapon Ownership Message
                if (weaponsInMap & WepSet_FromWeapon(wpn))
                {
-                       Send_WeaponComplain(cl, wpn, W_Name(wpn), 1);
+                       Send_WeaponComplain(cl, wpn, 1);
 
                        if(autocvar_g_showweaponspawns)
                        {
                                entity e;
-                               string s;
-
-                               e = get_weaponinfo(wpn);
-                               s = e.model2;
 
                                for(e = world; (e = findfloat(e, weapon, wpn)); )
                                {
-                                       if(e.classname == "droppedweapon")
+                                       if(e.classname == "droppedweapon" && autocvar_g_showweaponspawns < 2)
                                                continue;
-                                       if not(e.flags & FL_ITEM)
+                                       if(!(e.flags & FL_ITEM))
                                                continue;
                                        WaypointSprite_Spawn(
-                                               s,
+                                               (get_weaponinfo(wpn)).wpmodel,
                                                1, 0,
-                                               world, e.origin,
+                                               world, e.origin + ('0 0 1' * e.maxs.z) * 1.2,
                                                self, 0,
                                                world, enemy,
                                                0,
@@ -101,23 +111,24 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
                }
                else
                {
-                       Send_WeaponComplain (cl, wpn, W_Name(wpn), 2);
+                       Send_WeaponComplain (cl, wpn, 2);
                }
 
                play2(cl, "weapons/unavailable.wav");
        }
-       return FALSE;
+       return false;
 }
 
 float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain, float skipmissing)
 {
        // 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;
        float weaponcur;
+       entity wep;
 
        if(skipmissing || pl.selectweapon == 0)
                weaponcur = pl.switchweapon;
@@ -127,19 +138,36 @@ 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);
+               wep = get_weaponinfo(weaponwant);
+               wepset = WepSet_FromWeapon(weaponwant);
                if(imp >= 0)
-                       if((get_weaponinfo(weaponwant)).impulse != imp)
-                               continue;
+               if(wep.impulse != imp)
+                       continue;
+
+               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;
+               }
+
+               // skip weapons we don't own that aren't normal and aren't in the map
+               if(!(pl.weapons & wepset))
+               if(!(weaponsInMap & wepset))
+               if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other)
+                       continue;
 
                ++c;
 
-               if(!skipmissing || client_hasweapon(pl, weaponwant, TRUE, FALSE))
+               if(!skipmissing || client_hasweapon(pl, weaponwant, true, false))
                {
                        if(switchtonext)
                                return weaponwant;
@@ -168,19 +196,36 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa
        if(complain)
        {
                self.weaponcomplainindex += 1;
-               c = mod(self.weaponcomplainindex, c) + 1;
+               c = (self.weaponcomplainindex % c) + 1;
                rest = weaponorder;
                while(rest != "")
                {
                        weaponwant = stof(car(rest)); rest = cdr(rest);
+                       wep = get_weaponinfo(weaponwant);
+                       wepset = WepSet_FromWeapon(weaponwant);
                        if(imp >= 0)
-                               if((get_weaponinfo(weaponwant)).impulse != imp)
+                               if(wep.impulse != imp)
                                        continue;
 
+                       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;
+                       }
+
+                       // skip weapons we don't own that aren't normal and aren't in the map
+                       if(!(pl.weapons & wepset))
+                       if(!(weaponsInMap & wepset))
+                       if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other)
+                               continue;
+
                        --c;
                        if(c == 0)
                        {
-                               client_hasweapon(pl, weaponwant, TRUE, TRUE);
+                               client_hasweapon(pl, weaponwant, true, true);
                                break;
                        }
                }
@@ -217,18 +262,18 @@ void W_SwitchWeapon(float imp)
 {
        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 { WEP_ACTION(self.weapon, WR_RELOAD); }
+       else if(!forbidWeaponUse()) { WEP_ACTION(self.weapon, WR_RELOAD); }
 }
 
 void W_CycleWeapon(string weaponorder, float dir)
 {
        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);
 }
@@ -266,7 +311,7 @@ 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))
+       if(client_hasweapon(self, self.cnt, true, false))
                W_SwitchWeapon(self.cnt);
        else
                W_SwitchToOtherWeapon(self);