Cities: Skylines Uses a Stock-Market Analogy to Influence Gameplay
12 hours ago
- #game-mechanics
- #reverse-engineering
- #software-design
- Cities: Skylines uses a stock-market-style system called the TransferManager to handle almost all interactions, such as garbage collection, emergency services, and citizen activities, by matching buy/sell offers.
- Offers are stored in a memory-efficient array with 262,144 slots per side (incoming/outgoing), using bit-packing to minimize memory usage (about 6 MB total). Each offer includes priority, amount, position, and flags.
- Garbage collection illustrates the system: buildings list outgoing offers with priority based on garbage amount, while landfills list incoming offers with priority that decreases as more trucks are dispatched, preventing overloading a single site.
- Matching occurs in a 256-frame rota per TransferReason. Higher-priority offers search lower-priority partners, but priority 0 offers can only be matched passively, ensuring busy entities don't initiate matches.
- Distance is quantized to a grid (37.5 units in city, 270 outside), and matching stops early if a partner is within an optimal distance (e.g., 32 units for emergencies), explaining why the closest station isn't always selected.
- Transfers are initiated by the active offer's side, dispatching vehicles or citizens. For garbage, landfills dispatch trucks to buildings, which load up to capacity, then return to deposit garbage, completing the cycle.
- The system supports 123 TransferReason types, demonstrating a reusable abstraction that scales across gameplay features, new content, and expansions efficiently.