Difference between revisions of "Monster behavior"

From DoomWiki.org

[unchecked revision][quality revision]
(Choosing target)
(minor fixes)
(6 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
[[Monsters]] in the [[Doom engine]] games have a primitive [[Wikipedia:Game artificial intelligence|artificial intelligence]] that follows a set of behavioral rules. The following rules apply to all monsters, unless stated otherwise.
 
[[Monsters]] in the [[Doom engine]] games have a primitive [[Wikipedia:Game artificial intelligence|artificial intelligence]] that follows a set of behavioral rules. The following rules apply to all monsters, unless stated otherwise.
  
 +
==Initial state and alertness==
 +
When the map is loaded, all monsters spawn in the idle state. Idle monsters are stationary and appear to be walking in place. This is because Doom monsters have no idle frames, instead going through their first two walking frames in a loop.
 +
 +
An idle monster looks in a 180-degree cone towards the direction of its initial orientation<ref name="doomsrc1">[[Doom source code]], p_enemy.c</ref>
 +
. The monster's initial target is usually the [[player]] who awakened the monster by moving into its line of sight, by making an attack in an area the monster can hear, or by harming the monster. If the initial target was another monster and the monster has not perceived a player while fighting the other monster, it returns to the idle state after killing its target monster.
 +
 +
In addition, a monster may have the [[Thing#Flags|"deaf" flag]] set onto its map [[thing]]. "Deaf" is actually a misnomer, as this flag (called <tt>MF_AMBUSH</tt> in the [[source code]]) is not so straightforward. A monster can still hear the player but it will not awake, instead going into the "state of full spatial alertness". In this state, the monster awakes when it has a direct line of sight to the player, even without the need to face him directly<ref name="doomsrc1" /> (by means of a simple line-of-sight check performed between two [[mobj]]s).
 +
 +
==Choosing and switching targets==
 +
A monster always chases one target at a time. Monsters will only [[monster infighting|choose another monster as their target]] if it accidentally hits them with an attack. [[Arch-vile]]s can never be the target of another monster, nor can [[pain elemental]]s, as the [[lost soul]]s launched by a pain elemental are targeted instead.
 +
 +
If the monster's current target is another monster, it always turns on the player after it is done with its current enemy, and monsters resurrected by arch-viles immediately turn on the player. Lost souls damaged by other monsters forget their targets after a single counterattack, whether it was successful or not, and then turn back to the player.
 +
 +
==Targeting threshold==
 +
After a monster awakens from its idle state and it is hit for the first time, a target countdown timer called "threshold" is activated. The longer a monster walks around with the same target, the lower the threshold gets. As long as the threshold remains positive, the monster will not change its target even if it is hit by another player or a monster. The monster will only choose a new target if the threshold reaches zero and the monster is hit by another monster or player, or if its current target dies. The threshold system does not apply to the arch-vile, which changes its target immediately to the player or monster that hurts it.
 +
 +
The base threshold counter is set to 100 [[tic]]s, or about 3 seconds<ref name="doomsrc2">Doom source code, p_inter.c, p_local.h</ref>.
 +
 
==Movement==
 
==Movement==
Monsters can move in any [[Wikipedia:Cardinal_direction|cardinal]] or [[Wikipedia:Ordinal_direction|ordinal]] direction.
+
Monster movement system can be generally described with several rules<ref name="mov1">Gipson</ref>:
 +
 
 +
*Monsters can move in any [[Wikipedia:Cardinal_direction|cardinal]] or [[Wikipedia:Ordinal_direction|ordinal]] direction.
 +
*Monsters are blocked by walls and other impassable objects, including other monsters.
 +
*Floor elevation changes must not exceed 24 [[unit]]s between any two adjoining sectors.
 +
*The difference in height between the floor and ceiling must be ''equal or greater than'' the monster's height.
 +
*The space between walls and other impassable objects must ''exceed'' the monsters width by some amount. There is no general consensus on this, commonly mentioned values are between 1 and 4 map units<ref name="mov2">Ampoker</ref><ref name="uds">Fell</ref>. Additionally, monsters in very narrow passages may exhibit some [[monsters fleeing|counter-intuitive behavior]].
 +
*Stairs mechanics are far more complicated. Monsters have problems with [[Stairs that can be ascended, but not descended|stairs with different ceiling heights between steps]], as there must be clearance between the highest floor segment and the lowest ceiling segment the monster can occupy at the same time. Also, there needs to be sufficient width the steps for the monster to navigate, but again the exact values are unclear<ref name="mov2"/>. Lastly, the faster and wider the monster is, the harder it is for it to negotiate stairs<ref name="dwf">{{Dwforums|55704|Demons are scary}}</ref>.
  
 
Monsters generally try to close in on their target via the shortest possible route. If the direct route to the target is blocked by a wall or a solid [[thing]] that the monster walks into, it randomly picks another direction to move in for a short while (to find another route to its target) until it reverts to heading straight toward its target again.
 
Monsters generally try to close in on their target via the shortest possible route. If the direct route to the target is blocked by a wall or a solid [[thing]] that the monster walks into, it randomly picks another direction to move in for a short while (to find another route to its target) until it reverts to heading straight toward its target again.
 +
 +
In their pursuit, monsters will try to open doors and activate lifts, except for those marked as player-only, however sometimes they [[Monsters open locked doors|succeed in that also]]. In addition, they have difficulties when trying to [[Monsters stuck in doortracks, walls or hanging off lifts|open an already opened door]].
  
 
A monster does not need to have a line of sight to follow its target, and will attempt to close in on its position within the level.
 
A monster does not need to have a line of sight to follow its target, and will attempt to close in on its position within the level.
  
If a monster with no melee attack reaches its target and "bumps" into it, it will move away from it for a while in a similar fashion it does when hitting any other obstacle.
+
If a monster has no target, it is in the idle state and will not move.
 +
 
 +
==Flying movement==
 +
Monsters with the ability to fly ([[cacodemon]]s, [[pain elemental]]s and [[lost soul]]s) are generally subjected to the rules above, except since they do not walk, they are not hindered by steps and dropoffs. Still, they obey additional restrictions<ref name="mov1"/>:
 +
 
 +
*A flying monster can only fly ''as high as the highest height it has been on''.
 +
*A flying monster can gain new altitude (rise higher than its starting altitude) ''by "climbing up" against the obstacle'', e.g. a decoration or the linedef between the two sectors of different heights. If said linedef is set to block monster movement, the monster will ''not be able to gain altitude at all''.
 +
*A flying monster can only change elevation as fast as its base movement speed.
 +
 
 +
It should be noted that attacking lost souls move like [[projectile]]s and are not subject to these mechanics. In all other respects, they follow these patterns.
 +
 
 +
==Melee and ranged attack use==
 +
When the monster wakes up upon seeing or hearing the player, it will delay its first attack by at least 8 tics (called ''reactiontime'' in the code). If aroused by damage, or when playing on Nightmare! [[skill level]], ''reactiontime'' is set to zero, making it attack right away without any delay.  
  
If a monster has no target, it is in the dormant state and will not move.
+
The further a monster is from its target, the less it will use its ranged attack (if it has one), and the closer, the more. This way the monster will close in on its target, where it can score more succesful hits. At long distances, [[spiderdemon]]s and lost souls in particular have higher attack probability than other monsters; for [[cyberdemon]]s, the probability is even higher.  
  
==Choosing target==
+
While hitscans cease to trace after 2048 map units, this does not prevent monsters with bullet attack to aim and shoot at their targets beyond this range. Arch-viles will not target enemies further than 896 units away.
A monster chases one target at a time. The monster's initial target is usually the [[player]] who awakened the monster from its dormant state by moving into its line of sight, by making an attack in an area the monster can hear (unless the monster has the "deaf" [[flag]] set) or by harming the monster. If the initial target was another monster and the monster has not perceived a player while fighting the other monster, it returns to the dormant state after killing its target monster.
 
  
After a monster awakens from its dormant state and it is hit for the first time, a target countdown timer called "threshold" is activated. The longer a monster walks around with the same target, the lower the threshold gets. As long as the threshold remains positive, the monster will not change its target even if it is hit by another player or a monster. If the threshold reaches zero, the monster may choose a new target to chase if it is hit by another monster or player or if it perceives another player. Note that this is only a possibility, and often the monster will choose to ignore the hits it takes and keep its current target even if its threshold is at zero. The threshold system does not apply to the [[arch-vile]], which changes its target immediately to the player or monster that hurts it.
+
After attacking, the monster will make at least one move before attacking again, compelled by the game logic. On Nightmare! or when the <tt>-fast</tt> [[parameter]] is used, this constraint is omitted, making the monster shoot as long as its target stays in sight, unless it flinches after being hit.
  
Monsters will only choose another monster as their target if it accidentally hits them with an attack. [[arch-vile]]s can never be the target of another monster, nor can [[pain elemental]]s, as the [[lost soul]]s launched by a pain elemental are targeted instead.
+
The monster will use its melee attack if the distance is less than 64 units. [[Revenant]]s are hardcoded to attack only in melee when in range of 196 units, however they still must get closer than 64 units to administer a punch.  
  
==Ranged attack use==
+
If a monster with no melee attack reaches its target and bumps into it, it will move away in a random direction in a similar fashion it does when hitting any other obstacle.
The further a monster is from its target, the more it will use its ranged attack (if it has one), and the closer, the less. The logic behind this is, that when the monster is in close proximity of its target, it will try to get to its target faster to be able to hit it with its melee attack.
 
  
 
==See also==
 
==See also==
*[[Lost soul charging backwards]]
 
 
*[[Monster infighting]]
 
*[[Monster infighting]]
 
*[[Monsters fleeing]]
 
*[[Monsters fleeing]]
 +
*[[Monsters stuck in doortracks, walls or hanging off lifts]]
 +
*[[Monsters open locked doors]]
 +
*[[Flawed collision detection]]
 +
*[[Stairs that can be ascended, but not descended]]
 +
*[[Lost soul charging backwards]]
 +
*[[Lost soul target amnesia]]
 +
*[[Baron attacks a monster behind him]]
 +
 +
== Sources ==
 +
*[http://www.trilobite.org/doom/flight.html Monster Flight Rules], by Richard Gipson
 +
*[http://www.trilobite.org/doom/doom_metrics.html Doom Metrics], by Scott Ampoker
 +
*[[Unofficial Doom Specs]], by Matt Fell
 +
 +
==References==
 +
<references/>
  
 
[[Category:Doom engine]]
 
[[Category:Doom engine]]
 
[[Category:Monsters]]
 
[[Category:Monsters]]

Revision as of 17:10, 9 September 2012

Monsters in the Doom engine games have a primitive artificial intelligence that follows a set of behavioral rules. The following rules apply to all monsters, unless stated otherwise.

Initial state and alertness

When the map is loaded, all monsters spawn in the idle state. Idle monsters are stationary and appear to be walking in place. This is because Doom monsters have no idle frames, instead going through their first two walking frames in a loop.

An idle monster looks in a 180-degree cone towards the direction of its initial orientation[1] . The monster's initial target is usually the player who awakened the monster by moving into its line of sight, by making an attack in an area the monster can hear, or by harming the monster. If the initial target was another monster and the monster has not perceived a player while fighting the other monster, it returns to the idle state after killing its target monster.

In addition, a monster may have the "deaf" flag set onto its map thing. "Deaf" is actually a misnomer, as this flag (called MF_AMBUSH in the source code) is not so straightforward. A monster can still hear the player but it will not awake, instead going into the "state of full spatial alertness". In this state, the monster awakes when it has a direct line of sight to the player, even without the need to face him directly[1] (by means of a simple line-of-sight check performed between two mobjs).

Choosing and switching targets

A monster always chases one target at a time. Monsters will only choose another monster as their target if it accidentally hits them with an attack. Arch-viles can never be the target of another monster, nor can pain elementals, as the lost souls launched by a pain elemental are targeted instead.

If the monster's current target is another monster, it always turns on the player after it is done with its current enemy, and monsters resurrected by arch-viles immediately turn on the player. Lost souls damaged by other monsters forget their targets after a single counterattack, whether it was successful or not, and then turn back to the player.

Targeting threshold

After a monster awakens from its idle state and it is hit for the first time, a target countdown timer called "threshold" is activated. The longer a monster walks around with the same target, the lower the threshold gets. As long as the threshold remains positive, the monster will not change its target even if it is hit by another player or a monster. The monster will only choose a new target if the threshold reaches zero and the monster is hit by another monster or player, or if its current target dies. The threshold system does not apply to the arch-vile, which changes its target immediately to the player or monster that hurts it.

The base threshold counter is set to 100 tics, or about 3 seconds[2].

Movement

Monster movement system can be generally described with several rules[3]:

  • Monsters can move in any cardinal or ordinal direction.
  • Monsters are blocked by walls and other impassable objects, including other monsters.
  • Floor elevation changes must not exceed 24 units between any two adjoining sectors.
  • The difference in height between the floor and ceiling must be equal or greater than the monster's height.
  • The space between walls and other impassable objects must exceed the monsters width by some amount. There is no general consensus on this, commonly mentioned values are between 1 and 4 map units[4][5]. Additionally, monsters in very narrow passages may exhibit some counter-intuitive behavior.
  • Stairs mechanics are far more complicated. Monsters have problems with stairs with different ceiling heights between steps, as there must be clearance between the highest floor segment and the lowest ceiling segment the monster can occupy at the same time. Also, there needs to be sufficient width the steps for the monster to navigate, but again the exact values are unclear[4]. Lastly, the faster and wider the monster is, the harder it is for it to negotiate stairs[6].

Monsters generally try to close in on their target via the shortest possible route. If the direct route to the target is blocked by a wall or a solid thing that the monster walks into, it randomly picks another direction to move in for a short while (to find another route to its target) until it reverts to heading straight toward its target again.

In their pursuit, monsters will try to open doors and activate lifts, except for those marked as player-only, however sometimes they succeed in that also. In addition, they have difficulties when trying to open an already opened door.

A monster does not need to have a line of sight to follow its target, and will attempt to close in on its position within the level.

If a monster has no target, it is in the idle state and will not move.

Flying movement

Monsters with the ability to fly (cacodemons, pain elementals and lost souls) are generally subjected to the rules above, except since they do not walk, they are not hindered by steps and dropoffs. Still, they obey additional restrictions[3]:

  • A flying monster can only fly as high as the highest height it has been on.
  • A flying monster can gain new altitude (rise higher than its starting altitude) by "climbing up" against the obstacle, e.g. a decoration or the linedef between the two sectors of different heights. If said linedef is set to block monster movement, the monster will not be able to gain altitude at all.
  • A flying monster can only change elevation as fast as its base movement speed.

It should be noted that attacking lost souls move like projectiles and are not subject to these mechanics. In all other respects, they follow these patterns.

Melee and ranged attack use

When the monster wakes up upon seeing or hearing the player, it will delay its first attack by at least 8 tics (called reactiontime in the code). If aroused by damage, or when playing on Nightmare! skill level, reactiontime is set to zero, making it attack right away without any delay.

The further a monster is from its target, the less it will use its ranged attack (if it has one), and the closer, the more. This way the monster will close in on its target, where it can score more succesful hits. At long distances, spiderdemons and lost souls in particular have higher attack probability than other monsters; for cyberdemons, the probability is even higher.

While hitscans cease to trace after 2048 map units, this does not prevent monsters with bullet attack to aim and shoot at their targets beyond this range. Arch-viles will not target enemies further than 896 units away.

After attacking, the monster will make at least one move before attacking again, compelled by the game logic. On Nightmare! or when the -fast parameter is used, this constraint is omitted, making the monster shoot as long as its target stays in sight, unless it flinches after being hit.

The monster will use its melee attack if the distance is less than 64 units. Revenants are hardcoded to attack only in melee when in range of 196 units, however they still must get closer than 64 units to administer a punch.

If a monster with no melee attack reaches its target and bumps into it, it will move away in a random direction in a similar fashion it does when hitting any other obstacle.

See also

Sources

References

  1. 1.0 1.1 Doom source code, p_enemy.c
  2. Doom source code, p_inter.c, p_local.h
  3. 3.0 3.1 Gipson
  4. 4.0 4.1 Ampoker
  5. Fell
  6. Demons are scary