- Joined
- Oct 12, 2011
- Messages
- 3,449
This system extends the functionality of IsTerrainWalkable by vex, it can detect a location's pathing color (in terrain editor, pathing color can be seen by pressing 'p'). However, it couldn't be 100% accurate, it fails to detect correctly at the edge of pathing area, probably due to:
- Minimum pathing size of structure unit of 64 => shabby accuracy.
- Sometimes IsTerrainWalkable seems to return wrong result in very certain cases.
Any help to fix this issue will be highly appreciated, I find this system can be used to make highly advanced systems. How not? It can detect 8 different pathing types!
Here is the code and demo map:
(Updated.
Now the inaccuracy only occurs at very edge of the pathing area and for specific colors only (yellow, white, and magenta). I noticed that the problem occurs when TerrainWalkablity is false.)
- Minimum pathing size of structure unit of 64 => shabby accuracy.
- Sometimes IsTerrainWalkable seems to return wrong result in very certain cases.
Any help to fix this issue will be highly appreciated, I find this system can be used to make highly advanced systems. How not? It can detect 8 different pathing types!
Here is the code and demo map:
JASS:
library PathingColor initializer onInit requires IsTerrainWalkable
globals
private constant integer FLYING_CHECKER = 'hgyr'
private constant integer BUILDING_CHECKER = 'n000'
private constant real COLLISION_SIZE = 64
endglobals
globals
private rect TempRect
private unit FlyChecker
private unit BuildChecker
private group DisableGroup = CreateGroup()
private group EnableGroup = CreateGroup()
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
private function IsInRect takes real x, real y returns boolean
return x > GetRectMinX(TempRect) and x < GetRectMaxX(TempRect) and y > GetRectMinY(TempRect) and y < GetRectMaxY(TempRect)
endfunction
function GetTerrainPathingColor takes real x, real y returns integer
local real x2
local real y2
local unit fog
local integer result = 0
call MoveRectTo(TempRect, x, y)
call GroupEnumUnitsInRect(DisableGroup, TempRect, null)
loop
set fog = FirstOfGroup(DisableGroup)
exitwhen fog == null
call GroupRemoveUnit(DisableGroup, fog)
call GroupAddUnit(EnableGroup, fog)
call SetUnitPathing(fog, false)
endloop
call SetUnitPosition(FlyChecker, x, y)
call SetUnitPosition(BuildChecker, x, y)
set x2 = GetUnitX(FlyChecker)
set y2 = GetUnitY(FlyChecker)
if (x-x2)*(x-x2)+(y-y2)*(y-y2) < 2 then
set result = result + 1
endif
if IsTerrainWalkable(x, y) then
set result = result + 2
endif
if IsInRect(GetUnitX(BuildChecker), GetUnitY(BuildChecker)) then
set result = result + 4
endif
loop
set fog = FirstOfGroup(EnableGroup)
exitwhen fog == null
call GroupRemoveUnit(EnableGroup, fog)
call SetUnitPathing(fog, true)
endloop
return result
endfunction
private function onInit takes nothing returns nothing
local player p = Player(PLAYER_NEUTRAL_PASSIVE)
set TempRect = Rect(0, 0, COLLISION_SIZE, COLLISION_SIZE)
set FlyChecker = CreateUnit(p, FLYING_CHECKER, 0, 0, 0)
call SetUnitInvulnerable(FlyChecker, true)
call PauseUnit(FlyChecker, true)
call ShowUnit(FlyChecker, false)
set BuildChecker = CreateUnit(p, BUILDING_CHECKER, 0, 0, 0)
call SetUnitInvulnerable(BuildChecker, true)
call PauseUnit(BuildChecker, true)
call ShowUnit(BuildChecker, false)
endfunction
endlibrary
(Updated.
Now the inaccuracy only occurs at very edge of the pathing area and for specific colors only (yellow, white, and magenta). I noticed that the problem occurs when TerrainWalkablity is false.)
Attachments
Last edited: