Jump to content

AI: Difference between revisions

46 bytes removed ,  16 December 2015
continuing rewrite
(beginning rewrite (correcting language issues and unacceptable section names))
(continuing rewrite)
Line 47: Line 47:
:*Vector-based: according to the angle at which the AI is facing the obstacle, the game decides either to let the character slide along the obstacle or to stop the character completely until the angle of the AI's vector of movement changes.
:*Vector-based: according to the angle at which the AI is facing the obstacle, the game decides either to let the character slide along the obstacle or to stop the character completely until the angle of the AI's vector of movement changes.


==Congitive possiblities of AI characters ... "COME TO YOUR SENSES!"==
==Vision and hearing==
[[File:VisionFields.JPG|thumb|right|alt=Visualization of vision fields.|An example of Blue Striker's central and peripheral vision.]]
[[File:VisionFields.JPG|thumb|right|alt=Visualization of vision fields.|An example of a blue Striker's central and peripheral vision.]]
[[File:SoundSpheres.JPG|thumb|right|alt=Visualization of sound spheres.|Three examples of sound spheres.]]
[[File:SoundSpheres.JPG|thumb|right|alt=Visualization of sound spheres.|Three examples of sound spheres.]]
When talking about life-like AI, senses have to be taken into an account. Sight, hearing, taste, smell, touch. Unfortunately Oni emulates only sight and hearing.
When emulating humans with AI, senses have to be taken into an account: sight, hearing, taste, smell, touch. Unfortunately, Oni emulates only sight and hearing.


'''Sight''' is important. Without it the only option for AI to recognize the enemy is to be attacked by the enemy first. Unlike majority of action games, Oni AI characters have two visions:
'''Sight''' is important. Without it, the only option for AI to recognize an enemy would be getting attacked by the enemy first. Unlike the majority of action games, Oni AIs have two kinds of vision:
:*Central - enemy seen by central vision = enemy recognized and attacked.
:*Central: an enemy seen by central vision will be recognized and attacked
:*Peripheral - enemy seen by peripheral vision = alert risen to low and AI goes into pursuit mode with given enemy, see '''LINK TO PURSUIT'''
:*Peripheral: an enemy seen by peripheral vision will raise the AI's alert level to low and the AI will go into pursuit of the enemy; see [[#Pursuit|Pursuit]] section




Modding hints - parameters of vision fields are stored in ONCC, under '''<VisionConstants>'''. Central vision field distance has to be greater than peripheral vision field distance, otherwise peripheral vision detection will be somehow broken (it will not detect). Since peripheral vision makes AI pursue the enemy but not attack it, it can be set quite large in order to surprise lousy stealth players. But be warned - nobody likes cheating AI ^_^.
Modding hints - the parameters of the vision fields are stored in ONCC, under '''<VisionConstants>'''. The central vision field distance has to be greater than the peripheral vision field distance, otherwise peripheral vision detection will somehow be broken (it will not detect). Since peripheral vision makes the AI pursue the enemy but not attack it, it can be set quite large in order to surprise lousy stealth players. But be warned: nobody likes cheating AI ^_^.






'''Hearing''' is crucial in Oni. Majority of AI character interaction is done via sound system. Oni recognizes these types of sound (in brackets 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 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) - causes alert rise to low level.
:*Interesting (green) - raises alert level to "low"
:*Danger (yellow) - causes alert rise to medium level.
:*Danger (yellow) - raises alert level to "medium"
:*Melee (orange) - causes alert rise to medium level but AI reacts a bit differently than in case of Danger sound.
:*Melee (orange) - raises alert level to "medium", but the AI reacts a bit differently than to a Danger sound
:*Gunfire (red) - causes alert rise to high level.
:*Gunfire (red) - raises alert level to "high"


:For more info about AI alert levels, see section [[#Reactions on stimuli a.k.a. "What was that?!"|Reaction on stimuli]]. These sound types are used by impact effects [[ONIE]] and danger sound type can be set in particle as a "danger radius".
:For more info about AI alert levels, see section [[#Reactions and awareness|Reactions and awareness]]. These sound types are used by impact effects ([[ONIE]]), and a danger sound type can be set in a particle's as part of its "danger radius".




:Modding hints: Sound system and ONIE are mighty tools if modder knows how to use them. Even doors can be attached a sound sphere of any one of those listed above, so a modder can create doors which draw attention (sound type interesting) of nearby AI characters if these doors are manipulated.
:Modding hints: The sound system and ONIE are mighty tools if a modder knows how to use them. Even doors can have attached to them a sound sphere of one of the types listed above, so a modder can create doors which draw the attention (sound type Interesting) of nearby AIs when those doors are used.


:Another example is a workaround for AI to get alerted by dead bodies -
:Another example is a workaround for AIs to get alerted by dead bodies:
::Set dead particle in ONCC to be one special custom made - this particle will for given time keep emiting custom impact effect. That custom impact effect will have no sound or effect attached, but will be set to be hearable by AI as a gunfire within a large radius (200 units).
::Set the death particle in the ONCC to emit a custom impact effect. That impact effect will have no sound or effect attached, but will be set to be heard by AIs as gunfire within a large radius (say, 200 units).




==Reactions on stimuli a.k.a. "What was that?!"==
==Reactions and awareness==
In real life each human being is unique with its reactions. But even then reaction differ - when calm or when nervous or when suspicious, a man does not always react the same way. And what about Oni?
In real life, each human being is unique in its reactions. But even then, reactions differ with mood; when calm or when nervous or when suspicious, a man does not always react the same way. And what about Oni?


In Oni, reaction on stimulus is based on type of stimulus (see previous section) and on level of AI alert level. Oni AI characters have these alert levels:
In Oni, reaction to a stimulus is based on the type of stimulus (see previous section) and on the alert level of the AI. Oni AIs have these alert levels:
:*Lull
:*Lull
:*Low
:*Low
Line 87: Line 87:
:*Combat
:*Combat


:Level of alert can be set via BSL as '''ai2_setalert''' ''ai_name/chr_index'' '''desired level of alert'''. Levels of alert play the role of "behavior modifier". Artificial Intelligence reacts on seen or heard allies/enemies according to its own level of alert. Level of alert can be increased by:
:The level of alert for an AI can be set via BSL using [[ai2_setalert]]. Alert levels play the role of "behavior modifier" in how an AI reacts to seeing or hearing allies and enemies. Alert levels can be increased in the following ways:
:*hearing a sound which causes rise of alert level (for detailed info read previous section)
:*hearing a sound which raises alert level (for detailed info, read previous section)
:*special rise of alert level from Lull to Low is by enemy being seen by peripheral vision or by enemy causing too many unimportant sounds
:*a special rise from Lull to Low can come from an enemy being seen by peripheral vision or by an enemy causing too many Unimportant sounds
:*special rise of alert level to Combat is by being hit by the enemy or by alarm being triggered (see [[OBD:BINA/OBJC/CONS]]) or by script functions '''ai2_tripalarm''', '''ai2_makeaware''' or '''ai2_attack''' (see [[BSL:Functions]]).
:*a special rise to Combat level will come from being hit by the enemy or by an alarm being triggered (see [[OBD:BINA/OBJC/CONS]]), or by the scripting functions [[ai2_tripalarm]], [[ai2_makeaware]] or [[ai2_attack]].


:Alert level also affects movement mode of AI driven characters. There are six movement modes - creep, walk, walk_noaim, run, run_noaim, by_alert_level. Those "_noaim" movement modes are forcing AI character to not aim with weapon in case the AI is armed (so AI character walks or runs with the gun in hand but it does not aim with it). Movement mode can be forced via bsl command '''ai2_setmovementmode'''. Alert level affects movement mode only if movement mode is set as '''by_alert_level'''. In that case:
:Alert level also affects the movement mode of AI-driven characters. There are six movement modes: "creep", "walk", "walk_noaim", "run", "run_noaim", and "by_alert_level". The "*_noaim" movement modes tell the AI that, if it is armed, it should walk or run with the gun in hand but not aim with it. Movement mode can be forced via the BSL command [[ai2_setmovementmode]]. Alert level affects movement mode only if movement mode is set as "by_alert_level". In that case:
:* Lull and Low alerts use walk_noaim
:*Lull and Low alerts use "walk_noaim"
:* Medium, High and Combat use run
:*Medium, High and Combat use "run"


:If patrol path ([[PATR]]) is assigned to a character, it can override movement mode for patrol path purposes and for example force Lull alert character to run with aimed weapon. However, when AI is disturbed and starts pursuit of ally/enemy, movement mode is then chosen by coresponding alert level (given the fact the movement mode is set as '''by_alert_level''').
:If a patrol path ([[PATR]]) is assigned to a character, it can force a Lull-alerted character to run with an aimed weapon. However, when the AI becomes aware of and starts its pursuit of an ally/enemy, the movement mode is then dictated by its alert level (if the movement mode is set as '''by_alert_level''').
:Level of alert can decrease via BSL ai2_setalert or with time , exact location of timers unknown (maybe hardcoded).
:An alert level can be decreased via BSL's ai2_setalert or with the passage of time (the location of the timer settings is unknown, maybe hardcoded).






Next component of AI reaction logic is its '''awareness''' of ally/enemy. Oni recognizes between ally (friendlythreat) and enemy (hostilethreat). Oni AI characters always know whether the disturbance was caused by ally or enemy. That means if player is playing as standard Konoko, shoots and some Striker gets alerted, the Striker knows which character (from [[CHAR]]) shot, which team does the character belong to and according to it the Striker reacts (but more about it later). Oni defines four levels of awareness:
The next component of the AI's reaction logic is its '''awareness''' of the ally/enemy. Oni distinguishes between allies ("friendlythreat") and enemies ("hostilethreat"). Oni's AIs always know whether a disturbance was caused by an ally or enemy. That means that if player is playing as Konoko and shoots, alerting some Striker, the Striker knows which character (from [[CHAR]]) shot and which team the character belongs to, and reacts accordingly (but more about that later). Oni defines four levels of awareness:
:'''firendlythreat'''
:'''friendlythreat'''
:*Definite - AI is 100% sure where ally stands and ignores him. Is achieved by seeing the ally with central vision field or by being hit by his gun by accident or by being told of its presence by BSL commands ai2_makeaware, ai2_tripalarm or ai2_attack.
:*Definite: the AI is 100% sure where the ally is located and ignores him. Is achieved by seeing the ally with the central vision field, being hit by his gun by accident, or being told of the ally's presence by the BSL function ai2_makeaware, ai2_tripalarm or ai2_attack.
:*Strong - AI has strong awareness of ally presence, but cannot pinpoint exact location of the ally character itself. Is caused by all sound types, which are described in previous section. Also if ally is off central vision field and <FriendlyThreatDefiniteTimer> runs out, AI decreases level of awareness from definite to strong.
:*Strong: the AI has a strong awareness of an ally's presence, but cannot pinpoint the exact location of the ally. Is caused by all sound types, which are described in previous section. If the ally is outside the central vision field and <FriendlyThreatDefiniteTimer> runs out, the AI decreases its level of awareness from Definite to Strong.
:*Weak - AI has weak awareness of the character's presence. It is caused either by seeing ally with peripheral vision or by <FriendlyThreatStrongTimer> running out.
:*Weak: the AI has a weak awareness of the ally's presence. It is caused either by seeing an ally with peripheral vision or by <FriendlyThreatStrongTimer> running out.
:*Forgotten - AI has ecountered some ally, but over time forgot about its presence. <FriendlyThreatWeakTimer> ran out.
:*Forgotten: the AI encountered some ally, but over time forgot about its presence (<FriendlyThreatWeakTimer> ran out).


:'''hostilethreat'''
:'''hostilethreat'''
:*Definite - AI is 100% sure where enemy stands and will go attack her/him. Is achieved by seeing the enemy with central vision field or by being hit by her/him (or her/his gun) or by being told of its presence by BSL commands ai2_makeaware, ai2_tripalarm or ai2_attack.
:*Definite: the AI is 100% sure where the enemy is located, and will go attack her/him. Is achieved by seeing the enemy with its central vision field, being hit by her/him (or her/his gun), or being told of the enemy's presence by the BSL function ai2_makeaware, ai2_tripalarm or ai2_attack.
:*Strong - AI has strong awareness of enemy presence, but cannot pinpoint exact location of the enemy character itself. Is caused by all sound types, which are described in previous section. If enemy manages to get is off central vision field and <HostileThreatDefiniteTimer> runs out, AI decreases level of awareness from definite to strong. If AI is allowed to investigate, corresponding pursuit behavior is excuted (more about this later).
:*Strong: the AI has a strong awareness of an enemy's presence, but cannot pinpoint the exact location of the enemy. Is caused by all sound types, which are described in previous section. If enemy manages to out of an AI's central vision field and <HostileThreatDefiniteTimer> runs out, the AI decreases its level of awareness from Definite to Strong. If the AI is allowed to investigate, the corresponding pursuit behavior is executed (more about this later).
:*Weak - AI has weak awareness of enemy's presence. It is caused either by seeing enemy with peripheral vision or by <HostileThreatStrongTimer> running out. If AI is allowed to investigate, corresponding pursuit behavior is excuted (more about this later)
:*Weak: the AI has a weak awareness of an enemy's presence. It is caused either by seeing an enemy with peripheral vision or by <HostileThreatStrongTimer> running out. If the AI is allowed to investigate, the corresponding pursuit behavior is executed (more about this later)
:*Forgotten - AI has ecountered some enemy, but over time forgot about its presence. <EnemyThreatWeakTimer> ran out.
:*Forgotten: the AI encountered an enemy, but over time forgot about its presence (<EnemyThreatWeakTimer> ran out).


:When AI character is freshly spawned, it does not have any contact with other characters (Tabula Rasa). Through sounds and vision, AI learns about presence of other characters and reacts on them according to team affiliation, alert level and awareness. Even when AI character "forgets" about ally/enemy, it does not completely abandon their existence. For example startle behavior when AI character sees an enemy is played only once vs this particular enemy. Even when AI character forgets, it won't play startle animation next time it sees this one enemy, but goes directly attack him.
:When an AI character is freshly spawned, it does not have any record of contact with other characters (a ''tabula rasa''). Through hearing and vision, an AI learns about the presence of other characters and reacts to them according to team affiliation, alert level, and awareness level. Even when an AI character ceases to be aware of an ally/enemy, it does not completely forget them. For example, the startle behavior when an AI sees an enemy is played only once for this particular enemy; it won't play the startle animation the next time it sees him, but will go directly to attacking him.
:Friendly warning: awareness "Forgotten" '''IS NOT''' equal to '''ai2_forget''' command. "Ai2_forget" clears AI character's memory back to Tabula Rasa status.
:Friendly warning: the awareness level "Forgotten" '''IS NOT''' equivalent to the result of the '''ai2_forget''' command. "Ai2_forget" actually sets the AI's memory back to ''tabula rasa'' status.