Cities: Skylines Uses a Stock-Market Analogy to Influence Gameplay

birdculture2 pts0 comments

How Cities: Skylines uses a stock-market analogy to drive almost everything in the game · jkm.dev

How Cities: Skylines uses a stock-market analogy to drive almost everything in the game<br>24 February 2021<br>Updated: 19 May 2026Revisited 5 years later and did another pass over the decompilation.<br>Describe how busier landfill sites compete less for new offers.<br>Describe the TransferOffer bit-packing layout and the total memory cost of the array.<br>Explain vestigial m_outgoingAmount member, the GetFrameReason rota, and the Active/Exclude/Unlimited flags.<br>Use game-unit radius for distance discussion.

development<br>cities-skylines<br>gaming

I wanted to find out how Cities: Skylines drives the constant motion you see in a growing city - residents looking for jobs, tourists visiting attractions, garbage trucks doing their rounds, even cims looking for love - and I couldn&rsquo;t find much written up about it. So I decompiled the game and dug in. What I found is that almost every interaction in the game runs through a single, elegant system: a stock-market-style trading market.<br>The fictional city of Cannburg<br>The basics<br>In a (simplified) stock market, there are &ldquo;buy&rdquo; and &ldquo;sell&rdquo; offers, with a middleman between the two to connect them together. Whenever you see a person, or vehicle, moving from one place to another in Cities Skylines, it&rsquo;s often due to a TransferOffer going through the TransferManager (our &ldquo;market&rdquo;). Buildings, vehicles, and cities can list offers to &ldquo;buy&rdquo;/&ldquo;sell&rdquo; certain things which, once they&rsquo;re matched with the other side of the deal, results in it being delivered or collected.<br>Offers get listed with a TransferReason, a priority and an amount. Priority is used as a way of ranking offers, and the amount is self-explanatory. The TransferReason can be something tangible like Oil, or Coal, for an industrial business, but it could also be Fire for a burning building, Crime if the police are needed, or even Partner for when a cim is looking for love. There are plenty of other types too: hearses, garbage collection, schools and shopping are just some of these.<br>The information in this post comes from reverse engineering Cities: Skylines and reading the decompiled code. The snippets are close to what&rsquo;s shipped with the game, with some renaming and removing of less relevant parts to make this post clearer. If you have a copy of the game, and want to take a look yourself, the Cities: Skylines Modding Guide has a great introduction.<br>Taking out the trash<br>Let&rsquo;s take a look at how garbage collection works to get an understanding of this transfer system from the outside before digging in.<br>The CommonBuildingAI class has a method HandleCommonConsumption, called from a building&rsquo;s SimulationStep, which tallies up electricity, garbage, water use, and so on. Garbage steadily accumulates into the building&rsquo;s m_garbageBuffer (the rate is just a number derived from building type, level, district policies and a few other factors).<br>Each simulation step, if the buffer has reached at least 200 and a 1-in-5 dice roll comes up and the player has unlocked garbage collection, the building considers putting its garbage up for collection.<br>Garbage waiting for collection<br>Before it does, it looks through its guest vehicles (m_guestVehicles) and adds up the free space on any already coming to carry TransferReason.Garbage - i.e. garbage trucks that are already en route but haven&rsquo;t arrived yet. That inbound capacity is subtracted from the buffer, and only if at least 200 garbage still needs collecting does it list a &ldquo;sell offer&rdquo; with AddOutgoingOffer (the building is selling its garbage):<br>Singleton.instance.AddOutgoingOffer(<br>TransferManager.TransferReason.Garbage,<br>new TransferManager.TransferOffer() {<br>Priority = remaining / 1000,<br>Building = buildingID,<br>Position = data.m_position,<br>Amount = 1<br>);<br>Only a single &ldquo;unit&rdquo; is ever requested (hence the Amount of 1) - but that 1 isn&rsquo;t one unit of garbage. Amount is a count of transactions: it means &ldquo;match me with one collection&rdquo;, i.e. send one truck. How much garbage actually leaves is decided later, separately - when the truck arrives, it loads up to its own cargo capacity from whatever is in m_garbageBuffer at the time. So a building sitting on 200 garbage, and one buried under 60,000 both post the same offer; each gets one truck, and the truck takes as much as it can carry. If garbage is left over, the buffer is still above the threshold at the next step, so the building just lists another Amount = 1 offer and another truck comes. A big backlog is drained over many steps, rather than one truck clearing it in a single heroic haul.<br>The size of the problem isn&rsquo;t expressed through Amount at all; it rides on Priority (remaining / 1000), so a building drowning in garbage outbids a tiny one and wins collections on more steps. Asking for just one truck at a time,...

garbage rsquo building cities skylines ldquo

Related Articles