From a78be73a3b6007629dde4edb7081551f26e778cc Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Fri, 28 Aug 2020 06:05:37 +1000 Subject: [PATCH] Add function to get ammo consumption of primary fire mode --- qcsrc/common/weapons/all.qc | 16 ++++++++++++++++ qcsrc/common/weapons/weapon.qh | 4 ++++ qcsrc/server/weapons/spawning.qc | 15 ++------------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/qcsrc/common/weapons/all.qc b/qcsrc/common/weapons/all.qc index bb4ae216a..6b675468c 100644 --- a/qcsrc/common/weapons/all.qc +++ b/qcsrc/common/weapons/all.qc @@ -237,6 +237,22 @@ string GetAmmoName(int ammotype) } } +#ifdef SVQC +int GetAmmoConsumptionPrimary(string netname) +// Returns ammo consumed per shot by the primary/default fire mode +{ + switch (netname) + { + case "arc": return cvar("g_balance_arc_beam_ammo"); + case "devastator": return cvar("g_balance_devastator_ammo"); + case "machinegun": return cvar("g_balance_machinegun_sustained_ammo"); + case "minelayer": return cvar("g_balance_minelayer_ammo"); + case "seeker": return cvar("g_balance_seeker_tag_ammo"); + default: return cvar(strcat("g_balance_", netname, "_primary_ammo")); + } +} +#endif + #ifdef CSQC int GetAmmoTypeFromNum(int i) { diff --git a/qcsrc/common/weapons/weapon.qh b/qcsrc/common/weapons/weapon.qh index 67f646cbe..d072dd915 100644 --- a/qcsrc/common/weapons/weapon.qh +++ b/qcsrc/common/weapons/weapon.qh @@ -231,6 +231,10 @@ string GetAmmoPicture(int ammotype); string GetAmmoName(int ammotype); +#ifdef SVQC +int GetAmmoConsumptionPrimary(string netname); +#endif + #ifdef CSQC int GetAmmoTypeFromNum(int i); int GetAmmoStat(int ammotype); diff --git a/qcsrc/server/weapons/spawning.qc b/qcsrc/server/weapons/spawning.qc index 8ade74aa4..ec9952fff 100644 --- a/qcsrc/server/weapons/spawning.qc +++ b/qcsrc/server/weapons/spawning.qc @@ -111,19 +111,8 @@ void weapon_defaultspawnfunc(entity this, Weapon wpn) { int ammo = 0; if (this.count > 0) - { - switch (wpn.netname) - { - case "arc": ammo = cvar("g_balance_arc_beam_ammo"); break; - case "devastator": ammo = cvar("g_balance_devastator_ammo"); break; - case "machinegun": ammo = cvar("g_balance_machinegun_sustained_ammo"); break; - case "minelayer": ammo = cvar("g_balance_minelayer_ammo"); break; - case "seeker": ammo = cvar("g_balance_seeker_tag_ammo"); break; - default: ammo = cvar(strcat("g_balance_", wpn.netname, "_primary_ammo")); - } - - ammo *= this.count; - } + ammo = this.count * GetAmmoConsumptionPrimary(wpn.netname); + // WEAPONTODO: magazines of MG, rifle and OK weapons are unaccounted for else { switch (wpn.ammo_type) -- 2.39.2