Keyboard shortcuts

Press ← or → to navigate between chapters

Press ? to show this help

Press Esc to hide this help

data/brains/

A brain: how an AI agent decides what to do. An archetype brain is a fixed priority list of built-in behaviours (wander, graze, charge, flee); a full brain scores activities by utility and runs each activity’s state tree. A brain names its senses, the memories it uses, and its awareness and LOD profiles, and may inherit from a parent: params merge by key, senses, memories, behaviours and activities merge as keyed lists ("-<key>" removes one), and abstract is not inherited. An archetype’s manifold-ai:brain component names its brain. Brains compile when the data loads, so every error names its file and line. Loaded by the server only.

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

Entry

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

FieldTypeRequiredDefaultDescription
idstringyesThe brain’s key, <mod-id>:<name>.
parentstring or NonenononeThe brain it inherits from.
abstractboolnofalsetrue for a template that is only inherited.
paramsmap of string to ParamValuenononeTyped parameters other fields use as "$name".
senseslist of SensenononeIts sensors.
memorieslist of stringnononeThe memory kinds it uses (manifold-ai:memory-kind keys).
awarenessstring or NonenononeIts awareness profile (manifold-ai:awareness-profile key).
lodstring or NonenononeIts LOD profile (manifold-ai:lod-profile key).
presentation_activitieslist of stringnononeThe names animation graphs see for what it is doing, by index; the first is shown when nothing else is.
invariantslist of CondnononeConditions every candidate behaviour or activity must pass.
knowledge_capu8no8The most things it keeps track of, at most 16.
traceTraceModenoOffIts decision trace.
kindBrainKind or NonenononeIts decision maker. An abstract brain may leave it out.

Example

From game/flagship-game/data/brains/creatures.ron:

Brain(
    id: "flagship-game:template_predator",
    abstract: true,
    params: {
        "sight_radius": Float(24.0),
        "flee_health": Float(0.25),
    },
    senses: [
        Sight(radius: "$sight_radius", lose_radius: Some(32.0),
              cones: { Unaware: 55.0, Engaged: 100.0 },
              interval_ticks: 10, targets: HostileTo),
        Damage,
    ],
    memories: ["manifold:last_hurt_by", "manifold:unreachable"],
    awareness: Some("manifold:default_awareness"),
    lod: Some("manifold:ambient_creature"),
)

Types

ParamValue

A typed brain parameter.

VariantWrittenDescription
FloatFloat(f32)A number.
IntInt(i64)An integer.
BoolBool(bool)true or false.
TagTag(string)A tag key.
AbilityAbility(string)An ability key.
DurationDuration(f32)Seconds.

Sense

A sensor.

VariantWrittenDescription
SightSight(radius: .., lose_radius: .., lose_grace: .., cones: .., vertical_half_angle: .., interval_ticks: .., targets: .., gain_per_s: .., falloff: .., eye_height: .., uses_light: .., light: ..)Sight, in cones that widen with awareness.
HearingHearing(sensitivity: .., gain: .., falloff: .., targets: .., calls: .., blur: ..)Hearing: noises and calls, heard within loudness × sensitivity blocks without line of sight. A heard target rises at most to Alert; engaging needs a sense in the awareness profile’s engage_requires. A brain has at most one.
DamageDamageBeing hit.
OwnerOwner(interval_ticks: ..)The owner’s whereabouts.
ItemsItems(radius: .., interval_ticks: .., write: .., filter: .., owner_clearance: ..)Dropped items nearby.

Sight fields:

