]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
get rid of W_WeaponBit
authorRudolf Polzer <divverent@alientrap.org>
Sun, 4 Mar 2012 15:25:33 +0000 (16:25 +0100)
committerRudolf Polzer <divverent@alientrap.org>
Sun, 4 Mar 2012 15:25:33 +0000 (16:25 +0100)
14 files changed:
qcsrc/common/items.qh
qcsrc/server/bot/havocbot/havocbot.qc
qcsrc/server/bot/havocbot/role_onslaught.qc
qcsrc/server/bot/havocbot/roles.qc
qcsrc/server/cl_client.qc
qcsrc/server/cl_player.qc
qcsrc/server/cl_weapons.qc
qcsrc/server/cl_weaponsystem.qc
qcsrc/server/defs.qh
qcsrc/server/g_damage.qc
qcsrc/server/mutators/gamemode_nexball.qc
qcsrc/server/mutators/mutator_nix.qc
qcsrc/server/t_items.qc
qcsrc/server/w_common.qc

index 1cae4d133d918788dbfd3d2ecd4c6bbad4205eb3..250aee11215c42100cdbc135b07d3956b5525e42 100644 (file)
@@ -101,47 +101,45 @@ void register_weapons_done();
 # define WEPSET_OR_EE(e,o) ((e).weapons |= (o).weapons)
 # define WEPSET_AND_EE(e,o) ((e).weapons &= (o).weapons)
 # define WEPSET_ANDNOT_EE(e,o) ((e).weapons &~= (o).weapons)
-# define WEPSET_TEST_EE(e,o) ((e).weapons & (o).weapons)
-# define WEPSET_CONTAINS_EE(e,o) (((e).weapons & (o).weapons) == (e).weapons)
+# define WEPSET_CONTAINS_ANY_EE(e,o) ((e).weapons & (o).weapons)
+# define WEPSET_CONTAINS_ALL_EE(e,o) (((e).weapons & (o).weapons) == (e).weapons)
 
 # define WEPSET_COPY_EA(e,a) ((e).weapons = (a))
 # define WEPSET_EQ_EA(e,a) ((e).weapons == (a))
 # define WEPSET_OR_EA(e,a) ((e).weapons |= (a))
 # define WEPSET_AND_EA(e,a) ((e).weapons &= (a))
 # define WEPSET_ANDNOT_EA(e,a) ((e).weapons &~= (a))
-# define WEPSET_TEST_EA(e,a) ((e).weapons & (a))
-# define WEPSET_CONTAINS_EA(e,a) (((e).weapons & (a)) == (a))
+# define WEPSET_CONTAINS_ANY_EA(e,a) ((e).weapons & (a))
+# define WEPSET_CONTAINS_ALL_EA(e,a) (((e).weapons & (a)) == (a))
 
 # define WEPSET_COPY_EW(e,w) ((e).weapons = power2of((w) - WEP_FIRST))
 # define WEPSET_EQ_EW(e,w) ((e).weapons == power2of((w) - WEP_FIRST))
 # define WEPSET_OR_EW(e,w) ((e).weapons |= power2of((w) - WEP_FIRST))
 # define WEPSET_AND_EW(e,w) ((e).weapons &= power2of((w) - WEP_FIRST))
 # define WEPSET_ANDNOT_EW(e,w) ((e).weapons &~= power2of((w) - WEP_FIRST))
-// no TEST necessary here, CONTAINS does the same
-# define WEPSET_TEST_EW(e,w) ((e).weapons & power2of((w) - WEP_FIRST))
+# define WEPSET_CONTAINS_EW(e,w) ((e).weapons & power2of((w) - WEP_FIRST))
 
 # define WEPSET_COPY_AE(a,e) ((a) = (e).weapons)
 # define WEPSET_EQ_AE(a,e) ((a) == (e).weapons)
 # define WEPSET_OR_AE(a,e) ((a) |= (e).weapons)
 # define WEPSET_AND_AE(a,e) ((a) &= (e).weapons)
 # define WEPSET_ANDNOT_AE(a,e) ((a) &~= (e).weapons)
