I'll try to explain as thoroughly as possible.
A user gains 1000 population per hour, that is broken down to 0.27 population per second (1000/3600), if X time has passed since the update then the population gain is X*0.27 and then capped at the maximum capacity that a user can have.
The problem is when I want to calculate the gold gain, the gain is dependant on the population and in which the user will gain 1 gold per population that they have per hour. So if they have 1000 population they will gain 1000 population per hour. However to do it the same as above is not accurate and it doesn't take into consideration the gains over time.
GainPerHour = 1000;
GainPerSecond = GainPerHour / 3600;
ActualGain = TimeDiffInSeconds * GainPerSec;
Population = Population + ActualGain;
I did the same for gold gain without realising how inaccurate it was, and I have no idea at all how to make it accurate without placing it within a loop for each second and calculating it on a per second basis, which would be far too slow.
One possible solution I think is to do the above for gold but with the OLD population value from before i was updated, and then a formula to work out the gain from what population was added, but with the capacity things that too could become complex. For example if 5000 seconds have passed but the user would have capped their population at 1000 seconds, it would need to take that into consideration for the actual gold gain.
I'm totally confused and lost at how to do this, any help is very much appreciated. I just hope you guys can make sense out of this..