Chaseandram
Overview
ChaseAndRam is a behaviour node used in the DST AI system to orchestrate a charging or chasing attack pattern against a selected target. It inherits from BehaviourNode and manages the entity’s locomotion and combat state during pursuit. When active, it lines up the entity for a charged "ram" (i.e., directional charge), executes attacks via combat:TryAttack(), and tracks progress using distance, time, and attack count limits. It integrates tightly with the combat, locomotor, and embarker components, and listens for onattackother and onmissother events to update internal state.
Dependencies & Tags
- Components used:
combat: Used forBattleCry(),ForceAttack(),TryAttack(), andSetTarget().locomotor: Used forGoToPoint(),RunInDirection(), andStop().health: Checked viaIsDead()to terminate on target death.embarker: Checked for platform-hopping logic viaGetCurrentPlatform().
- Tags:
- Adds
"ChaseAndRam"when the behaviour starts running or while charging. - Removes
"ChaseAndRam"on status change (e.g., failure, success, or interruption).
- Adds
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | — | The entity instance to which this behaviour is attached. |
max_chase_time | number | — | Maximum duration (in seconds) the entity will continue chasing before aborting. nil disables the limit. |
give_up_dist | number | — | Distance (in units) beyond which the target is considered too far; chaser gives up if it overshoots or falls too far behind. |
max_charge_dist | number | — | Maximum total distance moved from the start of the charge before aborting. nil disables the limit. |
max_attacks | number | — | Maximum number of attacks to perform before succeeding. nil disables the limit. |
numattacks | number | 0 | Tracks how many attacks have been recorded (via onattackother or onmissother). |
onattackfn | function | — | Internal callback for onattackother / onmissother events. |
startruntime | number? | nil | Timestamp marking when the chase began; used for timing out. |
startloc | Vector? | nil | World position at the start of the chase. |
ram_angle | number? | nil | Angle (in degrees) of the intended charge direction. |
ram_vector | Vector? | nil | Normalized direction vector of the intended charge. |
Main Functions
OnStop()
- Description: Cleans up event callbacks when the behaviour node is stopped (e.g., by parent behaviour or priority override). Prevents memory leaks or stale callbacks.
- Parameters: None.
- Returns:
nil.
OnAttackOther(target)
- Description: Increments the
numattackscounter and resets thestartruntimetimer (to restart the chase-time limit) whenever an attack event occurs—regardless of hit or miss. This ensures both successful and missed attacks count towardmax_attacks. - Parameters:
target(Entity?): The target of the attack event (may benilfor misses).
- Returns:
nil.
AreDifferentPlatforms(inst, target)
- Description: Determines if the entity and target are on different platforms (e.g., ground vs. bridge) using the
embarkercomponent. Used to adjust movement logic (e.g., disable ram and fall back to direct pathing). - Parameters:
inst(Entity): The owner entity.target(Entity): The target entity.
- Returns:
boolean—trueif the two entities are on different platforms andembarkeris present; otherwisefalse.
Visit()
-
Description: The core execution logic of the behaviour node. Operates in two phases:
READY(initialization and setup) andRUNNING(main chase/ram loop).In
READY:- Validates target exists and is alive.
- Sets
startruntime,startloc,ram_angle, andram_vector. - Adds
"ChaseAndRam"tag and transitions toRUNNING. - If no valid target, sets
status = FAILEDand removes"ChaseAndRam".
In
RUNNING:- Checks for invalid/dead target and transitions to
FAILED/SUCCESSaccordingly. - Continuously updates
ram_angleandram_vectorif in a rotatable state. - Handles platform transitions (
on_different_platforms) by disabling ram and switching to point pathing. - If angle to target ≤ 60°, performs
RunInDirection()(i.e., the ram). - If overstepped (
offset_angle > 60°and too far), stops, performsForceAttack(), and fails. - Attempts
combat:TryAttack()when not inatk_prestate. - Monitors all three termination conditions:
max_attacksreached →SUCCESS.- Distance moved ≥
max_charge_dist→FAILED. - Elapsed time ≥
max_chase_time→FAILED.
- Calls
self:Sleep(0.125)to yield control between ticks.
-
Parameters: None.
-
Returns:
nil(modifies internalstatusand invokes component actions).
Events & Listeners
- Listens to:
"onattackother"— TriggersOnAttackOther()to count attacks and reset timer."onmissother"— Also triggersOnAttackOther()(missed attacks count towardmax_attacks).
- Pushes: None. (Only fires actions on other components; does not emit game events.)
Notes for Modders
- This behaviour expects the target to be set via
combat:SetTarget(entity)before it is started. - The
Combatcomponent’sBattleCry()is called upon enteringRUNNINGand whenstartruntimeresets. - Platform-hopping logic is sensitive to presence of the
embarkercomponent—without it,AreDifferentPlatformsalways returnsfalse. - The comment in
Visit()notes thatStop()was deliberately omitted on entry to avoid stutter during state transitions (e.g., fromRunAway), implyingChaseAndRamshould be inserted into a behaviour tree carefully, ideally after states that own movement clearing.