From 0ea6fdd8e101803cdeab08ae96d8dfc31215eb80 Mon Sep 17 00:00:00 2001 From: Mircea Kitsune Date: Sun, 23 Jan 2011 00:58:26 +0200 Subject: [PATCH] Doh, it CAN be done differently than my ugly list. Use WR checks --- qcsrc/common/constants.qh | 1 + qcsrc/server/cl_weaponsystem.qc | 67 +------------------------------ qcsrc/server/w_crylink.qc | 9 +++++ qcsrc/server/w_electro.qc | 9 +++++ qcsrc/server/w_fireball.qc | 9 +++++ qcsrc/server/w_grenadelauncher.qc | 9 +++++ qcsrc/server/w_hagar.qc | 9 +++++ qcsrc/server/w_hlac.qc | 9 +++++ qcsrc/server/w_laser.qc | 5 +++ qcsrc/server/w_minelayer.qc | 9 +++++ qcsrc/server/w_minstanex.qc | 15 +++++++ qcsrc/server/w_nex.qc | 9 +++++ qcsrc/server/w_rocketlauncher.qc | 9 +++++ qcsrc/server/w_seeker.qc | 9 +++++ qcsrc/server/w_shotgun.qc | 9 +++++ qcsrc/server/w_sniperrifle.qc | 9 +++++ qcsrc/server/w_uzi.qc | 9 +++++ 17 files changed, 140 insertions(+), 65 deletions(-) diff --git a/qcsrc/common/constants.qh b/qcsrc/common/constants.qh index 78548a55c..da8cfaac1 100644 --- a/qcsrc/common/constants.qh +++ b/qcsrc/common/constants.qh @@ -621,6 +621,7 @@ float WR_KILLMESSAGE = 8; // (CSQC) sets w_deathtypestring or leaves it alone float WR_RELOAD = 9; // (SVQC) does not need to do anything float WR_RESETPLAYER = 10; // (SVQC) does not need to do anything float WR_IMPACTEFFECT = 11; // (CSQC) impact effect +float WR_SWITCHABLE = 12; // (CSQC) impact effect float HUD_PANEL_WEAPONS = 0; diff --git a/qcsrc/server/cl_weaponsystem.qc b/qcsrc/server/cl_weaponsystem.qc index e82cfaa26..3566b5524 100644 --- a/qcsrc/server/cl_weaponsystem.qc +++ b/qcsrc/server/cl_weaponsystem.qc @@ -896,7 +896,6 @@ void Send_WeaponComplain (entity e, float wpn, string wpnname, float type) .float hasweapon_complain_spam; -float W_Reload_AllowSwitching(float wpn); float client_hasweapon(entity cl, float wpn, float andammo, float complain) { local float weaponbit, f; @@ -936,7 +935,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) if(wpn != WEP_TUBA && wpn != WEP_PORTO && wpn != WEP_HOOK) // skip non-reloadable weapons, or we access undefined cvars if(cvar(strcat("g_balance_", e.netname, "_reload_ammo"))) { - if(W_Reload_AllowSwitching(wpn)) + if(weapon_action(wpn, WR_SWITCHABLE)) f = 1; else f = 0; // necessary to avoid switching back and forth @@ -1067,7 +1066,7 @@ float weapon_prepareattack_checkammo(float secondary) e = get_weaponinfo(self.weapon); if(self.weapon != WEP_TUBA && self.weapon != WEP_PORTO && self.weapon != WEP_HOOK) // skip non-reloadable weapons, or we access undefined cvars if(cvar(strcat("g_balance_", e.netname, "_reload_ammo"))) - if(W_Reload_AllowSwitching(self.weapon)) + if(weapon_action(self.weapons, WR_SWITCHABLE)) return FALSE; // always keep the Mine Layer if we placed mines, so that we can detonate them @@ -1636,68 +1635,6 @@ void W_SetupProjectileVelocity(entity missile, float pSpeed, float spread) #define W_SETUPPROJECTILEVELOCITY(m,s) W_SetupProjectileVelocityEx(m, w_shotdir, v_up, cvar(#s "_speed"), 0, 0, cvar(#s "_spread"), FALSE) // shared weapon reload code -float W_Reload_AllowSwitching(float wpn) -{ - // check each reloadable weapon and see if we can switch to it - // returns true if there's either enough load in the weapon to use it, - // or we have enough ammo to reload the weapon to a usable point. - // The list below is ugly, but the only way I found to do this check - float ammo_amount; - switch(wpn) - { - case WEP_SHOTGUN: - ammo_amount = autocvar_g_balance_shotgun_primary_ammo; - return self.shotgun_load >= ammo_amount || self.ammo_shells >= ammo_amount; - case WEP_UZI: - ammo_amount = min(max(autocvar_g_balance_uzi_sustained_ammo, autocvar_g_balance_uzi_first_ammo), autocvar_g_balance_uzi_burst_ammo); - return self.uzi_load >= ammo_amount || self.ammo_nails >= ammo_amount; - case WEP_GRENADE_LAUNCHER: - ammo_amount = min(autocvar_g_balance_grenadelauncher_primary_ammo, autocvar_g_balance_grenadelauncher_secondary_ammo); - return self.grenadelauncher_load >= ammo_amount || self.ammo_rockets >= ammo_amount; - case WEP_MINE_LAYER: - ammo_amount = autocvar_g_balance_minelayer_ammo; - return self.minelayer_load >= ammo_amount || self.ammo_rockets >= ammo_amount; - case WEP_ELECTRO: - ammo_amount = min(autocvar_g_balance_electro_primary_ammo, autocvar_g_balance_electro_secondary_ammo); - return self.electro_load >= ammo_amount || self.ammo_cells >= ammo_amount; - case WEP_CRYLINK: - ammo_amount = min(autocvar_g_balance_crylink_primary_ammo, autocvar_g_balance_crylink_secondary_ammo); - return self.crylink_load >= ammo_amount || self.ammo_cells >= ammo_amount; - case WEP_HLAC: - ammo_amount = min(autocvar_g_balance_hlac_primary_ammo, autocvar_g_balance_hlac_secondary_ammo); - return self.hlac_load >= ammo_amount || self.ammo_cells >= ammo_amount; - case WEP_NEX: - ammo_amount = min(autocvar_g_balance_nex_primary_ammo, autocvar_g_balance_nex_secondary_ammo); - return self.nex_load >= ammo_amount || self.ammo_cells >= ammo_amount; - case WEP_MINSTANEX: - if(g_minstagib) - ammo_amount = 1; - else - ammo_amount = autocvar_g_balance_minstanex_ammo; - if(autocvar_g_balance_minstanex_laser_ammo) - ammo_amount = min(ammo_amount, autocvar_g_balance_minstanex_laser_ammo); - - return self.minstanex_load >= ammo_amount || self.ammo_cells >= ammo_amount; - case WEP_SNIPERRIFLE: - ammo_amount = min(autocvar_g_balance_sniperrifle_primary_ammo, autocvar_g_balance_sniperrifle_secondary_ammo); - return self.sniperrifle_load >= ammo_amount || self.ammo_nails >= ammo_amount; - case WEP_SEEKER: - ammo_amount = min(autocvar_g_balance_seeker_missile_ammo, autocvar_g_balance_seeker_tag_ammo); - return self.seeker_load >= ammo_amount || self.ammo_rockets >= ammo_amount; - case WEP_HAGAR: - ammo_amount = min(autocvar_g_balance_hagar_primary_ammo, autocvar_g_balance_hagar_secondary_ammo); - return self.hagar_load >= ammo_amount || self.ammo_rockets >= ammo_amount; - case WEP_FIREBALL: - ammo_amount = min(autocvar_g_balance_fireball_primary_ammo, autocvar_g_balance_fireball_secondary_ammo); - return self.fireball_load >= ammo_amount || self.ammo_fuel >= ammo_amount; - case WEP_ROCKET_LAUNCHER: - ammo_amount = autocvar_g_balance_rocketlauncher_ammo; - return self.rocketlauncher_load >= ammo_amount || self.ammo_rockets >= ammo_amount; - default: - return TRUE; - } -} - .float reload_complain; float W_ReloadCheck(float ammo_amount, float ammo_shot) { diff --git a/qcsrc/server/w_crylink.qc b/qcsrc/server/w_crylink.qc index 73f9f5864..74b6e9273 100644 --- a/qcsrc/server/w_crylink.qc +++ b/qcsrc/server/w_crylink.qc @@ -703,6 +703,15 @@ float w_crylink(float req) { W_Crylink_Reload(); } + else if (req == WR_SWITCHABLE) + { + // checks if this weapon can be switched to, when reloading is enabled + // returns true if there's either enough load in the weapon to use it, + // or we have enough ammo to reload the weapon to a usable point + float ammo_amount; + ammo_amount = min(autocvar_g_balance_crylink_primary_ammo, autocvar_g_balance_crylink_secondary_ammo); + return self.crylink_load >= ammo_amount || self.ammo_cells >= ammo_amount; + } return TRUE; }; #endif diff --git a/qcsrc/server/w_electro.qc b/qcsrc/server/w_electro.qc index cd03bdceb..01da65d83 100644 --- a/qcsrc/server/w_electro.qc +++ b/qcsrc/server/w_electro.qc @@ -591,6 +591,15 @@ float w_electro(float req) { W_Shotgun_Reload(); } + else if (req == WR_SWITCHABLE) + { + // checks if this weapon can be switched to, when reloading is enabled + // returns true if there's either enough load in the weapon to use it, + // or we have enough ammo to reload the weapon to a usable point + float ammo_amount; + ammo_amount = min(autocvar_g_balance_electro_primary_ammo, autocvar_g_balance_electro_secondary_ammo); + return self.electro_load >= ammo_amount || self.ammo_cells >= ammo_amount; + } return TRUE; }; #endif diff --git a/qcsrc/server/w_fireball.qc b/qcsrc/server/w_fireball.qc index ea34c80af..e3b9e3342 100644 --- a/qcsrc/server/w_fireball.qc +++ b/qcsrc/server/w_fireball.qc @@ -470,6 +470,15 @@ float w_fireball(float req) { W_Fireball_Reload(); } + else if (req == WR_SWITCHABLE) + { + // checks if this weapon can be switched to, when reloading is enabled + // returns true if there's either enough load in the weapon to use it, + // or we have enough ammo to reload the weapon to a usable point + float ammo_amount; + ammo_amount = min(autocvar_g_balance_fireball_primary_ammo, autocvar_g_balance_fireball_secondary_ammo); + return self.fireball_load >= ammo_amount || self.ammo_fuel >= ammo_amount; + } return TRUE; }; #endif diff --git a/qcsrc/server/w_grenadelauncher.qc b/qcsrc/server/w_grenadelauncher.qc index 77bf031b3..5e5f96163 100644 --- a/qcsrc/server/w_grenadelauncher.qc +++ b/qcsrc/server/w_grenadelauncher.qc @@ -438,6 +438,15 @@ float w_glauncher(float req) { W_GrenadeLauncher_Reload(); } + else if (req == WR_SWITCHABLE) + { + // checks if this weapon can be switched to, when reloading is enabled + // returns true if there's either enough load in the weapon to use it, + // or we have enough ammo to reload the weapon to a usable point + float ammo_amount; + ammo_amount = min(autocvar_g_balance_grenadelauncher_primary_ammo, autocvar_g_balance_grenadelauncher_secondary_ammo); + return self.grenadelauncher_load >= ammo_amount || self.ammo_rockets >= ammo_amount; + } return TRUE; }; #endif diff --git a/qcsrc/server/w_hagar.qc b/qcsrc/server/w_hagar.qc index 2a8e4d7f4..907db356c 100644 --- a/qcsrc/server/w_hagar.qc +++ b/qcsrc/server/w_hagar.qc @@ -262,6 +262,15 @@ float w_hagar(float req) { W_Hagar_Reload(); } + else if (req == WR_SWITCHABLE) + { + // checks if this weapon can be switched to, when reloading is enabled + // returns true if there's either enough load in the weapon to use it, + // or we have enough ammo to reload the weapon to a usable point + float ammo_amount; + ammo_amount = min(autocvar_g_balance_hagar_primary_ammo, autocvar_g_balance_hagar_secondary_ammo); + return self.hagar_load >= ammo_amount || self.ammo_rockets >= ammo_amount; + } return TRUE; }; #endif diff --git a/qcsrc/server/w_hlac.qc b/qcsrc/server/w_hlac.qc index bdbb88bc6..c87baf216 100644 --- a/qcsrc/server/w_hlac.qc +++ b/qcsrc/server/w_hlac.qc @@ -301,6 +301,15 @@ float w_hlac(float req) { W_HLAC_Reload(); } + else if (req == WR_SWITCHABLE) + { + // checks if this weapon can be switched to, when reloading is enabled + // returns true if there's either enough load in the weapon to use it, + // or we have enough ammo to reload the weapon to a usable point + float ammo_amount; + ammo_amount = min(autocvar_g_balance_hlac_primary_ammo, autocvar_g_balance_hlac_secondary_ammo); + return self.hlac_load >= ammo_amount || self.ammo_cells >= ammo_amount; + } return TRUE; }; #endif diff --git a/qcsrc/server/w_laser.qc b/qcsrc/server/w_laser.qc index 33a9c164d..f3bd6e0b1 100644 --- a/qcsrc/server/w_laser.qc +++ b/qcsrc/server/w_laser.qc @@ -349,6 +349,11 @@ float w_laser(float req) return TRUE; else if (req == WR_RELOAD) W_Laser_Reload(); + else if (req == WR_SWITCHABLE) + { + // laser uses no ammo, always switchable + return TRUE; + } return TRUE; }; #endif diff --git a/qcsrc/server/w_minelayer.qc b/qcsrc/server/w_minelayer.qc index 6d307bb2f..1b35ab4ef 100644 --- a/qcsrc/server/w_minelayer.qc +++ b/qcsrc/server/w_minelayer.qc @@ -508,6 +508,15 @@ float w_minelayer(float req) { W_MineLayer_Reload(); } + else if (req == WR_SWITCHABLE) + { + // checks if this weapon can be switched to, when reloading is enabled + // returns true if there's either enough load in the weapon to use it, + // or we have enough ammo to reload the weapon to a usable point + float ammo_amount; + ammo_amount = autocvar_g_balance_minelayer_ammo; + return self.minelayer_load >= ammo_amount || self.ammo_rockets >= ammo_amount; + } return TRUE; }; #endif diff --git a/qcsrc/server/w_minstanex.qc b/qcsrc/server/w_minstanex.qc index 8b01ceee8..81c1987fa 100644 --- a/qcsrc/server/w_minstanex.qc +++ b/qcsrc/server/w_minstanex.qc @@ -348,6 +348,21 @@ float w_minstanex(float req) { W_Minstanex_Reload(); } + else if (req == WR_SWITCHABLE) + { + // checks if this weapon can be switched to, when reloading is enabled + // returns true if there's either enough load in the weapon to use it, + // or we have enough ammo to reload the weapon to a usable point + float ammo_amount; + if(g_minstagib) + ammo_amount = 1; + else + ammo_amount = autocvar_g_balance_minstanex_ammo; + if(autocvar_g_balance_minstanex_laser_ammo) + ammo_amount = min(ammo_amount, autocvar_g_balance_minstanex_laser_ammo); + + return self.minstanex_load >= ammo_amount || self.ammo_cells >= ammo_amount; + } return TRUE; }; #endif diff --git a/qcsrc/server/w_nex.qc b/qcsrc/server/w_nex.qc index e93262e92..d3e1b07d6 100644 --- a/qcsrc/server/w_nex.qc +++ b/qcsrc/server/w_nex.qc @@ -313,6 +313,15 @@ float w_nex(float req) { W_Nex_Reload(); } + else if (req == WR_SWITCHABLE) + { + // checks if this weapon can be switched to, when reloading is enabled + // returns true if there's either enough load in the weapon to use it, + // or we have enough ammo to reload the weapon to a usable point + float ammo_amount; + ammo_amount = min(autocvar_g_balance_nex_primary_ammo, autocvar_g_balance_nex_secondary_ammo); + return self.nex_load >= ammo_amount || self.ammo_cells >= ammo_amount; + } return TRUE; }; diff --git a/qcsrc/server/w_rocketlauncher.qc b/qcsrc/server/w_rocketlauncher.qc index ab30b0712..3dec2732a 100644 --- a/qcsrc/server/w_rocketlauncher.qc +++ b/qcsrc/server/w_rocketlauncher.qc @@ -551,6 +551,15 @@ float w_rlauncher(float req) { W_RocketLauncher_Reload(); } + else if (req == WR_SWITCHABLE) + { + // checks if this weapon can be switched to, when reloading is enabled + // returns true if there's either enough load in the weapon to use it, + // or we have enough ammo to reload the weapon to a usable point + float ammo_amount; + ammo_amount = autocvar_g_balance_rocketlauncher_ammo; + return self.rocketlauncher_load >= ammo_amount || self.ammo_rockets >= ammo_amount; + } return TRUE; }; #endif diff --git a/qcsrc/server/w_seeker.qc b/qcsrc/server/w_seeker.qc index b1cde626a..42f0ec349 100644 --- a/qcsrc/server/w_seeker.qc +++ b/qcsrc/server/w_seeker.qc @@ -563,6 +563,15 @@ float w_seeker(float req) { W_Seeker_Reload(); } + else if (req == WR_SWITCHABLE) + { + // checks if this weapon can be switched to, when reloading is enabled + // returns true if there's either enough load in the weapon to use it, + // or we have enough ammo to reload the weapon to a usable point + float ammo_amount; + ammo_amount = min(autocvar_g_balance_seeker_missile_ammo, autocvar_g_balance_seeker_tag_ammo); + return self.seeker_load >= ammo_amount || self.ammo_rockets >= ammo_amount; + } return TRUE; }; #endif diff --git a/qcsrc/server/w_shotgun.qc b/qcsrc/server/w_shotgun.qc index 50ad77bde..48ef90e1b 100644 --- a/qcsrc/server/w_shotgun.qc +++ b/qcsrc/server/w_shotgun.qc @@ -237,6 +237,15 @@ float w_shotgun(float req) { W_Shotgun_Reload(); } + else if (req == WR_SWITCHABLE) + { + // checks if this weapon can be switched to, when reloading is enabled + // returns true if there's either enough load in the weapon to use it, + // or we have enough ammo to reload the weapon to a usable point + float ammo_amount; + ammo_amount = autocvar_g_balance_shotgun_primary_ammo; + return self.shotgun_load >= ammo_amount || self.ammo_shells >= ammo_amount; + } return TRUE; }; #endif diff --git a/qcsrc/server/w_sniperrifle.qc b/qcsrc/server/w_sniperrifle.qc index 359ab4dfa..01326774f 100644 --- a/qcsrc/server/w_sniperrifle.qc +++ b/qcsrc/server/w_sniperrifle.qc @@ -276,6 +276,15 @@ float w_sniperrifle(float req) self.sniperrifle_accumulator = time - autocvar_g_balance_sniperrifle_bursttime; self.clip_load = autocvar_g_balance_sniperrifle_reload_ammo; } + else if (req == WR_SWITCHABLE) + { + // checks if this weapon can be switched to, when reloading is enabled + // returns true if there's either enough load in the weapon to use it, + // or we have enough ammo to reload the weapon to a usable point + float ammo_amount; + ammo_amount = min(autocvar_g_balance_sniperrifle_primary_ammo, autocvar_g_balance_sniperrifle_secondary_ammo); + return self.sniperrifle_load >= ammo_amount || self.ammo_nails >= ammo_amount; + } return TRUE; }; #endif diff --git a/qcsrc/server/w_uzi.qc b/qcsrc/server/w_uzi.qc index d84128343..3ec7019e6 100644 --- a/qcsrc/server/w_uzi.qc +++ b/qcsrc/server/w_uzi.qc @@ -365,6 +365,15 @@ float w_uzi(float req) { W_UZI_Reload(); } + else if (req == WR_SWITCHABLE) + { + // checks if this weapon can be switched to, when reloading is enabled + // returns true if there's either enough load in the weapon to use it, + // or we have enough ammo to reload the weapon to a usable point + float ammo_amount; + ammo_amount = min(max(autocvar_g_balance_uzi_sustained_ammo, autocvar_g_balance_uzi_first_ammo), autocvar_g_balance_uzi_burst_ammo); + return self.uzi_load >= ammo_amount || self.ammo_nails >= ammo_amount; + } return TRUE; }; #endif -- 2.39.2