ok, here's a concrete example.
these are the current "rules of behavior" for predators in Caveman 3.0, stuff like saber-tooths and such:
1. select target: closest detected PC, NPC, or animal of different species.
2. if cornered (surrounded bya combo of terrain and / or other entities), attack.
3. if in collision recovery, do collision recovery
4. if not in collision avoidance and obstacle ahead, go into collision avoidance mode
5. if in collision avoidance mode, avoid collision
6. if taking incoming missile fire and have a target, attack.
7. if taking incoming missile fire and don't have a target, go into "flee from missile fire of unknown origin" mode <g>.
8. if in "flee from missile fire" mode, flee from missile fire.
9. if half dead and have a target, flee
10. if have a target, and range to target is <= 20 ft (a nearby threat): if the target is stronger, flee - else attack.
11. if not fleeing from nearby campfire, and near a campfire, go into "flee from campfire" mode. // this is the new rule i just added
12. if in "flee from campfire" mode, flee from campfire // this is the new rule i just added
13. if fatigued, rest
the above rules are common for all non-avian AI's except for the "maintain distance" AI used by things like proto-horses. the game has 13 types of AI altogether.
the following rules are the ones specific to predators, they are applied after the common AI rules, if no common AI rule has yet been acted upon:
14. if hunting, and there's a carcass nearby, turn to the carcass. if more than a few feet away, run, else stand. once they're standing at the carcass, after a random amount of time, they will "finish eating", which switches them from "hunting" mode to "graze" mode.
15. if hunting, but no carcass nearby, and have a target, attack.
16. if hunting, but no carcass, and no target, switch from hunting mode to graze mode.
17. do graze mode. graze mode transitions at random between the following states: stand, wander, flock, and migrate (in the case of a "leader" of a group). after a random amount of time, the animal will "get hungry" and switch to "hunting" mode.
so i have variables for
target type (animal or human)
target ID number
range to target
"in collision recovery" fag
collision recovery direction (what direction to move to recover)
collision recovery counter (how many updates they've been in collision recovery)
"in collision avoidance" flag
collision avoidance moveto x (where they should move to to avoid the collision)
collision avoidance moveto z
"taking missile fire" flag
taking missile fire direction (what direction to run from missile fire of unknown origin)
taking missile fire counter (how many updates they've been running from missile fire of unknown origin)
hit points (for "is half dead?")
damage (for "is half dead?")
"fleeing from campfire" flag (at the moment i'm using the flee from missile fire variables for flee from campfire).
"flee from campfire" direction (at the moment i'm using the flee from missile fire variables for flee from campfire).
"flee from campfire" counter (at the moment i'm using the flee from missile fire variables for flee from campfire).
fatigue (for "if fatigued, rest")
"is hunting" flag
graze AI state variable (stand, wander, flock, or migrate)
wander direction (what direction to wander off in)
wander counter (how many updates they've been wandering)
its was having to add yet another flag, direction, and counter for "flee from campfire" that prompted my original post.
note that a lot of them are the "flag, direction and counter" pattern (so to speak). with "flag and target x,z" being another "pattern" used.
i suppose i could determine all the mutually exclusive states that use the "flag, direction, and counter" pattern (so to speak), and just use a single flag, direction and counter for them all. that would simplify things somewhat...
basically i'm using rule based decision trees to create "expert systems" for each of the 13 AI types in the game.
is there another approach that's going to be less complicated?
in the past when i've looked at other methods of implementing a set of behavior rules such as the one above, none has really struck me as being simpler or better.
also, a lot of folks seem to swear by planners. would a planner be appropriate for implementing the above rule set?
if so, how? for some reason, i;ve never quite gotten the idea of how they work. maybe i just haven't read up enough on them. but the examples i've seen don't really seem to fit well with implementing rule sets like the one above.
a simple example of how a planner would implement even just a couple of the rules would be greatly appreciated.