Carnival Crowkidbrain
Based on game build 714014 | Last updated: 2026-02-27
Overview
The carnival_crowkidbrain component implements the behavior tree for the Carnival Crowkid entity, orchestrating its AI decisions in response to game state, nearby entities, and environmental conditions. It dynamically selects behaviors such as watching minigames, stoking campfires, activating carnival decorations, chatting with players, wandering near its home, or fleeing danger via flight behavior. This component relies heavily on the behaviour system and integrates with several components (homeseeker, minigame_spectator, minigame, burnable, fueled, carnivaldecorranker) to coordinate decision-making.
Dependencies & Tags
-
Components used:
homeseeker— for home position tracking and homelessness detection.minigame_spectator— to access the current minigame and determine intro/outro states.minigame— accessed viaminigame_spectator, used to read minigame type, state, and distance parameters.burnable— to check if a campfire or home is burning (prevents engagement with burning targets).fueled— used to determine if a campfire needs fuel viaGetPercent().carnivaldecorranker— to determine decor rank and select appropriate chatter strings.
-
Tags:
- Checks tags:
notarget,INLIMBO,hostile,inactive,carnivaldecor,campfire,fire,burnt. - Does not add or remove tags itself (only reads them for decision logic).
- Checks tags:
Properties
No public instance properties are explicitly initialized in the constructor. All persistent state is stored as keys on inst, such as inst.next_activate_time, inst._watch_campfire, and inst.ShouldFlyAway.
Main Functions
HasValidHome(inst)
- Description: Determines if the entity has a valid, non-burning home that is still registered and not burnt.
- Parameters:
inst— the entity instance. - Returns:
trueif the home exists, is valid, not burnt, and not currently burning; otherwisefalse.
GetHomePos(inst)
- Description: Returns the 3D world position of the entity’s home if it exists and is valid.
- Parameters:
inst— the entity instance. - Returns:
{x, y, z}position table ornilif home is invalid.
GetFaceTargetFn(inst)
- Description: Finds the nearest player within a 3-tile radius who is not on cooldown for chatter; if found, triggers a talk cooldown and returns the player as a face target.
- Parameters:
inst— the entity instance. - Returns: Player entity if conditions met, otherwise
nil.
KeepFaceTargetFn(inst, target)
- Description: Verifies the current face target is still valid (same player, within 3-tile radius).
- Parameters:
inst,target— the previously selected player entity. - Returns:
trueif target is still valid;falseotherwise.
IsHomeless(inst)
- Description: Determines if the entity lacks a
homeseekercomponent or has no home set. - Parameters:
inst— the entity instance. - Returns:
trueif nohomeseekercomponent or no home assigned;falseotherwise.
ShouldFlyAway(inst)
- Description: Evaluates whether the entity should flee (e.g., during lunar hailing, if in danger, or not currently occupied by state tags like
sleeping,busy,flight). - Parameters:
inst— the entity instance. - Returns:
trueif conditions for flight are met (e.g., nearby hostile entities or special world states),falseotherwise.
FlyHome(inst)
- Description: If
ShouldFlyAwayistrue, triggers aGOHOMEaction toward the entity’s home. - Parameters:
inst— the entity instance. - Returns:
BufferedActionresult ornil.
ActivateDecor(inst)
- Description: Attempts to activate or stoke a nearby carnival decoration or campfire (if fuel is low). Has chain-delay logic to prevent spam activation.
- Parameters:
inst— the entity instance. - Returns:
BufferedActionresult (e.g.,ADDFUELorACTIVATE) ornil.
WatchCampfireFn(inst)
- Description: Locates a nearby campfire at night and stores it as
_watch_campfire. Verifies if the stored campfire is still valid and burning. - Parameters:
inst— the entity instance. - Returns:
trueif a valid, burning campfire is found and watched;falseotherwise.
GetCurrentCampfirePos(inst)
- Description: Returns the world position of the currently watched campfire if valid.
- Parameters:
inst— the entity instance. - Returns:
{x, y, z}position table ornil.
WatchingMinigame(inst)
- Description: Returns the current minigame this entity is spectating via its
minigame_spectatorcomponent. - Parameters:
inst— the entity instance. - Returns: Minigame entity or
nil.
IsWatchingMinigameIntro(inst)
- Description: Checks if the current minigame is in its intro phase.
- Parameters:
inst— the entity instance. - Returns:
trueif minigame intro is active;falseotherwise.
WatchingMinigame_MinDist(inst)
- Description: Returns the
watchdist_minparameter of the current minigame. - Parameters:
inst— the entity instance. - Returns: Numeric distance threshold (from
minigame.watchdist_min).
WatchingMinigame_TargetDist(inst)
- Description: Returns the
watchdist_targetparameter of the current minigame. - Parameters:
inst— the entity instance. - Returns: Numeric distance threshold (from
minigame.watchdist_target).
WatchingMinigame_MaxDist(inst)
- Description: Returns the
watchdist_maxparameter of the current minigame. - Parameters:
inst— the entity instance. - Returns: Numeric distance threshold (from
minigame.watchdist_max).
IsWatchingMinigameOutro(inst)
- Description: Checks if the current minigame is in its outro phase.
- Parameters:
inst— the entity instance. - Returns:
trueif minigame outro is active;falseotherwise.
DoTossReward(inst)
- Description: Spawns a
carnival_prizeticketand launches it toward the minigame location. - Parameters:
inst— the entity instance. - Returns:
nil(side-effect only).
GetMinigameParticipantsLuckChance(inst)
- Description: Calculates reward chance for the crowkid based on participant luck and scores.
- Parameters:
inst— the entity instance. - Returns: Numeric probability (increased by luck factor).
OnEndOfGame(inst)
- Description: Handles post-minigame logic: evaluates success, sets
_good_ending, pushesminigame_spectator_start_outro, and optionally schedules a reward toss if score or luck thresholds are met. - Parameters:
inst— the entity instance. - Returns:
nil(side-effect only).
Events & Listeners
-
Pushes:
"minigame_spectator_start_outro"— pushed byOnEndOfGame()when minigame ends.
-
Listens to: None (no
inst:ListenForEventcalls are present).