Wednesday, September 22, 2010

07 – Time & time compression

When implementing the passage of time, the most important aspect that must be decided is the scale. A unit of time in real life equals to how many units of time in the game?

For starters one can implement a time scale that is uniform. Time always flows at the same pace. For some games this is the best choice. For something like simulating dwarves building an epic fortress underground, figuring out the scale is very difficult. Digging and building should take a lot of time in the game. You want your dwarves to slave away for years before they have a truly awesome fortress. A small encampment should be built in a few days, but you want at least to dig out some tunnels, plant some crops, wait for them to grow and harvest them. This process should take roughly a month and a half. But for the person that is playing the game time will flow like normal and the months that have passed for your dwarves will be only minutes or hours of real time. And here lies the problem. If you want to give a brisk pace to the game, you end up with all short actions taking far too long or not being visible on screen. Take walking across a tile. In real life it would take your dwarves a couple of seconds at most to walk such a small distance. Such small intervals would not be visible when animating the game. Or you can make the interval longer, so you have time to display the dwarves as they are moving along. But these long intervals will wind up far too long. To illustrate this problem, according to the Dwarf Fortress Wiki it takes 13 minutes for an average dwarf to walk a tile. You can try to compromise, but I was not able to come up with a scale where fast actions moved fast enough and a month of game time was under 5-6 hours of real time.

Then there are non-uniform time scales. For my implementation I have chosen time-compression. When all your dwarves are idle or moving along on their path, time in game will run like normal, with a speed somewhat faster than in The Sims™ series. A second of real time is roughly one minute in game (a little more or less, but I don’t want or need to figure out the exact amount, especially since this amount will fluctuate slightly based on the FPS of the game). The game will always run at this speed or faster. Actually, it will run at a speed where it can finish the shortest task in one cycle. So when all your dwarves are busy digging out a piece of wall, time will pass at a speed of roughly two hours per cycle. For now, it takes a dwarf two hours to cut out a tile from the mountain. With time compression, in one minute of real time when everybody is idle or walking, in game only minutes will pass and in the next minute, when all are busy chipping away a few days will pass. The time scale is adjusted on the fly. So if all seven dwarves are working and time is in super fast mode and one needs to walk over to somewhere else, while he is moving time will slow down. I hope I managed to explain this correctly. It is quite strange to see time fluctuate like this, but once you get used to it I think it is a good system.

Another subtle advantage of dynamic time compression is that you can reward the players who are careful to optimize paths and not waste a lot of time walking around with their dwarves with convenience bonuses. These players will be able to do more in the same amount of real time than someone who has very long and crowded walk ways or who places key industries that rely on each other at great distances. For your dwarves it will not make any difference, because walking a step only takes one second for them. A few extra steps are a few extra minutes for them, but for players these are moments when time compression is not working. One must be very careful though to not impose a much too harsh penalty, because eventually even a very good fortress may get cursed with perpetual slow passage of time when its complexity reaches over a yet unknown threshold.

This post was full of rambling…

So new features: the above mentioned time compression, a display for you clock showing the date and time and a very useful pause button also accessible by the letter P on your keyboard.



Statistics S13:
2968 lines of code in 23 files
76.8 KiB of code

No comments:

Post a Comment