Jump to content

AI: Difference between revisions

276 bytes removed ,  18 December 2015
continuing rewrite
(continuing rewrite)
(continuing rewrite)
Line 247: Line 247:




==Combat behavior part 1 : "Hokey religions and ancient weapons..."==
==Basic combat behaviors==
[[File:combatRanges.PNG|thumb|right|alt=Example of combat ranges.|Combat ranges of an AI character.]]
[[File:combatRanges.PNG|thumb|right|alt=Example of combat ranges.|Combat ranges of an AI character.]]
Of course an action game like Oni is not complete without guns blazing and fists flying through the air. But combat in real life is usually very fickle and everything has to be considered. How can Oni AI possibly deal with such a complex task?
Of course, an action game like Oni is not complete without guns blazing and fists flying through the air. But combat in real life is usually very fickle and everything has to be considered. How can Oni's AI possibly deal with such a complex task?


:Oni AI character has to have definite awareness of the enemy in order to actively attack him. Alert level of the AI character when in combat mode is Combat (duh). Definite awareness can be achieved by these ways:
:An AI in Oni has to have a definite awareness of the enemy in order to actively attack him. The alert level of an AI when in combat mode is Combat (duh). Definite awareness can be achieved by these ways:
:*Enemy was seen by this AI character's central vision field.
:*The enemy is seen in this AI's central vision field.
:*AI character is made to attack the enemy by [[BSL]] function '''ai2_attack'''.
:*The AI is made to attack the enemy by the BSL function ai2_attack.
:*AI character was hurt by the enemy, be it melee or gun damage.
:*The AI is hurt by the enemy, be it melee or gun damage.


