f = weapon_action(wpn, WR_CHECKAMMO1);
f = f + weapon_action(wpn, WR_CHECKAMMO2);
- // 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")))
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
+ // 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")))
#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
-// ----------------------------------------------------------------
-
+// shared weapon reload code
float W_ReloadCheck(float ammo_amount)
{
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")))
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");
+ print("Cannot reload, not enough ammo\n");
self.ammo_counter = -1; // reload later
W_SwitchToOtherWeapon(self);
return 0;
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
void W_Shotgun_SetAmmoCounter()
{
- // set ammo counter to the weapon we have switched to
+ // set ammo_counter to the weapon we have switched to, if the gun uses reloading
if(!autocvar_g_balance_shotgun_reload_ammo)
- self.ammo_counter = 0; // also keeps the crosshair ammo from displaying
+ self.ammo_counter = 0; // also keeps crosshair ammo from displaying
else
self.ammo_counter = self.shotgun_load;
}
{
float t;
- // now do the ammo maths
- self.ammo_counter = self.old_ammo_counter; // restore ammo counter, in case we still had ammo in the weapon while reloading
- while(self.ammo_counter < autocvar_g_balance_shotgun_reload_ammo && self.ammo_shells) // make sure we don't add more than the amount of ammo we have
+ // now do the ammo transfer
+ self.ammo_counter = self.old_ammo_counter; // restore the ammo counter, in case we still had ammo in the weapon before reloading
+ while(self.ammo_counter < autocvar_g_balance_shotgun_reload_ammo && self.ammo_shells) // make sure we don't add more ammo than we have
{
self.ammo_counter += 1;
self.ammo_shells -= 1;
void W_Shotgun_Reload()
{
- // reloading is disabled for this weapon
+ // return if reloading is disabled for this weapon
if(!autocvar_g_balance_shotgun_reload_ammo)
return;
- float t;
-
if(!W_ReloadCheck(self.ammo_shells))
return;
+ float t;
+
sound (self, CHAN_WEAPON2, "weapons/campingrifle_reload.wav", VOL_BASE, ATTN_NORM);
t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_shotgun_reload_time + 1;
flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
W_AttachToShotorg(flash, '5 0 0');
+ // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
{
if(!autocvar_g_balance_shotgun_reload_ammo)
{
return TRUE;
}
+ else if (req == WR_RELOAD)
+ {
+ W_Shotgun_Reload();
+ }
return TRUE;
};
#endif
void W_SniperRifle_SetAmmoCounter()
{
- // set ammo counter to the weapon we have switched to
+ // set ammo_counter to the weapon we have switched to, if the gun uses reloading
if(!autocvar_g_balance_sniperrifle_reload_ammo)
- self.ammo_counter = 0; // also keeps the crosshair ammo from displaying
+ self.ammo_counter = 0; // also keeps crosshair ammo from displaying
else
self.ammo_counter = self.sniperrifle_load;
}
{
float t;
- // now do the ammo maths
- self.ammo_counter = self.old_ammo_counter; // restore ammo counter, in case we still had ammo in the weapon while reloading
- while(self.ammo_counter < autocvar_g_balance_sniperrifle_reload_ammo && self.ammo_nails) // make sure we don't add more than the amount of ammo we have
+ // now do the ammo transfer
+ self.ammo_counter = self.old_ammo_counter; // restore the ammo counter, in case we still had ammo in the weapon before reloading
+ while(self.ammo_counter < autocvar_g_balance_sniperrifle_reload_ammo && self.ammo_nails) // make sure we don't add more ammo than we have
{
self.ammo_counter += 1;
self.ammo_nails -= 1;
void W_SniperRifle_Reload()
{
- // reloading is disabled for this weapon
+ // return if reloading is disabled for this weapon
if(!autocvar_g_balance_sniperrifle_reload_ammo)
return;
- float t;
-
if(!W_ReloadCheck(self.ammo_nails))
return;
+ float t;
+
sound (self, CHAN_WEAPON2, "weapons/campingrifle_reload.wav", VOL_BASE, ATTN_NORM);
t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_sniperrifle_reload_time + 1;
if (autocvar_g_casings >= 2)
SpawnCasing (((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3, self);
+ // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
{
if(!autocvar_g_balance_sniperrifle_reload_ammo)