Hello, I want to create building that increase yield on Plains with Hills. My solution was to use LUA and make new terrain with better yields that will replace Plains where hills are also presented, and then use Building_TerrainYieldChanges table from Community Patch.
The problem is, my LUA doesn't replace terrain. I'm sure that my terrain is added to database - i see it in pedia. I'm also sure my LUA use correct TerrainID (tested with "print" fuction). Also i used this method to add new feature and it worked.
Can you please explain me what is the problem, or advice me how to implement similar effect other way?
LUA fragment in spoiler
function xxx(iPlayer)
local pPlayer = Players[iPlayer]
local iMyBuilding = GameInfoTypes["BUILDING_MESAVERDE"]
for pCity in pPlayer:Cities() do
local bCityHasMyBuilding = false
if pCity:IsHasBuilding(iMyBuilding) then
print("building ok");
bCityHasMyBuilding = true
end
if bCityHasMyBuilding then
local iNumPlots = pCity:GetNumCityPlots()
local iMyTerrain = GameInfoTypes["TERRAIN_MESAVERDE"]
for iPlot = 0, iNumPlots - 1 do
local pPlot = pCity:GetCityIndexPlot(iPlot)
if pPlot:IsHills() and (pPlot:GetTerrainType() == TerrainTypes.TERRAIN_PLAINS) then
if (pPlot:GetOwner() == iPlayer) then
pPlot:SetTerrainType(iMyTerrain, false, false)
print("feature set!")
end
end
end
end
end
end
GameEvents.PlayerDoTurn.Add(xxx);
The problem is, my LUA doesn't replace terrain. I'm sure that my terrain is added to database - i see it in pedia. I'm also sure my LUA use correct TerrainID (tested with "print" fuction). Also i used this method to add new feature and it worked.
Can you please explain me what is the problem, or advice me how to implement similar effect other way?
LUA fragment in spoiler
Spoiler LUA :
function xxx(iPlayer)
local pPlayer = Players[iPlayer]
local iMyBuilding = GameInfoTypes["BUILDING_MESAVERDE"]
for pCity in pPlayer:Cities() do
local bCityHasMyBuilding = false
if pCity:IsHasBuilding(iMyBuilding) then
print("building ok");
bCityHasMyBuilding = true
end
if bCityHasMyBuilding then
local iNumPlots = pCity:GetNumCityPlots()
local iMyTerrain = GameInfoTypes["TERRAIN_MESAVERDE"]
for iPlot = 0, iNumPlots - 1 do
local pPlot = pCity:GetCityIndexPlot(iPlot)
if pPlot:IsHills() and (pPlot:GetTerrainType() == TerrainTypes.TERRAIN_PLAINS) then
if (pPlot:GetOwner() == iPlayer) then
pPlot:SetTerrainType(iMyTerrain, false, false)
print("feature set!")
end
end
end
end
end
end
GameEvents.PlayerDoTurn.Add(xxx);