Dwarf Fortress Under the Hood: 3D Tile Sim, Job Queues & Connectivity Pathfinding
Engine & Tech Stack
Engine / language: a bespoke C++ engine; the Steam release renders through SDL with tilesets (historically curses/OpenGL).
Map representation: a 3D grid of tiles across z-levels; every tile carries material, temperature and liquid state. The world is simulated at multiple scales, from worldgen down to the local embark.
Core AI & Decision Making
Architecture: agent-based dwarves with needs, personalities and a thoughts/emotions model: custom C++ logic rather than a formal behavior tree.
Dispatch: tasks flow through a labor/job queue; enabled labors plus proximity and reachability decide who picks up which job.
State Management & Data Architecture
Model: object-oriented custom C++, historically single-threaded. Fluids use a 7-level flow cellular automaton; temperature, wear and gas are all simulated.
Worldgen: generates and simulates centuries of history (civilizations, wars and figures) before play begins.
Tick Scheduling & Performance Tricks
Single main loop: the classic FPS bottleneck is pathfinding and item counts, so expensive updates (temperature, wear) are throttled and spread out.
Reachability caching: a connectivity map lets the game reject impossible destinations before running a full search.
Pathfinding & Spatial Systems
Algorithm:A* over the 3D tile grid.
Spatial trick: tiles are grouped into connectivity node-groups; if source and target aren't in the same group the path is rejected in O(1), avoiding wasted A* over huge fortresses.