]> 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 cb8ff3d5985dea0c82729c6d0475a38f03773259..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);
 
                                // 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))
        {
-               // 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")))
+               // 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
@@ -1627,21 +1623,31 @@ 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_ReloadCheck(float ammo_amount)
+.float reload_complain;
+float W_ReloadCheck(float ammo_amount, float ammo_shot)
 {
        entity e;
        e = get_weaponinfo(self.weapon);
 
        // our weapon is fully loaded, no need to reload
-       if (self.ammo_counter >= cvar(strcat("g_balance_", e.netname, "_reload_ammo")))
+       if (self.clip_load >= cvar(strcat("g_balance_", e.netname, "_reload_ammo")))
                return 0;
 
        // 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;
        }