What do you think about this update of my Path checker? (removed the description cz it's too long to be posted here)
library IsTerrainPathable initializer onInit
// Configuration
globals
private constant integer PATH_CHECKER = 'h000'
private constant integer FLY_CHECKER = 'h001'
private constant integer WALK_CHECKER = 'h002'
private constant integer BUILD_CHECKER = 'h003'
private constant player DUMMY_PLAYER = Player(15)
endglobals
globals
private unit PathChecker
private rect Box
private group Group = CreateGroup()
private group Group2 = CreateGroup()
private hashtable Hash = InitHashtable()
constant integer PATHING_COLOR_WHITE = 0
constant integer PATHING_COLOR_MAGENTA = 1
constant integer PATHING_COLOR_CYAN = 2
constant integer PATHING_COLOR_BLUE = 3
constant integer PATHING_COLOR_YELLOW = 4
constant integer PATHING_COLOR_RED = 5
constant integer PATHING_COLOR_GREEN = 6
constant integer PATHING_COLOR_BLACK = 7
endglobals
function IsTerrainWalkable takes real x, real y, boolean ignoreUnits returns boolean
local unit fog
local boolean b
if ignoreUnits then
return IssueBuildOrderById(PathChecker, WALK_CHECKER, x, y)
else
call MoveRectTo(Box, x, y)
call GroupEnumUnitsInRect(Group, Box, null)
loop
set fog = FirstOfGroup(Group)
exitwhen fog == null
call GroupRemoveUnit(Group, fog)
if IsUnitType(fog, UNIT_TYPE_GROUND) and not IsUnitType(fog, UNIT_TYPE_STRUCTURE) then
call SaveReal(Hash, GetHandleId(fog), 0, GetUnitX(fog))
call SaveReal(Hash, GetHandleId(fog), 1, GetUnitY(fog))
call SetUnitX(fog, GetRectMaxX(Box))
call SetUnitY(fog, GetRectMaxY(Box))
call GroupAddUnit(Group2, fog)
endif
endloop
set b = IssueBuildOrderById(PathChecker, WALK_CHECKER, x, y)
loop
set fog = FirstOfGroup(Group2)
exitwhen fog == null
call GroupRemoveUnit(Group2, fog)
call SetUnitX(fog, LoadReal(Hash, GetHandleId(fog), 0))
call SetUnitY(fog, LoadReal(Hash, GetHandleId(fog), 1))
endloop
return b
endif
endfunction
function IsTerrainFlyable takes real x, real y returns boolean
return IssueBuildOrderById(PathChecker, FLY_CHECKER, x, y)
endfunction
function IsTerrainBuildable takes real x, real y returns boolean
return IssueBuildOrderById(PathChecker, BUILD_CHECKER, x, y)
endfunction
function GetTerrainPathingColor takes real x, real y, boolean ignoreUnits returns integer
local integer color = 0
if IsTerrainFlyable(x, y) then
set color = color + 1
endif
if IsTerrainWalkable(x, y, ignoreUnits) then
set color = color + 2
endif
if IsTerrainBuildable(x, y) then
set color = color + 4
endif
return color
endfunction
private function onInit takes nothing returns nothing
set PathChecker = CreateUnit(DUMMY_PLAYER, PATH_CHECKER, 0, 0, 0)
call UnitRemoveAbility(PathChecker, 'Amov')
call ShowUnit(PathChecker, false)
if GetLocalPlayer() == DUMMY_PLAYER then
call FogEnable(false)
endif
set Box = Rect(0, 0, 512, 512)
endfunction
endlibrary
- Name is changed to IsTerrainPathable (or maybe PathabilityChecker, which one is better?)
- I found that every ground non-structure units generate blue and magenta pathing around them. Causing function IsTerrainWalkable to always return false if targeted around those units, which is unlike the result of Vex's checker. So I have to allow user to chose whether they want to ignore those unit's pathability or not. But now, it requires 2 unit groups and hashtable. But still, using SetUnitX/Y doesn't move the blue pathing along, just like if you use that function upon structure units, causing IsTerrainBuildable to return wrong value. I don't know is that worth it or not? What do you think?
- I did this update cz I can't use it in my Dark Matter spell due to it's behavior, and maybe can't be used as well in other certain type of spells. That's why I think it needs this update, but it costs the elegance and some speed