Dustmothbrain
Based on game build 714014 | Last updated: 2026-02-27
Overview
The DustMothBrain component implements the decision-making logic for the DustMoth entity using a behavior tree. It coordinates responses to threats (e.g., fleeing from entities with the scarytoprey tag), eating dustmothfood, repairing the home den via RepairDenAction, dusting nearby dustable objects, and idle wandering. The behavior tree is constructed in OnStart() using prioritized PriorityNode conditions and custom DoAction nodes backed by helper functions. This brain leverages common utilities from BrainCommon, inventory access, known locations, and workable states to adapt behavior dynamically.
Dependencies & Tags
- Components used:
homeseeker— accessed forhomelocation (inst.components.homeseeker.home) and validity checks.inventory— accessed viaGetItemInSlot(1)to check currently held item.knownlocations— accessed viaGetLocation("home")to retrieve the home location for wandering.workable— checked viainst.components.homeseeker.home.components.workable.workableto determine if the den needs repair.
- Tags:
"INLIMBO"— excluded fromNOTAGS, and used to filter out invalid entities during entity searches."player"and"NOCLICK"— excluded viaHUNTERPARAMS_NOPLAYER."scarytoprey"— included in threat detection (HUNTERPARAMS_NOPLAYERandRunAway)."dustmothfood"— included for food search inEatFoodAction."dustable"— included for dusting targets inDustOffAction.
- External scripts:
behaviours/runaway,behaviours/doaction,behaviours/wanderbrains/braincommon
Properties
No explicit public properties are initialized in the constructor beyond standard Brain inheritance. Internal state is managed via instance variables attached to self.inst during runtime.
Main Functions
DustMothBrain:OnStart()
- Description: Initializes and assigns the behavior tree root node. Constructs a prioritized sequence of conditions and actions that define DustMoth behavior, including panic responses, stuck detection/unstuck logic, repair, eating, dusting, and wandering.
- Parameters: None.
- Returns:
nil.
AttemptPlaySearchAnim(inst, target)
- Description: Conditionally triggers the
"dustmothsearch"event and rotates the entity towardtargetto visually indicate search activity. Respects a cooldown (TUNING.DUSTMOTH.SEARCH_ANIM_COOLDOWN) and a random chance (SEARCH_ANIM_CHANCE). - Parameters:
inst(Entity): The entity instance owning this brain.target(Entity ornil): The target entity to face; may benil.
- Returns:
nil.
RepairDenAction(inst)
- Description: Attempts to generate a buffered
REPAIRaction if the DustMoth is not busy (busystate tag), is fully charged (_chargedistrue), has a valid home den, and the den is not currently workable (indicating it needs repair). - Parameters:
inst(Entity): The entity instance.
- Returns:
BufferedAction(if conditions met and action valid), otherwisenil.
EatFoodAction(inst)
- Description: Attempts to generate a buffered
EATaction. First checks if the inventory slot 1 containsdustmothfood; if not, searches withinEAT_FOOD_DISTfor valid food items (alive ≥ 1 second and on valid ground). Triggers a search animation before consuming. - Parameters:
inst(Entity): The entity instance.
- Returns:
BufferedAction(if food found), otherwisenil.
DustOffAction(inst)
- Description: Attempts to generate a buffered
PETaction (used as a "dust off" proxy) on the nearestdustableentity withinDUSTOFF_DIST, provided the entity is not busy and_find_dustablesistrue. Includes a custom distance calculation to allow close proximity interaction. - Parameters:
inst(Entity): The entity instance.
- Returns:
BufferedAction(if a validdustableis found), otherwisenil.
Events & Listeners
- Pushes:
"dustmothsearch"— fired byAttemptPlaySearchAnimto trigger visual feedback when searching for food or dustables.
- Listens to:
- None explicitly defined in this file (relies on parent
Brainclass or stategraph events implicitly).
- None explicitly defined in this file (relies on parent