Once combat mode is entered, then as long as HostileThreatDefinite timer for this enemy does not reach zero, AI character will always know exact location of this enemy and will attempt to attack it. The moment HostileThreatDefinite timer is depleted, AI character loses the privilege of knowing exact location, awareness decerases from definite to strong and AI character either switches from combat mode with this enemy to pursuit mode with this enemy (see section [[#Pursuit of enemy alias "I will find you..."|Pursuit of enemy]]) or, in case of other enemy being present in central vision field, picks this new enemy as a target to attack and keeps old enemy in strong (and later weak and later forgotten) awareness.
Once combat mode is entered, then as long as the HostileThreatDefinite timer for this enemy does not reach zero, an AI will always know the exact location of this enemy and will attempt to attack it. The moment HostileThreatDefinite timer is depleted, the AI loses the privilege of knowing the enemy's exact location, its awareness decreases from definite to strong, and the AI either switches from combat mode to pursuit mode with this enemy (see section [[#Pursuit|Pursuit of enemy]]) or, in case of another enemy being present in its central vision field, picks this new enemy as a target to attack and keeps the old enemy in strong (and later weak, then forgotten) awareness.


:Since generally method of combat depends on distance between participants, some sort of spacing is needed. Oni uses system of three ranges around AI, called combat ranges. See picture on right. Perimeters of these ranges can be set in [[CMBT]] profile.
:Since the means of combat depends on the distance between the participants, some sort of spacing is needed. Oni uses a system of three radii around the AI, called combat ranges. See picture on right. The size of these radii can be set in the [[CMBT]] profile.
:These ranges work as "triggers" to make the AI character execute various behaviors, based on enemy's position. Moreover, Oni can distinguish between states when enemy entered specified range or exited specified range. So all range possibilities in Oni which can be assigned some combat behavior are:
:These ranges work as "triggers" to make the AI character execute various behaviors based on the enemy's proximity. Moreover, Oni can distinguish between an enemy entering a specified range or exiting a specified range. All the range possibilities in Oni which can be assigned some combat behavior are:
:*Short - enemy is closest to the AI character
:*Short: enemy is close to the AI.
:*Medium - enemy is approaching the AI character and crossed from Long Range into Medium Range.
:*Medium: enemy is approaching the AI and crossed from Long Range into Medium Range.
:*Long - enemy is approaching the AI character and starts from the Long Range.
:*Long: enemy is approaching the AI starting at the Long Range.
:*Medium Retreat - enemy is retreating from Short Range into Medium Range.
:*Medium Retreat: enemy is retreating from Short Range to Medium Range.
:*Long Retreat - enemy is retreating from Medium Range into Long Range.
:*Long Retreat: enemy is retreating from Medium Range to Long Range.


:Well of course nothing is perfect and in Oni there is a bit of an issue with proper switching between combat ranges, so Long and Medium ranges are used only once at the beginning of enemy approach. Only Short, Medium Retreat and Long Retreat ranges are used on regular basis in a combat. Even when enemy runs into Long Retreat and goes back to to medium range, engine does not switch AI behavior range to Medium, but (contrary to its name) to Medium Retreat.
:Well, of course nothing is perfect, and in Oni there is a bit of an issue with proper switching between combat ranges, so Long and Medium ranges are used only once at the beginning of an enemy approach. Only Short, Medium Retreat and Long Retreat ranges are used on a regular basis in combat. Even when an enemy runs into Long Retreat and goes back to to Medium range, the engine does not switch the AI's behavior range to Medium, but (contrary to its name) to Medium Retreat.




OK, we have positioning, now for actual behaviors AI character can be set to execute within these ranges. There are fourteen possible combat behaviors (in brackets are xml strings):
OK, we have positioning down; now for the actual behaviors that an AI can be set to execute within these ranges. There are fourteen possible combat behaviors (in brackets are the XML strings):
:*None (None) - simply nothing
:*None (None): simply nothing.
:*Stare (Stare) - AI character stands and stares, does not even rotate to face enemy
:*Stare (Stare): the AI stands and stares; it does not even rotate to face the enemy.
:*Hold and fire (HoldAndFire) - AI character stands still and fires a weapon. If this character does not have a weapon, then she/he switches to melee.
:*Hold and fire (HoldAndFire): the AI stands still and fires a weapon. If this character does not have a weapon, then it switches to melee.
:*Firing charge (FiringCharge) - AI character runs towards the enemy and fires a weapon. If this character does not have a weapon, then she/he switches to melee.
:*Firing charge (FiringCharge): the AI runs toward the enemy and fires a weapon. If this character does not have a weapon, then it switches to melee.
:*Melee (Melee) - AI character always uses melee, even when she/he holds a loaded weapon.
:*Melee (Melee): the AI always uses melee, even when it holds a loaded weapon.
:*Barabbas shoot (BarabasShoot) - AI character stands still and fires a weapon with hardcoded three seconds pause between shots. If this character does not have a weapon, then he switches to melee. If this character meets certain conditions, she/he can start health regeneration. More detailed info about regeneration mechanics [[Barabas' regeneration| can be read HERE.]]
:*Barabbas shoot (BarabasShoot): the AI stands still and fires a weapon with hardcoded three-second pauses between shots. If this character does not have a weapon, then it switches to melee. If this character meets certain conditions, it can start regenerating health. More detailed info about regeneration mechanics [[Barabas' regeneration|can be read here.]]
:*Barabbas advance (BarabasAdvance) - AI character runs towards the enemy and fires a weapon with '''secondary fire mode''' (as if player pressed right button). If this character does not have a weapon, then she/he switches to melee. If this character meets certain conditions, she/he can start health regeneration. More detailed info about regeneration mechanics [[Barabas' regeneration| can be read HERE.]]
:*Barabbas advance (BarabasAdvance): the AI runs toward the enemy and fires a weapon using the '''secondary trigger''' (as if the player pressed right mouse button). If this character does not have a weapon, then it switches to melee. If this character meets certain conditions, it can start regenerating health. More detailed info about regeneration mechanics [[Barabas' regeneration|can be read here.]]
:*Barabbas melee (BarabasMelee) - AI character uses melee, even with loaded weapon in hand. If this character meets certain conditions, she/he can start health regeneration. More detailed info about regeneration mechanics [[Barabas' regeneration| can be read HERE.]]
:*Barabbas melee (BarabasMelee): the AI uses melee, even with a loaded weapon in hand. If this character meets certain conditions, it can start regenerating health. More detailed info about regeneration mechanics [[Barabas' regeneration|can be read here.]]
:*Superninja fireball (SuperNinjaFireball) - Mukade's long range behavior. With this behavior AI cannot shoot weapons and cannot use melee, simply runs towards the enemy. However, if weapon is held, character can use melee (probably something from weapon melee override). AI character is occasionally teleported into the back of the enemy (AnimType 222 - Teleport In) if distance to enemy is greater than 100. It seems like it should work regularly once distance to enemy exceeds 100, but in reality something screws this teleport mechanics ^_^. Anyway, to add more to this behavior AI executes two special TRAM animations:
:*Superninja fireball (SuperNinjaFireball): Mukade's long range behavior. With this behavior, an AI cannot shoot weapons and cannot use melee; it simply runs toward the enemy. However, if a weapon is in hand, the character can use melee (probably something from the weapon melee override). The AI is occasionally teleported behind the enemy (AnimType 222 - Teleport In) if the distance to the enemy is greater than 100 world units (however, something is screwy with this teleportation mechanic). Anyway, to add more to this behavior, the AI executes two special [[TRAM]]s (animations):
:**AnimType 224 - Ninja Fireball, after the use there is 20 seconds pause before then this [[TRAM]] is used again.
:**AnimType 224 - Ninja Fireball (Mukade's heat-seeking Devil Star); after using this, there is a 20-second cool-down before this can be used again.
:**AnimType 225 - Ninja Invisible, grants 10 second cloak, after the use there is 20 seconds pause before this TRAM is used again.
:**AnimType 225 - Ninja Invisible (grants a 10-second cloak); after using this, there is a 20-second cool-down before this can be used again.
::'''IMPORTANT''' There is an annoying problem with this behavior. When it is called, it checks character's position height-wise from the origin of the game world (coordinates 0,0,0) and if the height is below 550, this character is automatically moved to height 550 (which in almost all cases means death by falling).
::'''IMPORTANT''' There is an annoying problem with this behavior, which was coded with the Rooftops boss fight in mind. When it is called, it checks the character's position height-wise from the origin of the game world (coordinates {0, 0, 0}) and if the height is below 550, this character is automatically moved to height 550 (which in almost all cases means death by falling).
:*Superninja advance (SuperNinjaAdvance) - Mukade's medium range behavior. With this behavior AI cannot shoot weapons and cannot use melee, simply runs towards the enemy. However, if weapon is held, character can use melee (probably something from weapon melee override). This behavior gives ability to use AnimType 225 - Ninja Invisible which grants 10 seconds invisibility. In order to be able to use this ability, AI has to be at least 50 (or 40?) units far from its enemy. Cooldown for this special technique is 20 seconds. Again, annoying '''over 550 height check''' is present.
:*Superninja advance (SuperNinjaAdvance) - Mukade's medium range behavior. With this behavior, an AI cannot shoot weapons and cannot use melee; it simply runs toward the enemy. However, if a weapon is in hand, the character can use melee (probably something from the weapon melee override). This behavior also allows the use of AnimType 225 - Ninja Invisible. In order to be able to use this ability, the AI has to be at least 50 (or 40?) world units away from its enemy. The cool-down for this special technique is 20 seconds. Again, the annoying "over 550" height check is present.
:*Superninja melee (SuperNinjaMelee) - Mukade's short range behavior. With this behavior AI cannot shoot weapons but can use melee. This behavior gives ability to use AnimType 225 - Ninja Invisible which grants 10 seconds invisibility. In order to be able to use this ability, AI has to be at least 50 (or 40?) units far from its enemy. Cooldown for this special technique is 20 seconds. This behavior also grants ability to teleport away from enemy to certain distance (around 100 units) if any one of these conditions is met:
:*Superninja melee (SuperNinjaMelee): Mukade's short range behavior. With this behavior, the AI cannot shoot weapons, but <u>can</u> use melee. This behavior allows the use of AnimType 225 - Ninja Invisible. In order to be able to use this ability, the AI has to be at least 50 (or 40?) world units away from its enemy. The cool-down for this special technique is 20 seconds. This behavior also grants the ability to teleport away from the enemy to a certain distance (around 100 world units) if any one of these conditions is met:
:**About 35 points of damage dealt to this character in a short time (exact amount of damage and exact timing not known).
:**About 35 points of damage dealt to this character in a short time (exact amount of damage and exact timing not known).
:**This character get thrown by any throw.
:**This character get thrown.
::Again, annoying '''over 550 height check''' is present.
::Again, the annoying "over 550" height check is present.
:*Run for alarm (RunForAlarm) - see section [[#Alarm behavior - "She's everywhere!"|Alarm behavior]].
:*Run for alarm (RunForAlarm): see section [[#Alarm behavior|Alarm behavior]].
:*Mutant Muro melee (MutantMuroMelee) - AI character is only allowed to melee, will not fire weapons. This behavior casts chenille (overpower effect) on the user. Of course in order to see visible effect character has to have set <HasDaodanPowers> to 1 in [[ONCC]]. This chenille mode does not grant damage overpower effect, melee attacks deal their usual damage. If ONCC has set both <HasDaodanPowers> and <HasSuperShield> to 1, the chenille mode called by this behavior grants super shield.
:*Mutant Muro melee (MutantMuroMelee): the AI is only allowed to melee, not fire weapons. This behavior places "chenille" (the overpower effect) on the user. In order to see this visual effect, the character has to have <HasDaodanPowers> set to 1 in their [[ONCC]]. This chenille mode does not grant the actual damage overpower effect. If the ONCC has both <HasDaodanPowers> and <HasSuperShield> set to 1, the chenille mode called by this behavior grants "super shield".
::Chenille mode lasts forever if it is not terminated either via BSL or by AI character performing a [[TRAM]] which has a DisableShield flag. After 10 seconds interval, chenille is turned back on. Another specialty of this behavior is automatic backwards evasion move when about 35 points of damage or a throw are applied on the AI character. Chenille mode is turned off if this AI character switches to some other combat behavior because the enemy moved to some other combat range.
::Chenille mode lasts forever if it is not terminated either via BSL or by the AI performing a TRAM which has a DisableShield flag. After a 10-second interval, chenille is turned back on. Another specialty of this behavior is an automatic backward-evasion move when about 35 points of damage or a throw are inflicted on the AI. Chenille mode is turned off if this AI switches to some other combat behavior because the enemy moved to some other combat range.
:*Mutant Muro thunderbolt (MuroThunderbolt) - Upon initial contact AI chracter turns on chenille mode and runs towards enemy. If chenille mode is turned off, then until definite awareness of the enemy is lost this behavior will not cast chenille mode again. This behavior also allows the AI character to use special long range attack - chracter turns off chenille, goes into AnimState 69 (Thunderbolt) and loops special TRAM animation of AnimState 69 (Thunderbolt) and AnimType 231 (Muro_Thunderbolt). That lasts for 10 seconds. Then AI makes 5 seconds pause during which it runs towards enemy. If after those 5 seconds AI character is still executing Mutant Muro thunderbolt behavior, AI character starts again looping the TRAM animation which has AnimType 231 and AnimState 69.
:*Mutant Muro thunderbolt (MuroThunderbolt): Upon initial contact, the AI turns on chenille mode and runs toward the enemy. If chenille mode is turned off then, until definite awareness of the enemy is lost, this behavior will not cast chenille mode again. This behavior also allows the AI to use a special long range attack: the character turns off chenille, goes into AnimState 69 - Thunderbolt, and loops a special TRAM animation of AnimState 69 - Thunderbolt and AnimType 231 - Muro_Thunderbolt. That lasts for 10 seconds. Then the AI stops the animation for 5 seconds and runs toward the enemy. If, after those 5 seconds, the AI is still executing Mutant Muro thunderbolt behavior, the AI resumes the looping TRAM between AnimType 231 and 69.
::This behavior's special (looping TRAM animation) lasts even when enemy enters some other combat range with the exception of Short range. If enemy enters Short range while the looped animation is running, the loop is forced to stop and AI character starts using Short range behavior.
::This behavior's special looping animation continues even when an enemy enters some another combat range, with the exception of Short range. If the enemy enters Short range while the looped animation is running, the loop is forced to stop and the AI starts using Short range behavior.








Modding hints: Combat behaviors can have severe impact on AI performance in a fight but can as well hinder the AI
Modding hints: Combat behaviors can have a severe positive or negative impact on AI performance in a fight.
:*Remember: due to a glitch, crucial behaviors for combat are Short, MediumRetreat and LongRetreat. Long And Medium are used only at the beginning of an ecounter.
:*Remember: due to a glitch, the crucial behaviors for combat are Short, MediumRetreat and LongRetreat. Long and Medium are used only at the beginning of an encounter.
:*In general, use common sense. There is little use in setting Firing Charge as Short range behavior.
:*In general, use common sense. There is little use in setting Firing Charge as the Short range behavior.
:*Barabbas Shoot and Barabbas Melee behaviors have access to heal ability which can be a great asset for introducing mutants or stronger enemy units. However, remember that Barabbas Shoot limits rate of fire to one shot per three seconds.
:*Barabbas Shoot and Barabbas Melee behaviors have access to a healing ability which can be a great asset for introducing mutants or stronger enemy units. However, remember that Barabbas Shoot limits rate of fire to one shot per three seconds.
:*Barabbas Advance is the only behavior which allows AI to fire a weapon with secondary fire mode. However the behavior is quite glitched (AI character often looks away and fires stray shots). Still, with proper gun and proper setup it can be useable for boss fights.
:*Barabbas Advance is the only behavior which allows an AI to fire a weapon in its secondary fire mode. However the behavior is quite glitchy (the AI often looks away and fires stray shots). Still, with the proper gun and proper setup it can be useable for boss fights.
:*Superninja's behaviors sound excellent for cunning enemy units, however annoying check for character's minimal allowed height from world origin and subsequent forced repositions severely impact these behaviors' usefulness. Despite the height limit, with deliberately designed level which is uplifted enough on purpose, the behavior will not cause random AI character repositioning. Then it can be used to its fullest.
:*Superninja's behaviors sound excellent for cunning enemy units, however the annoying check for a character's minimal allowed height from the world origin, and subsequent forced re-positioning, severely impact these behaviors' usefulness. With a level which is deliberately raised to the correct height, the behavior will not cause random AI character re-positioning. Then it can be used to its fullest.
::One other important thing about these behaviors - if AI character does not have required [[TRAM]]s in her/his [[TRAC]], the AI character can get stuck if she/he uses these behaviors.
::One other important thing about these behaviors: if the AI does not have required the TRAMs in its [[TRAC]], the AI can get stuck if it uses these behaviors.
:*If there is no console with ALARM CONOSLE flag within Alarm sarch distance, then behavior "Run For Alarm" will make AI enemy just stand and stare. Set this behavior with caution and consider using a workaround where medium and short combat ranges have very close diameters with Run For Alarm being MediumRetreat behavior, so Run For Alarm behavior is executed only for a brief amount of time as AI practically immediately switches to LongRetreat. However even one frame is enough because if alarm is found, AI character is requested to perform alarm run which can override combat (see section [[#Alarm behavior - "She's everywhere!"|Alarm behavior]] for more info).
:*If there is no console with the ALARM CONSOLE flag within the Alarm search distance, then the behavior "Run For Alarm" will make an AI just stand and stare. Choose this behavior with caution, and consider using a workaround where Medium and Short combat ranges have very close radii, with Run For Alarm being the MediumRetreat behavior, so that the Run For Alarm behavior is executed only for a brief amount of time as the AI almost immediately switches to LongRetreat. Even one frame is enough, because if an alarm is found, the AI is requested to perform an alarm run which can override combat (see section [[#Alarm behavior|Alarm behavior]] for more info).
:*MutantMuro melee can be used to create tricky foes which have to be eliminated from distance because if player comes up close, these enemies will turn on their (super)shield and won't put it away (no TRAM with DisableShield flag). That means player has to put some distance between him and these AI characters in order to make them disable the shield.
:*MutantMuro melee behavior can be used to create tricky foes which have to be fought from a distance because if the player comes up close then the AI will turn on its (super)shield and won't put it away (by providing no TRAM with the DisableShield flag). That would make the player put some distance between him and the AI in order to make it disable the shield.
:*MutantMuro thunderbolt should NEVER be assigned to Short range behavior as that will negatively affect its special attack. Set it as LongRetreat or MediumRetreat. This kind of behavior (with proper [[TRAM]]s) can be used to create foes who will perform special long range attack if player tries to keep a distance. This ranged attack does not have to be the same as Muro's tractor thunderbolt. For quick example, AI character can be made to fire a sort of aggressive plasma beam.
:*MutantMuro thunderbolt should NEVER be assigned as the Short range behavior, as that will negatively affect its special attack. Set it as LongRetreat or MediumRetreat. This kind of behavior (with proper TRAMs) can be used to create foes who will perform a special long range attack if the player tries to keep his distance. This ranged attack does not have to be the same as Muro's tractor thunderbolt. For example, an AI could be made to fire an aggressive energy-beam type of attack.








==Combat behavior part 2 : "Guns or not, my fists are hot."==
==Extra combat behaviors==
Combat ranges and various AI combat behavior was discussed in previous section. Even with combat ranges, there are still other parts of combat to be taken care of - picking up weapons from the ground, melee overrides of weapons, behavior if character is unarmed and of course, firing weapons or using hand to hand combat. Files inspected in this section will be [[CMBT]] profiles and [[ONCC]] files.
Combat ranges and various AI combat behavior was discussed in previous section. Even with combat ranges, there are still other parts of combat to be taken care of - picking up weapons from the ground, melee overrides of weapons, behavior if character is unarmed and of course, firing weapons or using hand to hand combat. Files inspected in this section will be [[CMBT]] profiles and [[ONCC]] files.