Keyboard shortcuts

Press ← or → to navigate between chapters

Press ? to show this help

Press Esc to hide this help

data/state_trees/

A state tree: the steps of one AI activity, such as a pet’s fetch. States run tasks (move, follow, use an ability, claim an item) and move between each other on transitions; Sequence and Selector are shorthand for common shapes. A full brain’s activities name the tree they run. State names are unique within a tree. Loaded by the server only.

Registrymanifold-ai:state-tree
Filesdata/state_trees/*.ron, *.update.ron, *.final.ron
Sidesserver: only the server loads it
Readsmanifold-ai:memory-kind, manifold-ai:curve
ContractBrains, data stage

Entry

A record, written StateTree(..); the name before the parentheses is optional.

FieldTypeRequiredDefaultDescription
idstringyesThe tree’s key, <mod-id>:<name>.
rootStateNodeyesThe root state.

Example

From game/flagship-game/data/state_trees/pet.ron:

StateTree(
    id: "flagship-game:pet_cower",
    root: State(name: "cower", complete_when: Some(Task(1)), tasks: [
        Face(target: Memory("manifold:last_hurt_by"), background: true),
        Wait(seconds: (2.0, 3.0)),
    ]),
)

Types

StateNode

A state, or shorthand that expands into states when the tree loads.

VariantWrittenDescription
StateState(State)A state: State(name: .., tasks: [..], children: [..]).
SequenceSequence(Group)Children in order, each moving to the next on success; a failure fails the sequence.
SelectorSelector(Group)Children in order, each moving to the next on failure; a success succeeds the selector.

State

A state.

A record: State(..) or (..).

FieldTypeRequiredDefaultDescription
namestringyesThe state’s name, unique in its tree.
enterCond or Nonenoalways enterableA condition for entering it.
selectChildSelectnoOrderedHow it chooses among its children.
taskslist of TasknononeTasks it runs while active.
complete_whenCompletion or NonenoAny with tasks, else when a child completesWhen it completes.
transitionslist of TransitionnononeIts transitions.
timeout(f32, Status) or NonenononeSeconds after which it completes with a status: (5.0, Failed).
childrenlist of StateNodenononeIts child states.
holdboolnofalseWhether it keeps running when the tree is reselected (a fetch is not abandoned midway).
reenter_defaultboolnotrueWhether going to it while it is active restarts it.
presentsstring or NonenononeThe presentation activity graphs see while it is active (a presentation_activities name).
utilitylist of ConsiderationnononeConsiderations, when its parent selects by utility.
lockslist of stringnononeActivity tags it locks (ai.activity.reposition): while it is active, activities with a matching tag or a descendant are not selected. The running activity is never locked by its own states.

Cond

An AI condition, evaluated with the brain in context.

VariantWrittenDescription
AlwaysAlwaysAlways holds.
NeverNeverNever holds.
AllAll([Cond])Every condition holds.
AnyAny([Cond])At least one holds.
NotNot(Cond)The condition does not hold.
MemorySetMemorySet(string)The memory (manifold-ai:memory-kind key) is set.
MemoryOlderThanMemoryOlderThan(string, f32)The memory was written more than this many seconds ago, or is unset: MemoryOlderThan("<memory>", 5.0).
DistanceDistance(from: .., to: .., min: .., max: ..)The distance between two subjects is within bounds.
StatBelowStatBelow(string, float-or-param)The stat’s current fraction of its maximum is below the value: StatBelow("manifold:health", 0.25).
HasTagHasTag(string)The agent has the tag, or a descendant.
AwareAware(of: .., at_least: ..)The agent’s awareness of a subject is at least a state.
PerceivedPerceived(Subject)The agent perceives the subject now.
ReachableReachable(Subject)Navigation can reach the subject.
CandidateTaggedCandidateTagged(string)The activity or behaviour being considered has the tag.
InStateInState(string)The agent’s state tree is in the named state.
OwnerOnlineOwnerOnlineThe agent’s owner is online.

Distance fields:

FieldTypeRequiredDefaultDescription
fromSubjectnoSelfFrom.
toSubjectyesTo.
minfloat-or-param or Nonenono lower boundAt least this far, in blocks.
maxfloat-or-param or Nonenono upper boundAt most this far, in blocks.

Aware fields:

FieldTypeRequiredDefaultDescription
ofSubjectnoTargetThe subject.
at_leastAwarenessStateyesThe least state.

Subject

A subject an AI condition names.

VariantWrittenDescription
SelfSelfThe agent itself.
TargetTargetThe activity’s or behaviour’s target.
OwnerOwnerThe agent’s owner.
HomeHomeThe agent’s home.
MemoryMemory(string)A memory’s entity or position (manifold-ai:memory-kind key).
CarriedCarriedThe item the agent carries.

AwarenessState

An awareness state.

VariantWrittenDescription
UnawareUnawareHas not noticed.
SuspiciousSuspiciousNoticed something.
AlertAlertLooking for it.
EngagedEngagedActing on it.

ChildSelect

How a state chooses among its children.

VariantWrittenDescription
OrderedOrderedThe first child whose enter holds.
UtilityUtility(keep_ratio: ..)The child with the best utility score.
RandomRandomA random child.

Utility fields:

FieldTypeRequiredDefaultDescription
keep_ratiof32no0.75Keep the current child while its score is at least this fraction of the best.

Task

A task a state runs.

VariantWrittenDescription
MoveToMoveTo(target: .., stop_within: .., speed: .., fail_on: ..)Walks to a target.
FollowFollow(target: .., band: .., speed: .., teleport_beyond: .., fail_on: .., background: ..)Keeps within a distance band of a target.
FaceFace(target: .., background: ..)Turns to face a target.
WaitWait(seconds: ..)Waits.
WanderWander(radius: .., around: ..)Wanders.
UseAbilityUseAbility(ability: .., target: .., max_range: ..)Requests an ability.
ClaimClaim(target: ..)Claims a target, so no other agent takes it (released when the state’s scope ends).
ReleaseRelease(target: ..)Releases a claim.
PickUpPickUp(item: ..)Picks up a dropped item.
PutDownPutDownPuts the carried item down at the agent’s feet.
PlayAnimationPlayAnimation(play: ..)Plays an animation by its play name.
EmitEmit(Emit)Emits a cue, an ally call or a noise.
SetMemorySetMemory(kind: .., value: .., ttl: ..)Writes a memory.
ClearMemoryClearMemory(kind: ..)Clears a memory.

MoveTo fields:

FieldTypeRequiredDefaultDescription
targetBindyesWhere.
stop_withinf32no1.0Succeeds within this many blocks.
speedf32no1.0A fraction of walking speed; above 1 sprints.
fail_onlist of FailOnnononeConditions that fail it.

Follow fields:

FieldTypeRequiredDefaultDescription
targetBindyesWhom.
band(f32, f32)yesThe band, (near, far) in blocks.
speedf32no1.0A fraction of walking speed.
teleport_beyondf32 or NonenoneverTeleports to the target beyond this many blocks.
fail_onlist of FailOnnononeConditions that fail it.
backgroundboolnofalseWhether it runs alongside the state’s other tasks without deciding its completion.

Face fields:

FieldTypeRequiredDefaultDescription
targetBindyesWhat.
backgroundboolnofalseWhether it runs in the background.

Wait fields:

FieldTypeRequiredDefaultDescription
secondssecondsyesHow long.

Wander fields:

FieldTypeRequiredDefaultDescription
radiusfloat-or-paramno8.0How far, in blocks.
aroundAroundnoHomeAround what.

UseAbility fields:

FieldTypeRequiredDefaultDescription
abilitystringyesThe ability (manifold:ability key), or "$param". An unknown key fails the data stage (DATA010).
targetBindnoTargetAt whom.
max_rangef32no16.0Fails beyond this many blocks.

Claim fields:

FieldTypeRequiredDefaultDescription
targetBindyesWhat.

Release fields:

FieldTypeRequiredDefaultDescription
targetBindyesWhat.

PickUp fields:

FieldTypeRequiredDefaultDescription
itemBindyesWhich.

PlayAnimation fields:

FieldTypeRequiredDefaultDescription
playstringyesThe play.

SetMemory fields:

FieldTypeRequiredDefaultDescription
kindstringyesThe memory (manifold-ai:memory-kind key).
valueBindyesThe value.
ttlf32 or Nonenothe memory kind’sSeconds until it expires.

ClearMemory fields:

FieldTypeRequiredDefaultDescription
kindstringyesThe memory.

Bind

Who or what a task acts on.

VariantWrittenDescription
TargetTargetThe activity’s target.
OwnerOwnerThe agent’s owner.
SelfSelfThe agent itself.
HomeHomeThe agent’s home.
MemoryMemory(string)A memory’s entity or position.
ClaimedClaimedWhat the current scope claimed.
CarriedCarriedThe item the agent carries.
PointPoint(f32, f32, f32)A fixed point: Point(x, y, z).

FailOn

A condition that fails a task.

VariantWrittenDescription
TargetGoneTargetGoneThe target is gone.
TargetLostTargetLostThe target is lost.
ReservationLostReservationLostThe claim was lost.
OwnerGoneOwnerGoneThe owner is gone.
OwnerFartherOwnerFarther(f32)The owner is farther than this many blocks.
TimeoutTimeout(f32)The task ran longer than this many seconds.

Around

Where wandering centres.

VariantWrittenDescription
HomeHomeThe agent’s home, else where it first stood.
SelfSelfWhere the agent is.
OwnerOwnerThe agent’s owner.

Emit

An emission.

VariantWrittenDescription
CueCue(string)A gameplay cue by key.
CallCall(tag: .., radius: ..)An ally call about the activity’s target: its last-known position and confidence, heard by allies whose Hearing sensor listens for the tag.
NoiseNoise(tag: .., loudness: ..)A noise other agents hear.

Call fields:

FieldTypeRequiredDefaultDescription
tagstringyesThe call’s tag (call.help).
radiusf32yesAllies within this many blocks hear it, 1 to 255.

Noise fields:

FieldTypeRequiredDefaultDescription
tagstringyesThe noise’s tag (noise.growl).
loudnessf32yesHeard within this many blocks (times the listener’s sensitivity), 1 to 255.

Completion

When a state completes.

VariantWrittenDescription
AnyAnyWhen any task completes.
AllAllWhen every task completes.
FirstSuccessFirstSuccessWhen a task succeeds.
TaskTask(u8)When task i (from 0) completes.
NeverNeverNever: only transitions leave it.

Transition

A transition.

A record: Transition(..) or (..).

FieldTypeRequiredDefaultDescription
onTriggeryesWhat fires it.
guardCond or NonenononeA condition that must hold.
toTaskTargetyesWhere it leads.
min_intervalu16no10Ticks between Tick firings.

Trigger

What fires a transition.

VariantWrittenDescription
SucceededSucceededThe state succeeded.
FailedFailedThe state failed.
CompletedCompletedThe state completed either way.
EventEvent([Event])Any of these events.
TickTickEvery min_interval ticks.

Event

A change event transitions and interrupts subscribe to.

VariantWrittenDescription
MemoryMemory(string)The memory (manifold-ai:memory-kind key) changed.
NewKnowledgeNewKnowledgeThe agent perceived something new.
StateRoseStateRoseAn awareness state rose.
StateFellStateFellAn awareness state fell.
TargetLostTargetLostThe target was lost.
DamagedDamagedThe agent took damage.
CallHeardCallHeardThe agent heard a call.
OwnerStateChangedOwnerStateChangedThe owner’s state changed.
ActivityEndedActivityEndedThe activity ended.
SignalSignalA signal from code.

TaskTarget

Where a transition leads.

VariantWrittenDescription
GotoGoto(state: .., reenter: ..)To a named state.
NextNextTo the next sibling.
CompleteComplete(Status)Completes the state with a status.
ReselectRootReselectRootReselects from the root.
EndActivityEndActivity(Status)Ends the activity with a status.

Goto fields:

FieldTypeRequiredDefaultDescription
statestringyesThe state’s name.
reenterbool or Nonenothe state’s reenter_defaultWhether to restart it when it is already active.

Status

A completion status.

VariantWrittenDescription
SucceededSucceededSuccess.
FailedFailedFailure.

Consideration

A utility consideration: an input, normalised by (v − min) / (max − min) and clamped, through a curve.

A record: Consideration(..) or (..).

FieldTypeRequiredDefaultDescription
inputInputyesWhat it measures.
minf32no0The input that scores 0 before the curve.
maxf32no1The input that scores 1 before the curve.
curveCurveSpecnoPreset("manifold:linear")The curve.

Input

A consideration’s input. The target’s own stats and tags are read only while it is perceived now or known outright (the owner, a memory’s entity); a remembered target out of sight reads 0.

VariantWrittenDescription
TargetDistanceTargetDistanceBlocks to the target.
OwnerDistanceOwnerDistanceBlocks to the owner.
HomeDistanceHomeDistanceBlocks to home.
ReachableReachable1 when navigation can reach the target, else 0.
LineOfSightLineOfSight1 when the agent perceives the target now, else 0. It reads what the agent already knows and never casts a new sight ray.
TargetAwarenessTargetAwarenessThe awareness state of the target, 0 to 3.
TargetConfidenceTargetConfidenceThe confidence in the target’s position, 0 to 1.
TargetRelationTargetRelationThe agent’s relation to the target when last sensed: Friendly 0, Neutral 0.5, Hostile 1.
GroupKnowsGroupKnowsNot available yet (Talos D6, group knowledge): refused at load.
SelfStatRatioSelfStatRatio(string)The agent’s stat (manifold:stat key) as a fraction of its maximum.
SelfStatSelfStat(string)The agent’s stat’s current value.
SelfHasTagSelfHasTag(string)1 when the agent has the tag or a descendant, else 0.
TargetStatRatioTargetStatRatio(string)The target’s stat as a fraction of its maximum.
TargetHasTagTargetHasTag(string)1 when the target has the tag or a descendant, else 0.
CooldownReadyCooldownReady(string)1 when the ability (manifold:ability key, or "$param") is granted to the agent, idle and off cooldown, else 0.
MemoryAgeMemoryAge(string)Seconds since the memory was written (large when unset).
MemorySetMemorySet(string)1 when the memory is set, else 0.
TimeOfDayTimeOfDayThe world’s time of day, 0 to 1.
TimeInActivityTimeInActivitySeconds in the current activity.
BondStrengthBondStrength(string)Not available yet (Talos D7, relationship memories): refused at load.
ThreatThreatNot available yet (Talos D6, threat tables): refused at load.
TokenAvailableTokenAvailable(string)Not available yet (Talos D6, coordination tokens): refused at load.
AdScoreAdScoreNot available yet (Talos D6, smart objects): refused at load.
ConstantConstant(f32)A constant.
CustomCustom(string)Not available yet (Talos D5, a mod’s consideration-input hook): refused at load.

CurveSpec

A curve’s shape, over x in 0..1.

VariantWrittenDescription
LinearLinear(m: .., k: .., b: .., c: ..)y = m · (x − c)^k + b.
PolynomialPolynomial(m: .., k: .., b: .., c: ..)y = m · (x − c)^k + b, with a fractional k allowed.
LogisticLogistic(m: .., k: .., b: .., c: ..)y = k / (1 + e^(−m · (x − c))) + b.
LogitLogit(m: .., k: .., b: .., c: ..)y = ln(v / (1 − v)) / m + b with v = x − c, rescaled to 0..1.
NormalNormal(m: .., k: .., b: .., c: ..)y = m · e^(−k · (x − c)²) + b: a bell.
SineSine(m: .., k: .., b: .., c: ..)y = m · sin(k · π · (x − c)) + b.
StepStep(at: ..)0 below at, 1 at or above it.
PiecewisePiecewise([(f32, f32)])Straight lines between (x, y) points, flat outside them; x ascending.
InverseInverse(CurveSpec)1 − curve(x).
PresetPreset(string)A manifold-ai:curve entry by key.

Linear fields:

FieldTypeRequiredDefaultDescription
mf32yesSlope.
kf32yesExponent.
bf32yesVertical shift.
cf32yesHorizontal shift.

Polynomial fields:

FieldTypeRequiredDefaultDescription
mf32yesSlope.
kf32yesExponent.
bf32yesVertical shift.
cf32yesHorizontal shift.

Logistic fields:

FieldTypeRequiredDefaultDescription
mf32yesSteepness.
kf32yesHeight.
bf32yesVertical shift.
cf32yesMidpoint.

Logit fields:

FieldTypeRequiredDefaultDescription
mf32yesSteepness.
kf32yesUnused; write 1.0.
bf32yesVertical shift.
cf32yesHorizontal shift.

Normal fields:

FieldTypeRequiredDefaultDescription
mf32yesHeight.
kf32yesNarrowness.
bf32yesVertical shift.
cf32yesCentre.

Sine fields:

FieldTypeRequiredDefaultDescription
mf32yesAmplitude.
kf32yesFrequency.
bf32yesVertical shift.
cf32yesPhase.

Step fields:

FieldTypeRequiredDefaultDescription
atf32yesThe threshold.

Group

A sequence or selector.

A record: Group(..) or (..).

FieldTypeRequiredDefaultDescription
namestringyesThe group’s name, unique in its tree.
enterCond or Nonenoalways enterableA condition for entering it.
stepslist of StateNodeyesIts steps, in order.
taskslist of TasknononeTasks it runs while active.
transitionslist of TransitionnononeIts transitions.
holdboolnofalseWhether it keeps running when the tree is reselected.
presentsstring or NonenononeThe presentation activity graphs see while it is active.
utilitylist of ConsiderationnononeConsiderations, when its parent selects by utility.
lockslist of stringnononeActivity tags it locks while it is active, as a state’s locks.

Value forms used here: float-or-param, seconds.