Wednesday, August 3, 2011

51 – NRGY

The subject of this post is the result on today's pre-alpha work, but since I have a lot of new and updated features, I decided to make it a feature post. And stay tuned for an Irrlicht rant.

First I must explain the four core needs of a dwarf. While dwarves haves a lot of statistics, nothing is more important than: energy, food, alcohol and water. All these core needs are numerical values that express how much said need is satisfied, so the higher they are, the more time the dwarf can do other stuff before they must replenish these needs. Every second of in game time, these values decrease, roughly with a value equal to the unit. The good old 1! But each dwarf has his/her own rate of needs decay, generally withing the range of +/-5%. So needs decay with values between 0.95 and 1.05.

Energy tells you how much a dwarf can work. Even idling tires a dwarf slowly and eventually the dwarf will have to go to sleep. Every dwarf has his own energy decay rate. Doing physically tiring tasks will deplete energy faster. So every second, the dwarf's energy will decay by personal decay rate + task difficulty penalty (adjusted by the skill level and perks). Like all needs, reaching the value of zero does not mean game over. Zero energy simply means that the dwarf's body has spent the energy reserves it is used to and would normally stop working. But the dwarf can go into negative if needed. Zero energy is you, if you had a physically challenging job, and you just got home after a particularly hard day. A moderate amount of negative energy is still you from above, but after getting home you went to the gym and did a killer work out. A high amount of negative energy need is you, if after the work out, you had to fight an army of ninjas and came out victorious. The dwarf will certainly feel that he is in negative the next day, being sore, grumpy, having to sleep longer and still being less productive. But the system is not designed to be punishing. It is designed for the case when the immediate survival of your fortress depends on the execution of a long task. You give the order, the dwarf checks out his energy levels and says to you "I would really like to go to bed in 5 minutes. Is this task going to take me less than 5 minutes? No? Well, see you tomorrow!". And then you die. But with this system dwarves can go into negative, but almost always will just go a little bit in that direction. In case of emergency, they will work their ass off. If a dwarf still has positive energy when he starts a task, his honor will dictate that he finishes it, even if he falls over when it is done. After a full night's of sleep, a dwarf will always be at 100% energy, i.e. enough energy to idle for about 20 hours.

This is the model for energy that I will be using in 0.1, and if I do not get a better idea, for several versions from now on. It is a system for the ages!

Food need is similar but won't make it in 0.1. Just to give a few details, the food need behaves similar to energy. Once we get to negative values and the dwarf is not very busy doing something urgent, he will take a break and go eat something. Dwarves can either eat when they are hungry, or if you designate an official group meal time in your great dinning room, dwarves will wait until then, unless they are starving. Having official eating events will cause the dwarves to plan their tasks around these hours (thus being slightly less productive), will take longer eating (thus being slightly less productive), but will socialize, make friends and their morale will rise. If no food is available, once the dwarf gets desperate, will try to eat raw a plant from nature, even if it is not edible. The plant will be destroyed and the dwarf may get sick. If no plant is available, the dwarf will try to kill a pet. Or even a fellow dwarf. And different foods have different nutritious values. With high quality cooked food, a dwarf will eat twice a day and be happier, while with raw/low quality food, he will eat 3-4 times a day and have average happiness. Not eating for about 4 days will kill the dwarf. Since they are so resilient physically, they also need a lot of food. There is chance that the dwarf will wander off in search of food if starving, leaving the fortress forever.

Water need is identical to food, except that you can not designate official drinking times in the great dinning room and eating will often cause the dwarf to replenish his water and alcohol needs too, without taking extra time. As long as the dwarf took a break to eat, he might as well take a drink too. Water need has desperation actions similar to food need, but with natural water sources. I'm not sure about desperation kills and drinking of blood. A dwarf will dehydrate in about 2 days and die. Water need is planned for 0.2.

