Creature AI

From The Cataclysm: Dark Days Ahead Wiki
Jump to navigation Jump to search
Guide created using an unknown version of Cataclysm DDA.
The information present here might not apply to the current version of CDDA.


Action order

  • Formulate a plan (find a path ending in some target). Can result in retaining old plans instead
  • Use special abilities that aren't on cooldown (here some abilities check if they can be executed, so that stunned zombies won't bite)
  • Possibly lose the turn due to:
    • Lack of moves
    • Stun (this time stumble before losing the turn)
    • Being naturally immobile
  • Execute first action of plan (move/attack/bash)
    • If no plan exists, try to find the player by scent instead
    • If the scent is too weak, try to follow last heard sound
  • If no action was executed, stumble. Naturally stumbling monsters can stumble even after executing actions (potentially "jumping" a tile)

Planning

Planning involves iterating over all potentially hostile creatures and picking the closest hostile target. During this phase some anger/fear triggers (see below) are also processed.

Pathfinding

Currently only NPCs can find their path around obstacles. Zombies can exhibit a pathfinding-like behavior only by following player's scent.

Monsters will always go straight for a visible target or a heard sound (sound's perceived location is randomized). If the target is blocked (for example by wire fence), the monster may instead stumble and take a step in random direction.

Stumbling

Stumbling is a semi-random move executed by stunned, badly coordinated, purposeless or otherwise confused monsters. Non-aquatic monsters will not stumble into water, but can stumble out of it or onto a dangerous/unfavorable terrain.

Naturally stumbling monsters (such as Zombies) will stop stumbling when their target is closer than 4 steps away from them (including when the target is a sound, not a seen creature).

Attitude

Monsters have two different sets of attitudes - one set to player and NPCs, the other to any creature.

Attitude to player and NPCs depends on monster's friendliness (currently binary - the creature is either on player's side or not) and morale and anger modified by target's traits (for example, Terrifying or Animal Empathy).

Possible attitudes to players and NPCs are:

  • Friendly - will follow the player when there are no targets around. Can't be achieved with morale, anger and traits alone
  • Ignore - not angry or scared enough to act yet
  • Passive - can't get angry or scared enough to act (caused by docile state)
  • Follow/stalk - not angry enough (or too scared) to attack yet, but will try to stay near the player
  • Flee - will run from the nearest creature
  • Enslaved - will follow the player, but ignore other creatures
  • Hostile - angry enough to attack and not scared enough to stalk

Attitude to monsters depends on morale and anger and monster faction relations.

Possible attitudes to all creatures are:

  • Friendly - will ignore the target
  • Neutral - either strictly neutral (won't ever get angry at it) or just too scared/not angry enough to act
  • Hostile - will attack or flee from the target

Morale

Morale is monster's willingness to fight rather than flee. Many creatures have triggers that lower it ranging from being hurt to simply seeing a hostile being close by. Creatures such as zombies or robots tend to have constant morale.

Friendly monsters ignore morale stat and are always ready to fight.

Aggressiveness (anger)

Aggressiveness or anger (aggressiveness generally refers to monster type, while anger refers to particular monster's current state) is monster's will to hurt non-friendly creatures. As with morale, creatures have anger triggers that make them more (or less) angry. Zombies (and similar) usually have constantly high anger, while animals tend to get angry when neutral or hostile creatures linger nearby.

Friendly monsters are always hostile towards non-friendly monsters.

Triggers

Triggers are events that change creature's morale or anger.

Triggers can be anger triggers (increase anger by stated number of points), fear triggers (decrease morale) and placate triggers (decrease anger).

Currently the following triggers are implemented:

  • Stalk - 1 in 20 chance of 1 point, but only if anger > 0
  • Hostile nearby - 5 points for every visible hostile or potentially hostile creature within 5 tiles
  • Fire nearby - (5*strength) points for every fire (ie. 2 raging fires are 30) within 3 tiles and 49 for player with a torch within 3 tiles
  • Hurt - 1 + (damage / 3) (round down) points when damaged
  • Friend attacked - (bugged?) 15 points to every monster when a monster of this kind is attacked in melee
  • Friend died - 15 points to every monster of same species that sees this monster die
  • Sound - number of points equal to (volume - distance) or (2*volume - distance) for creatures with good hearing