each weapon-derived class has its own field called AMMO and its own enumeration called WeaponType used to identify that weapon in the game.
This way, if I want to pickup some ammo for that weapon, I just need to do something like:
until it finds the weapon with that enumeration and, once found, gives it some ammo
I don’t like this system. I find it unflexible.
I want AMMUNITIONS to be independent and for each weapon that I will introduce in the game, I should define which kinds of ammo it uses for its PrimaryFire and which ones for its SecondaryFire
Let’s pretend I want to make a Lightning gun in Unreal Tournament style.
Well, there will be ammunitions called, for example, “Electricity”
Now let’s say I want to make another weapon, which uses Bullets for its PrimaryFire, but as secondary fire it usesElectricityammunitions.
From this example, you see that Electricity and Bullet are two kinds of Ammunitions that don’t really belong to a specific weapon. They’re independent
Enumerate ammo and specify primary and secondary types of compatible ammo for each weapon as fields. Add type field to ammo. Check compatible types of ammo and weapon before pickup.
EAmmoType is an enum, so you don’t have to search through an array of structs, you can convert the enum to a byte, and use that as an index into an array of integers. just set up the array in the same order as the Enum.
What if I have a particular weapon where it’s secondary fire uses a kind of ammo which requires the weapon to change something like the way it traces?Should I make a C++ class for each of these ‘particular’ weapons?