-# define WEPSET_TEST_AE(a,e) ((a) & (e).weapons)
-# define WEPSET_CONTAINS_AE(a,e) (((a) & (e).weapons) == (e))
+# define WEPSET_CONTAINS_ANY_AE(a,e) ((a) & (e).weapons)
+# define WEPSET_CONTAINS_ALL_AE(a,e) (((a) & (e).weapons) == (e))
 
 # define WEPSET_COPY_AA(a,b) ((a) = (b))
 # define WEPSET_EQ_AA(a,b) ((a) == (b))
 # define WEPSET_OR_AA(a,b) ((a) |= (b))
 # define WEPSET_AND_AA(a,b) ((a) &= (b))
 # define WEPSET_ANDNOT_AA(a,b) ((a) &~= (b))
-# define WEPSET_TEST_AA(a,b) ((a) & (b))
-# define WEPSET_CONTAINS_AA(a,b) (((a) & (b)) == (b))
+# define WEPSET_CONTAINS_ANY_AA(a,b) ((a) & (b))
+# define WEPSET_CONTAINS_ALL_AA(a,b) (((a) & (b)) == (b))
 
 # define WEPSET_COPY_AW(a,w) ((a) = power2of((w) - WEP_FIRST))
 # define WEPSET_EQ_AW(a,w) ((a) == power2of((w) - WEP_FIRST))
 # define WEPSET_OR_AW(a,w) ((a) |= power2of((w) - WEP_FIRST))
 # define WEPSET_AND_AW(a,w) ((a) &= power2of((w) - WEP_FIRST))
 # define WEPSET_ANDNOT_AW(a,w) ((a) &~= power2of((w) - WEP_FIRST))
-// no TEST necessary here, CONTAINS does the same
 # define WEPSET_CONTAINS_AW(a,w) ((a) & power2of((w) - WEP_FIRST))
 
 # ifdef CSQC
index 42b829ffd401213e1b0c2cbad0a78c8e2f8fcc27..a97f184d561691bc88e5c2b32318a3a0eea21cc0 100644 (file)
@@ -168,7 +168,7 @@ void havocbot_ai()
                        for(i = WEP_FIRST; i <= WEP_LAST; ++i)
                        {
                                e = get_weaponinfo(i);
-                               if (WEPSET_TEST_EE(self, e) && (e.spawnflags & WEP_FLAG_RELOADABLE) && (self.weapon_load[i] < cvar(strcat("g_balance_", e.netname, "_reload_ammo"))))
+                               if (WEPSET_CONTAINS_EW(self, i) && (e.spawnflags & WEP_FLAG_RELOADABLE) && (self.weapon_load[i] < cvar(strcat("g_balance_", e.netname, "_reload_ammo"))))
                                        self.switchweapon = i;
                        }
                }
index f37f821f118e595a1aae8088c2112f40bf0957f3..90150e2ab3c4d027b6219c905497ea821563c858 100644 (file)
@@ -38,7 +38,7 @@ void havocbot_goalrating_ons_offenseitems(float ratingscale, vector org, float s
        for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
        {
                // Find weapon
-               if(WEPSET_TEST_EW(self, i))
+               if(WEPSET_CONTAINS_EW(self, i))
                if(++c>=4)
                        break;
        }
index d9cddacbd2ed4b9907ec236f074f344b01128160..ac8ddd161b05c749a1e94bf79b29799bf2674c95 100644 (file)
@@ -86,7 +86,7 @@ void havocbot_goalrating_items(float ratingscale, vector org, float sradius)
                                                continue;
 
                                        if( !WEPSET_EMPTY_E(head) )
-                                       if( !WEPSET_CONTAINS_EE(player, head) )
+                                       if( !WEPSET_CONTAINS_ALL_EE(player, head) )
                                                continue;
 
                                        if (head.ammo_shells && player.ammo_shells > self.ammo_shells)
index bf4a25950f49749cc2510ff1eebe87bd065c3272..2c89b3e3e9622c3fdf44b765f5f70a8428ca4e9c 100644 (file)
@@ -749,7 +749,7 @@ void PutClientInServer (void)
                        WEPSET_COPY_EA(self, start_weapons);
                }
 
-               if(WEPSET_TEST_EA(self, WEPBIT_SUPERWEAPONS)) // exception for minstagib, as minstanex is a superweapon
+               if(WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS)) // exception for minstagib, as minstanex is a superweapon
                        self.superweapons_finished = time + autocvar_g_balance_superweapons_time;
                else
                        self.superweapons_finished = 0;
