]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add function to get ammo consumption of primary fire mode
authorbones_was_here <bones_was_here@xa.org.au>
Thu, 27 Aug 2020 20:05:37 +0000 (06:05 +1000)
committerbones_was_here <bones_was_here@xa.org.au>
Thu, 27 Aug 2020 20:05:37 +0000 (06:05 +1000)
qcsrc/common/weapons/all.qc
qcsrc/common/weapons/weapon.qh
qcsrc/server/weapons/spawning.qc

index bb4ae216a5a5d6db8a582404ec1a7779a4b39823..6b675468c91c4c6a7f870dcc82663785250ca4ba 100644 (file)
@@ -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)
 {
index 67f646cbe5b328dbbb8d7671cbef65db65189fc9..d072dd915ec99242d199c809bcc5b4827069aedf 100644 (file)
@@ -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);
index 8ade74aa40da69efb610d8c84c4a6a1e5e552835..ec9952fff27039ee857fdc9b036ffbc6d65618e0 100644 (file)
@@ -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)