City Network

Kaitzilla

Lord Croissant
Supporter
Joined
Jun 21, 2008
Messages
13,100
Location
America!
This thread is for talking about the mystery of trade networks!
DanF talks about it here of course: https://forums.civfanatics.com/threads/trade-routes.159047/page-4#post-7999426

I mostly know how to form domestic + foreign trade routes :gold: and domestic city networks with my cities in the early-game, but some details still elude me. :hmm:
Basically, how can I ensure resources like foreign gems can be traded and domestic/foreign trade routes for :gold: form as early as possible?



As near as I can tell, it is a somewhat complex interplay between exploration (defogging black tiles) and actually establishing trade by building roads and researching Sailing and later Astronomy.

I know going to war with an AI civ means you can't use their tiles anymore to trade through.
Or that a barbarian city spontaneously forming on the coast who is at war with all civs really messes up coastal trade!

I hope this thread can help with the baffling times 2 rivers running close to each other can connect up somehow and allow trade.

-----------------------------------

Check out this shocking situation after discovering sailing.
The city network threads the needle through an island! :lol:



A city network is active if a city connects to a 2nd city to form a trade group and gets 3 yellow arrows above the city name.
To trade resources to another civilization, the city must connect to the capital's trade group.

**Edit**
Fixed last sentence.
 
Last edited:
I'll keep trying to link more threads that talk about this subject.
Acametis had a good post on it last year: https://forums.civfanatics.com/threads/sailing-exploration-trade-routes.668670/#post-16060011


Every founded city starts with a free road under it. :)

Zooming out far enough, it is possible to see what tiles are activated as trade groups by clicking on the :gold: button in the bottom right above the mini-map.



Basically, at the start of the game every tile inside your cultural borders that has a road, railroad, river, lake, coast, or ocean tile enlarges a city's trade group.
When two trade groups are finally connected, they merge into one trade group and form domestic trade routes, a city network, and can share connected resources.

Next is how to use coastal tiles inside city borders.
The three ways are:
1) Found a city on the coast
2) Found a city and then connect it to a river that leads to the coast
3) Build a fort on the coast inside your borders and then connect a road to it.

Even with 100:culture: given to all 3 test cities with roads leading to the coast, only the southern city meets one of the 3 ways to use coastal tiles.
It connects to a river that leads to the coast.

No city forms a 3-arrow city network with each other. :(

 
Last edited:
Insightful posts! Would be good to ponder the arcane mechanisms by which this happens.

Question on the first post. Is this correct? I thought you needed sailing for the ‘neutral territory’ piece?

‘Cities on the same river are linked together so long as the river stays within your borders or in neutral territory’

Also, is the mechanism by which you get resource trades and foreign trade routes the same? I thought I was getting one and not the other, but perhaps I am mistaken.
 
Also, is the mechanism by which you get resource trades and foreign trade routes the same? I thought I was getting one and not the other, but perhaps I am mistaken.
Yes, foreign trade routes and foreign resource trades are different.

Even if the human player is backwards as hell and has no Sailing, as long as the AI has Sailing and has explored along to the coast to the player, resources can be traded very early on Deity.
It is easy to tell when the AI has explored enough because the magical 3 arrows shows up next to the AI name on the scoreboard in the bottom right. :)



------------------

Getting foreign trade routes with the AI for the human player is harder.
Open borders has to be signed first.

With no roads, Sailing tech is needed.
Then the human player has to sail until they unfog 1 tile into the AI's costal tile city network.



Even after unfogging 1 deep into AI waters, it takes 1 more turn for the trade route :gold: to start up. :)
 
Last edited:
‘Cities on the same river are linked together so long as the river stays within your borders or in neutral territory’

Oh!
Yes, that is a misleading Civlopedia entry. :nono:

Sailing tech is absolutely required for neutral river tiles to connect cities.

 
Last edited:
The main mystery is always how Thebes has that ****** corn.


Rivers! >_<

I'll figure it out eventually.
 
Last edited:
To connect cities before Sailing when border pops are not enough, roads can connect cities even through neutral tiles.



Hmm, building on the remains of an old road network, tiles must still be defogged before they can be used.

 
The main mystery is always how Thebes has that ****** corn.