@@ -1895,7 +1895,7 @@ void player_powerups (void)
                }
                if (self.items & IT_SUPERWEAPON)
                {
-                       if (!WEPSET_TEST_EA(self, WEPBIT_SUPERWEAPONS))
+                       if (!WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS))
                        {
                                self.superweapons_finished = 0;
                                self.items = self.items - (self.items & IT_SUPERWEAPON);
@@ -1916,7 +1916,7 @@ void player_powerups (void)
                                }
                        }
                }
-               else if(WEPSET_TEST_EA(self, WEPBIT_SUPERWEAPONS))
+               else if(WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS))
                {
                        if (time < self.superweapons_finished || (self.items & IT_UNLIMITED_SUPERWEAPONS))
                        {
index 5a162742387c471883838d67a24a478e21357786..754b2ae76da61752c8b31551c884ae6fc6c7e88b 100644 (file)
@@ -360,7 +360,7 @@ void SpawnThrownWeapon (vector org, float w)
                float j;
                for(j = WEP_FIRST; j <= WEP_LAST; ++j)
                {
-                       if(self.weapons & W_WeaponBit(j))
+                       if(WEPSET_CONTAINS_EW(self, j))
                                if(W_IsWeaponThrowable(j))
                                        W_ThrowNewWeapon(self, j, FALSE, org, randomvec() * 175 + '0 0 325');
                }
index 4a12ce1850323e10f7b11282a76874cb0f426e66..60ad8eee1b997103bae2b0f44663a8c618205936 100644 (file)
@@ -163,11 +163,6 @@ string W_Name(float weaponid)
        return (get_weaponinfo(weaponid)).message;
 }
 
-float W_WeaponBit(float wpn)
-{
-       return (get_weaponinfo(wpn)).weapons;
-}
-
 float W_AmmoItemCode(float wpn)
 {
        return (get_weaponinfo(wpn)).items & IT_AMMO;
@@ -203,7 +198,7 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto
        wep.flags |= FL_TOSSED;
        wep.colormap = own.colormap;
 
-       if(W_WeaponBit(wpn) & WEPBIT_SUPERWEAPONS)
+       if(WEPSET_CONTAINS_AW(WEPBIT_SUPERWEAPONS, wpn))
        {
                if(own.items & IT_UNLIMITED_SUPERWEAPONS)
                {
@@ -213,8 +208,9 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto
                {
                        float superweapons = 1;
                        for(i = WEP_FIRST; i <= WEP_LAST; ++i)
-                               if(own.weapons & WEPBIT_SUPERWEAPONS & W_WeaponBit(i))
-                                       ++superweapons;
+                               if(WEPSET_CONTAINS_AW(WEPBIT_SUPERWEAPONS, i))
+                                       if(WEPSET_CONTAINS_EW(own, i))
+                                               ++superweapons;
                        if(superweapons <= 1)
                        {
                                wep.superweapons_finished = own.superweapons_finished;
@@ -306,7 +302,7 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto
 
 float W_IsWeaponThrowable(float w)
 {
-       float wb, wa;
+       float wa;
 
        if (!autocvar_g_pickup_items)
                return 0;
@@ -321,11 +317,8 @@ float W_IsWeaponThrowable(float w)
        if (g_nexball && w == WEP_GRENADE_LAUNCHER)
                return 0;
 
-       wb = W_WeaponBit(w);
-       if(!wb)
-               return 0;
        wa = W_AmmoItemCode(w);
-       if(start_weapons & wb)
+       if(WEPSET_CONTAINS_AW(start_weapons, w))
        {
                // start weapons that take no ammo can't be dropped (this prevents dropping the laser, as long as it continues to use no ammo)
                if(start_items & IT_UNLIMITED_WEAPON_AMMO)
@@ -340,7 +333,7 @@ float W_IsWeaponThrowable(float w)
 // toss current weapon
 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
 {
-       float w, wb;
+       float w;
        string a;
 
        w = self.weapon;
@@ -355,11 +348,10 @@ void W_ThrowWeapon(vector velo, vector delta, float doreduce)
        if(!W_IsWeaponThrowable(w))
                return;
 
-       wb = W_WeaponBit(w);
-       if(self.weapons & wb != wb)
+       if(!WEPSET_CONTAINS_EW(self, w))
                return;
+       WEPSET_ANDNOT_EW(self, w);
 
-       self.weapons &~= wb;
        W_SwitchWeapon_Force(self, w_getbestweapon(self));
        a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);
        if not(a)
@@ -459,8 +451,8 @@ void W_WeaponFrame()
        //if (self.button0)
        //      print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(self)), " >= ", ftos(self.weapon_nextthink), "\n");
 
-       float wb;
-       wb = W_WeaponBit(self.weapon);
+       float w;
+       w = self.weapon;
 
        // call the think code which may fire the weapon
        // and do so multiple times to resolve framerate dependency issues if the
@@ -470,18 +462,18 @@ void W_WeaponFrame()
        while (c < W_TICSPERFRAME)
        {
                c = c + 1;
-               if(wb && ((self.weapons & wb) == 0))
+               if(w && !WEPSET_CONTAINS_EW(self, w))
                {
                        if(self.weapon == self.switchweapon)
                                W_SwitchWeapon_Force(self, w_getbestweapon(self));
-                       wb = 0;
+                       w = 0;
                }
 
                v_forward = fo;
                v_right = ri;
                v_up = up;
 
-               if(wb)
+               if(w)
                        weapon_action(self.weapon, WR_THINK);
                else
                        weapon_action(self.weapon, WR_GONETHINK);
index 4f496e56ebb7f102ea22f58ea14d53944e49544a..d2c2546d2f3e091660282b3626e6b5521996011c 100644 (file)
@@ -727,7 +727,7 @@ void Send_WeaponComplain (entity e, float wpn, string wpnname, float type)
 
 float client_hasweapon(entity cl, float wpn, float andammo, float complain)
 {
-       float weaponbit, f;
+       float f;
        entity oldself;
 
        if(time < self.hasweapon_complain_spam)
@@ -741,8 +741,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
                        sprint(self, "Invalid weapon\n");
                return FALSE;
        }
-       weaponbit = W_WeaponBit(wpn);
-       if (cl.weapons & weaponbit)
+       if (WEPSET_CONTAINS_EW(cl, wpn))
        {
                if (andammo)
                {
@@ -783,7 +782,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
        {
                // DRESK - 3/16/07
                // Report Proper Weapon Status / Modified Weapon Ownership Message
-               if(weaponsInMap & weaponbit)
+               if (WEPSET_CONTAINS_AW(weaponsInMap, wpn))
                {
                        sprint(cl, strcat("You do not have the ^2", W_Name(wpn), "\n") );
                        Send_WeaponComplain (cl, wpn, W_Name(wpn), 1);
@@ -796,7 +795,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
                                e = get_weaponinfo(wpn);
                                s = e.model2;
 
-                               for(e = world; (e = findfloat(e, weapons, weaponbit)); )
+                               for(e = world; (e = findfloat(e, weapon, wpn)); )
                                {
                                        if(e.classname == "droppedweapon")
                                                continue;
@@ -867,10 +866,15 @@ void W_SwitchToOtherWeapon(entity pl)
 {
        // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway)
        float w, ww;
-       w = W_WeaponBit(pl.weapon);
-       pl.weapons &~= w;
-       ww = w_getbestweapon(pl);
-       pl.weapons |= w;
+       w = pl.weapon;
+       if(WEPSET_CONTAINS_EW(pl, w))
+       {
+               WEPSET_ANDNOT_EW(pl, w);
+               ww = w_getbestweapon(pl);
+               WEPSET_OR_EW(pl, w);
+       }
+       else
+               ww = w_getbestweapon(pl);
        if(ww)
                W_SwitchWeapon_Force(pl, ww);
 }
index a46c8f7e7119aad27b12b28b3692b657c0372ee0..e6fba28393a8d553a4a525164ca913ddc5ba0bc4 100644 (file)
@@ -349,7 +349,6 @@ typedef .float floatfield;
 floatfield Item_CounterField(float it);
 
 float W_AmmoItemCode(float wpn);
-float W_WeaponBit(float wpn);
 string W_Name(float weaponid);
 
 void FixIntermissionClient(entity e);
index bdaeef0a53d19d3ed48ae81cf3468b560350ffb4..ab9096c45a0cf6bb62c22314de18ca37b366fb3d 100644 (file)
@@ -141,7 +141,7 @@ void GiveFrags (entity attacker, entity targ, float f, float deathtype)
                // after a frag, exchange the current weapon (or the culprit, if detectable) by a new random weapon
                float culprit;
                culprit = DEATH_WEAPONOF(deathtype);
-               if(!culprit || !(attacker.weapons & W_WeaponBit(culprit)))
+               if(!culprit || !WEPSET_CONTAINS_EW(attacker, culprit))
                        culprit = attacker.weapon;
 
                if(g_weaponarena_random_with_laser && culprit == WEPBIT_LASER)
@@ -163,12 +163,12 @@ void GiveFrags (entity attacker, entity targ, float f, float deathtype)
                        if(w)
                        {
                                attacker.weapons |= w;
-                               attacker.weapons &~= W_WeaponBit(culprit);
+                               attacker.weapons &~= get_weaponinfo(culprit).weapons;
                        }
                }
 
                // after a frag, choose another random weapon set
-               if not(attacker.weapons & W_WeaponBit(attacker.weapon))
+               if not(WEPSET_CONTAINS_EW(attacker, attacker.weapon))
                        W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
        }
 
index 8554a12238f08c2aea42b1bec64e5017de5f2492..fd1a8fb591879f5a3152c9de6da99292eb1e343b 100644 (file)
@@ -141,7 +141,7 @@ void GiveBall(entity plyr, entity ball)
     self = plyr;    
     self.weaponentity.weapons = self.weapons;
     self.weaponentity.switchweapon = self.weapon;
-    self.weapons = W_WeaponBit(WEP_PORTO);      
+    WEPSET_COPY_EW(self, WEP_PORTO);
     weapon_action(WEP_PORTO, WR_RESETPLAYER);
     self.switchweapon = WEP_PORTO;
     W_SwitchWeapon(WEP_PORTO);
@@ -941,9 +941,9 @@ MUTATOR_HOOKFUNCTION(nexball_PlayerSpawn)
     self.weaponentity.weapons = 0;
     
     if(nexball_mode & NBM_BASKETBALL)
-        self.weapons |= W_WeaponBit(WEP_PORTO);
+        WEPSET_OR_EW(self, WEP_PORTO);
     else
-        self.weapons = 0; //    W_WeaponBit(WEP_PORTO);
+        WEPSET_CLEAR_E(self);
 
     return FALSE;
 }
index 28bb8446902b29249d375d94e953886da444961c..2e5e425eb815ab316690088e63383f0e0fdcfcd8 100644 (file)
@@ -144,7 +144,7 @@ void NIX_GiveCurrentWeapon()
        self.weapons = 0;
        if(g_nix_with_laser)
                self.weapons = self.weapons | WEPBIT_LASER;
-       self.weapons = self.weapons | W_WeaponBit(nix_weapon);
+       WEPSET_OR_EW(self, nix_weapon);
 
        if(self.switchweapon != nix_weapon)
                if(!client_hasweapon(self, self.switchweapon, TRUE, FALSE))
index b26c840ff0c8834ba446c01939fe8760095a95c1..2365733c7abfb855e7f4766e295a7c783b9ec059 100644 (file)
@@ -428,7 +428,7 @@ float Item_GiveTo(entity item, entity player)
                if (player.switchweapon == w_getbestweapon(player))
                        _switchweapon = TRUE;
 
-               if not(player.weapons & W_WeaponBit(player.switchweapon))
+               if not(WEPSET_CONTAINS_EW(player, player.switchweapon))
                        _switchweapon = TRUE;
 
                pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
@@ -1806,7 +1806,7 @@ float GiveItems(entity e, float beginarg, float endarg)
        else
                e.superweapons_finished += time;
 
-       if not(e.weapons & W_WeaponBit(e.switchweapon))
+       if not(WEPSET_CONTAINS_EW(e, e.switchweapon))
                _switchweapon = TRUE;
        if(_switchweapon)
                W_SwitchWeapon_Force(e, w_getbestweapon(e));
index fab3b41b22808002cca28a5316f0664d65346d21..3343fa7c3f5f24d9977e41b05e4da32a498bc0ac 100644 (file)
@@ -6,7 +6,7 @@ void W_GiveWeapon (entity e, float wep, string name)
        if (!wep)
                return;
 
-       e.weapons = e.weapons | W_WeaponBit(wep);
+       WEPSET_OR_EW(e, wep);
 
        oldself = self;
        self = e;