AlifePlus is a mod for STALKER Anomaly by Damian Sirbu, built on the 2007 X-Ray engine. I went through the source expecting the usual modding situation and found a layered reactive event pipeline with Bresenham-derived rate limiting, which is why I'm writing this.
STALKER simulates about 2000 NPCs across 30 maps. Most are "offline", meaning statistical entities on a graph. A few hundred near the player are "online" with physics, animations, combat. The engine fires Lua callbacks on events: deaths, teritory transitions, item pickups. AlifePlus pattern-matches on those callbacks and dispatches reactive behaviors through a pub/sub bus. None of it is hardcoded -- the mod watches A-Life and reacts to what it sees.
Pub/sub and radiant evaluation
A message bus writte from scratch sits in the middle. Causes are predicates that evaluate world state on a callback and publish a typed event and consequences subscribe to cause types and run side effects. The two sides are decoupled.
The main evaluation pattern is called "radiant," which carries Bethesda baggage if you've been near Skyrim. Their Radiant AI is a plain loop that scan NPCs and does various fixed stuff.
Here the word means something else. A squad transitions between smart terrains (the normal A-Life heartbeat, the engine does this anyway) and at that point the arriving squad evaluates its surroundings. Stashes, unguarded outposts, threats. Whatever it notices, it's also the one that acts on it. Observer is also the actor.
Admission stack
STALKER proceses A-Life at two speeds: current level gets per-frame updates with a real-time budget, the other 29 levels share round-robin. That's roughly 50:1 -- fifty background callbacks per on-map callback. Without balancing, the player's level drowns in noise from maps they'll never see that session. And whatever balances it runs inside a Lua VM on every callback, so there's no room for floats, divisions, or allocations.
The Bresenham gate. Two counters: on-map, off-map. A ratio parameter (-10 to +10) sets the admission slope. The check is two integer multiplications and a comparison. At ratio 8, off-map passes only when off_count times 8 doesn't exceed 2 times on_count -- 4:1 favoring the player's level. No floats. Counters reset at 32768.
Why Bresenham? His 1962 line algorithm decides whether to step vertically at each pixel using integer cross-multiplication to avoid float division. Rate-balancing two monotonically increasing counters turns out to be the same problem. Pixel axes become event counters, line slope becomes admission ratio, error term is implicit in the comparison. It self-corrects and if one stream runs ahead, the other catches up on the next event. Maybe eight lines of code doing what I'd normally use a token bucket for, except with genuinely zero overhead.
Split buckets. Below that, a token bucket paces cause evaluation. First version: one global bucket, shared across everything. The radiant stream includes an adapter that converts player movement into virtual transitions at 4-10/sec. Global bucket at one token per three seconds -- the radiant stream drank everything. From the docs, an instrumented playtest showed 356 of 356 reactive events blocked over six minutes. All deaths, all heals, all pickups, gone, because some squad grabbed the last token 300ms earlier.
Framework
STALKER's Lua bindings come through luabind with near-zero documentation and an inconsistent nil landscape. Server objects and game objects represent the same entity through different interfaces, callbacks hand you different ID types, and faction resolution takes different calls for humans vs mutants vs the player.
AlifePlus never touches engine APIs directly. Damian built a shared abstraction layer called xlibs underneath all his mods: squad search with filter predicates, safe object resolution, the pub/sub bus, TTL data structures, chase lifecycle, faction and level resolution. A facade over bindings that were GSC's internal tooling from 2006, commented in Russian in C++ headers, never meant for outside use.
TLDR
I went into a game mod expecting naive coding and found a layered admission stack, a decoupled pub/sub, high level math, and a trace system that holds up under inspection—running in Lua, on a 2007 engine, under a zero-dropped-frames budget.
It reads better than most production code I've reviewed.
AlifePlus is open source. Code, architecture docs, and xlibs are on GitHub.
Top comments (0)