Jump to content

AI: Difference between revisions

172 bytes added ,  16 December 2015
continuing rewrite; if only Czech had a definite article ^_^
(continuing rewrite; if only Czech had a definite article ^_^)
Line 61: Line 61:




'''Hearing''' is crucial in Oni. The majority of AI character interaction is done via the sound system. Oni recognizes these types of sound (colors in parentheses are used for sound visualization when '''[[ai2_showsounds]]''' is set to 1):
'''Hearing''' is crucial in Oni. The majority of AI character interaction is done via the sound system. Oni recognizes these types of sound (colors in parentheses are used for sound visualization when [[ai2_showsounds]] is set to 1):
:*Unimportant (blue) - is ignored to some extent if alert level of AI is "lull", but after some period of time, the AI will register it.
:*Unimportant (blue) - is ignored to some extent if alert level of AI is "lull", but after some period of time, the AI will register it.
:*Interesting (green) - raises alert level to "low"
:*Interesting (green) - raises alert level to "low"
Line 119: Line 119:




==Pursuit of enemy alias "I will find you..."==
==Pursuit==
Everything that was needed was explained in section above so let's take a look at '''pursuit''' behavior. Pursuit behavior in Oni emulates the situation when a man knows "somebody is here", but does not see anybody.
Now that alert and awareness levels have been covered, let's take a look at '''pursuit''' behavior. Pursuit behavior in Oni emulates the situation when a person knows "somebody is here", but does not see anybody. In Oni there are following types of '''pursuit''' behavior:
:*None: No pursuit taking place
:*Forget: the AI drops to the Forgotten level of awareness of this enemy
:*GoTo: the AI moves to the source of the disturbance and performs 600 frames (10 seconds) of Look behavior
:*Wait: the AI simply stands and waits to see/hear something more
:*Look: the AI turns in place, looking all around
:*Move: unimplemented; probably was meant to be similar to Look, but with character randomly moving around
:*Hunt: unimplemented; probably was meant to make AI purposefully hunt around for the enemy
:*Glance: the AI does not rotate its whole body, but only turns its head


Oni deals with this problem by using pursuit behaviors. In Oni there are following types of '''pursuit''' behavior:
Plus there are three types of '''lost''' behavior (when an AI had definite contact with the enemy but the enemy managed to get away):
:*None - simply nothing
:*ReturnTo Job: the AI returns to its job
:*Forget - AI goes into forgotten awareness with this enemy
:*KeepLooking: the AI does not return to its job, and keeps using the last used pursuit behavior
:*GoTo - AI moves to the source of distrubance and executes timer-based 600 frames Look behavior (600 frames = 10 seconds)
:*FindAlarm: the AI tries to switch to alarm behavior (see section [[#Alarm behavior|Alarm behavior]]); if it does not succeed, then it returns to its job.
:*Wait - AI simpy stands and waits
:*Look - AI rotates on spot and looks all around
:*Move - unimplemented, probably was meant to be similar to Look, but with character randomly moving around
:*Hunt - unimplemented, probably was meant to make AI purposefully look around for the enemy
:*Glance - AI does not rotate whole body, only rotates its head


Plus there are three types of '''lost''' behavior (when AI has definite contact with enemy but enemy manages to get away)
:*ReturnTo Job - AI returns to its job
:*KeepLooking - AI does not return to its job but keeps using the last used pursuit behavior
:*FindAlarm - AI tries to switch to alarm behavior (see section [[#Alarm behavior - "She's everywhere!"|Alarm behavior]]), if it does not suceed, AI returns to its job.




In Oni, a character is spawned in the level from a character profile (a [[CHAR]] file). This CHAR profile contains links to:
:*[[ONCC]] file, for character class, eg. Konoko or Comguy_1
:*[[CMBT]] file, for the combat profile for this character
:*[[MELE]] file, for the melee profile  for this character
:*[[PATR]] file (OPTIONAL), for the patrol path
:*[[NEUT]] file (OPTIONAL), for neutral behavior (e.g., a civilian giving the player a powerup)


In Oni, a character which is spawned in the level is a character profile from [[CHAR]] file. This CHAR profile contains links to:
:Pursuit behavior is executed only within the '''Pursuit range''', which is the parameter <PursuitDistance> in the [[CMBT]] profile attached to the AI. If anything suspicious happens outside of this range, the AI only looks in the direction of the disturbance for a short time, then ignores it and returns to its job.
:*[[ONCC]] file - character class, eg. Konoko or Comguy_1
:Pursuit behavior greatly depends on the AI's level of alert. There are four parameters regarding alert levels in the CHAR profile:
:*[[CMBT]] file - combat profile for this character
:*Initial: the AI is spawned with the specified level of alert
:*[[MELE]] file - melee profile  for this character
:*Minimal: the minimal alert level this AI can have
:*[[PATR]] file - OPTIONAL, patrol path
:*JobStart: the alert level of the AI when it starts some job (typically a patrol)
:*[[NEUT]] file - OPTIONAL, neutral behavior (for example civilians giving player some powerup)
:*Investigate: From the alert level specified here, and all greater alert levels, the AI will tend to pursue any suspicious sound it hears or any hostile peripheral contact it makes


:Pursuit behavior is executed only within the '''Pursuit range''', which is a parameter <PursuitDistance> in [[CMBT]] profile attached to the AI character. If anything suspicious happens outside of this range, AI only looks in the direction of disturbance for a short time, then ignores it and returns to job.
:Pursuit behavior greatly depends on level of alert. There are four parameters regarding alert levels in [[CHAR]] profile:
:*Initial - AI is spawned with this level of alert
:*Minimal - minimal alert level this AI can have
:*JobStart - Alert level of the AI when it starts some job (most typically a patrol)
:*'''Investigate''' - From this alert level and all greater alert levels AI will tend to pursue any suspicious sound it hears or any hostile peripheral contact it makes.


:Also in [[CHAR]] are five fields regarding pursuit behavior:
:*Lull/Low alert level and '''strong''' awareness behavior: in XML labeled as <StrongUnseen>
:*Lull/Low alert level and '''weak''' awareness behavior: in XML labeled as <WeakUnseen>
:*Medium/High/Combat alert level and '''strong''' awareness behavior: in XML labeled as <StrongSeen>
:*Medium/High/Combat alert level and '''weak''' awareness behavior: in XML labeled as <WeakSeen>
:*Lost (when an AI had a definite contact but lost it): in XML labeled as <Lost>


:Also in [[CHAR]] there are five fields regarding pursuit behavior:
:*Lull/Low alert level '''strong''' awareness behavior - in xml labeled as <StrongUnseen>
:*Lull/Low alert level '''weak''' awareness behavior - in xml labeled as <WeakUnseen>
:*Medium/High/Combat alert level '''strong''' awareness behavior - in xml labeled as <StrongSeen>
:*Medium/High/Combat alert level '''weak''' awareness behavior - in xml labeled as <WeakSeen>
:*Lost - behavior when AI had definite contact (confirmed enemy) but lost it, in xml labeled as <Lost>


:If an AI registers any sound or peripheral vision contact inside its pursuit range while its alert level is below the alert level set in its '''Investigate''' parameter, then this AI will only look in the direction of the disturbance for a short time, then ignore it and return to its job. However, if the alert level of the AI is high enough, the AI goes into pursuit mode. That means that the AI will get a '''strong awareness''' of the enemy (or only '''weak''' in the case of peripheral contact), go to the source of the disturbance (the center of the sound sphere in the case of a sound, or the spot where the enemy stood in the case of peripheral eye contact), and will perform the pursuit behavior Look for 10 seconds. After this initial Look mode expires, the AI will perform the pursuit behavior prescribed in its [[CHAR]] profile.
:The length of each pursuit behavior's execution depends on the HostileThreat timers ([[ONCC]] file), as described in the section above.


:If inside pursue range AI character registers any sound or peripheral vision contact while its alert level is below alert level set in '''Investigate''' parameter, then this AI will only look in a direction of disturbance for a short time, then ignores it and returns to job. However, if alert level of the AI is high enough, AI character goes into pursue mode. That means AI will get '''strong awareness''' of the enemy (only '''weak''' in case of peripheral contact), goes to the source of disturbance (center of sound sphere in case of sound or the spot where enemy stood in case of peripheral eye contact) and will perform pursuit mode Look for 10 seconds. After this initial Look mode expires, AI starts with pursuit behavior prescribed in its [[CHAR]] profile.
:Length of each pursuit behavior execution depends on HostileThreat timers ([[ONCC]] file) as described in section above.






 
Modding hints: '''Pursuit mode complications and weird glitches'''
Modding hints: '''Pursuit mess and weird glitches'''
:Watch [http://www.youtube.com/watch?v=OMFK5iKcZ5Q this YouTube video]. Pursuit mode is quite buggy, so when setting pursuit behaviors, there are several important things a modder has to have in mind.
:[http://www.youtube.com/watch?v=OMFK5iKcZ5Q Watch this YouTube video.]
:*The pursuit distance parameter in CMBT is important in deciding whether the character should be more of a pursuer or more of a guard.
:Pursuit mode is quite buggy, so when altering this behavior, there are several important things modder has to have on mind.
:*Within the pursuit distance, peripheral vision pursuit follows its own rules. When an AI sees an enemy with its peripheral vision, this AI always goes into weak awareness mode and either just glances in the direction of this enemy (alert level was below Investigate level) or moves to the spot and performs weak investigation pursuit behavior (alert level was at Investigate on higher).
:*Pursuit distance parameter in [[CMBT]] is important in deciding whether the character should be more a pursuer or more a guard.
:*Remember that there are TWO sets of pursuit behavior:
:*Within the pursuit distance, peripheral vision pursuit runs its own league. When AI character sees enemy with its peripheral vision, this AI always goes into weak awareness mode and either just glaces at direction of this enemy (alert level was below investigate level) or moves to the spot and performs weak investigation pursuit behavior (alert level was on investigate level on higher).
:**strong and weak pursuit for lull/low alert levels. In XML these are called <StrongUnseen> and <WeakUnseen>, however those names simply reflect how many changes were made to this part of the game.
:*Remember there are TWO sets of pursuit behavior:
:**strong and weak pursuit for medium/high/combat levels, in XML called <StrongSeen> and <WeakSeen>.
:**strong and weak pursuit for lull/low alert levels. In xml these are called <StrongUnseen> and <WeakUnseen>, however those names simply reflect how many changes were made to this part fo the game.
:*From all the available pursuit behaviors, only GoTo, Look, Glance, Forget and Wait can be effectively used as CHAR pursuit behavior parameters. Hunt and Move are not finished code-wise.
:**strong and weak pursuit for medium/high/combat levels, in xml called <StrongSeen> and <WeakSeen>.
:*'''Remember that general pursuit behavior is simply glitched, and the parameters from CHAR are more often ignored than actually used.''' The glitchiness is somehow connected with vision. When AI vision is turned off via '''ai2_blind=1''', pursuit mechanics work as they should. However, the moment that AIs are allowed to see, then when pursuit should be performed, it results in:
:*From all available pursuit behaviors GoTo, Look, Glance, Forget and Wait can be effectively used in CHAR pursuit behavior parameters. Hunt and Move are not finished code-wise.
:**pursuit values from CHAR being ignored if pursuit mode was called while the character was idle or moving along a patrol path. The AI character performs basic GoTo + timer-based Look for the whole period of pursuit behavior, for both strong and weak awareness. Looks so-so but definitely is a glitch.
:*'''Remember that whole pursuit behavior is glitched and parameters from CHAR are more often ignored than actually used.''' This glitch is somehow connected with sight. When sight of AI characters is turned off via '''ai2_blind=1''', whole pursuit mechanics work as they should. However, the moment AI character is allowed to see, then when pursuit should be performed it gets:
:**one GoTo + timer based Look being called, but the timer for Look fails to decrement, so the AI simply stands and stares forever. This happens when pursuit mode is called while an AI stands at a job location on a patrol path. And, well... it looks really bad.
:**bugged and results in pursuit values from [[CHAR]] being ignored if pursuit mode was called while the caracter was idle or moving in a patrol path. Our AI character performs basic GoTo + timer-based Look for the whole time of pursuit, for both strong and weak awareness. Looks so-so but definitely is a glitch.
:**correct behavior roughly 10% of the time. It is quite random, but it looks like the AI has to be somehow disturbed while going for the source of a previous disturbance. And then Oni writes to the developer console "pursuit mode Hunt not yet implemented" ^_^.
:**bugged and results in one GoTo + timer based Look being called, but timer for Look does not decrement, so AI simply stands and stares. This happens when pursuit mode is called while AI stand at job location in patrol path. And well... it looks really bad.
:*The best way how to deal with the pursuit/vision issue is to either ignore it (so the character often gets glitched) or use a BSL script to create a small [[BSL:Manual#Looping|looping function]] where ai2_blind is set to 1 for at least one second (60 frames), then set to 0 again. It can cause funny moments of an AI completely ignoring an enemy right in front of it, but it silently fixes these pursuit problems.
:**in roughly 10% the pursuit performs correctly. It is quite random, but looks like AI has to be somehow disturbed while going for the source of previous distrubance. And then Oni writes into console "pursuit mode Hunt not yet implemented" ^_^.
:*The best way how to deal with pursuit sight issue is to either ignore it (so char get often glitched) or use BSL script to create a small self-looping function where ai2_blind is set to 1 for at least one second (60 frames), then set to 0 again. It can cause funny moments of AI completely ignoring enemy right in front of it, but it silently fixes these pursuit problems.