Then the question is a good algorithm to do that.
And how often to apply it (each turn once at the start of the player turn?)
Then the question is a good algorithm to do that.
Trade benefits really only get compiled at the start of a turn. And even if a network is severed, it shouldn't mean they spent the turn without whatever access they had at the start of it - thus if a Bonus access (say, Oil) coming from the trade network is somehow giving a strategic military benefit (say, a Boiling Oil Building is active at the castle walls but would be disactivated if there were no access to Oil) were severed by enemy units destroying or blocking all pathways in and out of the city, it would still continue to have that benefit until the next turn when we can presume that the severing from the network has finally allowed stores of that resource to become exhausted.And how often to apply it (each turn once at the start of the player turn?)
At most once per game turn (it will also calculate cross border networks and sea networks afterwards).And how often to apply it (each turn once at the start of the player turn?)
Bonus access from trade will remain with the plot group calculation. I have no intention to mix that up.Trade benefits really only get compiled at the start of a turn. And even if a network is severed, it shouldn't mean they spent the turn without whatever access they had at the start of it - thus if a Bonus access (say, Oil) coming from the trade network is somehow giving a strategic military benefit (say, a Boiling Oil Building is active at the castle walls but would be disactivated if there were no access to Oil) were severed by enemy units destroying or blocking all pathways in and out of the city, it would still continue to have that benefit until the next turn when we can presume that the severing from the network has finally allowed stores of that resource to become exhausted.
As I mentioned before I want to start with the national land based trade network.
For each land area and each player a national trade network is generated. The cities of that player in that area are added as nodes to a graph and a trade importance is calculated. Then for each city the pathing distance to each city within a given maximum coordinate distance is calculated and added as edge to the graph.
So now we have a graph with nodes that have trade importance and edges that have a pathing distance.
The next step should eliminate edges from the graph so that cities that have a high trade importance attract connections from the lesser important ones so the direct connections between the less important cities are eliminated and the connection runs over the major trade centers (so they are at the center of star like trade connections).
One complication is that the trade path depends on terrain in different ways than moving units. For example moving along rivers is easier than across country. Perhaps rivers should be considered the equivalent of "tracks" or "mud paths" for trade purposes.
I tried around a bit but could not get the original algorithm to work to my satisfaction.
So instead I plan now to do a flooding algorithm on the plots which floods out the trade influence from the cities and whoever reaches a plot first has the trade dominance over that plot (except for the plots directly around a city which are always assigned to that city).
So you get a kind of trade aura around each city and when you neighbor to another trade aura you form a local trade connection.
I guess the trade auras could also be used for city vincinity.
That means trade aura spread can be governed by different costs than movement.
You flood from all cities at the same time so the cost is something like N log N with N being the number of plots on the map.How expensive are these to calculate? The flood algorithm sounds like something that would need to be done every turn for every city, and that could be bad for turn times. Are you going to thread that?
You flood from all cities at the same time so the cost is something like N log N with N being the number of plots on the map.
A short update on this: The code for calculating the trade dominance auras and local trade routes is written. There are some things I am not entirely happy with yet (like that the trade routes from a strong trade city go around a weak city instead of through it and fully trade dominating it) but I will probably put a first version on the SVN tomorrow or so. There is no real gameplay effect yet. It just does the calculation and can display the result but that way you can see how it looks like and bring in your own ideas.
Especially in regards to what should influence trade importance of a city and the trade cost along a plot edge.
Next step will then be to calculate far trade routes from the local trade graph and tieing the calculated values back into game mechanics like the trade routes of each city.
It is not threaded (as the algorithm depends on execution order and would be significantly more complex in a threaded environment).Sounds cool to me, I look forward to seeing the next step and the ingame effects. I just have a couple questions. Is the code for this threaded or not? How much time do the routines for this use?
A trade importance is calculated for each city (that calculation is still very simple and needs some refinement and addition of more factors). That trade influence then floods out from the city with easier spreading along rivers and routes (and several other things). When such a trade aura meets another city's trade aura for the first time, they establish a trade connection on that plot.Can you give us a summary explanation of the dynamic in definite terms so we know what we're looking at there? Exactly what does this do? I know you did explain your intent... but I also know what we come up with in the end usually differs a bit from the plan as it was improved or refined along the way.
A trade importance is calculated for each city (that calculation is still very simple and needs some refinement and addition of more factors). That trade influence then floods out from the city with easier spreading along rivers and routes (and several other things). When such a trade aura meets another city's trade aura for the first time, they establish a trade connection on that plot.
The trade aura of a city is where it has trade dominance and when it is still strong enough as it hits another city's initial trade aura it can also take full trade dominance of that city. Each plot can only belong to the trade aura of one city.
And that is what you see in the new globe views. The trade dominance auras and the local trade routes connecting the cities (the colors of cities of the same player are varied slightly). Trade routes are colored for one city until the trade connection plot and then for the other.
I wonder if you could piggy-back a better realistic culture implementation onto the flooding (essentially a second value using the same algorithm [which could be calculated in the same iteration without significant extra overhead])...
As long as this isn't the sole basis for "Realistic Culture Spread" even in Civ V plots with resources get priority over everything else when expanding. I've stopped using "Realistic Culture Spread" because it is so frustrating not being able to get that one stone resource in the second tier because it is on a forested hill in the desert. Mind you not using "Realistic Culture Spread" is just lacking fulfillment.
The way the algorithm works does not really allow to calculate more than one set of auras at the same time because different flow rules would cause different edges to be first in the priority queue (and it would be different where you stop).In his post AIAndy said:
That trade influence then floods out from the city with easier spreading along rivers and routes (and several other things).
Existence of a bonus could easily be 'another thing' and the same set of 'other things' would not necessarily have to apply to a trade-aura value as it id tot a culture-aura value. Like properties, auras can be generalized and have (potentially XML-defined) flow rules.