Multiplayer Interactive-Fiction Game-Design Blog



Download 8.87 Mb.
Page126/151
Date02.02.2017
Size8.87 Mb.
#15199
1   ...   122   123   124   125   126   127   128   129   ...   151

05 AI daily schedules


How to provide an AI with a daily schedule.


AI daily schedules

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.








More advanced scheduling

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:



  1. 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.





  2. 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.)



  3. Create an AIScheduleLocation() method that

    also traps the "attendmooselodge" and returns the room where the moose

    lodge meetings take place.





  4. If you want your NPC to be able to answer the question,

    "What are you doing?", then write AIScheduleWhatDoing() to

    trap "attendmooselodge".





  5. 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.



  6. 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.


Foraging - cAIForage

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:







  1. Create your monster or character as usual, which will be based

    on cMonster or cCharacter, and which are ultimately

    based on cAI.





  2. Add the cAIForageExtra superclass above the cMonster

    or cCharacter class. Placing it above is important sinec cAIForageExtra

    overrides some default behavior.



  3. Set pAIForageExtraWant to the class of object the AI wants.

    If you don't set it, it will default to "cFood".



  4. 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().





  5. 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).





  6. Set pAIForageExtraLocationWorkItinerant to cause the AI

    to move sequentially from work room to work room, or to wander between all

    of them.




  7. 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):



  1. Add the cGuardExitExtra super-class to the object.





  2. Fill in pAIScheduleLocationWork with the room that the guard

    is protecting.





  3. 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.







  4. pGuardExitExtraBlockDirection should be filled with the

    direction that the guard prevents players from going.







  5. 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.








Beggars - cBeggarExtra

You can make a NPC that begs for food, drink, money, or whatever using

the cBeggarExtra class.



  1. 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:





  1. Add a schedule to the NPC so it wanders around and begs.





  2. Change pAILikeEquip to control what comments it makes about what

    the player is carrying.





  3. pAIOfferCanBribe defaults to TRUE, but if you don't want the

    beggar to accept money then set this to FALSE.





  4. Change pAIOfferForget to adjust how frequently gifts can

    be given to the beggar.



  5. Change pAIOfferMaxAmount to determine how much the beggar will accept.







  6. pAIOfferMinLike controls how much the NPC must like the player before

    accepting gifts.







  7. pAIValueObject defines what objects the beggar likes. The default is

    for food and drink.







  8. pBeggarExtraMinTime affects the number of seconds that must ellapse

    between each "beg", so that beggars don't beg too often.







  9. pBeggarExtraSpeak is a list of phrases that the beggar will speak.

    You'll need to change this if you modify pAIValueObject.







  10. pBeggarExtraSpeakScriptPriority controls the priority of the begging script,

    ensuring that the beggar doesn't beg when running away from a monsters.







Download 8.87 Mb.

Share with your friends:
1   ...   122   123   124   125   126   127   128   129   ...   151




The database is protected by copyright ©ininet.org 2024
send message

    Main page