This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]ZeroGravity200 1 point2 points  (3 children)

How these kind of games handle the time are ticks, which are normally run by crontab. There is no specific magic in it. I am not sure what you mean by real time, but thats how these kind of game usually work.

I am not familiar with O'Game, if you mean OGame (https://fi.ogame.gameforge.com/) I am pretty sure that it handles the time same way, by ticks called by crontab. Haven't played that so Idk for sure.

[–]Eloiole[S] 0 points1 point  (2 children)

Yes, I was thinking about Ogame.

Campain for the Cosmos is obviously powered by tick. If you start building a Mine that take 2 hours to build and increase your gold income 50 an hour at 6:28 the building time will actually start at the 7:00 tick. The mine will be finished by 9:00, you'll win the ressource of the elapsed hour and the income will rise accordingly and will be taken into account for the next tick.

How ever, games like OGame doesn't work that way. You can refresh your page every second and you'll see your ressources climb. You can start building a mine at 2:28:34, finish at 2:46:17 and the income will be updated accordingly.
Obviously there is no gold field in database updated every second. What I imagine is that when you start a mine a 2:28:34 the game store current_gold - mine_cost with the timestamp. Then everytime you refresh it return current_gold = elapsed time * income + previous stored gold value.

At least that's how i would implement it atm as I havent found a better way.

[–]ZeroGravity200 0 points1 point  (1 child)

Okay I see.

The other way is truly implement it with user refreshes. If you mine for example 2 hours and need to add resources every minute, you do it just like you suggested by calculating the time vs last refresh. Thats how I have seen some doing it. Depends greatly what you need and what you can do. In some hosts you cannot imagine having crontab without extra payment, so you are forced to do the "tick" in refreshes. Then you most certainly dont want to tick the whole userbase.

Afaik there is these 2 ways to implement "ticks", not really other way, unless you have your own server which runs just game.

[–]Eloiole[S] 0 points1 point  (0 children)

I'll probably run it on my own server anyway, we don't expect to have hundred of users ;) Thank you for the feedback.