1 route per type, regardless of destinationIs it limited to 1 trade route of each type, per other city? Or just 1 route per type, regardless of destination?
The routes efficiency is dependent of the type, and the code set the most efficient route available, but the problem is that road and river routes are much faster to get than sea routes, if we allow 3 undefined routes per city, all coastal cities will use 3 sea routes as they are far more efficient.Trade route hierarchy?
Historically, transportation by ships would almost always be a lot faster and cheaper than going by land, until maybe railroads / motor vehicles in the late 19th-20th century. A trade route going by rivers or coastal waters, should always be prefered over land routes, and therefore it doesn't make sense to restrict trade routes to one of each type.
As an example, in the Roman Empire (c. 30 BC - 476 AD), you could transport 100 tonnes of grain over 5000 km by sea with just a 20 man crew, cheaper than you could move the same weight only 110 km by land (using 150 wagons drawn by oxen). The average speed according to the same estimate was 15 km / day for wagons, and 100 km / day for ships.
I'm already keeping track of the current routes, so it's only the length of the route that need to be tested for enemy units before recalculating, but keeping track of the most efficient route between two cities is a good idea, and try to update a current route to that one first (after being changed because of enemy units) will make things faster. Still have to be updated from time to time for sea routes (because of canal cities that can be added and, obviously, roads)Always shortest route?
If we implement such an hierarchy, then you'd only need to calculate paths once (when founding a city), and always go by the shortest route (for each type?). A city with a coastal trade route that gets blocked, will not risk sending their ships around the enemy (looking for a new longer path of the same type), rather they would look for alternative destinations or try to trade by a less effective and more safe alternative, such as using a land route. In which case, you could attempt to use the other route types, only if the shortest trade route is blocked.
Keeping track of trade route tiles and units?
Would it be draining performance to keep a list of current trade route tiles, and if any units occupies these tiles? For e.g. is there an enemy unit on tiles x-y?
Or how about keeping and updating a list of the current location and owner for every unit, and then you'd run a check only on units that are standing on trade route tiles, or only check units whose owner is at war (with anyone). Barbarian units would potentially have to be checked a lot, if they wander around.
If trade route paths are determined only once (upon founding of a city), then you could record those tiles in a table. And checking just those tiles for enemy units should be simple right?
We'll need the routes to/from capitals for stability at one point or another. A centralized network was my first idea, we could go back to that. I'd need a step by step description for multiple center in the same civilization.Start with the biggest cities?
The problem remains on how to limit trade routes and checks, and that's a tougher nut to crack. Maybe start each run with the biggest cities (presumably having the most wealth) and let them establish trade routes first. If you can list cities by their unique resources/goods and production rate, then you could prioritise trade with cities that can supply the most of demanded goods and unique luxuries.
Such a system might mean a lot of trade routes going to the capital cities, but you'd need to stop the code from running through the minor cities without any luxury/prioritised goods. If a big city trades with a smaller city, and the resulting trade leaves the smaller city without goods to trade, then you'd want to skip the trade route check of the smaller city, since it no longer has any surplus to trade. Maybe there should be a cut off point where the current city's, or the other city's, stock and/or production rate is too low, to merit trade.
Hopefully, such a top down system could match cities together, and then you could skip checking trade routes for smaller cities (that have nothing unique/prioritised to trade). Of course, all these examples are more or less based on bartering. If you want trade where currency could be used in trading, then you'd need to establish a cut off point where the coins available and/or the stock is too low to merit trade.
Not sure that the calculation are causing the slowdown, but I'm approaching turn 250 on my current Enormous map, I'll try to put more timers in sub-functions to determine where it is exactly.Slower trade? Less interactions per turn?
Regarding resource transfers, supply etc. It seems that having instantaneous resource transfers every turn is requiring a lot of processing, and I'm not sure it's necessary? I mean, if instead transportation was slower, maybe taking a few turns to accomplish its delivery, then you wouldn't need to redistribute resources every turn, and therefore you wouldn't need to check/update trade routes every turn.
And I would have to re-code/re-balance the whole resource system, so I hope it's not that.
AFAIK automated units are impossible with the current modding access.Trader units - performance drain?
If taking the slow road above, you could have automatically spawned trader units pop up and then let those units carry the resources (in their stock) to their destination. I suppose that sadly this would require even more processing, though it would be nice to have units to plunder. Another benefit of a slow transportation/trade system would be that you could determine the price upon delivery or before dispatch. Though it could be difficult to determine when and how often trade missions should be conducted, but maybe it could be tied to total population, demand and stock (%) of the city.
In this system, you could have both the sending and receiving city to commit to the transaction beforehand, for e.g:
Spoiler Example :
City A needs 200 tonnes of grain (estimated from previous turns lacking supplies, or predicted future needs).
City B has 100 tonnes of grain stored/surplus (maybe produced in the current or previous turn).
City A commits to importing 100 tonnes of grain from City B in return for other resources or valuables that City B needs.
City B dispatches their trader unit.
City A will now look to import the lacking food from other cities, but it will only buy/request 100 tonnes, counting on their trading partner.
Upon delivery, City B receives the gold/resources in return, and carries them home to the city of origin.
Slow vanilla trading units?
Of course, you could bring back vanilla trader units, and let the player choose which city to trade with, showing the resources that are available and demanded by both cities (requiring more UI programming...) including estimates of how much could be traded and gained from such a mission. Unlike vanilla however, these trader units would actually carry their stock, deliver and return.
Some computers won't like to process every players at once at then end of the game's turn, better to process each player during their turn, start is easier from a coding perspective with the available events.End of turn script?
Is there any difference between start and end of turn? Can you run code when clicking to end the turn, before starting the next turn, or is there no difference?
no automated units, sadly, we could do that with civ5 without the DLL (my convoy units in the WWII mod were exactly that, but also automated for the player, you had to protect/escort them with your other units)Manual supply (to blocked cities)?
With an automatic supply/trade system, you'd probably want to have the possibility of trying to bring supplies around an enemy blockade. The simplest solution in my mind, would be to add the ability to build supply units, for whcih the city will transfer food to the temporary production stock (just like weapons for a unit).
Upon completion, the unit can be freely maneuvered and escorted to any city (where goods can be delivered).
I guess that the A.I. couldn't handle the freedom well. So instead, the A.I. Civs could get a special trader unit, that only has blocked/out of reach cities as it's possible destinations.
Unlike vanilla traders, this unit would try to move around enemy military units or attack them, though its movement would be completely automated.