Three Hundred :: Mechanic #071
  Squidi.net Sites:     Webcomics   |   Three Hundred Mechanics   |   Three Hundred Prototypes
 Three Hundred
   - Index Page
   - About...
   - By Year

 Collections
   - Comp-Grid
   - Procedural
   - Tactics
   - Tiny Crawl
   - Misc


 
PreviousMechanic #071Next

  Mechanic #071 - Tiny World Commander

Category: Simulation
Posted: 12/23/07

A way of directly controlling sim-adventurers in an indirect sort of way.


  Description

This is the second in a three part series detailing the mechanics behind a simulation-RPG. This entry concerns itself with a set of mechanics used to expose and manipulate what a sim-adventurer is thinking and doing. Again, sims are hardly my area of expertise, so hopefully I'm not reinventing the wheel.

Sim games always bugged me because you never knew the rules by which the sim people operated. Playing SimCity, it seemed almost entirely random which roads would become congested or which buildings would be most populated. Sure, you knew what was going on in general, but it still felt so completely arbitrary. Even the Sims, which actually goes the extra mile and gives you moderate control over the individual characters, seemed almost retarded at times (most of the time, by my count).

I think this brings a certain appeal to it. The mystery gives personality and life to what might otherwise seem mechanical. Sure you know that they have to pee REALLY bad, but what personality drives them to pee on the floor rather than use the toilet in the same room? But I'm of the mind that it doesn't matter. Play through a game of the original Final Fantasy some times. You have complete control over those cookie cutter lifeless characters, but by the end, you'll have anthropomorphized those little buggers into little people anyway.

So, my goal with this entry is allow the player a window into what the sim people are thinking, even giving them a push in one direction or another. People put a lot of effort into making good AI, but the end result is that it just looks like magic to most players. It's similar to procedural content in that way. Why go to all the effort to make good AI when you can fake good looking AI? Frequently, the most mechanical and obvious AI seems the most brilliant to the player.


  The Goal Stack

At the core of this is the Goal Stack. It originally came to me when I was trying to figure out how to write an adventure game. The problem is that many actions are high level actions that are made up of smaller ones. For instance, before you can insert the key into the door, the character must first walk there. My solution was a stack (it usually is, I loves me stacks - greatest data structure ever).

[stack1.png]

At the very base of the stack is the ultimate goal. Putting it in terms of a sim-adventurer, perhaps the goal is, "I want to reach level 14". The AI looks at this goal and realizes, wait a second, I'm only level 12. So before I can reach level 14, I must first reach level 13. So "I want to reach level 13" is pushed on the stack ahead of the prime goal.

[stack2.png]

Then the AI looks at the top goal. Reach level 13. Okay, he is currently level 12 and only needs a total of 14,000 experience to reach level 13. Good. Now the goal "achieve total of 14,000 exp" is pushed on the stack. To reach that goal, the adventurer must kill monsters. So "kill monster" is pushed on stack.

[stack3.png]

The AI looks at the goal. The adventurer is in town right now. No monsters there to kill. First, the adventurer must go to a dungeon. So "goto dungeon" is pushed on the stack. That's easy. That step can be broken down no further. So the adventurer leaves the town and selects a dungeon and enters it - upon which, that goal is popped off the stack.

[stack4.png]

Now the current goal is to kill a monster. The AI realizes that before you can kill a monster, he must find one first. Well, the adventurer is in a dungeon, so the next step is to "locate monster". The new goal will cause the adventurer to walk around the dungeon until it finds a monster, where the goal is popped off the stack. Then the AI sees that the goal is to kill a monster, he's in a dungeon, there is a monster right next to him, so he now fights the monster.

[stack5.png]

After the monster has been slain, the goal is popped off the stack and the current goal becomes reach 14,000 experience. Well, the AI reasons, it is still shy of that goal. In order to achieve that goal it must, that's right, "kill a monster". That is repeated until the 14,000 experience points are collected.

[stack6.png]

That goal is popped off and the current goal becomes achieve level 13. To do that, the adventurer must return to town and level up at the adventurer's guild. By now you should see how this works. The first step is leave dungeon. Level 13 year? No, go to town. Level 13 yet? No, go to adventurer's guild? Level 13 yet? No, talk to guy. Level 13 yet? Yes. Finally. Now... Level 14 yet? No. need to achieve 18,000 exp, need to kill monster, need to go to dungeon, etc.


  Improvements

[stack7.png]

This system alone wouldn't work for complex behavior with only one goal, so there are a few improvements to make for it. The first is that there should be multiple goals. These can be rated by the player from 1 - 4 stars, which will help the AI prioritize them. Each goal will be stacked up to the next immediate action, then those actions compared against the priority and ease of accomplishment (something like going to town from a dungeon would be less inclined than finding another monster, for example).

It is entirely possible for multiple goals to arrive at the same step. For instance, you may two goals to "achieve level 14" and to "achieve rank 4 in guild". Each of these might be accomplished by killing a monster. At this point, those two goals become sub-goals of "kill a monster". The priority of a goal with sub-goals will be the highest of the sub-goals (for instance, if the two branches are four and two stars, then the goal itself will be four).

In some cases, there may be more than on way to achieve a goal. In these situations, the choice goal will be selectable, affecting the stack above it. For instance, something may require you to achieve level 14 and gain 13,000 gold. You can select which goal is active through a drop down box for that goal's slot. In the case of OR (level OR money) the AI will select the easiest way to accomplish the goal for the slot (though you can change it). For AND (level AND money), it doesn't matter which goal is selected since both must be accomplished eventually - though you can still select which goal is being worked on right now.


  Equipment Hints

As the little sim-adventurer goes through the dungeons, he will collect loot which he intends to hold, equip, or sell/trade. This is represented by three inventory bags. The adventurer will initially sort each item he finds into bags according to his nature, but you are allow to move items between bags at will. For instance, if he finds a nice sword but decides he doesn't want to use it, but you really think he should keep it around, just move it from the trade bag to the equipment bag. When facing monsters, he'll select his equipment from that bag only.

The trade bag is sort of special. By putting an item in that bag, the adventurer is indicating that he no longer wants that item and that he will get rid of it as soon as possible. Trading will become a goal with the priority based on how full the bag is (if the trade bag fills up, unloading it becomes an immediate priority). When the sim returns to town, he'll simple sell the items for gold at the shops.

However, adventurers may run into each other in a dungeon, under which they will initiate a trade. They will offer each other items from their trade bag. If they want an item from their friend's bag, they'll either purchase it outright with gold, or trade another item for it towards the cost. For instance, Maxim and Hubert meet in a dungeon. Maxim wants the short sword (10gp) and the ball of twine (1gp) while Hubert wants the Sword of Instant Death (20gp). When they trade, the difference will be 9gp that Hubert owes Maxim. Depending on how much two traders like each other (perhaps go to the same church) there is a margin of acceptance where additional cost might be overlooked. Since Hubert and Maxim like each other (sort of), the extra 9gp might be waived.


  Related

 

 





Copyright 2007-2014 Sean Howard. All rights reserved.