The more interesting need that is tightly related to water need is the alcohol need. After so many generation of alcohol consumption, the dwarf's need for alcohol is passed down genetically from one generation to the next. While a dwarf may seem tipsy or even drunk, especially to other races, they actually can't get drunk in the traditional sense of the word. Their clarity of though is only mildly reduced by alcohol and their hand eye coordination only improves. There is a critical point where this improvement stops, drastically reverses and the dwarf is practically completely smashed, but they have long since fallen asleep by then. On the other hand, not drinking alcohol regularly causes them to become slow, clumsy and depressed. These effects will worsen, up to a 60% acquired slowness (tasks will take 60% longer to finish), but a dwarf can't die from alcohol withdrawal as long as they don't die from thirst. Satisfying at least 75% of you water need with alcohol will keep your alcohol need at 100%. 

So this is the theory. Let's get to the features!



Energy system reworked
The above described energy system has been fully implemented. The other three needs were added, but they don't decay. I had energy system and decay in place for a while: see the videos with dwarves going to bed after they dig. The old system had some caveats though. Only dwarves who did something suffered energy decay, while idle dwarves would never need to go to bed. And energy was taken in one huge chunk at the start of the task. This is fixed now: all dwarves suffer form energy decay and the decay is gradual. Every dwarf has his own personal energy decay rate (which will be passed down to offsprings).



Digging operation fully realized energy wise
When doing a difficult task, to the personal energy decay rate you add a penalty based on the difficulty of the task. This penalty is zero for all tasks except digging. The reason for this is I only bothered implementing the new system for wall digging. Other actions will follow as the pre-alpha progresses. The dwarf's mining skill now has an impact on digging. Skills range from 0 to 20, but all dwarves start out with a skill of 5, meaning they are dabbling. I'll detail the dwarven education system some other time and explain why they all start out at level 5. Skill 5 is essentially skill zero, giving zero advantages. But as skill level increases, the mining skill will reduce the penalty energy decay (only when mining). At skill level 20 the penalty will be zero. The skill level also influences the time needed to finish an operation. Digging though soil takes one hour and has only a 25% penalthy. Digging though rock takes two hours and has 100% penalty. A skill of 5 does not effect this time and a skill of 20 reduces the time by 15%, with 1% per skill level. A dwarf with skill under 5 can not dig.




Dwarf inspection panel
With all these needs and a lot of stuff going on at once, it can be hard to keep focused. So I added this small panel:


This panel will grow based on the number of dwarves you have, but never be large enough to cover the small button in the corner that opens the options panel. It lists all dwarves, with their image, nickname, and four bars. Each bar represents a different need: energy, food, alcohol and water, in this order. They are color coded. These bars will grow or shrink in real time:


The vertical line is the zero level, so you can see when a need is starting to go bellow zero:


And in the corner, besides each dwarf, you will get a little status string. Right now it only shows which dwarf is sleeping:


I will extend this status to show what each dwarf is doing.



Skinned panels
You may have noticed that some panels now have textures. This is phase one of bringing the panels on par with the concept art I never got to show.



Fixed sleep scheduling bug
There was a long standing bug in the sleep scheduling algorithm. I suspected the presence of the bug for a while now. I think even in the videos you may notice a sleeping dwarf changing beds. But the bug was more severe than that. The game checks the list of idle dwarfs to determine if there is a good candidate to put to sleep and if there is, proceeds to schedule the choosing of beds, path finding, occupying and other book keeping operations. During this process, due to a very subtle and hard to find bug, the candidate dwarf was lost and replaced with the first idle dwarf.



Fixed mouse selection bug
When interacting with the map, you update the current selection with the mouse. I found a new bug here. First, I was scared that during the Irrlicht GUI elimination I broke mouse support, but actually the problem was caused by the fact that I am allocating a larger map than it is used. Bug fixed now, but the fix is not ideal. Added task to fix this properly: planned task #1.



Automatic nicknames
During world creation (manual or automatic), all dwarves without nicknames will get a random one. The game usually presents you information about the dwarves using their nickname, so having an empty string instead of a nickname does not help. Nicknames will be changeable at any point in the game. Normal names are long and hard to pronounce, so having you dwarves called Mike and Joe helps a lot. Or if you are pragmatic, M1 and M2 for your miners.




Never wait for sleepers
Imagine the following scenario: all you dwarves go to bed at roughly the same time. You are stuck waiting for minutes until the in game hours have passed and your dwarves are awake again. Not a problem! If the current time compression is x1 and all your dwarves are sleeping, time compression will change to x180. As soon as one of them wakes up, time compression returns to x1. This way you don't miss anything and you don't have to grab a sandwich. Alternatively, I could pop up a window: "All your dwarves are sleeping. Would you like to skip tot he next event?". And clicking yes would warp you to the moment the first dwarf wakes up. Using time compression seems more natural, for now at least.



Reworked status bar
The status bar now displays the number of idle dwarves. If this is more than zero, it will use the color red. I shrunk the pause button, since most people will be using the keyboard shortcut to pause (space). The button looks ugly because I am using ASCII art (|> and ||) to represent "play" and "pause". My buttons do not support icons yet.



Here is a video showing the panel and energy decay in action:

8 comments:

  1. looks awesome! can't wait to play it.

    how are you planning on handling the dwarf status display when you have more dwarves? a shortcoming of DF is that you pretty much NEED to use Dwarf therapist once you've got more than 50 dwarves or so.

    what are you plans for gaining more dwarves? migration waves? or maybe a more active recruitment system where you could recruit dwarves with the skills you are looking for.

    ReplyDelete
  2. very nice indeed.
    speaking of the dwarves panel- will it always be visible or can you hide it? in prophet of ham's example, if you have 50 dwarves can you choose to only see the status of the miners?

    also, i like the idea of having optional time compression. (maybe i want to go get a sandwich while all dwarves are sleeping :P)

    keep it up!

    ReplyDelete
  3. To Ian Fischer: Thanks dude!

    To prophet of HAM:
    I designed the game around a lower number of dwarves, but every dwarf is a lot more important. Newcomers that are here to stay will be rare and losing 2-3 dwarves in a battle will be a total disaster. Loosing you expedition leader 10 times the disaster.

    While you will have probably more than 50 dwarves, the main team you control will less than that. You'll have to wait a few months for the full explanation once I start working on this feature.

    But if the situation ever becomes so unmanageable that you need a tool like Dwarf Terapist, this tool will be built in an probably promoted to the main interface with which you control your dwarves.

    To simo:
    I can do that with the panel. I could all kind of filters.

    Time compression is not optional and is always on. You can adjust the speed of the game, but it is designed to get you to the action as soon as possible. You can pause and grab an sandwich.

    ReplyDelete
  4. Nice, can't wait to play it :)

    ReplyDelete
  5. Looks great, lots of information I was interested in there.

    One thing I would worry about though is mention of lower dwarf counts. I personally really enjoy large outposts, as it feels like I am building a city. Maybe 50 dwarves the largest count you'd ever likely expect people to get to seems like a bit o a bummer to me. Of course it may play better than I expect!

    I think in summary I'm saying the problem with DF is not large numbers of dwarves but the games inability to handle the control of them.

    ReplyDelete
  6. Hi all,
    this all looks VERY promising and I´m looking forward to try it.

    as Mochnant said someone prefers large armies of miners and at this point it would prob.cause troubles in handling them but some others (like me) prefer only few TRAINED speciallists (remember old Bullfrog´s Dungeon Keeper? - Few Imps, some faceslacks and the job is done)

    But i guess you have all that planned for the future...

    Keep up the great work,bye

    Kidly.


    P.S.:Playable demo would help you with bug-catching ;-)

    ReplyDelete
  7. There is no technical reason for a smaller number of dwarves as can be seen in the stress tests on Youtube, where I use hundreds of dwarves to dig thousand of tiles.

    I just choose to design it around a few but very valuable dwarves. This is not Lemnings, where you have a huge amount of largely interchangeable creatures and loses are acceptable.

    There is another problem: my game is a lot more immediate than DF. Dwarves are on a 24 hour biological schedule, die quickly when their needs are not satisfied, tasks take shorter periods to finish. A harsh winter will be a lot more severe and if you will not make to spirng, you will know this after a week of in game time at most. With hundreds of dwarves and an immediate gameplay, you would not be able to follow all of your dwarves, and would wind up giving orders to only a subset of them while the rest idle away. Or you would use pause very often. Rather than forcing you to pause all the time, how about I design a turn based alternative mode?

    As for a playable demo, it will come someday for sure. But I would rather not do bug testing on my future customers, so the demo will be as bug free as humanly possible.

    But I'll try to create a "not playable" but interactive tech demo soon.

    ReplyDelete