MonsterBrain
What a creature decides, frame by frame. **Policy only** — it reads what the world told it and writes a destination. It never touches an entity, a path or a raycast; the `Creature` component does the engine's half and hands the answers in.
game.monsters.MonsterBrain
What a creature decides, frame by frame. Policy only — it reads what the world told
it and writes a destination. It never touches an entity, a path or a raycast; the
Creature component does the engine's half and hands the answers in.
The states are the game: patrol, investigate, chase, search, attack, recover.
On every difficulty a creature runs exactly this logic — difficulty moves only how far it
sees, how far it hears and how long it looks before giving up.
It never knows where the player is. It knows where the player was — a sighting, or a sound it heard. That is the difference between a hunter and a cheat.
local agent = Brain.new("resident", position)
Brain.hear(agent, senses, "sprint", noisePosition) -- true when it heard it
local state = Brain.tick(agent, senses, dt, ctx) -- ctx carries what the component saw
Brain.speedFor(agent, senses)
ctx is the component's half: playerPosition, canSee (physics line of sight),
playerHidden, angleToPlayer, arrived, difficulty, rand. agent.pending comes
back with what happened this frame (spotted, attack, lostSight, gaveUp).
Scoped to this part · feeds back into the world's score.