I modeled the economy in Python before implementing it in the game
I’d like another developer’s take on this, especially if you’ve connected an economic simulation to a market that players can trade in.
Before writing the trading code, I built a standalone partial-equilibrium household model in plain Python. No dependencies. It covers eleven polities, each with its own income factor, cash and in-kind income shares, regional price multipliers, and import dependency. I grouped households by income bracket rather than profession so I could compare the cost of the same basket of goods across regions.
In the home kingdom, one person’s daily basket comes to 2.5G for food, 0.8G for housing, 0.4G for fuel, 0.3G for clothing and tools, and 0.2G for averaged medical expenses. That’s 16.8G a day for a household of four.
I use that as a reference when checking game prices. It gives me something to measure a sword against besides other swords: how much bread could someone buy for the same money?
The model runs four scenarios across twelve regions: baseline, bad harvest, trade route disruption, and population pressure. That’s 48 combinations in a few seconds with one command.
The conservation checks made the biggest difference. Every run asserts that:
- Pre-tax income equals post-tax income plus tax.
- Cash and in-kind income add up to net income.
- Central and local revenue add up to total revenue.
- Total income stays constant when population rises by 25% while production stays fixed.
If one of those identities fails, I know something is wrong before I start interpreting the results. Before adding them, I’d been trying to balance a model that was silently leaking money.
The numbers changed the town’s backstory
The game’s town has about 2,000 people and a garrison of 120. Its modeled tax base came to roughly 468,000G a year. Paying the garrison at the local daily wage would cost 414,720G.
That would consume almost 89% of the town’s tax base in wages alone, leaving very little for anything else.
I hadn’t planned that problem. Rather than change the numbers to make it disappear, I worked it into the setting. Royal support was cut off three years ago. The garrison combines full-time service with rotational duty, some pay comes in grain rather than coin, and the surrounding farmland covers the remaining burden.
Those details gave me a much clearer sense of the town’s politics. I knew who had to pay, who wasn’t getting paid in cash, and why the arrangement was under strain.
That’s been the most useful part of simulating the economy first. A result that doesn’t fit can give me a problem for the people in the world to live with, provided I’ve checked that it isn’t just a bug.
Two pricing rules
Prices have a floor of 0.4× base price and no ceiling. I want shortages to be able to push prices sharply upward, while abundant goods still retain some value.
Zero supply means “not for sale.” It doesn’t mean an infinite price. That sounds obvious, but I got it wrong on the first pass.
The macro model and the in-game market aren’t fully connected yet. For now, the model is a reference for checking game prices. Getting the two to work together is the next major task.
If you’ve done that, how did you handle the connection? I’m particularly concerned about what happens once players can trade freely and start doing things the household model never assumed they would.