Skip to content

Chase functions

inkoalawetrust edited this page May 3, 2023 · 1 revision

These are ZScript exports of different chunks of A_Chase's native C++ code, they are used as building blocks for custom chase functions like KAI_LandVehicleChase() so that they still support existing ZDoom features like patrol routes.

Some also include parameters to modify their behavior. And most of the exported functions have a Flags parameter, that can be used to pass A_Chase flags that are used by those functions. That parameter is mandatory for the functions that use it.

HandleNativeFright()

Port of: https://sourcegraph.com/github.com/ZDoom/gzdoom/-/blob/src/playsim/p_enemy.cpp?L2568-2572

Return type(s):

  • Returns true if the caller should be spooked.

Function:

Used by the stock attack decision code of ShouldAttack() as it is itself a rip of A_Chase code.

KAI_Chase_PreChecks()

Port of: https://sourcegraph.com/github.com/ZDoom/gzdoom/-/blob/src/playsim/p_enemy.cpp?L2325-2376

Parameters:

  • Flags: The A_Chase flags to use, this is mandatory, and for custom chase functions should pass the chase flags passed to said function.

Return type(s):

  • None

Function:

Runs as the code that A_Chase runs before it begins to handle moving and attacking. Should be called first before the other exported code !

KAI_Chase_FriendsAttackPlayerEnemies()

Port of: https://sourcegraph.com/github.com/ZDoom/gzdoom/-/blob/src/playsim/p_enemy.cpp?L2401-2432

Parameters:

  • Flags: The A_Chase flags to use, this is mandatory, and for custom chase functions should pass the chase flags passed to said function.

Return type(s):

  • Returns true if the caller found an enemy of the player to attack.

Function:

Used by friendly monsters to make them target whoever attacked the player they work for if they have nothing else to attack

KAI_Chase_Retarget()

Port of: https://sourcegraph.com/github.com/ZDoom/gzdoom/-/blob/src/playsim/p_enemy.cpp?L2433-2467

Parameters:

  • Flags: The A_Chase flags to use, this is mandatory, and for custom chase functions should pass the chase flags passed to said function.
  • FriendsIdle: Makes friendly monsters with no target to attack go to their Spawn or See state, instead of staying on their see state and calling KAI_Wander() like hostile monsters without the CHF_DONTIDLE flag do. Default is false. Useful for NPCs that should have custom idling behavior rather than just wandering with the stock parameters.

Return type(s):

  • Returns true if the caller finds a new target, false otherwise.

Function:

Handles changing the NPCs' target if it has none left, and going to its' idle state or staying in See and calling KAI_Wander() if it can't find a new target. This function is pretty important for custom chase functions, so if you are making one, you should definitely add this in.

KAI_Chase_PatrolHandling()

Port of: https://sourcegraph.com/github.com/ZDoom/gzdoom/-/blob/src/playsim/p_enemy.cpp?L2486-2535

Parameters:

  • WaitState: The state the NPC should go to when it reaches a delayed patrol point. Default is null, which means it should just call SetIdle() to find a state to wait to.
  • DetourFactor, AngleLimit, ChaseFlags, Flags: Parameters passed to KAI_MoveTowards() while the NPC is heading towards the next goal point.

Return type(s):

  • Returns a boolean that is true if the function switched to the next patrol point in a route. False otherwise.
  • Returns a second boolean that is true if the NPC has a goal that it took one steps towards with KAI_MoveTowards. Basically returning if the function made the NPC move to a goal or not.

Function:

Runs the code that handles making NPCs move from one patrol point to another, unlike the native patrol handling code, this code actually handles moving to the next patrol point as well. Meaning that this function could be used alone to make something like an on rails NPC, like some kind of train or traffic system.

KAI_Chase_HandleActiveSound()

Port of: https://sourcegraph.com/github.com/ZDoom/gzdoom/-/blob/src/playsim/p_enemy.cpp?L2669-2673

Parameters:

  • Flags: The A_Chase flags to use, this is mandatory, and for custom chase functions should pass the chase flags passed to said function.
  • Frequency: How often the active sound will decide to play.

Return type(s):

  • Returns true if the actor played its' [[ActiveSound|https://zdoom.org/wiki/Actor_properties#ActiveSound], false otherwise.

Function:

Handles randomly playing the NPCs' active sound.

KAI_Chase_HandleStrafing()

Port of: https://sourcegraph.com/github.com/ZDoom/gzdoom/-/blob/src/playsim/p_enemy.cpp?L2537-2566

Parameters:

  • StrafeTarget: The actor to strafe from.
  • Flags: The A_Chase flags to use, this is mandatory, and for custom chase functions should pass the chase flags passed to said function.
  • ForceStrafe: Should the actor strafe regardless of the strafe delay or strafe chance. Default is false.
  • StrafeRange: How close to the StrafeTarget must the caller be to strafe ? Default is 64*10 (640) map units.

Return type(s):

  • None

Function:

Handles the strafing mechanic of CHF_FASTCHASE/Hexen's player bosses.

See also:

Clone this wiki locally