• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Wurst] Pathing

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
Straight up converted from: TerrainPathability - Wc3C.net

Should save people some time though.

Wurstbin

Wurst:
package pathable

constant real    MAX_RANGE     = 10.
constant integer DUMMY_ITEM_ID = 'wolg'

item pathChecker = null
rect find  = null
item array hid
integer hidMax = 0

function moveBackItems()
    while(hidMax > 0)
        hidMax = hidMax - 1
        SetItemVisible(hid[hidMax], true)
        hid[hidMax] = null

function hideItem()
    if IsItemVisible(GetEnumItem())
        hid[hidMax] = GetEnumItem()
        hid[hidMax].setVisible(false)
        hidMax = hidMax + 1

function hideNearbyItems(real x, real y)
    MoveRectTo(find, x, y)
    EnumItemsInRect(find ,null, function hideItem)

function isTerrainWalkable(real x, real y) returns boolean
    hideNearbyItems(x, y)
    pathChecker.setPos(vec2(x, y))

    real itemPosX = pathChecker.getX()
    real itemPosY = pathChecker.getY()

    pathChecker.setVisible(false)
    return (itemPosX-x)*(itemPosX-x)+(itemPosY-y)*(itemPosY-y) <= MAX_RANGE*MAX_RANGE and not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY)

public function vec2.isTerrainWalkable() returns boolean
    return isTerrainWalkable(this.x, this.y)

public function isTerrainWalkable(vec2 pos) returns boolean
    return isTerrainWalkable(pos.x, pos.y)

init   
    find = Rect(0., 0., 128., 128.)
    pathChecker = CreateItem(DUMMY_ITEM_ID, 0, 0)
    ..setVisible(false)
 
Top