Dev Diary 12: Trade part 2
Greetings, dear reader! We're back, having been working hard at the Imperatrix stock exchange to bring you nothing but the cheapest deals and finest quality goods from distant exotic lands.
It's been a while, but we have been hard at work all this time, designing and debugging the huge trade overhaul that sits at the core of Imperatrix's economy. This has been the single largest piece of work for the mod and I think we will be able to share things a little more regularly now that the system is working as intended.
In our first dev diary about trade, we spoke about quite a few things:
- Demand
- Payments
- Categories of goods
- Internal trade
- Customs unions
- Infrastructure and trade capacity
- Production
- Prices of goods
This time around we are going to elaborate on detail on some of the above topics, as well as introducing some new topics:
- Trade zones
- How a purchase order works: tendering for best value and partial fulfilment
- Dynamic local prices
- Dynamic supply and demand
- Internal trade & customs unions: more detail
- International trade
- Shipping lanes
Trade zones
The world of Imperatrix is split up into Trade Zones: These are geographical super-regions that follow natural routes and boundaries to trade around the world.
Below is a screenshot taken in-game of the custom trade zone mapmode, which we have made possible with mapmode modding spearheaded by the Imperator modding community:
Tradezones give locality to trade. They determine the following factors:
- The local price of a tradegood - prices of goods are affected by the supply and demand within a tradezone, so there is no worldwide base price.
- The distance that must be traversed to complete a trade - shipping in tradegoods from distant tradezones requires more shipping and is more expensive.
These factors are central to how a purchase order is made: in Imperatrix, whenever a region order goods, it carries out a process to identify the best value trade available to it. This way, trade is competitive and dynamic. Let's explore how that works!
Purchase orders
Purchase orders are the basic unit of trade in Imperatrix: Victoria. When a governorship has unmet demand for a tradegood, it begins what our script calls a "shopping list" for it. A governorship takes its shopping list and looks at all the tradezones available to it, giving priority to its customs union (which may be a single country, a federation, or a colonial empire with its protectorates and subsidiaries) and then as a second priority it goes outside of the customs union to all other countries with which it has negotiated trade deals.
Let's imagine I'm a governorship in Imperatrix and I want to procure 100 units of coal to fuel all my factories. How do I procure that?
Pictured: our custom mapmode for federal customs unions, showing the German Confederation. As you can see, Prussia and Austria's outer territories are not included even though they are members of the Confederation. You may notice a missing blob in western Germany there, too: that's Hesse-Homburg, a small landgraviate which did not join the German Confederation until 1817.
Note that the figures below are demonstrative, and will be different in-game!
- First of all, I check my own inventory. I have 20 coal in my local stockpile already, great! So I generate an order for 80 coal... now I need to find
- What tradezones are available to me inside my customs union? I check the list... I'm a member of the German confederation, which has a customs union with 2 tradezones within it, but doesn't include some outer territories belonging to Prussia or Austria.
- OK, which of these tradezones has the better price for coal? The Baltic tradezone values coal at £0.021 per unit, while Central Europe values it at £0.035 per unit because of higher demand.
- I am located in Central Europe, so it would be very cheap to import the coal whereas to import it from the Baltic I would need to pay £0.043 in shipping fees for the transfer. Still, the total cost from the Baltic is £1.723 with shipping included, whereas to order from Central Europe would be £2.800 even with no extra shipping. So the best value is from the Baltic.
- I send my order for 80 coal to all suppliers in the Baltic tradezone, so any governorships and countries here that are also in my customs union get a cut of the sale. But, there's only 65 coal available in Eastern Europe for me to buy!
- My order is not complete then, so I go to Central Europe, the second best deal, and try to buy 15 more coal at the higher price. Once again, they can only partially fulfil my order, and I get 10 coal from there.
- I now need to go outside to buy the remaining 5 units, to my national trade partners. Our country has a trade deal with the United Kingdom, which has coal for sale in 2 tradezones: the Atlantic Seaboard (£0.090 per unit, shipping cost of £0.040 for a total cost £0.490) and North West America (£0.050 per unit, shipping cost of £0.80 total cost £0.330).
- Coal from North West America is cheaper overall, despite the more expensive shipping, so I import it from there. I send the money over and get the goods, completing my order.
Let's break down some of the assumptions in this process!
Shipping
Shipping costs have 2 factors:
- Physical distance and barriers between tradezones, which sets the base cost.
- Man-made trade infrastructure, which diminishes the cost.
Physical distance can't be changed per se, but with our system, it is also quite simple to add modifiers to distances: temporary climate effects altering the time it takes for ships to cross oceans may change the effective distance between tradezones one year.
Trade infrastructure is the same infrastructure that determines the trade infrastructure capacity which we mentioned in our first trade dev diary, i.e. what determines how many units of goods you can import and export from any given region. Certain buildings are especially important for shipping costs (more so than for trade capacity), namely seaports and river ports, and to a lesser extent railways and canals.
That means that if you had an expensive good in a tradezone that had huge amounts of trade infrastructure, it might be more likely to get bought from there instead of form a tradezone where the goods price was lower, but there was little infrastructure. (Infrastructure also has an impact on the price in the first place, which we'll explore later in this dev diary).
The infrastructure does not need to be your own and likewise you can build trade infrastructure that improves trade in nearby regions belonging to other countries, and this is an important intentional feature. Shipping was not just carried out by the nations involved in trade, but often by middle-men who had access to ports and other such transport routes. In Imperatrix, you will be able to profit off trade passing through your tradezones by building up the trade infrastructure: this will make your whole tradezone more attractive to trade in, even when it is not your own country trading, and the more trade infrastructure you build, the more of that shipping will go through your country on its way to its final destination, earning you big profits.
Increasing trade infrastructure simulates the development of international trade through technology. More advanced civilian shipping, ports, and land-based transport makes it more feasible to transport goods over long distances. Early on, only high value goods will be worth importing over large distances, but as trade over long distance becomes more affordable, even basic goods will be traded across the world.
Higher levels of infrastructure buildings will be locked behind relevant transport and industry techs, and we may implement a system like convoys to simulate civilian sea power.
Shipping lanes & trade power
Shipping has been generated between the Baltic and Central Europe, as well as between North West America and Central Europe.
In both cases, shipping traffic is generated in the source node and the destination node. In the case of the Baltic and Central Europe trade zones, that's it, because they are adjacent. But North West America and Central Europe are far apart, so shipping has to cross through the Atlantic Seaboard tradezone before it can get to Central Europe, creating shipping traffic in the Atlantic Seaboard as well.
If the tradegoods had needed to flow from East Asia to Europe, they would have had to go past the southern cape of Africa and round West Africa... unless, of course, the Suez Canal had been built, meaning there is a shorter route and trade would be directed past Arabia and through the Eastern Mediterranean.
It will be possible to build other such canals, the Panama Canal and Kiel Canal for instance, to create more efficient trade routes and re-route shipping through them.
But what is the impact of these shipping lanes?
As we discussed above, infrastructure is central to supplying shipping. A nation that has provinces with high trade infrastructure capacity, as well as the ports to exploit the value of that infrastructure, gets income from shipping that passes through its tradezones as the merchant vessels dock, load goods, repair, pay taxes and allow their sailors time for R&R at the shipyards. It may even be that the nation is supplying the ships to carry out trade on behalf of other nations.
Ports will create demand for shipping materials, so be prepared to pay the expenses for them if you want to maintain them (or pass on the cost to your capitalists!)
Larger ports give you trade power, and thereby a bigger cut of the shipping income in a tradezone. The income you can get is capped, so it may be that an underdeveloped tradezone doesn't have enough ports to exploit 100% of its shipping traffic; otherwise, your income is treated as a ratio of the total shipping traffic that stops off, departs from or passes through the tradezone.
It's therefore useful for a colonial empire to have major ports all over the world, so that you can benefit from the shipping. In some cases, a single city could be worth more than whole regions. This creates real in-game strategic value for historical locations such as Gibraltar, Hong Kong, Macau, Zanzibar and so on...
There are some further concepts within this part of gameplay that are yet to be developed, but are likely to be in Imperatrix: Victoria.
Refueling
When using ships that have engines, ports may also be able to sell fuel goods as shipping passes through them. Your nation may even be able to profit by importing coal or petrochemicals and re-selling it to ships that dock at your ports on trading missions.
Naval trade protection
Much like in EU4, it is possible to simulate trade protection missions with military fleets in Imperator. We would like to extend this concept to Imperatrix, perhaps as a way for the player to gain more shipping power in a tradezone by stationing its fleet there.
Prices of goods as well as shipping in Imperatrix are local to each tradezone. They are determined by a number of factors:
- The amount of demand for the given goods in the tradezone
- The amount of that good available on the market, which acts more or less as the supply. This is indirectly affected by industrialisation and trade infrastructure, as that determines how much of a good can get from its place of production to other regions. It's all well and good producing tonnes of gold in a deep mountain mine, but if there's no railway to ship it out, then it's still very hard to sell, and therefore expensive.
- The stockpile of that good on the market, which has a minor influence on the price. If stockpiles are big, prices will be slightly lower; eat away at your stockpiles, and prices will climb somewhat.
- The actual amount sold: the more a tradegood actually sells, the more its price will inflate -and vice versa. Demand may be high and production relatively low, which without this factor would lead to high prices; however, if the price is too high, local buyers will look elsewhere for these tradegoods, and suppliers will be forced to lower their prices. This is intended to naturally factor in the supply and demand curves we see in real-world economics. While this feature is central to determining prices realistically, it has not yet been implemented as balancing needs to be done on the basics first; however, it is simple to implement once we are ready.
It wasn't all plain sailing, of course. The trade script is very complex and has taken months of work to get right, and to optimise it. The first iterations of the script took upwards of two minutes to run... now, it takes around 5 seconds total - and we are working on bringing it down further, although we will work on that more during the Alpha and Beta as our focus will remain on core functionality so we can get the Alpha released.
Some interesting issues that plagued us during the development of the system are worth a mention...
- Trade was only taking place inside the customs union of the German Confederation while everywhere else was failing to buy or sell any goods! A poorly implemented trigger was the cause of this.
- Regions were getting profit for sales, but not paying for imports - free money for everyone! The script was failing to scope to the sellers when it was calculating the origin of expenses.
- Regional prices were only being calculated after trades were attempted, so no trades could take place since regions could not select the best value suppliers as tradegoods all had null prices! This was the hardest one to fix, because in the debug UI, the prices were showing up (the whole process happens all at once, so it looked like the prices were set).
- Regions were unable to fulfil their whole orders, because they only ever looked at the nearest tradezone. This is because the script that ranks the best value was only ever looking at the first item in the list, when Imperator's scripting language requires the maximum number to check to be explicitly stated.
Support from the Imperator modding co-op has been invaluable in working through the various bugs, quirks and mind-numbing terrors of creating the trade system. Without that wonderful community, this absolutely could not have been achieved, so my thanks go out to the modders you will know from Invictus, Improved UI, FMO, Terra Indomita and more.
I'm really hoping to bring an Alpha to the playing public as soon as possible, so some more work needs to be done to get things ready.
Trade
- Finalising tradegood placements on the map
- Balancing production from pops, buildings and industrialisation
- Balancing price calculation scripts
- Balancing demand scripts (at the moment we are using pre-scripted demand values... there will likely be a dev diary on the demand system alone, as this was something that has been written with quite a deal of care)
- Adding modifiers for provinces with natural harbours and along major shipping lanes
- Finishing the brand new trade interface which needs to display all these new values and ways to interact with them
Other features
Here's a teaser of other features that are being worked on now, or will be worked on in the near future now that trade is mostly done:
- Personal union / viceroyalties: unique titles
- War overhaul
- Diplomacy AI overhaul
- Constitutional systems
- Factory building AI
- Local business, jobs and wages for pops
- Federation laws
- Elections
It's hard to say for sure, but once these features are ready to test, we very much would like to start inviting Alpha testers to play the mod. Stay tuned.
Discord
Join our Discord server here:
https://discord.gg/nbxgkwy to get more regular previews, talk to the devs (we’re very responsive!) and even volunteer to contribute directly to the mod - no coding skills required.