Wobybigbrain
Overview
Wobybigbrain is a behavior tree (BT) implementation that defines the decision logic for Woby, Walter's loyal companion entity. It orchestrates high-priority actions such as combat avoidance (including retreat and observation), assisting the owner with CHOP and MINE tasks (when the walter_woby_taskaid skill is activated), and responding to rider mounting or player interaction prompts. The brain extends the base Brain class and composes multiple behavior nodes—leveraging WobyBrainCommon and BrainCommon modules—to prioritize context-sensitive behaviors (e.g., task assistance over wandering) and dynamically adjust movement and facing logic.
The component relies on several helper functions to determine targets (e.g., owner, rider, interactive players), validate combat proximity, and select actions based on Woby's current state and the player link UI. It also integrates with the follower, health, grouptargeter, walkableplatform, and skilltreeupdater components for context-aware decision-making.
Usage example
local WobyBigBrain = require("brains/wobybigbrain")
local inst = TheSim:FindEntity("woby", 1, { "woby" })
if inst ~= nil then
inst:AddComponent("brain")
inst.components.brain:SetBrain(WobyBigBrain(inst))
-- The brain automatically initializes its behavior tree on first tick
end
Dependencies & tags
Components used: follower, health, grouptargeter, walkableplatform, skilltreeupdater, combat (via _avoidtargetfn helper).
Tags checked/used internally: _combat, _health, wall, INLIMBO (for combat avoidance entity filtering).
No tags are explicitly added/removed by this component.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
_hasavoidcombattarget | function | HasAvoidCombatTarget | A stored reference to the HasAvoidCombatTarget function; used within the behavior tree for condition checks. |
No other public properties are initialized directly in the constructor.
Main functions
WobyBigBrain:OnStart()
- Description: Initializes the behavior tree (
self.bt) with a priority-based node hierarchy. This includes conditional guards, combat avoidance, interaction handling, task assistance, and fallback behaviors like following, wandering, and idle waiting. The tree is wrapped in a state guard (<busy state guard>) that prevents execution while Woby is jumping or transforming. - Parameters: None.
- Returns:
nil. - Error states: None. The function sets up
self.btfor execution by the ECSbraincomponent.
GetOwner(inst)
- Description: Returns the owner (leader) of Woby by delegating to
components.follower:GetLeader(), ornilif no follower component exists. - Parameters:
inst(Entity instance). - Returns: Entity instance (owner) or
nil. - Error states: Returns
nilifinst.components.followeris absent orGetLeader()returnsnil.
GetHomePos(inst)
- Description: Determines the reference position for wandering: the platform’s position if Woby is on a
walkableplatform, otherwise the owner’s position. - Parameters:
inst(Entity instance). - Returns: Position (x,y,z) or
nilif no platform or owner is available. - Error states: Returns
nilifGetCurrentPlatform()isniland no owner is present.
GetWanderDist(inst)
- Description: Returns the maximum wander radius:
platform_radiusif on a walkable platform, otherwise the defaultWANDER_DIST(12). - Parameters:
inst(Entity instance). - Returns: Number (distance).
- Error states: Defaults to
PLATFORM_WANDER_DIST(4) if the platform component or property is missing.
HasAvoidCombatTarget(self)
- Description: Checks if Woby should avoid nearby combat: either by validating an existing
runawayfromtarget, or by querying entities within combat range (COMBAT_TOO_CLOSE_DIST = 10) using_avoidtargetfn. Uses strict tags (_combat,_health) and exclusion tags (wall,INLIMBO). - Parameters:
self(Behavior tree node context, withself.runawayfromandself.inst). - Returns: Boolean (
trueif a combat target is within unsafe range). - Error states: Clears
self.runawayfromif validation fails.
_avoidtargetfn(self, target)
- Description: Determines whether a given entity (
target) represents a combat threat that Woby (via its owner) should avoid. Evaluates owner/target combat relationships, proximity, and recent activity (timeout-based). - Parameters:
self(behavior context),target(Entity instance). - Returns: Boolean (
trueif target is a combat threat). - Error states: Returns
falseif owner or target lackscombat/healthcomponents, is dead, or too far.
FindNew_MINE(inst, leaderdist, finddist, ...)
- Description: Wraps
BrainCommon.AssistLeaderDefaults.MINE.FindNewto locate a mineable target and adjusts the required distance to the target to be at leastWORK_MIN_DISTANCE + target.physics_radius. - Parameters:
inst,leaderdist,finddist, and optional arguments passed to the base finder. - Returns: Action table (e.g.,
action = "MINE",target = ...,distance = ...) ornil. - Error states: Returns
nilif the base finder returnsnil; otherwise, setsdistanceand notifies the player link via"tellwobywork".
FindNew_CHOP(inst, leaderdist, finddist, ...)
- Description: Similar to
FindNew_MINE, but for CHOP tasks. - Parameters:
inst,leaderdist,finddist, and optional arguments. - Returns: Action table or
nil. - Error states: Same as
FindNew_MINE.
IsAllowedToWorkThings(inst)
- Description: Returns whether Woby is permitted to assist with work tasks based on the
woby_commands_classifiedflag. - Parameters:
inst(Entity instance). - Returns: Boolean (
trueifinst.woby_commands_classified:ShouldWork()istrue).
HasTaskAidBehavior(inst)
- Description: Checks if the
walter_woby_taskaidskill is activated for the player link. - Parameters:
inst(Entity instance). - Returns: Boolean (
trueif skill is active).
Events & listeners
- Listens to: None explicitly (no
inst:ListenForEventcalls in this file). - Pushes:
"critter_avoidcombat"(with{avoid=true}or{avoid=false}) when entering/exiting combat avoidance state. - Pushes:
"tellwobywork"to the player link (inst._playerlink) after successfully selecting a CHOP or MINE target.