My player has 9 weapons and each one has its own energy which is stored in an array. There are pickups to restore energy. If the currently selected weapon is full, but others are low, I want to distribute the restored energy to them evenly.
My idea was to loop through the energy array as many times as the energy refill. If an energy is lower than max, 1 is added to it and 1 is added to a local var counter. If that counter is equal to the energy refill, the loop is stopped. This way, if there's only 1 weapon with low energy, then it'll get 1 energy with each loop until it's over. If multiple weapons are low on energy, they'll each get 1 until the refill amount is met, at which point the loop is stopped.
I dunno if it's my code or the method as a whole but it doesn't quite work - too much energy is being restored. Any other ideas or examples floating around?