Wednesday, September 29, 2010

09 – Isometric?

One of the goals of this project, besides creating a nice little sandbox game for myself, is to create something that anyone can pick up and have at least a slight idea of what is going on without prior preparation. But the past days, when I have shown someone my work, the universal answer was “WTF is going on here”. I have no problem with ASCII graphics and when a group of “d” letters is approaching menacingly I’m not thinking “hey, a d”, but “OMG, IT IS A BLINK DOG APOCALYPSE” (ADOM reference). And I know that people that are not familiar with such graphics have a steep learning curve. This is why I had some top down graphics, to lessen the impact and adaptation period that is necessary before picking up an ASCII game and before learning its specific mechanics. But I was not enough. So I tried isometric graphics.
Before I link to the video, there is a point to be made. I have my own hastily assembled tile set. It is not pretty, but I want to code right now, not mock around endlessly with graphics. Yet I need something good looking to illustrate the point that graphics play a large role in the ease of learning something. So for the purpose of a video I borrowed the awesome tiles from Stonesense (http://www.bay12forums.com/smf/index.php?topic=43260.0). I’ll proceed to let the people there know about me using their tiles for the purpose of the video, but until then I have included a disclaimer:
Disclaimer:
This video has been produced by using a version of DwarvesH and modifying it by applying the tiles form Stonesense (
http://www.bay12forums.com/smf/index.php?topic=43260.0) only for the purpose of creating an early demo video. DwarvesH is not available in any form with the tiles from Stonesense by default officially or unofficially and does not assume any right to use them. The process can be repeated by anyone by downloading both applications and using a simple image editing tool to selectively change the tiles from DwarvesH with those from Stonesense or the tiles from Stonesense with those from DwarvesH.

Now this looks a lot better! The response that I’m getting is also better. In the video I dig a couple of simple caves and demonstrate the rather slow covering of the landscape with snow and dying of plants. Pressing “T” advances the time artificially with one day. For such a big change, I would have liked a longer video, preferably HD, but I still don’t have adequate capturing software. I’ll try FRAPS next.
Not much left to say. Feature wise everything is the same, a little bit of extra polish and nothing got lost in the transition to isometric. Smashing!

Statistics S17:
3162 lines of code in 23 files
82.2 KiB of code

Thursday, September 23, 2010

08 – Santa Claus is coming tonight

It seems that the number of prerequirements before I can get to the meat of the game never seems to get any smaller. With the ability to harvest plants the world needs to be able to regenerate these plants. From here to implementing basic seasons is just a small step. Which I took. So I wanted to upload a video of seasons changing to show how the world progressively is covered by snow and then in spring the snow melts and plants show up. But on this computer I was no able to capture video with the required frame rate and most of the phasing from grass to snow was lost. This may be due to the fact that DwarvesH is eating up most of my processing power. Oh well, a picture can say a thousand words or something like that.

Let us start with winter. The fairly typical scenery is covered by patches of snow:



As time passes, more and more snow is able to get a hold of the surroundings and plants start to die. If you don’t have enough supplies this would be the perfect moment for a desperate harvesting spree:


And here we ore in the 23rd of December, with snow cowering everything and bowing down to no one except the infinite power of Santa Claus (I know that it should be the 24th, but I’m not retaking the screenshot only for that):


But here comes early spring:



…followed by the total melting of snow and the first plants:


With one month of development approaching fast, I would like to have at least the ability to harvest plants, cut down trees and designate stockpiles. Oh yeah, and digging! (about done with that)



Statistics S14:
3087 lines of code in 23 files
80.0 KiB of code

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

Tuesday, September 21, 2010

06 – Polish is the mother of all… c’mon, do some 3D!!!!

This post was supposed to be about how important is polish, even at such an early stage. I had a couple of polishing runs, one where I changed the scheduling and path finding so that now it looks a lot better, with less random jumping around. I have some great ideas for the final form of the algorithm based on some profiling and a little fooling around with it. In another session I did some general cleanup.

But my third session was cancelled. Unfortunately, even these primitive 2D graphics were too much for my very powerful development machine. I tried it also on an average machine with a comparatively very poor graphics card, and the result was similar. The performance of the rendering engine was capped by whatever (probably software rendering) the graphical toolkit was using to do the rendering. On my machine I had between 10-20 FPS and on the other machine even lower. It is even visible in the previous post’s video: there is some serious mouse lag.

But now everything is better. I ported my rendering engine over to Irrlicht. Now I have 84 FPS on the poor machine. The porting was very easy. I’m not sure if Irrlicht is the final way to go because Ogre3D is also a strong contender, but there is one lesson to be learned here: do not cheap out on using a third party tool that can offer hardware acceleration, platform independence, abstraction and simplification of common tasks, even if what you are programming is very simple at this stage and you may or may not wish to extend upon it. You can use anything from SDL to something you find on the net, but using something with a strong user base will make things easier for you.

I won’t post a screenshot because everything looks the same. Now there is no way I’m using something with the capabilities of Irrlicht to draw 2D tiles forever. With this change, switching to 3D tiles & perspective is up on the table for the near future.



Statistics S12:
With the introduction of Irrlicht image data is no longer included in the resulting executable and has no impact on the number of lines of code in the project like it did before. I will also exclude image data from the size of the code:
2922 line of code in 23 files
75.3 KiB of code

Wednesday, September 15, 2010

05 - 3000

Oh yeah, it is digging time!




Well with a video capturing my efforts for posterity, I think I am officially past the "guy doing stuff in paint and pretending to be a programer" phase. Am I right?

In the above video I start with a barely visible command to harvest a bush. Then the fun parts starts. I am designating some areas for digging. A nice fractal pattern should do for starters. Areas are marked with the right mouse button presses and by dragging the mouse. Nice and intuitive. I'll keep such an interface. The first thing you right click will determine the action for your selection when you release a mouse button. Clicking on a wall? Well, probably you want to designate it for digging. Clicking on a designation for digging? Remove the designation.

While I am drawing along, nothing is happening. The game is not paused. The pause button is not implemented yet. In the future you are going to want to pause when designing something more complex because the clock is ticking away, but for simple actions you won't have to pause. The dwarves are not working because the areas designated are not accessible. Once I designate a corridor that will connect these areas to the outside, one single dwarf begins working. As soon as other points are accessible, other dwarfs start working. Eventually all of them are busy chipping away.

The algorithms involved are not yet perfect but they do a fine job and I am not going to improve them yet. I actually like the little peculiarities in movement and scheduling. Dwarves consume huge quantities of alcohol. They should choose strange work patterns in consequence.

Also time passage is not accurate yet. Digging is almost instant. With time, I'll figure out the durations so everything feels right and is also challenging.

Uploading to YouTube was pretty simple. But I have a crap capture program. Not only did it manage to extend the duration of my capture, but it saved almost 800 MiB on disk. I had some fun uploading for 40 minutes.

So why the tile of the post? Because I have exactly 3000 lines of code. I did not try to achieve this round number for this post, but I guess it must be a sign.

With a minimum of features, it is time to implement saving and loading of games. I don't want to have to start all over every time I boot up DwarvesH.



Statistics S10:
3000 lines of code in 23 files
94,9 KiB (including 23,3 KiB image data)

Monday, September 13, 2010

04 - ...and Life

This is going to be a relatively short post based on how late it has arrived. And while the number of lines may have not increased in such a steady rhythm as before, I have invested a comparable time to tweaking the new scheduling system.

With a a very simple map populated by plants that don't do that much yet, I needed to add something more dynamic. The first step was to add movement. For my movement related needs I used the good old A* algorithm. It is fast and very easy to implement once you understand the way it works. There is no good reason not to use it.

But the hard part was the scheduling algorithm. It is bare bones, but after a lot of tweaking it is capable of looking though the list of available tasks and the list of available dwarfs and tries to match them, plot a course, compute the durations and then "animate" the dwarves so that they move with a good speed and an OK feel to it. And all this while the user can still input some basic commands without pausing the game; in this case one can add new plants to the task list. Here we can see it in action:


Dwarves that are doing something are marked with red. The bottom left dwarf has already picked his assigned plant and is blue again signaling that he is available for other tasks. If I add new plants, he will be the first to work, followed by the rest of the dwarves:


This could have been the perfect opportunity to introduce some videos. Pictured will have a hard time showing you that those five dwarves are walking around and making plants disappear (they claim that they are picking them up and preparing them for stockpiling, but I saw no new food reserves – not implemented yet). Alas, I don't have a video capture program on hand and I'm far too lazy to find a free one on Google at this hour and then mess around with video upload. But it is something for the future.

As you can see in one of the screen shots, there is little panel around the bottom informing you on what you have selected with the mouse. For plants it now has two buttons. I'm thinking to introduce a single "Do it" button for a lot of simple tasks. Naturally, dwarves and buildings will have a lot of options, but for things like plants, trees and cave walls I'll try a default action buttons which designates them for gathering, cutting down or digging.

For the next post, I'll do my best and add the second dwarf related element (the first being the dwarves themselves): digable cave walls. I hope they will enjoy it!




Statistics S009:

2655 lines of code in 22 files (including data editor)

84.2 KiB (including 20.4 KiB image data)

Tuesday, September 7, 2010

03 - Let there be... graphics?

While I may have not implemented everything that I've bragged about in my last post due to reasons that I'll get into later, I managed to get a basic game screen working. And it has graphics. The ugliest graphics you have ever seen! Please do not click on the image bellow. I even made it small so you won't be tempted to click on it:


Wait, wait! I'm only joking. Please do not run away. Actually, I looks quite good considering that I've spent a maximum of 30 minutes searching on Google for random tiles that resembled what I was looking for and added them to the tile list. I can foresee a bright future for the graphics in this game. Right now you can notice the grass that forms quite a pleasant and not overly repetitive pattern. A lot to improve on it, but I can imagine dozens of such pattern for grass, soil, ice, etc.. And variations based on climate. And you can see a few tiles for the plants that right now are placed randomly. I don't have enough tiles right now, but imagine that every game will look different (if the starting climate and conditions are different) and you can instantly tell by the graphics what is a pig tail plant and what is an angry lion. Great for your enjoyment and survivability and great for new players. New players might not know that it is a pig tail, but they will still know that it is a plant like thing and not an overly friendly and useful cat.

And you can see your seven starting dwarves. The tile is obviously a poor fit. The dwarf is to small and the shadow is not needed or at least is darker than it should be. With larger and color-coded-for-your-convenience dwarves and a rich tileset maybe it is possible to convey the inherent life and atmosphere of a dwarven fortress set inside an inhospitable mountain in a more visually compelling way. It sure gives me a lot to rant about.

As you can probably tell by reading the above paragraphs, I am not going to include support (at least for the foreseeable future) for "legacy" systems, i.e. console character based display. It is 2010 and we have cheap smart phones more powerful than anything that is implied by ASCII displays. Cheap netbooks should and will be powerful enough to run this thing, but that is as low as it will go. If you look at this game and say "1996" then a machine from "1996" should run it. More or less.

As for the "look at thing" mechanism, I haven't gotten around to it yet because all the other stuff I had to implement first. But I have a new and better idea so I would have ended up scratching the old way anyway. But you can click on stuff to get an awesome highlighting effect (this time with full size picture):



So let's talk trees. And plants. The first draft of the plant editor is here:


It is strong enough to assign most of the properties for the plants and it is easy to use. I have covered the plants I wanted for now. And here is a similar window, this time allowing you to define your trees:


Meanwhile, I've become unhappy with the design of these dialogs. They are good enough, but lack overview capabilities. I'll use a new design for future such dialogs which will be a lot better.

In the biome sections you have a button labeled "Choose" which brings up this atrocity:


Ohhhh God!!! What was I thinking? I must have been drunk when I thought that this would be a good design for a biome configuration window. Or for anything with so many items. I promise to never let it happen again.

Every editor you just saw is fully functional. They load and save data, and the game uses this data to populate the world. Right now it ignores biome information and there is nothing really to this "populate world" nonsense because for now I will only be placing plants. Without trees. I need to find some unique placeholder graphics for every plant and add options to the game so you can choose the environment. And then simulate plant growth.

See you next time!



Statistics S006:

2132 lines of code in 22 files (including data editor)

67.5 KiB (including 14.5 KiB image data)