How to provide an AI with a daily schedule.
If you want your AI to have a daily schedule, some automatic
scheduling exists.
-
To have the NPC work in a location,
set pAIScheduleLocationWork. If you want something
other than a 9-5 job, set pAIScheduleTimeWork.
-
To have your NPC return home and sleep,
set pAIScheduleLocationLive. The sleeping
hours can be set with pAIScheduleTimeSleep.
-
To have the NPC recreate (hang out) somewhere,
set pAIScheduleLocationRecreate. The time
can be set with pAIScheduleTimeRecreate.
The chances are that you'll want your NPC to do more than just
walk to work, walk home, and sleep. To control more advanced schedule options:
-
Come up with a lower-case name for an activity that the
NPC regularly does, such as "attendmooselodge" to have the
NPC attend a Moose Lodge meeting.
-
Create an AIScheduleEnum() method for the AI that
fills in ScheduleList with information about "attendmooselodge", such
as the time and the priority. (You can use this method to make sure
your NPC only attends the meetings once a week.)
-
Create an AIScheduleLocation() method that
also traps the "attendmooselodge" and returns the room where the moose
lodge meetings take place.
-
If you want your NPC to be able to answer the question,
"What are you doing?", then write AIScheduleWhatDoing() to
trap "attendmooselodge".
-
If you want your NPC to do any tasks while at the lodge (based on cAIGoal),
then you'll need to write a AIScheduleGoal() method. You
can control what the NPC does when its there, what it does before going there,
and what it does when it's finsihed.
-
If you have several characters who are a member of the Moose Lodge,
you have another choice: Create an oFactionMooseLodge based
on cFaction, and impliment the AIScheduleEnum(),
AIScheduleLocation(), and AIScheduleGoal() methods in the faction.
That way, all members of oFactionMooseLodge will show up to the meeting!
Note: The scheduling features described here only work
if the NPC has the oAIGoalSchedule running. This will be run by default.
However, if you override the default, you may need to include
oAIGoalSchedule in the goals that you include in the overridden version.
A more complex schedule, foraging, is included in
the cAIForage class. This lets you create monsters that wander
around looking for food, or NPCs which pick up tin cans as they see them.
To create a monster (cMonster) or character that forages:
-
Create your monster or character as usual, which will be based
on cMonster or cCharacter, and which are ultimately
based on cAI.
-
Add the cAIForageExtra superclass above the cMonster
or cCharacter class. Placing it above is important sinec cAIForageExtra
overrides some default behavior.
-
Set pAIForageExtraWant to the class of object the AI wants.
If you don't set it, it will default to "cFood".
-
Fill is pAIForageExtraEat to indicate if the foraging creature
will eat whatever it finds, or keep it in its possession. You can create
more complicated behaviors by wiring your own AIForafeExtraForageAct().
-
Set pAIScheduleLocationWork to a list of rooms where the NPC
forages, or which are destinations for foraging (and the AI will forage on
the way).
-
Set pAIForageExtraLocationWorkItinerant to cause the AI
to move sequentially from work room to work room, or to wander between all
of them.
-
Set pAIScheduleTimeWork to the hours that the AI forages.
That's it. Your character will wander around picking up (and potentially) eating
the appropriate objects. Plus, PCs can give the NPC the right sort of objects
and make the NPC more friendly.
You may also wish to modify the following properties and methods:
-
pAIForageExtraAmountWant and pAIForageExtraByValue cause the AI to "go home" if
it has foraged enough.
-
pAIForageExtraDropGoalPriority and pAIForageExtraRoomGoalPriority control
whether the AI stops to forage in the middle of combat.
-
pAIForageExtraGiveLike and pAIForageExtraGiveStopAttack affect how much the NPC likes
a PC that provides the foraged items... such as giving food to a foraging monster.
-
pAIScheduleIdleWork is used to describe the character
foraging. Defaults for monsters eating are already provided in cMonster.pAIScheduleIdleWork.
-
pAIForageExtraGiveNoThanksNarrate, pAIForageExtraGiveNoThanksSpeak,
pAIForageExtraGiveThanksNarrate, pAIForageExtraGiveThanksSpeak,
pAIForageExtraShowNoWantNarrate, pAIForageExtraShowNoWantSpeak,
pAIForageExtraShowWantNarrate, and pAIForageExtraShowWantSpeak all
control the AI's narrated and spoken reaction.
-
pAIScheduleWhatDoingWork lets the NPC say what it's looking
for when a player asks.
-
AIForageExtraForageAct() can be used to provide more complex
foraging activities than just eating and picking up objects.
Guarding an exit - cGuardExitExtra
To make a NPC guard an exit (and prevent players from leaving via the exit),
create a character (based on cCharacter or whatever):
-
Add the cGuardExitExtra super-class to the object.
-
Fill in pAIScheduleLocationWork with the room that the guard
is protecting.
-
pAIScheduleTimeWork should be filled in with the hours that
this guard keeps. If the guard isn't there all the time then make sure to
have other guards show up, or players only have to wait for the
guard to leave.
-
pGuardExitExtraBlockDirection should be filled with the
direction that the guard prevents players from going.
-
pGuardExitExtraCanPassProperty the the property that will
be set on the PC that indicates that the PC is allowed to pass.
You might also wish to set:
-
pGuardExitExtraBlockNarrate for a narration of how the guard
blocks the PC from going in the blocked direction.
-
pGuardExitExtraBlockSpeak is spoken by the guard when he
blocks the PC.
-
pGuardExitExtraFavor controls whether the player can get
friendly with the guard and ask for a favor.
-
pGuardExitExtraFavorGranted is what the guard says when it
grants the favor of passage.
-
pGuardExitExtraWaitForObject ensures that the guard waits
around until another guard shows up.
You can make a NPC that begs for food, drink, money, or whatever using
the cBeggarExtra class.
-
Add the cBeggarExtra super-class to the object, on top
of cRaceElf, or whatever.
That's it! The NPC will beg for food, drink, and money whenver a player enters
the room, or it enters a room with a player.
You might also wish to:
-
Add a schedule to the NPC so it wanders around and begs.
-
Change pAILikeEquip to control what comments it makes about what
the player is carrying.
-
pAIOfferCanBribe defaults to TRUE, but if you don't want the
beggar to accept money then set this to FALSE.
-
Change pAIOfferForget to adjust how frequently gifts can
be given to the beggar.
-
Change pAIOfferMaxAmount to determine how much the beggar will accept.
-
pAIOfferMinLike controls how much the NPC must like the player before
accepting gifts.
-
pAIValueObject defines what objects the beggar likes. The default is
for food and drink.
-
pBeggarExtraMinTime affects the number of seconds that must ellapse
between each "beg", so that beggars don't beg too often.
-
pBeggarExtraSpeak is a list of phrases that the beggar will speak.
You'll need to change this if you modify pAIValueObject.
-
pBeggarExtraSpeakScriptPriority controls the priority of the begging script,
ensuring that the beggar doesn't beg when running away from a monsters.
Share with your friends: |