FieldTypeRequiredDefaultDescription
radiusfloat-or-paramyesHow far it sees, in blocks.
lose_radiusfloat-or-param or NonenoradiusHow far it keeps seeing something it already saw.
lose_graceu16no40Ticks after the last sighting that lose_radius applies.
conesmap of AwarenessState to f32nononeThe cone’s half-angle in degrees per awareness state; a state without one uses the nearest lower state’s.
vertical_half_anglef32no70.0The vertical half-angle, in degrees.
interval_ticksu16no10Ticks between looks, 8 to 400.
targetsTargetFilternoHostileToWhom it looks for.
gain_per_sf32no1.5The awareness meter gained per second at full strength.
falloffCurveSpec or NonenononeHow strength falls with distance.
eye_heightf32 or Nonenothe archetype’sThe eye height, overriding the archetype’s.
uses_lightboolnofalseWhether the light at the target’s eye scales the gain, so a target in darkness is noticed more slowly.
lightCurveSpec or Nonenoa quarter of the gain in darkness, three quarters at half light, all of it in full lightWith uses_light, the gain’s factor by the light level (0 to 15) as a fraction.

Hearing fields:

FieldTypeRequiredDefaultDescription
sensitivityf32no1.0Scales how far it hears; above 0.
gainf32no0.3The awareness meter one noise adds at its source, before the falloff, 0 to 1.
falloffCurveSpec or Nonenolinear to 0How the gain falls with distance / range.
targetsTargetFilternoHostileToWhose noise raises awareness.
callslist of stringno["call"]The call tags it listens for, with their descendants. Only calls from allies (Friendly) are heard, and each gives second-hand knowledge of the caller’s target.
blurf32no0.15How far the heard position may be off on each horizontal axis, as a fraction of the distance.

Owner fields:

FieldTypeRequiredDefaultDescription
interval_ticksu16no10Ticks between updates.

Items fields:

FieldTypeRequiredDefaultDescription
radiusfloat-or-paramyesHow far, in blocks.
interval_ticksu16no10Ticks between looks.
writestringyesThe Entity memory the nearest accepted drop is written to.
filterItemFilternoAllWhich drops it accepts.
owner_clearancef32no0Drops this close to the owner are ignored (already delivered).

AwarenessState

An awareness state.

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

TargetFilter

Whom a sight sensor looks for.

VariantWrittenDescription
HostileToHostileToEntities its faction is hostile to.
PlayersPlayersPlayers, whatever the relation.
RelationsRelations([string])Entities in any of these relations: Relations(["Hostile", "Neutral"]).

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.

ItemFilter

Which dropped items the Items sensor accepts.

VariantWrittenDescription
AllAllEvery drop.
UnreservedUnreservedDrops no one else has claimed.

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.

TraceMode

A decision-trace mode.

VariantWrittenDescription
OffOffNo trace.
FlightRecorderFlightRecorderA 64-record ring kept at all times.

BrainKind

A brain’s decision maker.

VariantWrittenDescription
ArchetypeArchetype(evaluate_every: .., behaviours: ..)A fixed priority list of built-in behaviours; behaviours with disjoint control flags run at once.
FullFull(keep_ratio: .., min_utility: .., select_interval: .., fallback: .., activities: .., impulses: ..)Activities scored by utility, each running a state tree.

Archetype fields:

FieldTypeRequiredDefaultDescription
evaluate_everyu16no10Ticks between evaluations.
behaviourslist of BehaviourEntryyesThe behaviours.

Full fields:

FieldTypeRequiredDefaultDescription
keep_ratiof32no0.75Keep the current activity while its score is at least this fraction of the best.
min_utilityf32no0.01Scores below this never win.
select_intervalu16no40Ticks between selections, 20 to 160.
fallbackstring or NonenononeThe activity run when none scores.
activitieslist of ActivityyesThe activities.
impulseslist of ImpulsenononeImpulses at the brain level; each names the activity it injects.

BehaviourEntry

One behaviour of an archetype brain.

A record: BehaviourEntry(..) or (..).

