New land animal AI implemented

posted in Caveman
Published September 23, 2014
Advertisement
New land animal AI implemented



The new land animal AI has been implemented and plugged into the game.




The new land animal AI actually consists of 8 different types of AI:
1. AI for NPC allies of the player (travelling companions, hired warriors, and tamed pets).
2. AI for thieves
3. AI for neutral NPC cavemen
4. AI for animals and hostile cavemen who are defending a location
5. AI for hostile cavemen
6. AI for predators
7. AI for animals that defend their ground
8. AI for animals that maintain their distance






In refactoring the ground animal AI, it has taken a new form.

The old AI was more or less a setstate / runstate type design.

The new AI is more of the form:

[color=#0000ff]if (condition A) handle_condition_A()
else if (condition B) handle_condition_B()
else if (condition C) handle_condition_C()
else if (condition D) handle_condition_D()
etc.[/color]

The routines to handle different conditions turn and move the animal,trigger attacks, and play animations as required.






The conditions are more or less ordered from most to least important to respond to.

For example, all the animal AI code starts out the same:
if fatigued, restelse if rested, stop restingelse if cornered, attackelse if in collision recovery, do collision recoveryelse if taking fire { if have target, attack else flee in random direction }else if halfdead, fleeelse if have target within 20 feet { if target is stronger, flee else attack }







Instead of a single AI_state variable as used in a setstate / runstate design,
the new AI instead uses multiple state variables:

is_resting (boolean)
is_hunting (boolean)
in_collision_recovery (boolean)
orders (a predefined order such as goto location).
has_orders_target (boolean)
graze_state (stand, wander, flock, or migrate)
taking_fire (boolean)

this allows an animal to be in multiple AI states simultaneously, such as hunting, taking fire, in collision recovery, and resting.

IE, i'm on the hunt (targeting animals not bigger than me), but i'm taking fire from an unknown source, so i'm running,
but i've hit an obsticle, so i'm in collision recovery (bang and turn), and while in collision recovery, my fatigue has maxed out,
and i can't take another step, so i have to stop and catch my breath for a moment (rest).





One interesting thing is the fact that the handle_condition code for grazing actually uses a state machine variable (graze_state)
and uses a setstate / runstate type design.




I've been coding game AI on and off for 25 years now, and i keep coming back to expert systems implemented as multilevel decision trees
with multiple state variables, and the odd state machine thrown in at some level or another. Basically, each of the handle_condition
routines uses whatever AI type will work best for its particular task. In the case of graze, this just happens to be a state machine.
Most of the other handle_condition routines are decision trees, or simply code to turn some amount, move some amount, and possibly attack,
based on the condition being handled. At the lowest level, all the higher level AI routines eventually output calls to move, turn, attack,
and play animations as appropriate.




The dreaded avian AI is next! It turns out that AI for an avian predator is quite complex - perhaps amongst the most complex single entity AI I've ever heard of. And its ALMOST right, but not quite there. They still do this circle the target thing from time to time that doesn't seem correct, and i'm not quite sure what they're doing (as far as what their AI state is). Putting a simple trace variable on it will reveal what's going on, I just haven't gotten around to it yet. But implementing and testing the new avian AI should finally fix that odd behavior. I suspect it may have something to do with either resting but not landing first, or trying to fly and turn towards a target who is trying to move and turn towards you, resulting in the two of you moving in a circle, chasing each other.
1 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement