Devlog #005
Posted by Kenneth Ellersdorfer
Hello capitalists!
Welcome to our latest devlog for Capitalist Empire! Today, we’re diving into the new market simulation. Let's jump right in!
Economies
I've been working hard on setting up the game’s economy and started with a big question: What's the scope of our map? Is it a state, a country, a continent, or the whole world?
I decided the map represents a small region of a country, meaning each city has its local economy, while there's also a global economy. Events in the global economy will impact local economies. For instance, if the world hits a recession, cities and their residents should feel the effects.
The economic system is built around a stats framework for three key reasons:
- Easy to create and manage new economic simulation parameters.
- Flexible for developers to use these stats in events and other game features.
- The system is reusable for different economic simulations (global, city, item market, ...).
Let's start looking into how the economy actually works.
Here are the core stats for the global economy:
- Target annual inflation rate: Fixed at 1% for now, but can be changed by events and politics.
- Global economic state: Ranges from 0 (heavy recession) to 1 (heavy boom).
- Lead interest rate: Meant to control inflation to meet the target rate.
- Inflation rate: The annual percentage rate at which currency value decreases.
- Absolute inflation: The total inflation since the game’s starting year (2000).
These stats create a global economic base that influences other economies.
For the city economy, there is:
- Employment rate: The percentage of employed residents (more on that later).
- Consumer buying power: How wealthy people living in the city are.
Consumer buying power depends on the global lead interest rate and the city’s employment rate. So, keep your residents employed to maximize profits from their spending on your luxurious goods. In the future, I'll expand these dynamics, allowing you to role-play between being a ruthless entrepreneur or a friendly local businessman.
Employment
I want to give you a quick rundown of how the new employment system works. I've kept it straightforward for now:
- Job Allocation: Each building has a fixed number of jobs available.
- Local Workforce: Residents from the nearest city will fill these jobs.
- Productivity Impact: If there aren't enough residents to fill all the jobs in your buildings, productivity will drop.
- Upkeep Adjustment: The upkeep costs now adjust based on the number of workers employed in your buildings.
To kick things off, the global economy will also create remote jobs:
- In global boom: When the global economy is thriving, up to 25% of city residents can get remote jobs.
- In global recession: In times of severe recession, the number of remote jobs available will drop, supporting only up to 10% of city residents.
Looking ahead, I plan to expand the employment system to incorporate more detailed company policies such as wages, working hours, sick leave, and more. This will create a dynamic job market where employees actively seek the best opportunities and may switch jobs based on these factors. As a result, you'll need to stay competitive and potentially even outmaneuver your rivals to attract and retain top talent. However, since the game currently lacks AI and it may not be implemented in the near future, these features are still in the planning stages.
Markets
One of the newest features I've added is the market system. Markets are where you can trade *something*, and right now, the only market available is the item market:
In the item market, you can offload excess products to the global market, speculate on price changes, or buy items globally to distribute locally. The market simulation will mimic real-world trading with buy and sell orders from simulated market participants, creating a dynamic price discovery process. You might also encounter random events, like a shortage or excess supply, which can cause prices to spike dramatically.
The simulation operates based on these key stats:
- Volatility: Determines the market volume and how strong price fluctuations may occur.
- Demand & Supply: A random number generator is used to generate buy and sell orders, which combined with player orders result in demand & supply calculated to move the markets. Events may also affect this.
Beyond the item market, I plan to introduce a global stock market where you can invest your hard-earned profits and take risks for potential rewards. Additionally, a bond market will be added, allowing you to buy bonds of varying risk levels and earn higher interest than simply keeping money as cash.
There are also plans to include options trading, such as buying calls and puts, for every market. However, this feature is still in planning stage and will require more thought before it's ready to be implemented.
Integrating the markets
Integrating the market simulation into the game turned out to be more challenging than just implementing the simulation. I decided to keep the simulation loosely coupled with the rest of the game code as most systems are, but I needed a way to track which buildings were used for the player orders. This way, when you remove an order, or it gets executed, the items are routed to the correct building automatically. Also, what should I do if the building gets deleted while the order is still open?!
So, first things first. Not too long ago, I rewrote the system that handled player and state logic, like money management, to be an actor system where each entity like player, state, market sim, ... is an actor. This means there's already a place to store data for specific actors in the game world.
I implemented a component for the player actor to register and track orders. Now, there are two interfaces: the item markets have an order book where the simulation can create market orders, and the player actor uses this system. When the player creates an order via the API, the order's handle (a unique identifier) is recorded along with the target building. Additionally, creating an order creates a reservation in the building. For example, if you create an order to buy 10x coal, the building will have a reservation for 10x coal incoming. If you create a sell order, it will reserve 10x coal currently stored in the building.
This ensures that the building targeted by an order always has the necessary space or items, preventing situations where you try to sell more than you own or buy more than you have space for.
But just as I finished implementing this, I realized: What if the building is demolished while the order is open? It took me some time to think about this. My first idea was to pause the game whenever an order detects its target building has been deleted and show a dialog where the player can configure where to put the overflow or pull the sold items from. This would be complex, as it needs to work for both buying and selling and set up multiple sources (e.g., an order for 10x coal, pulling 2 from Building #1, 3 from Building #2, and 5 from Building #3). However - for futures trading, I would need this anyway with an additional option to settle in cash.
For now, I decided against implementing this due to its complexity and minimal gain. Instead, I simply disallowed destroying a building with any open orders. This is an easy solution for now, and the more complex solution can be implemented when I start working on advanced trading methods like futures on commodities/items.
Automatic trade rules
After adding all the new market features, I realized that manually managing everything would get frustrating fast. Plus, I’ve never been a fan of the old interface for retail stores that let you set up automatic price updates:
It was hard to understand, tricky to use, and didn’t offer enough flexibility. So, I’ve decided to get rid of it!
But of course, it needs to be replaced with something better.
The solution I came up with is a system where you can create rules for how to price items.
These rules are based on a "value source" and then modified by certain actions. Here's what you can use as a base value source right now:
- Global market ask: The current lowest price someone is selling the item for on the global market.
- Global market bid: The highest price someone is willing to buy the item for on the global market.
- Global market price: The average of the global market ask and bid prices.
- Buy chance: Automatically calculate a price based on the chance that people in a city will buy the item.
Once you have set the base value, you can apply operations to it:
- Percentage offset: Adjust the price by a set percentage (e.g., +10% or -5%).
- Offset: Add a fixed value to the price (e.g., increase by 5).
- Multiplication: Multiply the price by a fixed number (e.g., 1.2x).
This system makes it quite easy to avoid micromanaging prices and works seamlessly with the automatic trading system I've built.
To simplify things even more, warehouses can automatically place trade orders to sell extra products or buy needed materials for manufacturing.
In this screenshot, you can see a setup where a manufacturing site buys raw materials (Wood & Iron) from the global market, processes them, and then sells the finished product (Iron Furniture) back on the market. With pricing rules, there’s no need for constant adjustments, and you’ll always be close to the best price for your goods.
I’m really happy with how this system turned out!
Difficulty settings
If all this sounds a bit overwhelming, don't worry! I'm including difficulty settings that let you tailor the complexity of the economy to your preference. You can choose between a detailed, full-fledged capitalist economy or a simpler, more classic "item x is worth y" model. My goal is to make the game enjoyable for everyone, so you'll have the flexibility to adjust the game’s complexity to suit your taste!
Future improvements
As I’ve been developing these features, I’ve spent a lot of time envisioning the future of the game. I’m excited about the range of possibilities this will offer.
My goal is to create an immersive experience where you have the freedom to pursue your ambitions:
- Run a production company, crafting and selling goods.
- Develop cities into vibrant metropolises within your country.
- Provide basic infrastructure to cities such as sewers, internet connections, energy, ...
- Play the role of a ruthless tycoon, exploiting resources and people, causing pollution and bribing corrupt politicians.
- Take a more passive approach, investing in AI companies or speculating on the stock market.
No matter how you choose to play, the ultimate goal remains the same: become the richest business in the world!
Thanks for reading,
Have a nice day!