Intro #
Time to cover the core of the game: The economy and trade simulation. Which, obviously, in a game about trade is very important to get right.
Basic Concepts #
Given that a map can have hundreds or thousands of inhabited solar systems, and tens of thousands of inhabited planets, I have decided to make the solar system the smallest unit I will simulate. Its natural resources, population, etc. are derived from the planets, but I do not simulate individual planets’ economic activity. This also fits well into the gameplay, as the solar system is (at least currently) also the smallest entity a player interacts with.
And I wanted to have an actual simulation of a living economy, not just some randomly generated trade goods and prices. Boy did I underestimate the effort that would take. More on that below.
The Big Picture #
So here in a graph is the big picture of how it all relates to each other. You may want to open this in a new window. I should also mention that it’s a work-in-progress.
The idea is that planets (orange, at the top) are sources of raw materials (blue) which factories (green) convert into other refined, intermediate products (teal) and in the end consumer or industrial end products (also teal).
This results in a fairly complex network of dependencies, which are the foundation for trade. Factories are created where the necessary products are easily available, either locally or in neighbour systems. But demand can outpace supply, which then requires shipping resources from further away, and at higher prices - hence the chance for profit.
Not pictured is that all the final products are also consumed, either by industry not represented in this graph (such as services and utilities) or by consumers. This is another possible source of profit, because again supply and demand depend on different factors. While supply largely depends on available resources, demand depends mostly on the population size. As a result, many of the most densely populated solar systems are net importers.
One more thing you will notice is that I have decided on some abstraction for the materials and goods. With an entire galactic economy to simulate, I don’t deal with, say, iron and aluminium and titanium and silver and gold. I deal with base metals and precious metals. That is a simplification but a reasonable one, and after much consideration I am fairly certain that going into more detail would not add enough to the gameplay to justify the explosion in complexity it would bring.
Here’s a screenshot of an earlier iteration where I still had more detailed goods:
Production Simulation #
Setting up the production chains from this is not too difficult. Every factory is defined as its inputs and outputs, and also has worker and energy demands to simulate production costs aside from the material costs.
The simulation part is straightforward: A factory will look for its input materials. If it can’t find them, it generates demand and keeps looking. Demand (see below) brings in trade. Once the input materials are there, the factory starts producing. Each factory has its own production time. At the end of which, it puts its output materials - usually just one but sometimes several - on the market for other factories to consume. And then it restarts the cycle.
Workers and energy can also limit production, but I am not using them at this time, I’ve prepared them for later. First I want to get the basic simulation running.
Trade Simulation #
In the game, the player is by far not the only merchant in the galaxy. So the economy simulation also handles trade. In order to do that, it implements a signalling system, in which unmet demand is propagated along trade routes to neighbouring/connected systems, which can then send their surplus and/or propagate the signal further so the demand can be satisfied from further away. Trade routes also add transportation costs, so while theoretically a signal can propagate to the other end of the galaxy, most of the time it wouldn’t be profitable to bring the resources this far.
Price Simulation #
This turned out to be the by far most difficult part. I wanted “free floating” prices, with the market determining the price of goods. This way, trade can influence prices, and a once profitable trade route can become less interesting over time as the demand is satisfied and prices drop.
The end-boss enemy here were large swings and extreme values. How to prevent the price of a good that is scarce going to infinity? How to prevent the price of a good that is oversupplied dropping to zero?
The upper boundary turned out to be a hard problem. In the real world, there are constraints on prices, namely how much people are willing to pay. If something is too expensive, potential buyers will either not buy it at all, or look for substitutes. This is true even for basic necessities. If bread becomes unaffordable, people will eat rice or potatoes or something else.
This is impossible to do in my simulation. I would have to do a lot more and simulate entirely different layers of the economy, such as wages, housing and other costs of living, establish household budgets, just to derive the breaking price point for bread. Quick aside: Economics has studied these effects and found that in general, basic necessities are inelastic to price changes, meaning that demand does not drop if the price increases. Up to a certain breaking point at which people look for alternatives and demand suddenly plunges to near zero.
This is a trading game, not a study in economics, so once more I have decided to not go to that level of detail. Plus, of course, my general categories already include all the alternatives. “Bread” may have a point beyond which people switch to rice or whatever, but “Food” does not.
So instead, all things consumed have three values defined:
- how much (per population unit) is absolutely necessary
- how much above and beyond that will be consumed if it is available
- how unhappy people will be when the demand is not met.
This gives me some tangible consequences for demand not being met. It does not (yet) give me an upper bound for prices. But I’ll get to that.
Full Cost Accounting #
Going back to what I do have, I realized that I can calculate reasonable prices. Because I know the costs of raw materials - a value I manually assign - and the cost of all the manufacturing steps, and the input and output amounts. So I can simply calculate it:
- Follow up the production tree until you the raw materials.
- Take the price of these, multiply it by the input amounts, add the production costs, divide by the output amounts. VoilĂ , here’s the price of one unit of intermediate product.
- Repeat that for all the steps in the chain. In the end, you will end up with the total cost of the end product, taking all intermediate steps, all materials and all production costs into account.
- Since for my raw materials I have set a minimum, a maximum and a default price, I can run this calculation three times and get the absolute minimum, the “if nobody takes a cut beyond their usual margin” maximum and the total default price.
These numbers, plus the unhappy-if-not value I can use to determine how far above the default price people will still buy, and then set a maximum price there or nearby.
As of writing this article, I’m still fiddling with that, fine-tuning this and that, but I can already see that I’m getting there.
This all works because of one small thing I did not mention above. Because of course the entire simulation is more complex than this short article can express. I already have factories taking both buying and selling prices into account, and shutting down if they cannot possibly make a profit. This will reduce supply, which in turn will raise prices, so sooner or later they will turn on again. So if they produce something that people are not buying anymore because the price exploded, I could take that into account and stop them if there’s no demand, because if nobody is buying then any price tag is purely hypothetical. I’m not currently doing it, but that could be a next step to refine the simulation further.
Game and Performance #
I knew that this economy simulation would have to do some heavy lifting. So for this part of the game, I choose to write everything using Unity’s Jobs and Burst Compile systems for optimal performance. It made the code somewhat more complex, but it did pay off. In a medium-sized galaxy, the entire simulation runs in split seconds with no noticeable impact on the game. Even in the larger galaxies I have tried so far, it is very smooth. I have not yet tried out the maximum sizes, but I’m confident that it’ll work well there, too.
Closing Remarks #
As one of the most important aspects of the game, I will certainly tinker with the economy simulation for quite some time. For the moment, my focus is on getting it somewhat running so that I can work towards getting an early demo out to all of you.
If you want to receive updates, wishlist the game on Steam. I will cross-post updates there.