Detecting Railroad Connection?

MouseyPounds

Prince
Joined
Nov 8, 2010
Messages
417
Location
Maryland, USA
Is there an easy way to detect if a city is getting the railroad connection production bonus? The only way I've come up with so far is by searching the production tooltip text, which is far from ideal. Spoilered below is what I'm currently using (which actually detects the lack of a RR connection), with the relevant statement hilighted red.

Spoiler :
Code:
pPlayer = Players[Game.GetActivePlayer()]
pTeam = Teams[pPlayer:GetTeam()]

iNumUnconnected = 0
iNumNoProdBonus = 0

for c in pPlayer:Cities() do
	if (c ~= nil and not c:IsCapital() and not pPlayer:IsCapitalConnectedToCity(c)) then
		iNumUnconnected  = iNumUnconnected  + 1
		print(string.format("%s is not connected to trade network.", c:GetName()))
	end
	-- There has to be a better way to do this....
	sTooltip = c:GetYieldModifierTooltip(YieldTypes.YIELD_PRODUCTION)
	if (c ~= nil and not c:IsCapital() and [COLOR="Red"]string.find(sTooltip,Locale.ConvertTextKey("TXT_KEY_PRODMOD_RAILROAD_CONNECTION",GameDefines.INDUSTRIAL_ROUTE_PRODUCTION_MOD),1,true) == nil)[/COLOR] then
		iNumNoProdBonus = iNumNoProdBonus + 1
		print(string.format("%s does not have a railroad connection.", c:GetName()))
	end
end
if (iNumUnconnected > 0) then
	print(string.format("There are %d cities without a trade connection",iNumUnconnected))
else
	print("All cities are connected!")
end
if (iNumNoProdBonus > 0) then 
	print(string.format("There are %d cities without a railroad connection",iNumNoProdBonus))
else
	print("All cities have railroad connections!")
end

I seriously hope there is a better way to do this but I didn't notice a relevant function on the Player or City object pages on the wiki. Any ideas?
 
Well I downloaded everything .. but having trouble getting my ModBuilder script seen by Civ V Mod Browser.. will try again tomorrow
 
I have a similar problem wanting to know if a city has a trade route with the capital. Does anyone know of any better way than checking the tooltip to do this?

I would also like to be able to check if any two cities on the map have a harbour/road connection between each other for a trade system I am trying to make. I guess this is even less likely to be possible, but it's worth asking if there's a way, right? :lol:
 
The tooltip hack is only needed for the railroad bonus; pPlayer:IsCapitalConnectedToCity(pCity) can be used to check for a simple trade route to the capital (see an example in the code in the first post.)

As for city-to-city connections, if both have harbors you can probably use a check like:
Code:
 (pCity:GetNumBuilding(GameInfoTypes.BUILDING_HARBOR) > 0 and not pCity:IsBlockaded())
for both cities, but I expect detecting road connections would be quite difficult.
 
The tooltip hack is only needed for the railroad bonus; pPlayer:IsCapitalConnectedToCity(pCity) can be used to check for a simple trade route to the capital (see an example in the code in the first post.)

As for city-to-city connections, if both have harbors you can probably use a check like:
Code:
 (pCity:GetNumBuilding(GameInfoTypes.BUILDING_HARBOR) > 0 and not pCity:IsBlockaded())
for both cities, but I expect detecting road connections would be quite difficult.

Thanks, I spent ages trying to find something like that on the wiki but I guess I was just expecting for it to be worded differently. :lol:

Civ 5 has pretty patchy LUA documentation. :S
 
The tooltip hack is only needed for the railroad bonus; pPlayer:IsCapitalConnectedToCity(pCity) can be used to check for a simple trade route to the capital (see an example in the code in the first post.)

As for city-to-city connections, if both have harbors you can probably use a check like:
Code:
 (pCity:GetNumBuilding(GameInfoTypes.BUILDING_HARBOR) > 0 and not pCity:IsBlockaded())
for both cities, but I expect detecting road connections would be quite difficult.

That does assume that a) both cities are on the same body of water (which is not always the case if the map contains a land-locked sea) and b) even if they are on the same body of water, that a continous path of discovered water exists between the two cities
 
That does assume that a) both cities are on the same body of water (which is not always the case if the map contains a land-locked sea) and b) even if they are on the same body of water, that a continous path of discovered water exists between the two cities

Unfortunately there does not appear to be a better method.
 
Unfortunately there does not appear to be a better method.

I've written some Lua methods for finding a route between two cities (actually any two plots) by Land, Road, Rail, Coastal, Ocean or Submarine.

This code can be tested from the Routes panel available via version 2 of my "Live Tuner - Techs and Policies Panels" mod (see http://forums.civfanatics.com/showthread.php?t=426226). The route finding code is in its own .lua file and can be included/distributed in your own mod

 
I've written some Lua methods for finding a route between two cities (actually any two plots) by Land, Road, Rail, Coastal, Ocean or Submarine.

This code can be tested from the Routes panel available via version 2 of my "Live Tuner - Techs and Policies Panels" mod (see http://forums.civfanatics.com/showthread.php?t=426226). The route finding code is in its own .lua file and can be included/distributed in your own mod


Thanks, I will look at this. :)
 
Top Bottom