]> 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 057c5cb1dc767fde25d85b66a61ca8ee519cbf32..a6841d2d785d5eed7f7976644e98032cf1c5b497 100644 (file)
@@ -925,8 +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(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;
@@ -1047,6 +1052,11 @@ float weapon_prepareattack_checkammo(float secondary)
        if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
        if (!weapon_action(self.weapon, WR_CHECKAMMO1 + secondary))
        {
+               // 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
                local entity mine;
                if(self.weapon == WEP_MINE_LAYER)
@@ -1611,3 +1621,44 @@ 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)
+
+// shared weapon reload code
+.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.clip_load >= cvar(strcat("g_balance_", e.netname, "_reload_ammo")))
+               return 0;
+
+       // no ammo, so nothing to load
+       if(!ammo_amount)
+       {
+               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;
+       }
+
+       if (self.weaponentity)
+       {
+               if (self.weaponentity.wframe == WFRAME_RELOAD)
+                       return 0;
+
+               // allow switching away while reloading, but this will cause a new reload!
+               self.weaponentity.state = WS_READY;
+       }
+
+       return 1;
+}
\ No newline at end of file