DEV Community

Cover image for AlifePlus: Reactive Architecture on STALKER's A-Life
kale vara
kale vara

Posted on

AlifePlus: Reactive Architecture on STALKER's A-Life

AlifePlus is a mod for STALKER Anomaly by Damian Sirbu, built on the 2007 X-Ray engine. I went through the source and the architecture is way more serious than you'd expect from a game mod. Here's what's in there.

Background

STALKER simulates about 2000 NPCs across 30 maps. Most are "offline" — just entries in a graph, no physics or animations. A few hundred near the player are "online" with combat, pathfinding, the works. The engine fires Lua callbacks on events like deaths, zone transitions, and item pickups.
AlifePlus hooks into those callbacks and layers a reactive behavior system on top.

Pub/sub bus

There's a central message bus called xbus. One side has causes — predicates that check world state when a callback fires, then either emit a typed event or return nil. The other side has consequences that subscribe to cause types and run side effects. They don't reference each other and adding a new reaction to an existing cause is one file. BPMN style.

Evaluation model

The mod has reactive and radiant-reactive events. The mod calls its evaluation pattern "radiant," but it works differently from Bethesda's Radiant AI. In Skyrim, a multi-threaded loop scans NPCs on a timer and assigns behaviors — O(n) per tick no matter what. Here, when a squad transitions between smart terrains (which the engine already does), that squad evaluates its surroundings: stashes, unguarded outposts, threats. The thing that notices is the thing that acts.
A great side effect is that quiet areas cost nothing.

Rate limiting

Consequences run by priority and every path through every handler gets logged with a trace ID. Grep one ID, get the full decision tree.

The player's level gets roughly 50x more callbacks than background levels. Without throttling, 29 maps you're nowhere near drown out everything local. And whatever does the throttling runs inside Lua on every callback, so there's no budget for floats or allocations.

Here they use the same trick as Bresenham's line algorithm from 1962. That algorithm avoids float division by using integer cross-multiplication to decide whether to step vertically at each pixel. Here, pixel axes become event counters and line slope becomes admission ratio. If one stream runs ahead, the other catches up on the next event.

Below the Bresenham gate, token buckets pace cause evaluation. First version had one global bucket. Problem: the mod converts player movement into virtual transitions at 4-10/sec, and at one token per three seconds that stream ate everything. Logs from a playtest showed 356 out of 356 reactive events blocked over six minutes. Deaths, heals, pickups — all gone because the radiant stream grabbed the last token.

The design coice is having separate buckets per event class so that eg deaths dont compete with heals but also "bursty" events are allowed to get through if appropriate.
The same idea is in QoS traffic classesbecause heterogeneous traffic in one pool means the loudest source starves everything else.

Full admission stack

So at the end of the day we have in order: level check, Bresenham ratio gate, class-isolated bucket, per-cause sliding window, predicate.
All layers use only simple integer math and are optimized to obsession.

xlibs

STALKER's Lua bindings come through luabind with almost no documentation. Server objects and game objects represent the same entity through different interfaces, callbacks hand you different ID types, and faction resolution works differently for humans vs mutants vs the player.

Damian built a shared abstraction layer called xlibs under all his mods: squad search with filter predicates, safe object resolution, the pub/sub bus, TTL data structures, faction and level resolution. It's a facade over bindings that were GSC's internal tooling from 2006, commented in Russian, never meant for outside use.

Takeaway

Layered admission control, decoupled pub/sub, proper trace logging, and a shared platform library. In Lua. On a 2007 engine. For a game mod.

AlifePlus is open source. Code, architecture docs, and xlibs are on GitHub.

Top comments (0)