Deerbrain
Based on game build 714014 | Last updated: 2026-02-27
Overview
The deerbrain component defines the behavior tree logic for deer entities. It dynamically selects between two modes: herd-based behavior (e.g., staying near the herd location, grazing, responding to herd-wide alerts) and solo behavior (e.g., wandering, facing players, fleeing from attackers). The brain prioritizes threat responses (panic, combat threats) over movement and idle behaviors, and integrates with the global deerherding system to synchronize herd-wide alert states and movement goals.
Dependencies & Tags
- Components used:
combat: ChecksHasTarget()and accessestarget.deerherding: QueriesIsActiveInHerd(),IsGrazing(),SetHerdAlertTarget(),GetClosestHerdAlertTarget(),HerdHasAlertTarget(), and readsherdlocation.hauntable: Readspanicproperty.knownlocations: CallsGetLocation("herdoffset")to compute herd-relative positions.
- Tags: None explicitly added/removed by this component.
Properties
No public properties are defined in the constructor. The component operates solely through behavior node logic and external component interactions.
Main Functions
The deerbrain does not define any public methods beyond the constructor. Its behavior is entirely driven by behavior tree nodes initialized in OnStart(). Helper functions used internally include:
ResetData(inst)
- Description: Initializes or updates the deer's herd alert target by finding the closest player within
START_ALERT_DISTand registers it viadeerherding:SetHerdAlertTarget(). Called once per behavior tree loop at the root level. - Parameters:
inst: The deer entity instance.
- Returns:
nil
GetAlertTargetFn(inst)
- Description: Returns the closest herd alert target (e.g., a player or predator flagged as a threat) as determined by
deerherding:GetClosestHerdAlertTarget(). - Parameters:
inst: The deer entity instance.
- Returns:
Instornil
KeepAlertTargetFn(inst, target)
- Description: Returns
trueif the herd has any active alert targets, allowing theFaceEntitynode to continue facing toward threats. - Parameters:
inst: The deer entity instance.target: The current alert target (unused).
- Returns:
boolean
GetNonHerdingFaceTargetFn(inst)
- Description: Locates the closest player within
SOLO_START_FACE_DISTfor solo-mode face behavior. - Parameters:
inst: The deer entity instance.
- Returns:
Instornil
KeepNonHerdingFaceTargetFn(inst, target)
- Description: Continues facing a player unless the target has the
"notarget"tag or is beyondSOLO_KEEP_FACE_DIST. - Parameters:
inst: The deer entity instance.target: The entity currently being faced.
- Returns:
boolean
GetWanderDistFn(inst)
- Description: Returns the constant wandering distance
WANDER_DIST_DAY(10). - Parameters:
inst: The deer entity instance (unused).
- Returns:
number
GetLocationInHerd(inst)
- Description: Computes the herd's target position by summing the global
deerherding.herdlocationvector and theherdoffsetlocation stored inknownlocations. - Parameters:
inst: The deer entity instance.
- Returns:
Vector3ornilif either location is unavailable.
GetGrazingLocation(inst)
- Description: Computes a grazing position offset farther from the herd center (
herdlocation + herdoffset * 2) used during grazing sequences. - Parameters:
inst: The deer entity instance.
- Returns:
Vector3ornilif locations are missing.
GetGrazingAngle(inst)
- Description: Computes a random facing angle centered on the herd offset's direction, with a variance of
66 * DEGREES. - Parameters:
inst: The deer entity instance.
- Returns:
number(angle in radians)
IsHerdGrazing(self)
- Description: Returns
trueif the globaldeerherdingcomponent is currently in a grazing state (usesIsGrazing()). - Parameters:
self: The behavior tree context table (containsself.inst).
- Returns:
boolean
GetRunAwayTarget(inst)
- Description: Returns the current combat target only if it is a valid player entity.
- Parameters:
inst: The deer entity instance.
- Returns:
Instornil
ShouldMoveAsHerd(self)
- Description: Checks whether the deer should move toward the herd center: returns
trueif its squared distance toGetLocationInHerd()exceeds half ofTUNING.DEER_HERD_MOVE_DIST. - Parameters:
self: The behavior tree context table (containsself.inst).
- Returns:
boolean
Events & Listeners
The component does not register any event listeners or push events directly. It relies entirely on the behavior tree infrastructure to react to state changes and component updates (e.g., via WhileNode and FailIfSuccessDecorator).