Prison Architect Under the Hood: Needs-Based AI, Regime Scheduling & Grid Pathfinding
Engine & Tech Stack
Engine / language: a custom in-house engine written in C++ by Introversion Software, drawing 2D sprites through OpenGL — no third-party game engine.
Map representation: a fixed 2D tile grid; every cell carries terrain plus wall/floor material, an object reference, and parallel utility layers (electricity, water pipes).
Content & modding: heavily data-driven — objects, materials, rooms and grants are declared in plain-text .txt config files, with Lua scripts loaded at startup for custom mod logic.
Core AI & Decision Making
Architecture: prisoner behavior is a needs-based utility model. Each prisoner tracks a vector of needs — sleep, food, hygiene, bladder, recreation, family, safety, comfort, freedom — that decay over time and bias which action looks most valuable.
Dispatch: the current need set is filtered through the active Regime, the hour-by-hour schedule of Sleep / Eat / Work / Yard / Lockup blocks; the highest-pressure legal action for the current block wins. Staff and workmen instead pull from a shared job queue (construction, hauling, cleaning, guarding), each claiming the nearest available task.
State Management & Data Architecture
Model: object-oriented entity + component style rather than strict ECS. The world is a tree of managers (map, objects, utilities, deployment, intelligence/reports) owning collections of entities; each entity — prisoner, guard, door, object — holds its own state and component data.
Updates: systems advance their own entities each step and communicate through events/reports (incidents, needs alerts, contraband) that surface on the deployment and intelligence screens.
Tick Scheduling & Performance Tricks
Staggered work: cheap logic (movement, immediate needs) runs often, while expensive simulations — utility propagation (power/water), temperature, need decay, reports — update on slower macro passes rather than every visual frame.
Why it scales: batching per-tile propagation and spreading entity AI across ticks keeps hundreds of prisoners and thousands of utility tiles from all updating in one frame; the game-speed control multiplies steps per frame, not the interval.
Pathfinding & Spatial Systems
Algorithm: grid A* over the tile map — a long-standing hotspot Introversion repeatedly optimized with path caching and threaded path requests.
Spatial partitioning: the map is carved into rooms/sectors bounded by walls and doors, giving fast reachability and "nearest room of type" lookups and pruning A* to relevant areas. The cost matrix weights walls, doors (including staff-only access) and floor material.