Rivers! >_<
IIRC, the simplified speculation was if two tiles are connected by the path in which all the tiles are either connected by roads or are riverside the tiles count as connected. It does not matter if the tiles get riverside status from different rivers, enough that they touch each other and are riversides.
 
IIRC, the simplified speculation was if two tiles are connected by the path in which all the tiles are either connected by roads or are riverside the tiles count as connected. It does not matter if the tiles get riverside status from different rivers, enough that they touch each other and are riversides.
Yes. A riverside tile is a riverside tile. The rivers themselves don't actually have to be continuous, just the tiles that are riverside have to be contiguous with each other.

They still need to be all in your culture to route through without Sailing. It actually makes some sense as it's similar to trading with Coast before Sailing too -- contiguous coast tiles in your cultural create a route. The "all same river" or "continuous, unfogged coast chain" should only apply for Sailing routes that travel outside of culture.

A fantastic example of this is in the Thebes/Corn thread, with Speilban's example of the Iron being hooked up in Aksum in one of the pictures. The road hooks the Iron to the "riverside" tile route, but you can trade it to the city without Sailing because all the riverside tiles are touching inside culture (and because Sailing isn't required to trade down roads either).

A further confusion to me, is that in the same thread Thebes is on a hill, which means you can't pass irrigation through it even it is still a riverside tile for trade purposes. If the East river didn't run any N past Thebes, you still have the Corn hooked up (it's being traded due to Corn, 1W/1SW from Thebes all being riverside because of the river mouth and Thebes is riverside too due to E river...would still be hooked even if W river didn't exist, I think), but couldn't farm the tiles 1NE of Thebes unless 1N had irrigation passed first or you farm 1E.

Also pretty funny that the Corn in that Thebes thread only hooks up because of the river mouth.
 

Attachments

  • thebes corn route.png
    thebes corn route.png
    3.7 MB · Views: 65
Your attachment seems to suggest that the tile 1W of Thebes is connected to Thebes, but that's not the case.

I remember being puzzled by that Thebes thread at the time, so here's another stab at it. The main function responsible for river connections, slightly edited for readability, is isRiverConnection:
Spoiler :
NB: isRiverCrossing(d) means that a move from the current plot in direction d crosses a river.
Code:
bool CvPlot::isRiverConnection(DirectionTypes eDirection) const
{
    switch (eDirection)
    {
    case DIRECTION_NORTH:
        return (isRiverCrossing(DIRECTION_EAST) ||  isRiverCrossing(DIRECTION_WEST));
    case DIRECTION_NORTHEAST:
        return (isRiverCrossing(DIRECTION_NORTH) || isRiverCrossing(DIRECTION_EAST));
    case DIRECTION_EAST:
        return (isRiverCrossing(DIRECTION_NORTH) || isRiverCrossing(DIRECTION_SOUTH));
    case DIRECTION_SOUTHEAST:
        return (isRiverCrossing(DIRECTION_SOUTH) || isRiverCrossing(DIRECTION_EAST));
    case DIRECTION_SOUTH:
        return (isRiverCrossing(DIRECTION_EAST) ||  isRiverCrossing(DIRECTION_WEST));
    case DIRECTION_SOUTHWEST:
        return (isRiverCrossing(DIRECTION_SOUTH) || isRiverCrossing(DIRECTION_WEST));
    case DIRECTION_WEST:
        return (isRiverCrossing(DIRECTION_NORTH) || isRiverCrossing(DIRECTION_SOUTH));
    case DIRECTION_NORTHWEST:
        return (isRiverCrossing(DIRECTION_NORTH) || isRiverCrossing(DIRECTION_WEST));
    }
    return false;
}
So to go N from a plot p, a river has to be present either to the E or to the W of p.
And, so long as both plots are adjacent to some river, it's sufficient if isRiverConnection is true for one direction. Here's a screenshot listing for each plot the directions for which isRiverConnection returns true:
Spoiler :

river-connections.jpg

