Genghis.Khan
Person
As the title says, I would like to make an improvement unbuildable if it is in a five-plot-radius of any city. Checking if it is is not the problem, the problem is that there is no event like Unit.CanBuild, so I'm am not sure if there is a Lua solution to this problem (maybe some UI trick to hide the build button if the unit is in an unbuildable spot, or is there another simpler way to do this?)
The code to check if the unit is in a buildable spot would be something like this:
Can somebody help me to find a way to do this?
The code to check if the unit is in a buildable spot would be something like this:
Code:
function ColonyValidSpots ()
local OnlyColonySpots = GameInfo.Improvements.Colonies
local unitID = GameInfo.Units.UNIT_COLONIST
for pUnit in Player:Units() do
if pUnit.GetUnitType == unitID then
local currentplot = pUnit:GetPlot()
for i = 0, GameDefines.MAX_MAJOR_CIVS - 1 do
if Players[i]:IsEverAlive() then
for pCity in Players[i]:Cities() do
local plotX = pCity:GetX()
local plotY = pCity:GetY()
local plotCity = City:AtPlot(plotX, plotY)
for i = 0, plotCity:GetNumCityPlots() -1 do
if plotCity:GetCityIndexPlot(i) ~= nil then
if Map.PlotDistance(currentPlot:GetX(), currentPlot:GetY(), plotCity:GetX(), plotCity:GetY()) < 5) then
--return false somehow
else
return true
end
end
end
end
end
end
end
end
Can somebody help me to find a way to do this?