FieldTypeRequiredDefaultDescription
namestringyesIts name, the key children merge by.
priorityu8yesIts priority, unique in the brain; 0 is highest.
controlslist of ControlFlagnononeThe controls it takes.
presentsstring or NonenononeThe presentation activity while it runs.
startCond or NonenoalwaysA condition to start.
keepCond or NonenoalwaysA condition to keep running.
requireslist of RequirementnononeChecks before it starts.
interrupt_onlist of Event or Nonenonew knowledge, a rising or falling state, damage and a lost targetEvents that make the brain re-evaluate at once.
tagslist of stringnononeActivity tags (ai.activity.combat).
behaviourBehaviouryesThe behaviour.

ControlFlag

A control a behaviour takes.

VariantWrittenDescription
MoveMoveMovement.
LookLookLooking.
JumpJumpJumping.
TargetTargetThe target.
AttackAttackAttacking.
VoiceVoiceSounds.

Requirement

A check a behaviour makes before it starts.

VariantWrittenDescription
ReachableReachableIts target is reachable and not given up on.
LineOfSightLineOfSightIts target is in line of sight.

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.

Behaviour

A built-in behaviour.

VariantWrittenDescription
WanderWander(radius: .., around: .., pause: .., speed: ..)Wanders about.
GrazeGraze(duration: .., chance: .., cooldown: ..)Stops to graze.
LookAtNoticedLookAtNoticed(min_state: .., max_distance: .., glance: ..)Looks at what it noticed.
ChargeAttackChargeAttack(ability: .., min_range: .., max_range: .., recovery: .., approach_speed: ..)Closes in and uses a charge ability.
FleeWhenFleeWhen(when: .., distance: .., speed: ..)Flees when a condition holds.
ReturnHomeReturnHome(leash: ..)Returns home when it strays too far.
InvestigateInvestigate(min_state: .., radius: .., speed: .., look: ..)Walks to where a noticed target was last known (a noise, a call, a target that slipped out of sight), re-aiming when a new noise moves it, then looks around there. A target engaged in plain sight is left to the combat behaviours.
CallAlliesCallAllies(tag: .., radius: .., min_state: .., cooldown: ..)Calls allies about its best target at or above min_state, then waits out a cooldown.

Wander fields:

FieldTypeRequiredDefaultDescription
radiusfloat-or-paramno8.0How far, in blocks.
aroundAroundnoHomeAround what.
pause(f32, f32)no(2.0, 6.0)Seconds between moves, (min, max).
speedf32no0.5A fraction of walking speed.

Graze fields:

FieldTypeRequiredDefaultDescription
duration(f32, f32)yesSeconds, (min, max).
chancef32no0.5The chance to start when it may.
cooldown(f32, f32)no(4.0, 10.0)Seconds before another graze, (min, max).

LookAtNoticed fields:

FieldTypeRequiredDefaultDescription
min_stateAwarenessStatenoEngagedThe least awareness state.
max_distancef32no32.0The farthest, in blocks.
glance(f32, f32)no(2.0, 4.0)Seconds per glance, (min, max).

ChargeAttack fields:

FieldTypeRequiredDefaultDescription
abilitystringyesThe ability (manifold:ability key), or "$param". An unknown key fails the data stage (DATA010).
min_rangef32yesThe closest it charges from, in blocks.
max_rangef32yesThe farthest it charges from, in blocks.
recoveryf32yesSeconds of recovery after each charge.
approach_speedf32no1.0A fraction of sprint speed while closing in.

FleeWhen fields:

FieldTypeRequiredDefaultDescription
whenCondyesThe condition.
distancef32yesHow far, in blocks.
speedf32no1.0A fraction of sprint speed.

ReturnHome fields:

FieldTypeRequiredDefaultDescription
leashf32 or Nonenothe home’s radiusHow far, in blocks.

Investigate fields:

FieldTypeRequiredDefaultDescription
min_stateAwarenessStatenoAlertThe least awareness state of the target, Suspicious or above.
radiusf32no1.5Within this many blocks of the last-known position it counts as there.
speedf32no1.0A fraction of walking speed.
look(f32, f32)no(2.0, 4.0)Seconds it looks around once there, (min, max).

