I was looking for a way of checking whether a city-state has a road connection to a player's capital. I stumbled upon the IsCapitalConnectedToCity lua method, but unless I'm missing something, this method does not seem to work.
My LUA Code:
(the intent is to give Rome +1 influence/turn with every City State that has a road connection to Rome's capital)
The relevant part of lua.log (I have a road connection to Samarkand in this particular game):
As you can see, it never gets to the next print statement (even though it should for Samarkand) as the IsCapitalConnectedToCity always return false.
I went digging in the DLL a bit, and found that CvLuaPlayer::lIsCapitalConnectedToCity calls CvPlayer::IsCapitalConnectedToCity, which calls CvPlayer::IsCityConnectedToCity, which calls GC.getRouteFinder().GeneratePath with the X,Y coordinates of both cities. Putting a logging statement in there, I get:
(Rome is at (37,26), Samarkand is at (42,22)).
So it seems to correcly get both cities, but the pathfinder then determines that there is no road between them, even though there is. My knowledge of the A* algorithm is pretty much nonexistent, so I have no clue what is going on in CvAstar::GeneratePath that could cause this.
Anyone?
My LUA Code:
Code:
function InfluenceForRoads( iPlayer )
local pPlayer = Players[iPlayer];
if (pPlayer:IsAlive() and pPlayer:GetCivilizationType() == iCivilizationRome) then
print("InfluenceForRoads: this civilization is Rome");
for i, pOtherPlayer in pairs(Players) do
if (pOtherPlayer ~= pPlayer and pOtherPlayer:IsMinorCiv()) then
local pCity = pOtherPlayer:GetCapitalCity();
print("InfluenceForRoads: other Civ is a minor Civ with capital: " .. pCity:GetName());
if (pPlayer:IsCapitalConnectedToCity(pCity)) then
print("InfluenceForRoads: We have a road connection. Friendship before change: " .. pOtherPlayer:GetMinorCivFriendshipWithMajor(pPlayer:GetID()));
pOtherPlayer:ChangeMinorCivFriendshipWithMajor(pPlayer:GetID(), 1);
end
end
end
end
end
GameEvents.PlayerDoTurn.Add(InfluenceForRoads);
(the intent is to give Rome +1 influence/turn with every City State that has a road connection to Rome's capital)
The relevant part of lua.log (I have a road connection to Samarkand in this particular game):
Code:
[5583.057] CvX_Rome_Events: InfluenceForRoads: this civilization is Rome
[5583.057] CvX_Rome_Events: InfluenceForRoads: other Civ is a minor Civ with capital: Byblos
[5583.057] CvX_Rome_Events: InfluenceForRoads: other Civ is a minor Civ with capital: Ormus
[5583.057] CvX_Rome_Events: InfluenceForRoads: other Civ is a minor Civ with capital: Sidon
[5583.057] CvX_Rome_Events: InfluenceForRoads: other Civ is a minor Civ with capital: Kuala Lumpur
[5583.057] CvX_Rome_Events: InfluenceForRoads: other Civ is a minor Civ with capital: Belgrade
[5583.057] CvX_Rome_Events: InfluenceForRoads: other Civ is a minor Civ with capital: Genoa
[5583.057] CvX_Rome_Events: InfluenceForRoads: other Civ is a minor Civ with capital: Sydney
[5583.057] CvX_Rome_Events: InfluenceForRoads: other Civ is a minor Civ with capital: Quebec City
[5583.057] CvX_Rome_Events: InfluenceForRoads: other Civ is a minor Civ with capital: Wittenberg
[5583.057] CvX_Rome_Events: InfluenceForRoads: other Civ is a minor Civ with capital: Milan
[5583.057] CvX_Rome_Events: InfluenceForRoads: other Civ is a minor Civ with capital: Hong Kong
[5583.057] CvX_Rome_Events: InfluenceForRoads: other Civ is a minor Civ with capital: Monaco
[5583.057] CvX_Rome_Events: InfluenceForRoads: other Civ is a minor Civ with capital: Lhasa
[5583.057] CvX_Rome_Events: InfluenceForRoads: other Civ is a minor Civ with capital: Tyre
[5583.057] CvX_Rome_Events: InfluenceForRoads: other Civ is a minor Civ with capital: Samarkand
[5583.057] CvX_Rome_Events: InfluenceForRoads: other Civ is a minor Civ with capital: M'banza-Kongo
As you can see, it never gets to the next print statement (even though it should for Samarkand) as the IsCapitalConnectedToCity always return false.
I went digging in the DLL a bit, and found that CvLuaPlayer::lIsCapitalConnectedToCity calls CvPlayer::IsCapitalConnectedToCity, which calls CvPlayer::IsCityConnectedToCity, which calls GC.getRouteFinder().GeneratePath with the X,Y coordinates of both cities. Putting a logging statement in there, I get:
Code:
CvPlayer::IsCityConnectedToCity|Called GC.getRouteFinder().GeneratePath(iXstart = 37, iYstart = 26, iXdest = 42, iYDest = 22, iInfo = -1073741824, bReuse = false). Result = false
So it seems to correcly get both cities, but the pathfinder then determines that there is no road between them, even though there is. My knowledge of the A* algorithm is pretty much nonexistent, so I have no clue what is going on in CvAstar::GeneratePath that could cause this.
Anyone?