Molebatbrain
Based on game build 714014 | Last updated: 2026-02-27
Overview
MolebatBrain is a brain component that implements the decision-making logic for molebat entities. It uses a behavior tree (BT) with prioritized conditional nodes to govern state transitions between combat (chasing, dodging, summoning), nest building, nest cleanup, going home, sleeping, foraging/eating, face tracking, and wandering. It integrates with core systems such as combat, entity tracking, eater, and known locations to make context-aware decisions about behavior sequencing.
Dependencies & Tags
- Components used:
combat,eater,entitytracker,knownlocations - Tags:
"molebathill"(used for finding existing molehills),
"DECOR","FX","NOCLICK","INLIMBO","outofreach","notarget"(excluded in entity filtering),
"busy"(state tag checked viainst.sg:HasStateTag("busy")). - No tags are added or removed by this component itself.
Properties
The constructor initializes no custom properties; the component inherits from Brain and dynamically manages state via the behavior tree and event listeners (see "Events & Listeners").
| Property | Type | Default Value | Description |
|---|---|---|---|
self.inst | Entity | from Brain._ctor | Reference to the entity instance this brain controls. |
self.bt | BT | assigned in OnStart | Behavior tree root node, created and set during brain initialization. |
Main Functions
MoleBatBrain:OnStart()
- Description: Initializes and assigns the behavior tree root for the molebat. Called automatically when the brain component starts (typically during entity spawn or after a stategraph reset). Constructs a priority-weighted behavior tree with conditional nodes handling panic, summoning, combat, nest management, navigation, and idle behaviors.
- Parameters: None.
- Returns: None. Sets
self.bt.
Internal Helper Functions
The following functions are defined locally and used as callbacks within the behavior tree. They are not exported methods but are critical to the brain's operation.
CleanUpNest(inst)
- Description: Computes and returns an action to break the molebat's burrow (molehill) when the nest is flagged for cleaning. Used when
inst._nest_needs_cleaningis true. - Parameters:
inst(Entity) — The molebat instance. - Returns:
BufferedAction— An action to performACTIONS.BREAKon the burrow entity, ornilif cleanup is no longer needed.
ShouldBuildHome(inst)
- Description: Determines whether the molebat should build a new molehill home. Returns
trueonly if not busy, not already near an existing molehill, and not currently napping (ifWantsToNapexists). - Parameters:
inst(Entity) — The molebat instance. - Returns:
boolean—trueif the molebat should build a home, otherwisefalse.
CreateBurrow(inst)
- Description: Returns a buffered action to create a new molehill at a nearby walkable offset from the molebat’s current position. Uses
ACTIONS.MAKEMOLEHILLand random offset search. - Parameters:
inst(Entity) — The molebat instance. - Returns:
BufferedAction— An action to performACTIONS.MAKEMOLEHILLat a computed position, ornilif no valid offset is found.
ShouldGoSleepAtHome(inst)
- Description: Checks if the molebat is ready to sleep at its burrow. Requires that the molebat is not busy, wants to nap (if
WantsToNapis defined), and has a registered burrow entity. - Parameters:
inst(Entity) — The molebat instance. - Returns:
boolean—trueif the molebat should go to sleep at home.
GoSleepAtHomeAction(inst)
- Description: Returns a buffered action to travel to the registered burrow for napping.
- Parameters:
inst(Entity) — The molebat instance. - Returns:
BufferedAction— An action to performACTIONS.TRAVELto the burrow position.
ShouldGoHome(inst)
- Description: Checks if the molebat is sufficiently far from the registered "home" location and should return. Uses squared distance comparison against
GO_HOME_DSQ = 900. - Parameters:
inst(Entity) — The molebat instance. - Returns:
boolean—trueif the molebat is outside the home zone and not in combat.
GoHomeAction(inst)
- Description: Returns a buffered action to walk to the registered "home" location, provided the molebat has no active combat target.
- Parameters:
inst(Entity) — The molebat instance. - Returns:
BufferedAction— An action to performACTIONS.WALKTOtoward the home location, ornil.
EatFoodAction(inst)
- Description: Searches for edible food items near the molebat (within
SEE_FOOD_DIST = 25) and returns an action to eat the first valid candidate. Items must be alive ≥ 8 seconds, on passable terrain, edible, and withinGO_HOME_DSQof home. - Parameters:
inst(Entity) — The molebat instance. - Returns:
BufferedAction— An action to performACTIONS.EATon the target, ornil.
GetFaceTargetFn(inst)
- Description: Returns the nearest player within
START_FACE_DIST = 6that does not have the"notarget"tag. - Parameters:
inst(Entity) — The molebat instance. - Returns:
Entity— The nearest eligible player, ornil.
KeepFaceTargetFn(inst, target)
- Description: Determines whether the molebat should keep facing the current face target (i.e., player). Returns
trueif the target does not have"notarget"and is withinKEEP_FACE_DIST = 8. - Parameters:
inst(Entity) — The molebat instance.
target(Entity) — The current face target. - Returns:
boolean—trueif the face target should be maintained.
GetRunAwayTarget(inst)
- Description: Returns the current combat target for the
RunAwaybehavior. - Parameters:
inst(Entity) — The molebat instance. - Returns:
Entity— The combat target stored ininst.components.combat.target.
Events & Listeners
- Listens to:
None directly in this file. Entity removal listening for"burrow"is handled insideCleanUpNestviaEntityTracker, which internally registersinst:ListenForEvent("onremove", onremove, burrow). - Pushes:
"summon"— fired during the"Summon Allies"behavior tree branch when the molebat is in combat cooldown but eligible to summon allies (ShouldSummonAllies()returnstrue).