How Pizza Tycoon simulated traffic on a 25 MHz CPU
Discover how the 1994 DOS game "Pizza Tycoon" cleverly simulated city traffic on a 25 MHz CPU, a feat the author struggled to replicate with modern techniques. This deep dive reveals the ingenious, resource-constrained design choices that allowed the game to appear lively and dynamic without complex algorithms. It's a fascinating look at retro game development that challenges contemporary over-engineering.
The Lowdown
The author, FinnKuhn, details his journey in reimplementing the traffic simulation for "Pizza Legacy," an open-source version of the classic 1994 game "Pizza Tycoon." He initially found himself building overly complex systems that bogged down, contrasting sharply with the original's ability to render dynamic traffic on a humble 25 MHz 386 CPU. By reverse-engineering the original assembly code, with some help from LLMs, he uncovered the elegant simplicity that made the system work.
- City Grid & Tiles: The game's cities are based on a 160x120 grid, with each tile specifying a road type and its inherent properties.
- One-Way Road System: The crucial insight is that cars don't use pathfinding; each road tile dictates the permissible one-way direction of travel, simplifying movement logic.
- Cornering Logic: At corners, cars randomly choose to go straight or turn, with a rule preventing consecutive left turns to maintain realistic flow.
- Pixel-Based Movement: Cars move one pixel per frame. Intensive tile-boundary logic (like changing direction or sprite) is executed only once every 16 ticks when a car crosses a tile boundary, reducing CPU load.
- Staggered Processing: Cars start with a random 'progress' counter to ensure their tile-boundary logic doesn't all fire on the same frame, distributing computational effort.
- Efficient Collision Detection: The system uses a surprisingly simple, optimized O(n^2) pairwise collision check. It features quick early-exit conditions based on car directions and lanes, minimizing actual coordinate comparisons.
- Traffic Jam Simulation: When a car is blocked, it waits for 10 ticks, creating natural-looking traffic queues.
- Dynamic Spawning: Cars are spawned on straight road tiles based on traffic density when a viewport is loaded or scrolled. Cars exiting the screen are immediately respawned on the opposite side, facing the reverse direction, maintaining a continuous flow.
Ultimately, the article highlights that the original "Pizza Tycoon" succeeded by focusing on visual plausibility rather than perfect simulation accuracy. Its developers consciously avoided modern complexities like advanced pathfinding, detailed collision detection, or physics engines, proving that effective design often lies in the most straightforward, hardware-conscious solutions.