E.g. Thebes itself connects to the N, NE, SE and S. A diagonally adjacent river does not enable any outgoing connections, i.e. the Hill S of Thebes only gets connected from adjacent plots. If Thebes had a river segment to its S, then the Oil and the river to the NW would become connected to Thebes. Perhaps one could state the rule that "two river tiles (adjacent orthogonally or diagonally to any river) are connected if the closest approach of the two rivers is at most the diagonal length of a tile." In the Thebes example, that diagonal would run across the Hill tile S of Thebes. Not sure if this is universally true. I guess such a rule, if documented, wouldn't be unreasonable.

I suppose Spielban had figured out how it works, that a river segment connects tiles (so long as they're adjacent to some river) ahead of the river's flow, and also in the inverse direction, but not in a direction perpendicular to the river segment:
river flows edge of tiles. and we can say head of river is center of 4 tiles. [...]
 
E.g. Thebes itself connects to the N, NE, SE and S. A diagonally adjacent river does not enable any outgoing connections, i.e. the Hill S of Thebes only gets connected from adjacent plots. If Thebes had a river segment to its S, then the Oil and the river to the NW would become connected to Thebes.
Perhaps one could state the rule that "two river tiles (adjacent orthogonally or diagonally to any river) are connected if the closest approach of the two rivers is at most the diagonal length of a tile."
In the Thebes example, that diagonal would run across the Hill tile S of Thebes. Not sure if this is universally true. I guess such a rule, if documented, wouldn't be unreasonable.

This might be one of the best posts of the year. :thumbsup: :goodjob:


The definition might break down a bit if the connecting tile is touching two river ends.
No gold for the Viking capital here. :(




How about this definition?

A tile
shall connect two river trade groups if:

1) The tile is touching one river orthogonally or diagonally appropriately to gain +1:gold: and fresh water
AND
2) The tile is touching the second river with one of the 4 sides of the square it inhabits.


That should explain the Thebes situation nicely.



The tile 1 South of Thebes connects the east river to the southwest river. :)
It has +1:gold: and fresh water from the eastern river, and it physically touches the 2nd river on the southwest corner of its square.


The tile 1 West of Thebes does not connect the northwest river
It has +1:gold: and fresh water from the northwest river, but it is not physically touching the 2nd river to the east.

The tile 1 Northwest of Thebes does not connect the northwest river.
It has +1:gold: and fresh water from the northwest river, but it is not physically touching the 2nd river to the east.
 
