From: bones_was_here Date: Mon, 24 Feb 2025 12:38:31 +0000 (+1000) Subject: items: clean up weapon/ammo .count field q3compat code X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=046bcca59b303e12aeeb5384b9621be28d6f5d97;p=xonotic%2Fxonotic-data.pk3dir.git items: clean up weapon/ammo .count field q3compat code --- diff --git a/qcsrc/server/compat/quake3.qc b/qcsrc/server/compat/quake3.qc index 9565c5b7e..ef9331934 100644 --- a/qcsrc/server/compat/quake3.qc +++ b/qcsrc/server/compat/quake3.qc @@ -448,18 +448,18 @@ bool DoesQ3ARemoveThisEntity(entity this) return false; } -int GetAmmoConsumptionQ3(string netname) -// Returns ammo consumed per shot by the primary/default fire mode -// Returns 0 if the netname has no ammo cvar +/// Returns ammo consumed per shot by the primary/default fire mode. +/// Return value is undefined if entity isn't a weapon that uses ammo. +int GetAmmoConsumptionQ3(entity wpn) { - switch (netname) + switch (wpn) { - case "arc": return autocvar_g_balance_arc_beam_ammo; - case "devastator": return autocvar_g_balance_devastator_ammo; - case "machinegun": return autocvar_g_balance_machinegun_sustained_ammo; - case "minelayer": return autocvar_g_balance_minelayer_ammo; - case "seeker": return autocvar_g_balance_seeker_tag_ammo; - default: return cvar(strcat("g_balance_", netname, "_primary_ammo")); + case WEP_ARC: return WEP_CVAR(WEP_ARC, beam_ammo); + case WEP_DEVASTATOR: return WEP_CVAR(WEP_DEVASTATOR, ammo); + case WEP_MACHINEGUN: return WEP_CVAR(WEP_MACHINEGUN, sustained_ammo); + case WEP_MINE_LAYER: return WEP_CVAR(WEP_MINE_LAYER, ammo); + case WEP_SEEKER: return WEP_CVAR(WEP_SEEKER, tag_ammo); + default: return WEP_CVAR_PRI(wpn, ammo); } } diff --git a/qcsrc/server/compat/quake3.qh b/qcsrc/server/compat/quake3.qh index 1253c92a9..752ccd661 100644 --- a/qcsrc/server/compat/quake3.qh +++ b/qcsrc/server/compat/quake3.qh @@ -7,7 +7,7 @@ int q3compat = 0; bool autocvar_sv_q3compat_changehitbox; bool DoesQ3ARemoveThisEntity(entity this); -int GetAmmoConsumptionQ3(string netname); +int GetAmmoConsumptionQ3(entity wpn); .int fragsfilter_cnt; @@ -19,8 +19,8 @@ int GetAmmoConsumptionQ3(string netname); #define SPAWNFUNC_Q3AMMO(ammo_classname, xonwep) \ spawnfunc(ammo_classname) \ { \ - if(this.count && xonwep.ammo_type) \ - SetResource(this, xonwep.ammo_type, this.count * GetAmmoConsumptionQ3(xonwep.netname)); \ + if(this.count && xonwep.ammo_type != RES_NONE) \ + SetResource(this, xonwep.ammo_type, this.count * GetAmmoConsumptionQ3(xonwep)); \ SPAWNFUNC_BODY(GetAmmoItem(xonwep.ammo_type)) \ } diff --git a/qcsrc/server/weapons/spawning.qc b/qcsrc/server/weapons/spawning.qc index 4a669e499..3a20ec80e 100644 --- a/qcsrc/server/weapons/spawning.qc +++ b/qcsrc/server/weapons/spawning.qc @@ -113,7 +113,7 @@ void weapon_defaultspawnfunc(entity this, Weapon wpn) { int ammo = 0; if (q3compat && this.count > 0) - ammo = this.count * GetAmmoConsumptionQ3(wpn.netname); + ammo = this.count * GetAmmoConsumptionQ3(wpn); // WEAPONTODO: magazines of MG, rifle and OK weapons are unaccounted for else {