Provides an overview of goals that can be used to move NPCs around.
The AI library includes a number of goals designed for
NPC movement. Here's a quick overview: (For more inforamtion about
the goals look in the documentation specific to the goal
object.)
-
oAIGoalMoveFollowCircuit - With this goal, you
provide a set of destinations, such as Room A, Room F, and
Room Q, and the AI automatically wanders from Room A to Room F,
to Room Q, and then back to Room A. The path between A and F,
F and Q, and Q and A is automatically calculated.
This goal use useful for guards and other NPCs
with set movments.
-
oAIGoalMoveFollowObject - NPCs using this goal
will follow an object around, wherever it is in the world.
It can be used to have monsters chase after fleeing
characters, for pets, or to produce monsters that
stalk characters.
-
oAIGoalMoveFollowPath - This goal causes an AI
to follow an exact path between rooms. All rooms must be connected.
You probably won't use it; instead, look at oAIGoalMoveFollowCircuit
or oAIGoalMoveToRoom.
-
oAIGoalMoveFollowPersonalPC - NPCs follows
whatever PC is assigned to its pPersonalNPCFor property.
-
oAIGoalMoveRandomCircuit - This is like
oAIGoalMoveFollowCircuit except that the immediate destination
is randomly chosen from any of the rooms in the list.
Use this for unpredictable guards who check out
rooms, but not in any specific order.
-
oAIGoalMoveLeadObject - You can use this goal,
in conjuction with oAIGoalMoveToRoom, to have the NPC lead
a character along a path. If the character falls behind or
wanders off the path the NPC can (optionally) chase the
character down and ask the character to follow.
-
oAIGoalMoveToAdjacentRoom - This goal is a sub-goal
of all the movement goals. It causes a NPC to move to a
room that's adjacent to the one it's in. In the process it
will open (and unlock doors), and get up if it's knocked down.
-
oAIGoalMoveToObject - The AI will located an
object (by cheating) and head towards the room that contains
the object, like oAIGoalMoveToRoom. However, if the object
moves in the meantime, the object will identify the move and
adjust its course. Use this for panicked villagers
looking to find the town's guards.
-
oAIGoalMoveToOrigin - Invoking this goal will
cause the NPC to return to wherever it was created. This
is a useful goal for getting fleeing NPCs to return
to where they belong.
-
oAIGoalMoveToRoom - The AI will walk to the
specified room.
-
oAIGoalMoveWanderAroundMap - Using this, the NPC
will wandering around any room it can get to in a map (or
maps). Use this for wandering animals and monsters that
have no fixed location.
-
oAIGoalMoveWanderNearby - AI's with this goal will
wander around the starting room, but never very far from
it. You can use it for spawned monsters in dungeons that
should basically stick to their spawning point.
-
oAIGoalWaitForObject - Causes the AI to wait around
for an object to appear in the room. This is useful for "waiting
for the cows to come home" or cGuardExitExtra - waiting to make sure
the exit isn't left unguarded.
Some movement-related goals are used by the movement goals:
-
oAIGoalObjectLock - The AI will lock or unlock
an object, such as a door or chest.
-
oAIGoalObjectOpen - This causes the NPC to open
or close a door or container. Optionally, the NPC can unlock
or lock the container.
-
oAIGoalStandUpSitDown - Causes the NPC to stand
up or sit down.
-
oAIGoalEmote - Causes a NPC to emote.
04 Combat AI goals
Describes how the combat AI works.
The AI that handles combat is a bit tricky, so this section
will be a tad long...
Every AI (derived from cAI) remembers a list of dangerous enemies,
as well as friends that will help in combat. (This list is different
than the like/dislike list also supplied for AI's.)
Characters that a NPC meets are rated from 10.0 to -10.0 on the
enemies list. Values between 10.0 and 1.0 mean that the character
is an enemy that will attack the NPC. .999 and -.999 is a neutral
character whose intentions are unknown. -1.0 to -10.0 is a trusted
friend that will help defend the NPC in combat.
When a NPC first encounters a character, a call
to AIEnemiesListGuess() is called to see if the
NPC considers the character an enemy. The default behavior
for this function is to:
-
If the AI has pAIEnemyOfAllPCs then the AI will
automatically be an enemy of any character controlled by
a player. This is a good setting for a monster.
-
If the AI was spawned by the same room as another AI then
it will be a friend with the other AI.
-
If the AI is the same class as the other AI
it's an automatic friend too. Thus, if a number of tigers
are spawned in different rooms of the wilderness, they
will act as friends.
You can provide your own AIEnemiesListGuess() function for
an AI.
The enemies rating is affected by what the AI sees:
-
When a NPC is attacked, the attacker is almost invariably added
to the NPC's enemies list.
See cAI.PerceiveAttack for the code.
-
When the NPC see a friend attacked,
the attacker is likewise added (but not always).
See cAI.PerceiveAttack for the code.
-
If a character
attacks a NPC's enemy, they are (usually) made a friend.
See cAI.PerceiveAttack for the code.
-
If an AI starts yelling out for help
using AICombatCallForHelp(), the
code in cAI.PerceiveSpeak() may cause any
AI's that hear the yell to become enemies of the attackers.
You can programatically set and read the enemies' list values
using the following methods:
-
AIEnemiesCalculateTheOdds() - Used by AIs to
determine if they're likely to win a battle of if their
enemies are likely to win. It's based on AIEnemiesListUpdate().
You probably won't need to use this method directly.
-
AIEnemiesListGet() - Returns the enemies rating,
from 10 to -10, for a character. If the character has never
been met it returns NULL.
-
AIEnemiesListGuess() - Call this if no rating
is set. It will return a rating to begin with, or Undefined
if there's no opinion whatsoever. Calling ToNumber (
AIEnemiesListGuess()) will always return a number, since
Undefined will be converted to 0.
-
AIEnemiesListSet() - Sets a new rating for the
enemy or friend.
-
AIEnemiesListUpdate() - Finds all the characters
in a room and checks their enemies' list score. If it's
unknown, then it calls AIEnemiesListGuess() to fill them in.
This method can optionally return a list of enemies, friends,
or both enemies and friends.
Perceiving a possible conflict
AI's check for enemies in the room when:
-
The AI walks into a new room.
This code is on cAI.PerceiveInNewRoom().
-
When a character walks into the AI's room.
This code is on cAI.PerceiveActorEnter().
-
When an AI sees one character attacking another.
This code is on cAI.PerceiveAttack().
When danger might just have appeared, the AI code
calls AIPotentialConflict(). This checks for any
enemies in the room.
If there are enemies in the room, the code adds several
goals to the AI's list. The goals used are
in pAIGoalsConflict. If the goal is already in
the AI's list then it is not added a second
time.
The default goals that are added by pAIGoalsConflict are:
-
oAIGoalCombatRetreat - This causes the AI to test
out it's odds of winning every once in awhile. If it thinks its
odds are still good the AI suspends the retreat goal for another
10 seconds. If there are not enemies left, the retreat goal
finishes.
If the goal decides that the character is in danger,
based on a call to AIEnemiesCalculateTheOdds(),
then the AI will run away. pAICombatBravery is
used to determine how much the odds have to be stacked against
the AI before it runs, as well
as pAICombatWoundsRetreat to see if
it will selfishly abandon it's friends when its wounded.
If pAICombatRunDrop is set to TRUE, the AI will
drop an item to distract its attackers.
If pAICombatRunCallForHelp is set to TRUE the
AI will yell for help as it runs.
If pAICombatRunForGuard is set to TRUE, the AI
will run to the nearest guard and ask it for help. (This
one is particularly useful for villagers, which should run at
the slightest sign of danger and seek a guard.)
-
oAIGoalCombatCallForHelp - This causes the NPC
to call out for help once in awhile. AI's listen
for calls for help in their PerceiveSpeak() methods.
If they detect a call, they determine if the calling NPC
is a friend, enemy, or neutral. If it's a friend, they
may run to the friend's aid
if pAICombatCallForHelpRespondsFriends is not 0.
Likewise, if they hear an enemy calling for help, they may
decide to join in the kill.
The pAICombatCallForHelpRespondsEnemies property
affects this chance.
If you don't wish a NPC to call for help, override
its pAIGoalsConflict so it doesn't include the goal.
-
oAIGoalAttackEnemies - This goal causes the NPC
to attack any enemies in the room. It picks an enemy, by
various means, and attacks with a weapon. The code also
has the AI ready a weapon or potentially pick one up.
-
oAIGoalMoveChaseEnemies - If all the enemies
in a room are killed, oAIGoalAttackEnemies will finish.
The next goal in line causes the NPC to chase after enemies
in neighboring rooms, just in case some of the enemies
ran away. It finishes when no more enemies
are left in any neighboring rooms.
-
oAIGoalLootDeadBodies - Once all the enemies
are gone, this goal will have the NPC loot all the dead bodies.
It picks up the most valuable items first. It will hold onto
them for 30-60 minutes, after which point they're automatically
deleted. That means that characters who are killed by NPCs have
30-60 minutes to find the NPC and kill it, or they won't
get their gear back.
-
oAIGoalMoveToPreCombat - Finally, after all the
bodies have been looted, oAIGoalMoveToPreCombat causes the
NPC to return to the room it was in before combat began.
Once there, this goal finishes and the AI continues its
normal routine.
When a NPC is first created, it automatically adds the following
goal, as specified in pAIGoalsFirstActions.
List of other combat-related goals
Of course, you can
change pAIGoalsConflict and pAIGoalsFirstActions to
whatever goals you wish.
Some other combat-related goals that I haven't discussed yet
are:
-
oAIGoalAttackEnemy - Has the NPC take a swing
at an enemy. This is called from oAIGoalAttackEnemies.
-
oAIGoalCombatAim - Call this to have the
NPC change his aim (body part) location to a specific value.
-
oAIGoalCombatAimChoose - Call this to have the
NPC change his aim (body part) location automatically, based on
various personality properties.
-
oAIGoalCombatDefend - Call this to have the
NPC change his defense location to a specific value.
-
oAIGoalCombatDefendChoose - Call this to have the
NPC change his defense location automatically, based on
various personality properties.
-
oAIGoalCombatEnemy - Call this to have the
NPC change target a new enemy, based on a passed-in parameter.
-
oAIGoalCombatEnemyTargetChoose - Call this to have the
NPC change his targeted enemy, based on
various personality properties.
-
oAIGoalCombatDodgeParry - Call this to have the
NPC change his dodge/parry to a specific value.
-
oAIGoalCombatDodgeParryChoose - Call this to have the
NPC change his dodge/parry, based on
various personality properties.
-
oAIGoalCombatRetreatCallForHelp - This goal
causes the NPC to keep calling out for help until the goal
is killed. It's added and killed when the NPC retreats
in oAIGoalCombatRetreat.
-
oAIGoalObjectEquip - The NPC will equip
or unequip a single
object. It's called by oAIGoalObjectEquipAll.
-
oAIGoalObjectGetDrop - The combat AI uses this
goal to pick up weapons it wishes to equip, to loot bodies,
or to drop treasure in the hopes of distracting an attacker.
-
oAIGoalObjectGetWeapon - The AI will pick up
a weapon from the ground (or a dead body) if it's better than
its current weapon, and if it's usable by the NPC. This
is used by oAIGoalAttackEnemies if the AI's weapon breaks
or gets dropped.
Many of the combat-related goals rely on properties that affect
how the AI reacts in combat:
-
pAICombatAttackEnemySpeed - How rapidly the AI attacks
compared to the ideal attack speech for his weapon.
-
pAICombatAttackEnemySpeedVar - Amount of variation in
the AI's attack speed.
-
pAICombatAimLocation - Location where the AI tends to aim for.
-
pAICombatAimSwitch - Likelihood of the AI aiming for
a different body part.
-
pAICombatDefendBodyPart - Preferred defence location.
-
pAICombatDefendJustHit - How likely it is that the AI
will defend a body part that was just hit.
-
pAICombatDefendSwitch - Likelihood of changing defence locations.
-
pAICombatEnemyTargetAttacker - Likelihood that the AI
will attack the last character that attacked it.
-
pAICombatEnemyTargetSame - How likely the AI will keep
attacking the same enemy and not switch.
-
pAICombatEnemyTargetWeaker - Causes the AI to
attack weaker opponents in preference to stronger opponents.
-
pAICombatEnemyTargetWounded - Likelihood that the AI
will attack the most wounded character.
-
Because each NPC will have their own combat tactics, you might
wish to provide a AIGoalOverride() method that
overrides some standard combat goals,
such as oIAIGoalCombatDefendChoose, with a custom goal. For example:
You could use this to make the NPC only defend one part of his
body.
Share with your friends: |