Last edited:
Huh, so the 2nd river enables the trade group connection between two rivers even if only 1 tile is inside the borders. :hmm:
It seems correct.

 
Last edited:
The definition might break down a bit if the connecting tile is touching two river ends.
No Gold for the Viking capital here. :(
Right. Maybe "two adjacent river tiles are connected if ..." Non-river tiles don't connect anything (if we ignore Roads etc.).
Your definition also seems fine. Touching the (end of the) river with an edge or corner is perhaps more intuitive than the distance being no more than the length of a diagonal.
Huh, so the 2nd river enables the trade group connection between two rivers even if only 1 tile is inside the borders. :hmm: It seems correct.
Yeah, I guess so ...
 
AFAICT none of those explanations covers the truly horrifying nonsense in that thread: namely the last pic at the bottom of the first page. Why is the tile 1N2E of Thebes not in ANY trade network, which apparently means the tiles 1E and 1NE of that are in separate networks?
 
Hum, that's a fair point. I seem unable to reproduce this:
Spoiler :

thebes-5-and-6.jpg

Maybe I didn't build the exact same situation; I only see one Forest that differs from @Donald Duck1's screenshot (his post, for reference). To force a plot group update, I've given myself Astronomy in WB and immediately removed it again. Doesn't seem to happen automatically when placing or removing a river, or at least not reliably. (Save and reload also doesn't cause an update, I think; plot groups get saved.) Savegame for unmodded BtS attached.

On a different note, the logic of isRiverConnection is starting to make more sense to me. It's used for both river-to-sea and river-to-river connections. For river-to-sea, it works well, so perhaps that's what it was originally written for. For river-to-river, it mostly works, but there are counterintuitive cases that the programmer may not have been aware of. (Imo how it should work is that separate rivers only connect via tiles adjacent to both rivers. That would require a bunch of additional checks for diagonal river crossings and for river crossings at the destination tile.)
 

Attachments

  • thebes56.zip
    24.2 KB · Views: 20
Ok so that was just an artifact from failing to refresh the plot groups or something. Great work as always f1rpo. Looks like this is completely solved then. I'm glad to learn that when connecting to an AI I don't need to explore the city, just the trade group. I've been wasting that extra turn scouting, likely thinking it was necessary just because it takes the game a turn to recheck trade routes.
 
To force a plot group update, I've given myself Astronomy in WB and immediately removed it again. Doesn't seem to happen automatically when placing or removing a river, or at least not reliably. (Save and reload also doesn't cause an update, I think; plot groups get saved.) Savegame for unmodded BtS attached.
Thanks for solving this problem f1rpo :)

Yes, removing a river with World Builder does not update the plot groups.
It leads to some impossible situations until the plot groups update.
 
IIRC doesn't religious spread ignore tile reveal rules? I recall using rivers on some of my map tweaks to make it very likely certain AIs would cluster into religious blocs, a bit of an evil trick that never worked as well as I'd have liked (AI doesn't always research the way you expect, and player can just adopt that religion).

I recall you can also get some trade network weirdness if you use culture expansion to allow galleys to cross waters they could not otherwise, but I forget the exact interaction. It's the odd case where you can have open borders + non-reciprocal trade pre-astronomy, though I think it works similarly to that scenario where only one side has astro.
 
IIRC doesn't religious spread ignore tile reveal rules? I recall using rivers on some of my map tweaks to make it very likely certain AIs would cluster into religious blocs, a bit of an evil trick that never worked as well as I'd have liked (AI doesn't always research the way you expect, and player can just adopt that religion).
It looks like either side has to have a trade connection. CvCity::doReligion checks
if (pLoopCity->isConnectedTo(this))
which means that the holy city needs to be connected to the city being converted
Code:
bool CvCity::isConnectedTo(CvCity* pCity) const
{
	return plot()->isConnectedTo(pCity);
}
and, ultimately,
Code:
bool CvPlot::isConnectedTo(const CvCity* pCity) const
{
	FAssert(isOwned());
	return ((getPlotGroup(getOwnerINLINE()) == pCity->plotGroup(getOwnerINLINE())) ||
			(getPlotGroup(pCity->getOwnerINLINE()) == pCity->plotGroup(pCity->getOwnerINLINE())));
}
that the holy city and the converted city are connected for at least one of the city owners. Note that there is no distinction between the plot group of a city and that of the city's plot:
Code:
CvPlotGroup* CvCity::plotGroup(PlayerTypes ePlayer) const
{
	return plot()->getPlotGroup(ePlayer);
}
So it seems that the path for religion spread can't contain plots that no one has explored; because, otherwise,
Code:
bool CvPlot::isTradeNetwork(TeamTypes eTeam) const
{
	// ...
	if (!isOwned())
	{
		if (!isRevealed(eTeam, false))
		{
			return false;
		}
	}
	//....
}
should apply.
I recall you can also get some trade network weirdness if you use culture expansion to allow galleys to cross waters they could not otherwise, but I forget the exact interaction. It's the odd case where you can have open borders + non-reciprocal trade pre-astronomy, though I think it works similarly to that scenario where only one side has astro.
That's my experience too, and, digging up the code:
There's a special rule for owned water plots to be included in the trade network of the owner and its teammates – but not for any other civs, regardless of OB:
Spoiler :
Code:
bool CvPlot::isNetworkTerrain(TeamTypes eTeam) const
{
	FAssertMsg(eTeam != NO_TEAM, "eTeam is not assigned a valid value");
	FAssertMsg(getTerrainType() != NO_TERRAIN, "TerrainType is not assigned a valid value");

	if (GET_TEAM(eTeam).isTerrainTrade(getTerrainType()))
	{
		return true;
	}

	if (isWater())
	{
		if (getTeam() == eTeam)
		{
			return true;
		}
	}

	return false;
}
And a corresponding rule for unit movement (CvUnit::canMoveInto), again, plot ownership is decisive:
Spoiler :
Code:
if (m_pUnitInfo->getTerrainImpassable(pPlot->getTerrainType()))
{
	TechTypes eTech = (TechTypes)m_pUnitInfo->getTerrainPassableTech(pPlot->getTerrainType());
	if (NO_TECH == eTech || !GET_TEAM(getTeam()).isHasTech(eTech))
	{
		// sea units can enter impassable in own cultural borders
		if (DOMAIN_SEA != getDomainType() || pPlot->getTeam() != getTeam())
		{
			if (bIgnoreLoad || !canLoad(pPlot)) 
			{ 
				return false;
			}
		}
	}
}
The comment is from Firaxis.
 
Last edited:
Edit: I skimmed the thread too quickly and missed that the answer is already found! Thank you Kaitzilla, I agree that the analysis of Thebes has the complete ruleset -- two rivers (or river segments) are linked if they share corners with at least one tile that receives freshwater access from at least one of them. From there, any path of riverside tiles (including at kinks in the river, and including travelling along diagonals) will link a river system. This solves all my examples, including the lack of connection between Nanjing and Guangzhou. This should mean that river corners can link to river ends (a la Kaitzilla's Odense example), but river ends can not link to other river ends. I do not think river trading networks are understood. I have here 6 examples (Edit: I'll leave them up for corroboration of the other rules already elucidated here). I have not been able to figure out a ruleset by which Civ 4 calculates river trading that accounts for all 6 examples. I suspect it has something to do with how Civ 4 keeps track of rivers (they must be somehow associated with a tile, right? Even though they're between tiles?).

The following examples are all on turn 0, without the Sailing technology. (As a quick review, for anyone who may stumble on this thread while frantically googling: Civ 4's official rules are that you may trade on any river that remains within your territory or in neutral territory. Civ 4 BTS amended this rule to require sailing in order to trade along rivers in neutral territory [you can still trade within your own territory along rivers without the sailing technology]. This rule change makes the Civilopedia entries confusing, as you need to read the entry on BTS rule changes in order to get the full rule, and the City Network rule section is incomplete without it. As has been shown previously, and as I will further demonstrate here, even if you figure out the intended ruleset by reading the BTS rules in civilopedia, the rule does not work as intended).

Civ41.png


In the above picture, Shanghai and Beijing are trading.

Civ42.png


In the above picture, Nanjing and Guangzhou are not trading. Note that this is a direct refutation of the "riverside tiles behave as roads" theory -- there is a clear path of riverside tiles between Nanjing and Guangzhou that stays within my borders. Also note the similarity to the situation with Beijing and Shanghai.

Civ43.png


In the above picture, Xian and Chengdu are trading.

Civ44.png


In the above picture, Hangzhou and Tianjin are not trading.

Civ45.png


I particularly like this one. In the above picture, Macau and Shandong are trading.

Civ46.png


In the above picture, Kaifeng and Ningbo are trading.

Frankly, I'm at a loss. Edit: I am no longer at a loss, thanks again to Kaitzilla and f1rpo and all the other contributors in this thread, really fixed my headache! I had a working theory about how this all worked, but under my theory, Kaifeng and Ningbo should not have been trading. So now I'm back to square one, I just don't understand how this works. If anybody can make sense of it or has theories, let me know. Honestly, it's just not that important for strategy, I can't imagine this coming up in a game except in extremely niche circumstances (e.g. getting slightly quicker growth in your capital in the first 50 turns by linking up a luxury resource)

Also, for anybody looking to test this: Be careful. You can't amend river trade networks after you've placed your cities in worldbuilder. If you place two cities, and then draw a river between them, the cities will not be linked in a trade network. If you place two cities such that they are linked by a river network, and then delete the river in worldbuilder, the cities will remain linked despite the river being gone. Something about how this is calculated is done when the city is placed, and then not changed afterwards (or at least only recalculated at specific points in time, not every turn). This makes testing finnicky, and you have to be careful. Edit: Already solved early in the thread

I've attached my save file too, for anyone who would like to verify or play around more.

This is all very unimportant to strategy imo, but the question mark on this mehanic is kind of driving me a little nuts -- I just want to understand how it works!
 

Attachments

  • RiverTradingDemo.CivBeyondSwordSave
    79 KB · Views: 12
Last edited:
Top Bottom