My example will add until your current_ammmo reaches 18 , and will substract exactly what it added from ammo_available.
To make it add exactly what you fired (wich is pointless I think
since you'll always get 18 bullets anyway) :
Count the shots in ammo_counter
If ammo_counter <= ammo_available , substract ammo_counter from ammo_available and add it to current_ammo
Else , add ammo_available to current_ammo and set ammo_available to 0.
You'll get the same result , because :
You start with 18 bullets and 18 ammo_available...
You shoot 3 bullets...current_ammo is 15.
You reload (ammo_available becomes 15 (substracted 3 because of ammo_counter) and current_ammo becomes 18.
My first explanation :
You start with 18 bullets and 18 ammo_available...
You shoot 3 bullets...current_ammo is 15.
You reload (ammo_available becomes 15 (substracted 3 because thats how many you have to add till 18 for current_ammo) and current_ammo becomes 18. Do you see a diffrence
? Adding exactly what you fired thru a counter is the same as directly checking how many bullets you have to add till 18 and adding them (even without using the counter).