]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_weaponsystem.qc
Use only WR_SWITCHABLE to check if we can select our weapon. The ammo checks still...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_weaponsystem.qc
index faf18b8daefa64f0e646a19a1dd85fa16022ebb2..a6841d2d785d5eed7f7976644e98032cf1c5b497 100644 (file)
@@ -925,15 +925,13 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
                        {
                                oldself = self;
                                self = cl;
-                               f = weapon_action(wpn, WR_CHECKAMMO1);
-                               f = f + weapon_action(wpn, WR_CHECKAMMO2);
+                               f = weapon_action(wpn, WR_SWITCHABLE);
 
-                               // don't switch away from reloadable weapons, even if we're out of ammo, since the
-                               // weapon itself might still be loaded. The reload code takes care of the switching
+                               // allow switching to reloadable weapons, even if we're out of ammo, since the weapon itself
+                               // might still be loaded. The reload code takes care of complaining and forced switching
                                entity e;
-                               e = get_weaponinfo(self.weapon);
-                               if(cvar(strcat("g_balance_", e.netname, "_reload_ammo")))
-                                       f = 1;
+                               e = get_weaponinfo(wpn);
+                               if(wpn != WEP_TUBA && wpn != WEP_PORTO && wpn != WEP_HOOK) // skip non-reloadable weapons, or we access undefined cvars
 
                                // always allow selecting the Mine Layer if we placed mines, so that we can detonate them
                                local entity mine;
@@ -1054,11 +1052,9 @@ float weapon_prepareattack_checkammo(float secondary)
        if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
        if (!weapon_action(self.weapon, WR_CHECKAMMO1 + secondary))
        {
-               // don't switch away from reloadable weapons, even if we're out of ammo, since the
-               // weapon itself might still be loaded. The reload code takes care of the switching
-               entity e;
-               e = get_weaponinfo(self.weapon);
-               if(cvar(strcat("g_balance_", e.netname, "_reload_ammo")))
+               // always allow reloadable weapons, even if we're out of ammo, since the weapon itself
+               // could still be loaded. The reload code takes care of the rest
+               if(weapon_action(self.weapon, WR_SWITCHABLE))
                        return FALSE;
 
                // always keep the Mine Layer if we placed mines, so that we can detonate them
@@ -1626,22 +1622,32 @@ void W_SetupProjectileVelocity(entity missile, float pSpeed, float spread)
 #define W_SETUPPROJECTILEVELOCITY_UP(m,s) W_SetupProjectileVelocityEx(m, w_shotdir, v_up, cvar(#s "_speed"), cvar(#s "_speed_up"), cvar(#s "_speed_z"), cvar(#s "_spread"), FALSE)
 #define W_SETUPPROJECTILEVELOCITY(m,s) W_SetupProjectileVelocityEx(m, w_shotdir, v_up, cvar(#s "_speed"), 0, 0, cvar(#s "_spread"), FALSE)
 
-// ----------------------------------------------------------------
-// weapon reload code
-// ----------------------------------------------------------------
-
-float W_ReloadCheck(float ammo_amount)
+// shared weapon reload code
+.float reload_complain;
+float W_ReloadCheck(float ammo_amount, float ammo_shot)
 {
        entity e;
        e = get_weaponinfo(self.weapon);
-       if (self.ammo_counter >= cvar(strcat("g_balance_", e.netname, "_reload_ammo")))
+
+       // our weapon is fully loaded, no need to reload
+       if (self.clip_load >= cvar(strcat("g_balance_", e.netname, "_reload_ammo")))
                return 0;
 
-       if(!ammo_amount) // when we get here, ammo_counter must be 0 or -1
+       // no ammo, so nothing to load
+       if(!ammo_amount)
        {
-               print("cannot reload... not enough ammo\n");
-               self.ammo_counter = -1; // reload later
-               W_SwitchToOtherWeapon(self);
+               if(clienttype(self) == CLIENTTYPE_REAL && self.reload_complain < time)
+               {
+                       play2(self, "weapons/unavailable.wav");
+                       sprint(self, strcat("You don't have enough ammo to reload the ^2", W_Name(self.weapon), "\n"));
+                       self.reload_complain = time + 1;
+               }
+               // switch away if the loaded amount of ammo is not enough to keep using this weapon
+               if(self.clip_load < ammo_shot)
+               {
+                       self.clip_load = -1; // reload later
+                       W_SwitchToOtherWeapon(self);
+               }
                return 0;
        }
 
@@ -1650,13 +1656,9 @@ float W_ReloadCheck(float ammo_amount)
                if (self.weaponentity.wframe == WFRAME_RELOAD)
                        return 0;
 
-               // allow to switch away while reloading, but this will cause a new reload!
+               // allow switching away while reloading, but this will cause a new reload!
                self.weaponentity.state = WS_READY;
        }
 
        return 1;
-}
-
-// ----------------------------------------------------------------
-// end of weapon reload code
-// ----------------------------------------------------------------
\ No newline at end of file
+}
\ No newline at end of file