Created
April 26, 2017 19:14
-
-
Save stupidpupil/8a99533ef51fa6e57dfe8e7af8c82bdc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function plotIsOnAnIsland(pPlot) | |
local canGoOnLand | |
canGoOnLand = function (pStartingPlot, iDirection, iDistance, iDirectionConstraint) | |
if iDirectionConstraint == nil then | |
iDirectionConstraint = iDirection | |
end | |
local directionMeetsConstraint = function(dir) | |
return (math.abs(iDirectionConstraint-dir) < 2 or math.abs(iDirectionConstraint-dir) > 4) | |
end | |
local pCurrentPlot = pStartingPlot | |
pCurrentPlot = Map.GetAdjacentPlot(pCurrentPlot:GetX(), pCurrentPlot:GetY(), iDirection) | |
if pCurrentPlot and pCurrentPlot:IsWater() then | |
return false | |
end | |
if iDistance == 1 then | |
return true | |
else | |
local directionFan = { (iDirection-1) % 6, iDirection, (iDirection+1) % 6} | |
for _, iNextDirection in ipairs(directionFan) do | |
if directionMeetsConstraint(iNextDirection) then | |
if canGoOnLand(pCurrentPlot, iNextDirection, iDistance-1, iDirectionConstraint) then | |
return true | |
end | |
end | |
end | |
end | |
return false | |
end | |
for iDirection = 0,5 do | |
local pCurrentPlot = pPlot | |
if canGoOnLand(pCurrentPlot, iDirection, 3) then | |
return false | |
end | |
end | |
return true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment