January 11, 2011

Dev Update : AI and a new sector type

I'm done with the "City Center" sector type. It doesn't scale very well when using custom sector dimensions, but it's sufficient for now (sector size will probably be hardcoded in the public release anyway). The first screenshot is a map of such a sector. The central blue region will always contain a park and 4 office buildings. The two green regions will contain service buildings like hospitals, police stations,  restaurants, and the mayor office. The four outer red regions are either housing blocks or large parks. Remaining buildings are randomized. The second screenshot is a game representation of a restaurant. It's rough, and more objects (chairs and such) will be added as soon as I find a good and automated way of putting things into buildings.

Now, about the AI :)

If you haven't read the first design document about the AI system, it's now a good time to do so. The civilian AI system is mostly done. Depending on their needs, NPC will look for a related object able to satisfy them, path to it and use it until satisfied. Basically, NPC can sleep in their own bed, eat at their fridge or at a restaurant, work at an office when low on money and go for a walk when bored. It still need some tuning as NPC tend to eat too much (this is the USA ^^) and not sleep nearly enough. That's mainly because of the current design. When they reach an "alert" level for a specific need they switch task no matter what. So they can interrupt their bed time to take a quick lunch several times in the same night. That's something I will correct soon by adding a "safe" level for each need. It will be used by the NPC to determine how many time he will repeat his current action instead of using fixed values.

This is my "Spy" window (click to enlarge). It displays the current needs and orders of a selected NPC. It explains how the AI works in a better way than I could do myself. Needs are values between 0 (no need) and 1000 (omfg, i need to do this now). In the current implementation - that will be tweaked - when a specific need reach 750, the NPC will change his current order. Here, Minh Chang is very low on funds, so a new order has been calculated for him: to find and use a computer at an office. You can see in the lower part of the window the steps needed to do so: First, move to a position next to the computer. And according to the window, this step is achieved, so he is currently doing his second order: using the computer for a duration of 72 turns (well, it's 80 in fact, but a few turns have passed). Each turn, granted the NPC isn't hungry or sleepy, he will use the computer. Our NPC is an office worker, so the computer will give him a few dollars per use, lowering his need to work.

Currently, only 3 real needs are implemented  (work, sleep, eat). Plus, NPC will "Idle" in a park or a random location when they don't need to do anything else. The "Heal" need will be implemented next, as soon as combat and hospital zones are ready. A lot of 'needs' will be added during the game's development. Here's a few examples:

- Rearm : Thugs and policemen won't use ammo at first, but once it's done, this need will be based on their personal funds and ammunition level. They'll go to a weapon shop to satisfy this one.

- Stress : Working (for citizen) or killing people (for cops and thugs) is stressful. To reduce stress, people can buy expensive items in shops, go in places like bars, parks, night clubs and such.

- Drugs : It will be a special case, and it will deserve a full article when I'm done with the design.

Currently the need to sleep and to eat increase by 1 per turn. This is temporary and will be tuned based on what's the NPC is currently doing. Fighting or working consume more calories than hanging out in a park or sleeping.

Final thoughts

I'm quite content with this current version, all annoying bugs have been squashed, the pathfinder is responding correctly, and the general AI is working. I now need to implement support for the combat system. It's a big part of the game. I need to add the Hospital zone type and related objects, implement the doctor job, and of course the combat AI itself. When done with that I'll have to put ingame the faction system, a thing that will force me to rewrite my "PopulateTheCity" function (self explanatory i hope). Doing all that will take a week or two i guess. Next I'll have to put in place a very basic faction AI, at least for the police, and then we should be more or less ready for the release of the first, barely playable, test build. It's still scheduled for the end of this month, but don't yell if it's early February instead :p

2 comments:

  1. Good post. I love AI explications. Smart Terrains seem promising!

    Just a few questions though :

    - How much time does one of your 'turns' last? This is a roguelike so IIRC when playing DwarfFortress, it seemed that characters were updated(ie. moved) like each 0.5 seconds or something. Is that what you call turn?

    - Why don't you randomize the offices/services buildings throughout the whole sector instead of placing them in particular regions?

    - I don't know if you already spoke about that but, does every NPC in town is a unique character with a name and a schedule etc? Or will there be also randomly generated npcs like in GTA?

    ReplyDelete
  2. 1) Dwarf Fortress is a special case in the RL world. It automatically pass a turn every 0.x seconds depending on how you configure it (and your CPU), giving the feeling the game is happening in realtime. Standard RL are usually turn based like a game of chess (or anything similar), nothing happens until you decide to move, then all the NPC move, and then it's your turn again. That's what i mean by 'turn' here.
    However, I will probably include both systems as the engine I'm building is flexible enough. Turn based first, realtime will follow a bit later.

    2) Well, this particular map type is a bit more complicated to write than the others I've done so far, and still need some improvement to be honest. This said, I want the buildings next to the large road to be service related in this sector type (it's the city center after all). When I'm done, they will be dispatched between the horizontal and the vertical roads.

    3) I hope to put 'living' NPC only. Currently, the game can handle around 10.000 of them without lagging. However, I still have to add several things that will probably slow down the game (and also, several that may improve the situation). So it's still a bit early to be sure.

    ReplyDelete