Associate Ammo with Weapon?

OK so if there could be that case then change up your weapon definition to allow for that sort of behavior. Don’t just have an AmmoPerShot property on your weapon class, but have an array of WeaponAmmoInfo structs (or something multiple data containing objects)

At the very least something like this perhaps




class WeaponFireInfo
{
map<Ammoclass,int> AmmoToUse;
//constructors + whatever else is useful
}

//in your weapon definition
WeaponAmmoInfo SecondaryAmmo;
SecondaryAmmo.AmmoToUse.add(bullets,3);
SecondaryAmmo.AmmoToUse.add(Electricity,1);

void SecondaryFire()
{
owner.UseAmmo(secondaryAmmo);
//do weapon logic here.
}

//in the player
void useAmmo(weaponAmmoInfo Ammo)
{

for each( KeyValuePair Shot in Ammo.AmmoToUse)
{
DecrementAmmo(Shot.Key, Shot.value) ; assuming decrement ammo finds the class from Shot.Key in the players inventory and subtracts Shot.Value from its quantity.
}
}