CallAllies fields:

FieldTypeRequiredDefaultDescription
tagstringno"call.help"The call’s tag. Allies hear it when their Hearing sensor’s calls list the tag or an ancestor.
radiusf32yesAllies within this many blocks hear it, 1 to 255.
min_stateAwarenessStatenoEngagedThe least awareness state of the target it calls about.
cooldownf32no8.0Seconds before it calls again.

Around

Where wandering centres.

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

Activity

An activity of a full brain.

A record: Activity(..) or (..).

FieldTypeRequiredDefaultDescription
idstringyesIts key, the key children merge by.
treestringyesThe state tree it runs (manifold-ai:state-tree key).
entry_statestring or Nonenothe tree’s rootThe state it starts in.
rankRanknoFixed(1)Its rank: a higher rank always wins over a lower one.
weightf32no1.0Its score’s weight within its rank.
targetsTargetsnoNoneWhere its candidate targets come from.
requires_reachableboolnofalseWhether a target must be reachable.
invariantslist of CondnononeConditions it must pass.
considerationslist of ConsiderationnononeIts considerations; its score is their compensated product, times weight.
commitCommitnoa 1.25 bonus for 80 ticksHow much it resists switching away.
on_retargetRetargetnoReenterWhat a new target does.
tagslist of stringnononeActivity tags (ai.activity.follow).
presentsstring or NonenononeThe presentation activity while it runs.
impulseslist of ImpulsenononeImpulses that inject this activity outside the regular selection, such as fleeing the moment it is hurt.

Rank

An activity’s rank.

VariantWrittenDescription
FixedFixed(u8)A fixed rank.
DynamicDynamic(cases: .., default: ..)The first case whose condition holds, else default.

Dynamic fields:

FieldTypeRequiredDefaultDescription
caseslist of (Cond, u8)yes(condition, rank) pairs.
defaultu8yesThe rank when no case holds.

Targets

Where an activity’s candidate targets come from.

VariantWrittenDescription
NoneNoneNo target.
OwnerOwnerThe agent’s owner.
KnowledgeKnowledge(filter: .., min_state: .., max: ..)Things the agent perceived.
MemoryMemory(string)A memory’s entity.

Knowledge fields:

FieldTypeRequiredDefaultDescription
filterTargetFilternoHostileToWhom.
min_stateAwarenessStatenoAlertThe least awareness state.
maxu8no4The most candidates scored.

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.

Commit

How much an activity resists switching away.

A record: Commit(..) or (..).

FieldTypeRequiredDefaultDescription
bonusf32no1.25The score multiplier while committed.
min_ticksu32no80Ticks the bonus lasts.

Retarget

What a new target does to a running activity.

VariantWrittenDescription
ReenterReenterRestarts the activity.
RebindRebindKeeps running with the new target.

Impulse

An impulse: when its trigger fires and when holds, selection runs at the agent’s next step with the activity’s candidates raised to rank. A brain has at most 32: impulses: [(on: Damaged, when: Some(StatBelow("manifold:health", 0.2)), rank: 8)].

A record: Impulse(..) or (..).

FieldTypeRequiredDefaultDescription
onImpulseTriggeryesWhat fires it.
whenCond or NonenononeA condition that must also hold.
withinf32 or Nonenoas far as the agent hearsFor a Stimulus trigger only: stimuli within this many blocks.
activitystring or Nonenothe activity it belongs toThe activity it injects: required on a brain-level impulse; on an activity’s, that activity.
ranku8yesThe rank its activity’s candidates are raised to.

ImpulseTrigger

What fires an impulse.

VariantWrittenDescription
DamagedDamagedThe agent was damaged since its last step.
EventEvent([Event])Any of these change events.
StimulusStimulus(string)A heard stimulus with this tag or a descendant (noise.footstep). The brain needs a Hearing sensor, and declares at most 7 distinct stimulus triggers (tag and within).

Value forms used here: float-or-param.