A_Chase

From ZDoom Wiki
Jump to navigation Jump to search
DoomWiki.org
For more information on this article, visit the A_Chase page on the Doom Wiki.

void A_Chase [(statelabel melee [, statelabel missile [, int flags]])]

Usage

This is the standard monster walking function which has to be used in the walking frames of a monster. Typically, it is used in an actor's "See" state or a custom equivalent. When called, actors usually change their directions to a strict 45 degree angle to give the effect of pursuit. This angle changes based on which direction the target is, no matter if the calling actor can see it or not.

Parameters

Note: passing "_a_chase_default" to both the melee and missile parameters, puts the function in its default-behavior mode. In this mode, the monster jumps to Melee and Missile states when performing melee and ranged attacks, respectively, does not strafe randomly, plays its active sound, and moves twice as fast in Nightmare! difficulty setting or equivalent. Additionally, the flags parameter is ignored.
  • melee: The state to jump to when the monster decides to perform a melee attack. If this is null(ZScript only)/0 or "" (empty string)(DECORATE only), the monster will not be able to enter the melee state while chasing. Default is "_a_chase_default".
  • missile: The state to jump to when the monster decides to perform a ranged attack. If this is null(ZScript only)/0 or "" (empty string)(DECORATE only), the monster will not be able to enter the ranged state while chasing. Default is "_a_chase_default".
  • flags: Determines how the monster will behave when the function is called. Default is 0. Because of the special way in which A_Chase handles its state jumps, the preceding state parameters must be specified or these flags will be ignored.
Flags can be combined by using the | character between the constant names.
  • CHF_FASTCHASE – Actor will randomly attempt to strafe left or right around the target, like the "player bosses" in Hexen. Note that the calling actor will ignore their MaxDropOffHeight property when strafing, and so may strafe off cliffs or into pits from which they can not escape. Setting the NODROPOFF flag will prevent this from happening.
  • CHF_NOPLAYACTIVE – Actor will not play active sounds.
  • CHF_NIGHTMAREFAST – Actor will move twice as fast in Nightmare! difficulty setting or equivalent.
  • CHF_RESURRECT – Actor will enter the "Heal" state (if defined) upon encountering a revivable corpse, like the Arch-Vile.
  • CHF_DONTMOVE – Actor will not move.
  • CHF_NORANDOMTURN – Actor will not change its chasing angle to its target if its beyond a certain degree until something blocks the way (obstacle or wall).
  • CHF_NODIRECTIONTURN – Actor will not turn its angle to face the direction of travel.
  • CHF_NOPOSTATTACKTURN – Actor will not turn itself to its target after attacking.
  • CHF_STOPIFBLOCKED – Actor cannot turn away from obstacles blocking it. It will simply not move, but can still angle itself.
  • CHF_DONTIDLE – Hostile actors will not jump to their Spawn or Idle state once they no longer have a target. Allowing you to define custom states for them to jump to, when they have no target.
  • CHF_DONTTURN – Implies CHF_NORANDOMTURN, CHF_NOPOSTATTACKTURN and CHF_STOPIFBLOCKED.

Notes

  • This function is not subject to the same rules as other jump functions are in anonymous functions, and cannot be used inside if/else statements. A_Chase will perform its jump, no matter what circumstances apply.
  • Because this function and its variant have the capacity to put the actor into an attack state, they should not be used during the first tic of one of those states, as it may result in infinite recursion, which will usually manifest itself in the engine as a crash.

Examples

Here is an example of a new monster which uses the optional range attack as well as a melee attack if it is close to its target, like the Revenant.

class Scurymonster : Actor
{
    Default
    {
        Monster;
        Height 20; // Default variables.
        Radius 16; // Default variables.
        Speed 10;
    }

    States
    {
    Spawn:
        MONS A 10 A_Look;
        Loop;
    See:
        MONS ABCD 4 A_Chase("Meleeattack", "Cowattack");
        Loop;
    Cowattack:
        MONS E 5 A_SpawnProjectile("Cowmissile"); // Not included in-game.
        Goto See;
    Meleeattack:
        MONS F 5 A_CustomMeleeAttack(5);
        Goto See;
    }
}