They're Behaving Like Monsters! An Introduction to Stimulus-Based Behavior in Computer Role-Playing Games
In most face-to-face role-playing games (RPGs), programmers expect to do the thinking for the monsters and people that players will encounter in the adventures. But what about computer games? Assuming that you want your creatures to do more than just stand around waiting to be killed, robbed, or rescued, you're going to need a method of determining how these beings will behave in a variety of situations.
Developing the Stimuli
Human and animal behavior is driven by multiple stimuli, so let's model that. To keep things simple, we'll focus on five behaviors:
Each of these five basic stimuli exists as a weighted value. Further, there may be one or more "special" behaviors specific to that individual or race/type of creature. Examples include racial animosity (orcs versus elves, for example); superstition (such as aversion to the undead); or even an irrational compulsion (dwarves and gold, for instance). Each of these behaviors will also have a weighted value and should be considered along with the basic stimuli.
- For the fear and aggression stimuli to work properly, your creatures must be able to gauge their own strength and also form a relative opinion of anything else they encounter. A heightened fear stimulus would typically correlate to a lowered aggression level, and vice versa. It's important to note that some creatures may simply be more aggressive (or fearful) than others and would already have increased values in those stimuli.
- With desire, your creatures must be able to assign a value to items or treasure they covet. The simplest (but not necessarily most realistic) mechanic would be to use the in-game value of the item(s) in question. Food could be handled slightly differently, as it would usually be based on the creature's immediate hunger level. However, hoarding food when not hungry would be logical behavior for an individual creature that has gone hungry in the past.
- Boredom is probably the simplest stimulus to implement. Consider it a random chance of your creature doing something altogether unpredictable, such as wandering around when nothing interesting is going on. To make the behaviors feel more natural, an "attention span" attribute could be applied to certain creatures. This implies that they might lose interest in following a given behavior if it starts taking too long to complete or offers no obvious, immediate reward.
- Loyalty is weighed against all other stimuli and correlates to how likely a creature is to follow orders in the face of distraction. A moderately loyal creature might be content to carry out its assigned tasks as long as no other stimuli are present. Loyalty might also be affected by the creature's current health or hunger status. For example, a wounded creature might succumb more quickly than a healthy one to a fear stimulus.
I've used these techniques successfully in a play-by-mail RPG and in my current project, Heroic Adventure!, which is written entirely in Visual Basic .NET.