I wrote up this function real quick to find what the closest buildable location to another location was:
The only problem is... when I order a unit to move to the nearest buildable loc, they just seen to move to the given location "start", regardless whether or not its actually buildable. Any help on this?
JASS:
function GetNearestPathableLoc takes location start returns location
local real x = GetLocationX(start)
local real y = GetLocationY(start)
local location checking = null
local real increment = 1.0
local boolean pathable = false
loop
exitwhen pathable == true
set pathable = IsTerrainPathable(x+increment,y, PATHING_TYPE_BUILDABILITY)
set checking = Location(x+increment,y)
set pathable = IsTerrainPathable(x-increment,y, PATHING_TYPE_BUILDABILITY)
set checking = Location(x-increment,y)
set pathable = IsTerrainPathable(x,y+increment, PATHING_TYPE_BUILDABILITY)
set checking = Location(x,y+increment)
set pathable = IsTerrainPathable(x,y-increment, PATHING_TYPE_BUILDABILITY)
set checking = Location(x,y-increment)
set pathable = IsTerrainPathable(x+increment,y+increment, PATHING_TYPE_BUILDABILITY)
set checking = Location(x+increment,y+increment)
set pathable = IsTerrainPathable(x+increment,y-increment, PATHING_TYPE_BUILDABILITY)
set checking = Location(x+increment,y-increment)
set pathable = IsTerrainPathable(x-increment,y+increment, PATHING_TYPE_BUILDABILITY)
set checking = Location(x-increment,y+increment)
set pathable = IsTerrainPathable(x-increment,y-increment, PATHING_TYPE_BUILDABILITY)
set checking = Location(x-increment,y-increment)
set increment = increment + 1.0
endloop
return checking
endfunction
The only problem is... when I order a unit to move to the nearest buildable loc, they just seen to move to the given location "start", regardless whether or not its actually buildable. Any help on this?