Beargerbrain
Based on game build 714014 | Last updated: 2026-02-27
Overview
The BeargerBrain component implements the core AI logic for the Bearger character in Don't Starve Together. It constructs and maintains a behavior tree (self.bt) that orchestrates complex, context-sensitive behaviors such as chasing and attacking enemies, seeking and consuming food, stealing food from structures, harvesting resources (e.g., beehives, farms), and seasonal wander patterns. It integrates with multiple components to make decisions based on game state (e.g., season, base proximity) and entity properties (e.g., tags, health, position). This brain is responsible for autonomous decision-making during both active (summer) and migratory (autumn) phases, and it respects seasonal tuning parameters like travel distance and attack range.
Dependencies & Tags
- Components used:
combat: for targeting,CanTarget checks, andtargetproperty.eater: for food compatibility (CanEat,GetEdibleTags), used in food search.inventory: for checking if inventory is full, and finding edible items.container: for checking container emptiness and finding items viaFindItem.stewer,dryer,crop,harvestable,pickable: to determine readiness for harvesting and interaction.timer: for checking timer existence (e.g., "GroundPound").knownlocations: to store/retrieve spawn point location for seasonal home logic.workable: used implicitly viaitem.components.workablechecks (though no direct method is called onworkablein this script).
- Tags added/checked:
structure,beehive,honeyed,lunar_aligned,busy,wantstoeat,running,jumping,staggered.- Tags excluded from search (
NO_TAGS):FX,NOCLICK,DECOR,INLIMBO,burnt,outofreach. BASE_TAGS:{ "structure" }, used to detect proximity to player structures.PICKABLE_FOODS: internal lookup table (berries,cave_banana,carrot,red_cap,blue_cap,green_cap).
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst.seenbase | boolean | false | Tracks whether the Bearger has entered the vicinity of a player structure; becomes true once 2 or more structure tagged entities are within SEE_STRUCTURE_DIST. |
inst.wanderdirection | number | nil | Stores the current wander angle (in radians) set by SetWanderDirection and used by GetWanderDirection. |
inst.canrunningbutt | boolean | inferred (not set here) | Controls whether the ChaseAndRam behavior should terminate early if GroundPound timer is active. |
Main Functions
EatFoodAction(inst)
- Description: Constructs a priority-based food-gathering action. First checks inventory for edible items to eat. If none found and Bearger is not busy, scans nearby entities (within
SEE_FOOD_DIST) for edible, unharvested food. Prioritizes picking uphoneyeditems first (viaPICKUP), then other edible items (viaPICKUP). - Parameters:
inst: The Bearger entity instance.
- Returns:
BufferedActionif a valid target and action (EAT,PICKUP) is identified; otherwisenil.
StealFoodAction(inst)
- Description: Implements a priority-based foraging and stealing behavior. Scans nearby structures (within
SEE_STRUCTURE_DIST) and categorizes them into priority tiers: cooking pots/stewers and drying racks/crops/honeyed structures (fridge/chest/backpack) take precedence over unprocessed food sources (beeboxes, mushroom farms, raw plants). Prioritizeshoneyeditems when possible, and returns appropriate actions (e.g.,HARVEST,HAMMER,STEAL,PICK). - Parameters:
inst: The Bearger entity instance.
- Returns:
BufferedActionfor the highest-priority food source found, ornil.
AttackHiveAction(inst)
- Description: Finds and targets a beehive within
SEE_STRUCTURE_DISTthat is targetable (combat:CanTarget) and on valid ground, returning anATTACKbuffered action. - Parameters:
inst: The Bearger entity instance.
- Returns:
BufferedAction(inst, hive, ACTIONS.ATTACK)if a valid hive is found; otherwisenil.
ShouldEatFoodFn(inst)
- Description: Predicate function that returns
trueif the Bearger is at or near a player base (i.e., has encountered 2 or morestructureentities withinSEE_STRUCTURE_DIST). Used by the behavior tree to enable eating/stealing prioritization when near bases. - Parameters:
inst: The Bearger entity instance.
- Returns:
trueifinst.seenbaseistrueor base proximity condition is met during call; otherwisefalse.
GetHome(inst)
- Description: Returns the spawn point location during
summer(viaknownlocations:GetLocation("spawnpoint")); returnsnilin other seasons. Used byWanderas the home point for movement. - Parameters:
inst: The Bearger entity instance.
- Returns: Vector position of spawn point in summer,
nilotherwise.
GetTargetDistance(inst)
- Description: Returns season-dependent movement distance via
TUNING.BEARGER_SHORT_TRAVEL(summer) orTUNING.BEARGER_LONG_TRAVEL(autumn); returns0otherwise. - Parameters:
inst: The Bearger entity instance.
- Returns: Numeric distance threshold for Wander behavior based on season.
GetWanderDirection(inst)
- Description: Returns the stored wander direction (angle in radians) from
inst.wanderdirection. - Parameters:
inst: The Bearger entity instance.
- Returns: Number (radian angle) or
nil.
SetWanderDirection(inst, angle)
- Description: Stores the given
angle(radians) ininst.wanderdirection. - Parameters:
inst: The Bearger entity instance.angle: Number (radian angle) to store.
- Returns: Nothing.
OceanDistanceTest(inst, target)
- Description: Determines the maximum range at which Bearger can attack a target, respecting boat/water obstacles and special conditions. Returns
TUNING.BEARGER_ATTACK_RANGE - 0.25if Bearger can reach the target from shore (usingCanProbablyReachTargetFromShore) and target is not a beehive or whileGroundPoundtimer is inactive; otherwise returns a large offset (OUTSIDE_CATAPULT_RANGE). - Parameters:
inst: The Bearger entity instance.target: Entity to test distance against.
- Returns: Numeric distance threshold (e.g.,
TUNING.BEARGER_ATTACK_RANGE - 0.25) orOUTSIDE_CATAPULT_RANGE.
InRamDistance(inst, target)
- Description: Predicate used to determine if the Bearger should initiate a charge/ram based on target proximity. Returns
falseif target is within 10 units (i.e., already in melee range); otherwise returnstruefor land targets, or for off-land targets (boats/water) ifCanProbablyReachTargetFromShoreallows approaching within attack range. - Parameters:
inst: The Bearger entity instance.target: Entity to test distance against.
- Returns:
trueif ram/charge is appropriate;falseotherwise.
BeargerBrain:OnStart()
- Description: Initializes the behavior tree (
self.bt) with a hierarchical priority node structure that governs Bearger’s behavior. The root handles non-busy states, with sub-priorities for panic (if not lunar-aligned), charging/ramming, combat, base-near behavior (eating/stealing), wander, and idle. Integrates customDoActionnodes (EatFoodAction,StealFoodAction,AttackHiveAction) and behavioral utilities (ChaseAndAttack,ChaseAndRam,Wander,StandStill). Uses tuning parameters for chase duration, distance thresholds, and ocean reachability. - Parameters: None (uses
self.inst). - Returns: Nothing.
BeargerBrain:OnInitializationComplete()
- Description: Registers the Bearger’s current position as
"spawnpoint"inknownlocations, preserving it for seasonal use (e.g., return to spawn in summer). - Parameters: None (uses
self.inst). - Returns: Nothing.
Events & Listeners
- Listens to: None.
- Pushes: None.
Note: This brain does not directly register event listeners or push events; it relies on stategraph transitions and the behavior tree for reaction to game state changes.