From: Samual Lenks Date: Sun, 5 Jan 2014 15:54:01 +0000 (-0500) Subject: Add debug in case a weapon causes negative ammo X-Git-Tag: xonotic-v0.8.0~152^2~135 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=4ff469c32515d3cc9c551afce90b5dc6eab14bb8;p=xonotic%2Fxonotic-data.pk3dir.git Add debug in case a weapon causes negative ammo --- diff --git a/qcsrc/common/weapons/weapons.qc b/qcsrc/common/weapons/weapons.qc index 425fe5f64..628a70de5 100644 --- a/qcsrc/common/weapons/weapons.qc +++ b/qcsrc/common/weapons/weapons.qc @@ -261,6 +261,19 @@ void W_RandomWeapons(entity e, float n) e.weapons = result; } +string GetAmmoPicture(.float ammotype) +{ + switch(ammotype) + { + case ammo_shells: return "ammo_shells"; + case ammo_nails: return "ammo_nails"; + case ammo_rockets: return "ammo_rockets"; + case ammo_cells: return "ammo_cells"; + case ammo_fuel: return "ammo_fuel"; + default: return ""; // wtf, no ammo type? + } +} + #ifdef CSQC .float GetAmmoFieldFromNum(float i) { @@ -275,19 +288,6 @@ void W_RandomWeapons(entity e, float n) } } -string GetAmmoPicture(.float ammotype) -{ - switch(ammotype) - { - case ammo_shells: return "ammo_shells"; - case ammo_nails: return "ammo_nails"; - case ammo_rockets: return "ammo_rockets"; - case ammo_cells: return "ammo_cells"; - case ammo_fuel: return "ammo_fuel"; - default: return ""; // wtf, no ammo type? - } -} - float GetAmmoStat(.float ammotype) { switch(ammotype) diff --git a/qcsrc/common/weapons/weapons.qh b/qcsrc/common/weapons/weapons.qh index ba2e8a15e..720f65f6e 100644 --- a/qcsrc/common/weapons/weapons.qh +++ b/qcsrc/common/weapons/weapons.qh @@ -72,9 +72,10 @@ string W_FixWeaponOrder_AllowIncomplete(string order); string W_FixWeaponOrder_ForceComplete(string order); void W_RandomWeapons(entity e, float n); +string GetAmmoPicture(.float ammotype); + #ifdef CSQC .float GetAmmoFieldFromNum(float i); -string GetAmmoPicture(.float ammotype); float GetAmmoStat(.float ammotype); #endif diff --git a/qcsrc/server/weapons/weaponsystem.qc b/qcsrc/server/weapons/weaponsystem.qc index e99c450ec..70b916ced 100644 --- a/qcsrc/server/weapons/weaponsystem.qc +++ b/qcsrc/server/weapons/weaponsystem.qc @@ -813,7 +813,21 @@ void W_DecreaseAmmo(float ammo_use) self.(weapon_load[self.weapon]) = self.clip_load; } else + { self.(wep.ammo_field) -= ammo_use; + if(self.(wep.ammo_field) < 0) + { + backtrace(sprintf( + "W_DecreaseAmmo(%.2f): '%s' subtracted too much %s from '%s', resulting with '%.2f' left... " + "Please notify Samual immediately with a copy of this backtrace!\n", + ammo_use, + wep.netname, + GetAmmoPicture(wep.ammo_field), + self.netname, + self.(wep.ammo_field) + )); + } + } } // weapon reloading code