From be41dce70d8ee22249878d50accf08becc130205 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Sun, 4 Mar 2012 16:25:33 +0100 Subject: [PATCH] get rid of W_WeaponBit --- qcsrc/common/items.qh | 20 ++++++------ qcsrc/server/bot/havocbot/havocbot.qc | 2 +- qcsrc/server/bot/havocbot/role_onslaught.qc | 2 +- qcsrc/server/bot/havocbot/roles.qc | 2 +- qcsrc/server/cl_client.qc | 6 ++-- qcsrc/server/cl_player.qc | 2 +- qcsrc/server/cl_weapons.qc | 36 ++++++++------------- qcsrc/server/cl_weaponsystem.qc | 22 +++++++------ qcsrc/server/defs.qh | 1 - qcsrc/server/g_damage.qc | 6 ++-- qcsrc/server/mutators/gamemode_nexball.qc | 6 ++-- qcsrc/server/mutators/mutator_nix.qc | 2 +- qcsrc/server/t_items.qc | 4 +-- qcsrc/server/w_common.qc | 2 +- 14 files changed, 53 insertions(+), 60 deletions(-) diff --git a/qcsrc/common/items.qh b/qcsrc/common/items.qh index 1cae4d133..250aee112 100644 --- a/qcsrc/common/items.qh +++ b/qcsrc/common/items.qh @@ -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 diff --git a/qcsrc/server/bot/havocbot/havocbot.qc b/qcsrc/server/bot/havocbot/havocbot.qc index 42b829ffd..a97f184d5 100644 --- a/qcsrc/server/bot/havocbot/havocbot.qc +++ b/qcsrc/server/bot/havocbot/havocbot.qc @@ -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; } } diff --git a/qcsrc/server/bot/havocbot/role_onslaught.qc b/qcsrc/server/bot/havocbot/role_onslaught.qc index f37f821f1..90150e2ab 100644 --- a/qcsrc/server/bot/havocbot/role_onslaught.qc +++ b/qcsrc/server/bot/havocbot/role_onslaught.qc @@ -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; } diff --git a/qcsrc/server/bot/havocbot/roles.qc b/qcsrc/server/bot/havocbot/roles.qc index d9cddacbd..ac8ddd161 100644 --- a/qcsrc/server/bot/havocbot/roles.qc +++ b/qcsrc/server/bot/havocbot/roles.qc @@ -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) diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index bf4a25950..2c89b3e3e 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -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)) { diff --git a/qcsrc/server/cl_player.qc b/qcsrc/server/cl_player.qc index 5a1627423..754b2ae76 100644 --- a/qcsrc/server/cl_player.qc +++ b/qcsrc/server/cl_player.qc @@ -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'); } diff --git a/qcsrc/server/cl_weapons.qc b/qcsrc/server/cl_weapons.qc index 4a12ce185..60ad8eee1 100644 --- a/qcsrc/server/cl_weapons.qc +++ b/qcsrc/server/cl_weapons.qc @@ -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); diff --git a/qcsrc/server/cl_weaponsystem.qc b/qcsrc/server/cl_weaponsystem.qc index 4f496e56e..d2c2546d2 100644 --- a/qcsrc/server/cl_weaponsystem.qc +++ b/qcsrc/server/cl_weaponsystem.qc @@ -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); } diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index a46c8f7e7..e6fba2839 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -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); diff --git a/qcsrc/server/g_damage.qc b/qcsrc/server/g_damage.qc index bdaeef0a5..ab9096c45 100644 --- a/qcsrc/server/g_damage.qc +++ b/qcsrc/server/g_damage.qc @@ -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)); } diff --git a/qcsrc/server/mutators/gamemode_nexball.qc b/qcsrc/server/mutators/gamemode_nexball.qc index 8554a1223..fd1a8fb59 100644 --- a/qcsrc/server/mutators/gamemode_nexball.qc +++ b/qcsrc/server/mutators/gamemode_nexball.qc @@ -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; } diff --git a/qcsrc/server/mutators/mutator_nix.qc b/qcsrc/server/mutators/mutator_nix.qc index 28bb84469..2e5e425eb 100644 --- a/qcsrc/server/mutators/mutator_nix.qc +++ b/qcsrc/server/mutators/mutator_nix.qc @@ -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)) diff --git a/qcsrc/server/t_items.qc b/qcsrc/server/t_items.qc index b26c840ff..2365733c7 100644 --- a/qcsrc/server/t_items.qc +++ b/qcsrc/server/t_items.qc @@ -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)); diff --git a/qcsrc/server/w_common.qc b/qcsrc/server/w_common.qc index fab3b41b2..3343fa7c3 100644 --- a/qcsrc/server/w_common.qc +++ b/qcsrc/server/w_common.qc @@ -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; -- 2.39.2