]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Doh, it CAN be done differently than my ugly list. Use WR checks
authorMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Sat, 22 Jan 2011 22:58:26 +0000 (00:58 +0200)
committerMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Sat, 22 Jan 2011 22:58:26 +0000 (00:58 +0200)
17 files changed:
qcsrc/common/constants.qh
qcsrc/server/cl_weaponsystem.qc
qcsrc/server/w_crylink.qc
qcsrc/server/w_electro.qc
qcsrc/server/w_fireball.qc
qcsrc/server/w_grenadelauncher.qc
qcsrc/server/w_hagar.qc
qcsrc/server/w_hlac.qc
qcsrc/server/w_laser.qc
qcsrc/server/w_minelayer.qc
qcsrc/server/w_minstanex.qc
qcsrc/server/w_nex.qc
qcsrc/server/w_rocketlauncher.qc
qcsrc/server/w_seeker.qc
qcsrc/server/w_shotgun.qc
qcsrc/server/w_sniperrifle.qc
qcsrc/server/w_uzi.qc

index 78548a55c0c43b3237d91a610c646d4d217ab476..da8cfaac1890db4b7d57dd4f6f548e15ed185248 100644 (file)
@@ -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;
index e82cfaa26aaffccc1be27cdee79bd227fbd7ae99..3566b552480d311ead7c1d50ac3870b7078cc081 100644 (file)
@@ -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)
 {
index 73f9f5864bba1eae047001469e12ba997d2e8d73..74b6e92736dd426792fe2a827dbe2bda973e7c3a 100644 (file)
@@ -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
index cd03bdcebe2f74fc3c6409b50117f3b67e22d802..01da65d83861435646edd2cb6a1d418ebbb66ed8 100644 (file)
@@ -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
index ea34c80afcdaade523aa24ddbf0c3638271f8729..e3b9e334293d562c4e7dd390b4938ec2ed221a6f 100644 (file)
@@ -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
index 77bf031b3fb25935bba210a3abbe754b57125985..5e5f9616351c0466bdef1941b3e3bde089e00c5f 100644 (file)
@@ -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
index 2a8e4d7f47b0c35e0b9d8a8b2efc8d8ae08fb68a..907db356cd49030034814de35ef915bba47263a6 100644 (file)
@@ -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
index bdbb88bc67337b0b86ac05bae959360e00761749..c87baf2162dd59eb3b65ea918e976ff92d37a650 100644 (file)
@@ -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
index 33a9c164d42793fc16d15be54b8b933b44c553a5..f3bd6e0b1371245ac7e89f3b1b54529c06172311 100644 (file)
@@ -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
index 6d307bb2f971d777f36b5dc540c34240c9027d45..1b35ab4efd8d5a89f157da9cdbeb359e687c4a98 100644 (file)
@@ -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
index 8b01ceee849ff4cf48605b17ac8bb77809e73db0..81c1987fabb6ec17b2950399b9fd2e6b4b84bc03 100644 (file)
@@ -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
index e93262e92b471109a39423cf8843b2da21e6fe94..d3e1b07d6b28d6c41338f1faba8b3e428ba63f58 100644 (file)
@@ -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;
 };
index ab30b0712d5851070bdebffbfc66e3a852723961..3dec2732a6a4c680e16c0f6164bafe510f1ad9dc 100644 (file)
@@ -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
index b1cde626a0e74218028075eb035439e72cb8f5d2..42f0ec34957fddba9e091616a27efefe9f044b81 100644 (file)
@@ -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
index 50ad77bde336ae3636f19b4109c5325aa0668915..48ef90e1b49b5417977dff2f3a95af8ddf26d335 100644 (file)
@@ -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
index 359ab4dfad553994d34709516abddaf6075b487d..01326774f3012701563064e870c2549dc32fa5e4 100644 (file)
@@ -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
index d841283433f359a696466e420529754d2883bfd8..3ec7019e6858e8c01916a3b43562112015f091fc 100644 (file)
@@ -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