NPC AI system: Entity brain + Commander/Controller + Director (knowledge-bounded hive mind, optional decision-model slots) #32
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The plan
DEAD AIR's NPC AI is three layers. Each layer decides what the layer below it does and lets that layer decide how. No layer decides for the layer above it, and no layer micromanages the layer below it.
Knowledge flows up: NPC perception becomes team knowledge, team knowledge becomes Director knowledge. Alerts flow down: one Commander discovers the player and the Director can put every Commander — and every NPC — on alert.
The decision layer is swappable. Commander and Director are both decision roles with a heuristic default. A decision model (local, self-hosted) can optionally sit in place of either one — Commander, Director, or both — behind the same interface. The model is never a core dependency: it is opt-in and off by default, and the game runs fully on heuristics without it.
This is one of the less moddable elements. The framework owns the interfaces — the order vocabulary, the knowledge format, the Commander and Director interfaces, the tick. Mods can copy and modify brains, Commanders, and Directors, but they do not redefine the shape. That is deliberate: this element is meant to be pulled out and reused in other games easily, so the shape has to stay stable and self-contained, with minimal coupling to DEAD AIR specifics.
NPCEntity and the small brain
An NPCEntity can be whatever an NPC is — a fox, light infantry, a heavy gunner, anything else. It is optionally assigned to a Commander. The brain takes orders in and produces movement and action out.
Orders are things like: move there, target the player, run, interact with that. The brain figures out how: which navmesh path, whether the target is visible, what to do when stuck, when an interaction is in range. It does not pick what to do. If it is told to move somewhere, it moves; the decision that it should move there was made above it.
The brain also needs a default for when there are no orders, or orders go stale. What that default is — hold position, patrol, keep the last order — is an open question (see below).
Commander / Controller
One Commander runs one team and gives it directions. The name is still WIP — Commander and Controller are the same role.
The Commander's decisions are tactical and immediate: the small picture, this moment. It works from the same information its NPCs have, plus a bit more relating to the environment it is set up in — its turf, the local layout, the positions that matter there. That extra knowledge is about the environment, not about live NPC status: it does not tell the Commander a patrol went missing. The stealth rules below still hold.
Worked example — a team of a fox, two light infantry, and a heavy gunner. The Commander may use the fox for local roaming, scouting, and surprise attacks, or even baiting. The two light infantry stay nearby the fox as handlers. The heavy gunner stays in a smaller area, positioned by the Commander. That is role-based tasking: the Commander assigns roles and positions to the team, not just a single target.
The Commander also executes the Director's objectives. When the Director says "Reinforce XYZ", the Commander determines how best to do that — which units go, what route, what formation — and turns it into orders for its NPCs.
The Commander's decision cadence is fast: it is making team-tactic decisions in real time, on a small state (team knowledge plus local environment). This is the layer where a decision model would run at roughly a one-to-two-second cadence per team.
Director
A Director is fixed in placement and in charge of a base. It runs multiple Commanders, which run smaller groupings.
The Director's decisions are map-based tactics: the grand picture. It works from the union of what its Commanders know — everything they are aware of — plus the map-level picture of the base.
The Director issues objective commands to specific Commanders or all of them. The example command is "Reinforce XYZ". The Commanders determine how to carry that out. The Director does not plan their tactics.
The Director intervenes on Commander logic only to prevent coordination failures: two or more Commanders giving orders that will cause problems. The example is all Commanders reinforcing the east gate, leaving everywhere else undefended. The Director sees what the Commanders are doing and stops them combining into something bad. It does not micromanage; it keeps the whole map covered.
The Director's decision cadence is slow: base-wide coordination on a much bigger state (the union of all its Commanders' knowledge), so it runs far less often than a Commander.
Knowledge model — the bounded hive mind
The Commander and the Director function as a hive mind, but a bounded one: they only react to what they notice. They are not omniscient. What they know is only what their NPCs have reported, plus — for the Commander — its local environment, and — for the Director — the union of its Commanders.
The stealth rules follow from that:
So a silent kill is invisible until discovered, a discovered body creates a local alert, and a discovered player can create a base-wide alert. Stealth works because the hive mind's knowledge has gaps, and the gaps are exactly what the NPCs have not perceived.
Decision-model slots
A decision model sits as Director and Commander — both layers, not one. Each layer is an interface with a heuristic default implementation; a model is an alternate implementation behind the same interface.
A model in either slot sees only what that layer knows. A Commander model sees team knowledge and local environment — never the player's true position, never anything an NPC has not perceived. A Director model sees the union of its Commanders' knowledge — never anything outside it.
The model is optional in both slots. It is off by default, the game never requires it, and the heuristic implementation is the real game. If the model is absent, slow, or wrong, the layer falls back to heuristics — instantly, with no visible break. The model never sits in the per-frame loop and never blocks a decision: every call has a timeout, and a timeout means the heuristic decides.
The slots are model-agnostic. They do not assume a cloud service, a vendor, or a particular model. Local self-hosted decision models are the intended shape (small decision models that copy the state-plus-typed-questions contract). Cloud decision models (Kai, Jev) are API-only with closed weights and cannot run in these slots as shipped; a cloud model could only sit in a slot behind a developer-run relay, which is not part of this design.
Modding
This element is less moddable than items and maps, by design. What mods can do:
What mods cannot do: redefine the shape. The framework owns the order vocabulary, the knowledge format, the Commander and Director interfaces, and the tick. A new order type needs brain support, so the order vocabulary is framework-owned. That is what keeps the element stable enough to reuse.
Reusability
This element is meant to be pulled out and reused in other games easily. That is a design requirement, not an afterthought. Consequences:
Relation to other work
Open questions