Jump to content

AI: Difference between revisions

54 bytes removed ,  17 December 2015
continuing rewrite
(continuing rewrite; if only Czech had a definite article ^_^)
(continuing rewrite)
Line 182: Line 182:




==Alarm behavior - "She's everywhere!"==
==Alarm behavior==
{|align=right
{|align=right
|[[Image:CONTROL CONSOLE.png|58px|right]]
|[[Image:CONTROL CONSOLE.png|58px|right]]
Line 192: Line 192:
!Data
!Data
|}
|}
In order to make AI look more humane, it is a good idea to grant it ability to interact with the world the same way player does. In Oni that means for example to give AI option to use consoles.
In order to make the AI look more human, it is a good idea to grant it the ability to interact with the world the same way that the player does. In Oni, for example, that means giving the AI the ability to use consoles.


::[http://www.youtube.com/watch?v=jnsGuZxqW9I Watch this YouTube video.]
::[http://www.youtube.com/watch?v=jnsGuZxqW9I Watch this YouTube video.]
:BSL scripting provides a command to make AI go and use a console - '''ai2_doalarm''' ''ai_name/index'' '''number of console'''. This way AI can be told to use any console. But there is a method to make AI character use a console completely on it own.
:BSL scripting provides a command to make an AI go and use a console: [[ai2_doalarm]]. This way, an AI can be told to use any console. But there is a method to make an AI use a console completely on it own.
:In order to utilize those mechanics, there is a need for a console which has ALARM CONSOLE flag set (see [[OBD:BINA/OBJC/CONS]]). In XML this flag has a string '''IsAlarm'''. Such a console then can be used by AI characters without scripting.
:In order to utilize this mechanic, there is a need for a console which has the ALARM CONSOLE flag set (see [[OBD:BINA/OBJC/CONS]]). In XML this flag is called '''IsAlarm'''. Such a console then can be used by AI characters without scripting.


:Next, there are Alarm parameters in [[CMBT]] profiles which define AI character's alarm behavior:
:Next, there are Alarm parameters in [[CMBT]] profiles which define an AI's alarm behavior:
:*Search distance - a perimeter around the character where engine checks for any console with ALARM CONSOLE flag. In xml it is named <SearchDistance>.
:*Search distance: a radius around the AI where the engine checks for any console with the ALARM CONSOLE flag. In XML it is named <SearchDistance>.
:*Ignore distance - a perimeter around AI character where this AI character (which is currently executing alarm behavior) acknowledges enemies. Enemies outside of this perimeter are ignored by the AI character. In xml it is named <EnemyIgnoreDistance>.
:*Ignore distance: a radius around the AI where this AI character (which is currently executing alarm behavior) acknowledges enemies. Enemies outside of this radius are ignored by the AI character. In XML it is named <EnemyIgnoreDistance>.
:*Attack distance - a perimeter around AI character where this AI character (which is currently executing alarm behavior) temporarily stops its run for the console and attacks enemies if they are within this range and AI character sees them with central vision field. In xml it is named <EnemyAttackDistance>.
:*Attack distance: a range within which the AI (which is currently executing alarm behavior) will temporarily stop its run for the console and attack enemies if the AI sees them with its central vision field. In XML it is named <EnemyAttackDistance>.
:*Damage threshold - in xml named <DamageThreshold>. Time interval for which AI character keeps awareness of enemy who attacked it. If this enemy crosses Attack distance perimeter, AI temporarily stops its run for alarm and immediately attacks this enemy (does not have to see him with central vision field).
:*Damage threshold: The time interval for which an AI stays aware of an enemy who attacked it. If this enemy enters the Attack distance, the AI temporarily stops its run for alarm and immediately attacks this enemy (it does not have to see him with central vision field). In XML it is named <DamageThreshold>.
:*Fight timer - in xml called <FightTimer>, duh. Numer of frames for which AI character should fight with the enemy before it attempts to resume its run for alarm.
:*Fight timer: The number of frames for which the AI should fight with the enemy before it attempts to resume its run for the alarm. In XML it is called <FightTimer>.




:Logic for alarm running is set, now how to trip it? There are three ways how to make character run and use a console without BSL. the console must have ALARM CONSOLE flag set and ust lie within Search distance perimeter:
:So the settings for alarm-running behavior are set; now how to trip it? There are three ways to make a character run and use a console without BSL (but the console must have the ALARM CONSOLE flag set and must lie within Search distance):
:*in [[CMBT]]: If no gun behavior set to "Run for Alarm". In xml it is RunForAlarm string inside <NoGunBehavior>. By setting this parameter, AI character will attempt to run and use a console when it does not have a loaded weapon or spare clips in inventory (then it reload and continues shooting). If there is no alarm console nearby, AI will switch to Melee.
:*using CMBT profile: Set the no-gun behavior to "Run For Alarm" (in XML, use the string "RunForAlarm" inside <NoGunBehavior>). By setting this parameter, an AI will attempt to run and use a console when it does not have a loaded weapon or any spare clips in its inventory. If there is no alarm console nearby, the AI will switch to Melee.
:*in [[CMBT]]: Behaviors (Long, Medium, Short, MediumRetreat, LongRetreat) can be set to be "Run for Alarm". DO NOT confuse with "Run for alarm If no gun" behavior! This behavior is never used in retail Oni, the reason probably being the fact if there is no useable console within Alarm search distance radius, then AI character simply stands and stares even when enemy is visible with central vision field.
:*also in CMBT: The Behaviors (Long, Medium, Short, MediumRetreat, LongRetreat) can be set to "Run for Alarm". DO NOT confuse this with the "Run For Alarm" no-gun behavior! This behavior is never used in retail Oni, the reason probably being that if there is no useable console within Alarm search distance radius, then the AI simply stands and stares even when an enemy is visible within its central vision field.
:*In [[CHAR]]: Lost behavior "FindAlarm" - When AI character makes definite contact with enemy and then enemy manages to escape, AI executes "Lost" behavior (see "Pursuit of enemy" section). This behavior is typically set as ReturnToJob, but FindAlarm works well with no known issues. If alarm console is not found within search distance, AI returns to its job.
:*In [[CHAR]]: Use the "Lost" behavior "FindAlarm". When an AI makes definite contact with an enemy and then the enemy manages to escape, the AI executes this "Lost" behavior (see [[#Pursuit|Pursuit of enemy]] section). This behavior is typically set as ReturnToJob, but FindAlarm works well with no known issues. If an alarm console is not found within Search distance, the AI simply returns to its job.




:A couple of notes regarding AI character:
:A couple of notes regarding AIs:
:*in order to register enemy and attack her/him pre-emptively, AI character must have "HostileThreatDefinite" timer set in ONCC file to some value over 60 (Oni runs 60 frames per second).
:*in order to register an enemy and attack her/him pre-emptively, the AI must have the "HostileThreatDefinite" timer in its ONCC file set to some value over 60 (Oni internal clock runs at 60 frames per second).
:*"If no gun" behavior "Run for Alarm" can get glitched. "Alarm enemy attack distance" is set to some value, let's say 100. Now when AI character runs for alarm and enemy attacks it, then if in this [[CMBT]] profile there is not set melee override for range at least 100 (via melee override or by heving "Melee" set in corresponding combat ranges, see section [[#Combat behavior part 1 : "Hokey religions and ancient weapons..."|Combat behavior]]), chances are AI will get stuck in a loop trying to reach both enemy and console at the same time.
:*The no-gun behavior "Run For Alarm" can get glitchy. Say that "Alarm enemy attack distance" is set to 100; now when an AI runs for an alarm and an enemy attacks it, then if in the AI's CMBT profile the melee override is not set to a range of at least 100 (via melee override or by having "Melee" set in its corresponding combat ranges, see section [[#Basic combat behaviors|Basic combat behaviors]]), chances are that the AI will get stuck in a loop trying to reach both the enemy and the console at the same time.
:*Similar issue can happen with combat behavior Run For Alarm as well, but this time problems rise when this combat behavior Run For Alarm is set as Short range behavior.
:*A similar issue can happen with the combat behavior "Run For Alarm" as well, but this time problems arise when this combat behavior "Run For Alarm" is set as the Short-range behavior.


:A couple of notes regarding target console:
:A couple of notes regarding the target console:
:*Console must be in "activated" mode. If console is in deactivated or used modes, alarm behavior will not be executed.
:*It must be in "activated" mode. If the console is in a deactivated or "used" mode, the alarm behavior will not be executed.
:*Console must be directly accessible. Oni AI cannot use consoles in order to open path to get to the point of interest (target console in this case). Target console must be directly accessible. Still, it can be directly accessible across the whole level ^_^.
:*It must be directly accessible. Oni's AI cannot use consoles in order to open up a path to get to the point of interest (a target console in this case). But the target console can be across the whole level as long as it is not behind any locked doors.




:As already mentioned, Alarm behavior can be tripped by BSL command ai2_doalarm. In that case alarm behavior is executed but this time console is set by command instead of being looked for via Search distance. Also, by ai2_doalarm AI can be made to use any console, not only those with ALARM CONSOLE flag.
:As already mentioned, Alarm behavior can be tripped by the BSL command "ai2_doalarm". In that case, alarm behavior is executed but this time the console is being set by a command instead of being looked for within the Search distance. Also, with "ai2_doalarm" the AI can be made to use any console, not just those with the ALARM CONSOLE flag.






Modding hints: ability of AI to use consoles is an excellent tool for increasing a challenge.
Modding hints: the ability of the AI to use consoles is an excellent tool for increasing the challenge.
:*Beware of setting Run For Alarm combat behavior as close range one. Such a setup causes glitches.
:*Beware of setting the "Run For Alarm" combat behavior as the close-range one. Such a setup causes glitches.
:*On the other side, combat behavior Run For Alarm can be deliberately used to add element of surprise to fights. In [[CMBT]] profile, set Run For Alarm as either Medium or MediumRetreat behavoir, then shorten interval between <MediumRange> and <ShortRange> values (for example set "Medium Range" to 60 and "Short Range" to 59). Thanks to this setup, AI can attempt to find an alarm console while still being capable of fighting even when no alarm is nearby.
:*On the other hand, "Run For Alarm" can be deliberately used to add an element of surprise to fights. In the CMBT profile, set "Run For Alarm" as either the Medium or MediumRetreat behavior, then shorten the interval between the <MediumRange> and <ShortRange> values (for example, set "Medium Range" to 60 and "Short Range" to 59). Thanks to this setup, an AI can attempt to find an alarm console while still being capable of fighting when no alarm is nearby.
:*In [[BSL]] a modder can easily distinguish if console was used by player or AI thanks to '''chr_is_player('''ai_name''')''' function. All what is required is a BSL function being triggered when console is used. Here is example where console triggers a function called '''console1_used''':
:*In BSL, a modder can easily determine if a console was used by the player or an AI thanks to the [[chr_is_player]] function. All that's required is a BSL function being triggered when the console is used. Here is an example where a console triggers a function called "console1_used":
  func void console1_used(string ai_name)
  func void console1_used(string ai_name)
  {
  {
  if(chr_is_player(ai_name))
  if (chr_is_player(ai_name))
  {
  {
  *Some code in case player used the console*
    *Some code in case player used the console*
  }
  }
  else
  else
  {
  {
  *Some code in case AI used the console*
    *Some code in case AI used the console*
  }
  }
  }
  }
:*Other way of using alarm mechanics is to create a feeling of cooperation - player has to achieve something and in order to do so, an AI driven sidekick who goes after needed console and uses it is required.
:*Another way of using alarm mechanics is to create a feeling of cooperation -- in order for the player to achieve something, an AI-driven sidekick must use a console.


:*In extreme case, AI character can be even made to though the level on it own, moving from one console to another. That can be used to create chasing levels - AI character has to activate a certain number of consoles while player is required to stop this AI character from doing so. Thanks to Alarm behavior the task of tripping consoles can be fully completed by AI, no scripting needed. such a setup is on the one side prone to possible AI glitches, but on the other side can add element of randomness and increase replayability.
:*In extreme cases, an AI can be even made to move through the level on it own, from one console to another. That can be used to create "chase" missions -- an AI wants to activate a certain number of consoles, while the player is required to stop it from doing so. Thanks to Alarm behaviors, the task of tripping consoles can be fully completed by the AI, no scripting needed. Such a setup is on the one hand prone to possible AI glitches, but on the other hand can add an element of randomness and increase replayability.