River Connection Algorithm

Not sure if this is your intention or not, but it would be nice if rivers connected cities for trade route purposes (contingent on a tech like Sailing). Unfortunately that can't be done in Lua.

Have you tried using the RiverTradeRoad column in Traits table?
 
It's a part of Belgium's trait in the Scramble for Africa scenario. The description says "Rivers extend the length of land trade routes as if they were roads". I haven't checked how it works.
 
Sounds like that affects the range of land (international) trade routes. What I'm looking for is making connection to capital ("old" trade route) via rivers. whoward69's algorithm would allow testing for the river connection via Lua, but making the cities connected would require dll mod.
 
It's a part of Belgium's trait in the Scramble for Africa scenario. The description says "Rivers extend the length of land trade routes as if they were roads". I haven't checked how it works.

man, that would make a better American trait. Maybe for a Lincoln leaderhead...
 
There are a few things I'm interested in using this for 1) to make city connections via rivers (although Firaxis may have beaten me to this with RiverTradeRoad - I need to check it out), 2) to add gold yield to river bank tiles when there is a city connection on the river (think of it as "passing trade"), and 3) to make rivers navigable the first few tiles of their length (London, Rotterdam, etc are not on the coast but they are still sea ports)

The DLL mods that these would require I intend to implement via events, but haven't looked at what's requited in the C++ code yet

Edit: Terrain/Feature avoidance has been added by passing a call-back function - much the same way my land/sea route connection code works. The "standard" function excludes impassable features, mountains (unless the player is Cartage), lake plots if the player can't embark, plots with hostile units/cities, etc

Edit2: RiverTradeRoad is only used by the InternationalTradeRouteLandFinder methods, not by the city connection algorithms
 
LiveTuner - Routes Panel has been updated to include the river connections code. All the code is in RiverConnections.lua - methods of primary interest are RiverManager:getRiverRoutes(iFromX, iFromY, iToX, iToY) and RiverManager:getRiverBankRoute(iFromX, iFromY, iToX, iToY), but see also usage of gRiverManager in LiveTunerRoutes.lua
 
Look Ma! No roads!

attachment.php


Progress! Cities on the same river system as the capital are treated as connected as if by roads (combination DLL events and Lua)

Problem: Doesn't work for "capital - [river A - city -] road - city - river B - city" type connections
 

Attachments

  • LookMaNoRoads.jpg
    LookMaNoRoads.jpg
    122.2 KB · Views: 233
Problem: Doesn't work for "capital - [river A - city -] road - city - river B - city" type connections

so a city connected to a city that connects to the capital via river doesn't work?

I guess that means it works like rails and roads. the connections have to be the same type?
 
so a city connected (by road) to a city that connects to the capital via river doesn't work?

Not tried that combination. I know a city connected by a river to a city that is connected to the capital by a road doesn't work ... yet, but I'm working on it. But that's the pathfinder code and it's scary in there :eek:
 
This is wonderful! Can't wait to incorporate in my mod.

Does this really run through pathfinder code every turn? For every city to the capital? Seems like things could be optimized by assuming that rivers don't change. Then persist some city value m_bRiverConnectToCapital. (OK, not that simple. You would have to write something for capital change.)
 
Seems like things could be optimized by assuming that rivers don't change. Then persist some city value m_bRiverConnectToCapital. (OK, not that simple. You would have to write something for capital change.)

Tiles becoming revealed, cities being founded/razed, cities changing ownership, ZOC for hostile units, etc, etc, etc.

Some optimization is possible (and by hooking it up to my new terraforming events it's possible to know when the map changed and a rescan is needed). My code scans the map once and calculates all the river systems and stores all their associated plots, so you can quickly work out if two plots could be connected (ie they have a river in common) but you still need to traverse the river segments to see if they are passable that turn.
 
That makes sense. I was recalling discussion from Civ4 modding. I remember some modders commenting that the trade route system was taking up a good fraction of processing time. But I think that was an "all-to-all" problem rather than our current "all-to-capital" problem, so maybe not a problem to worry about in Civ5.
 
But I think that was an "all-to-all" problem rather than our current "all-to-capital" problem, so maybe not a problem to worry about in Civ5.

That would explain why the pathfinder is (still) calculating all-to-all :crazyeye:
 
Are you planning to allow your passable fort canals to connect rivers [for trade connection purposes]?

Wasn't intending to, as the AI has problems route-finding through "canals" if they are not within the current movement range (ie second or later moves away)
 
I think its great as is. river and road connections should be handled different.
The aim is to make rivers behave the same way as water. So if you have two cities on the same river both with a (say) River Jetty building, they will connect the same way as two cities with harbours

can you make different boni for a river connection (like more food?)
It's on the list, but one thing at a time!
 
:woohoo::woohoo::woohoo::woohoo::woohoo:
That's a road connection to Phoenix and then a river connection to New York

City connection icon - tick
Science bonus from the pantheon belief - tick
Gold bonus from the connection - tick
(all three without adding any extra code, so I'm confident that any other bonuses from city connections will also "just work")

attachment.php


EDIT: And speed wise, at least within the resolution of Lua's os.clock() function, it doesn't seem too bad
Code:
OnCityConnected: Map scan took 0.212 seconds for 6656 plots finding 30 rivers with a total of 402 segments
OnCityConnected: Washington to Santa Monica took 0.002 seconds
OnCityConnected: Washington to Cleveland took 0.003 seconds
OnCityConnected: Washington to Phoenix took 0.000 seconds
OnCityConnected: Washington to New York took 0.000 seconds
OnCityConnected: Santa Monica to Cleveland took 0.003 seconds
OnCityConnected: Santa Monica to Phoenix took 0.000 seconds
OnCityConnected: Santa Monica to New York took 0.000 seconds
OnCityConnected: Cleveland to Phoenix took 0.000 seconds
OnCityConnected: Cleveland to New York took 0.000 seconds
OnCityConnected: Phoenix to New York took 0.0001 seconds
 

Attachments

  • NoRoadsPartDeux.jpg
    NoRoadsPartDeux.jpg
    200.5 KB · Views: 202
Back
Top Bottom