# Thread: Gains over time

1. ## Gains over time

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.

----

Population gain:
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..

2. After more research and asking about, I've learnt that this will use a series equation..

http://en.wikipedia.org/wiki/Series_(mathematics)

That's as much progress as I've managed to make so far on this.

But to try and make it easier to understand what I have to do i'll try another example.

Say the user gains 1 population per second, the gold income that he would have would be the case of over the course of seconds...

1+2+3+4+5 up to the capacity of the population, so if it capped at 5 population over what was currently there then it would continue as 5+5+5+5 etc up to the end of the range.

I'm so terrible at trying to put things into explainations, so I really hope that this part with the first post makes more sense!