Mountain check failure.

JFD

Kathigitarkh
Joined
Oct 19, 2010
Messages
9,132
Location
The Kingdom of New Zealand
I'm evidently not seeing a problem with this code that's preventing it from working (although when I originally wrote it and released the associated mod, surely I must've tested it!). The intent is that it checks for a Mountain within a city's borders and if there is one, it does stuff.

Code:
function JFD_HasMountainWithinBorders(playerID)
	local player = Players[playerID]
	if player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_JFD_ARMENIA"] and player:IsAlive() then	
		for city in player:Cities() do
			if city:IsHasBuilding(GameInfoTypes["BUILDING_JFD_ARMENIAN_MONASTERY"]) then 
				for cityPlot = 0, city:GetNumCityPlots() -1, 1 do
					local plot = city:GetCityIndexPlot(cityPlot)
					if plot:IsMountain() and plot:GetOwner() == playerID then
						city:SetNumRealBuilding(GameInfoTypes["BUILDING_JFD_ARMENIAN_FAITH"], 1) 
					else
						if city:IsHasBuilding(GameInfoTypes["BUILDING_JFD_ARMENIAN_FAITH"]) then
							city:SetNumRealBuilding(GameInfoTypes["BUILDING_JFD_ARMENIAN_FAITH"], 0) 
						end
					end
				end
			else
				if city:IsHasBuilding(GameInfoTypes["BUILDING_JFD_ARMENIAN_FAITH"]) then
					city:SetNumRealBuilding(GameInfoTypes["BUILDING_JFD_ARMENIAN_FAITH"], 0) 
				end
			end
		end
	end
end
GameEvents.PlayerDoTurn.Add(JFD_HasMountainWithinBorders)
 
Code:
function JFD_HasMountainWithinBorders(playerID)
	local player = Players[playerID]
	if player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_JFD_ARMENIA"] and player:IsAlive() then	
		for city in player:Cities() do
			if city:IsHasBuilding(GameInfoTypes["BUILDING_JFD_ARMENIAN_MONASTERY"]) then
				city:SetNumRealBuilding(GameInfoTypes["BUILDING_JFD_ARMENIAN_FAITH"], 0) 
				for cityPlot = 0, city:GetNumCityPlots() -1, 1 do
					local plot = city:GetCityIndexPlot(cityPlot)
					if plot then
						if plot:IsMountain() and plot:GetOwner() == playerID then
							city:SetNumRealBuilding(GameInfoTypes["BUILDING_JFD_ARMENIAN_FAITH"], 1) 
							break;
						end
					end
				end
			else
				if city:IsHasBuilding(GameInfoTypes["BUILDING_JFD_ARMENIAN_FAITH"]) then
					city:SetNumRealBuilding(GameInfoTypes["BUILDING_JFD_ARMENIAN_FAITH"], 0) 
				end
			end
		end
	end
end
GameEvents.PlayerDoTurn.Add(JFD_HasMountainWithinBorders)
1. Your code in practice was caring only about the last plot from iteration.
2. Wasn't checking if plot exist (well, it matters only on edge of map, but still).
 
Back
Top Bottom