• 🏆 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!

Check specific pathing

Status
Not open for further replies.
Level 24
Joined
Jun 26, 2020
Messages
1,853
Hello, I wanna check if a point doesn't have a fly path blocker or isn't water, I made this function to check it:
Wurst:
function vec2.isPathGood() returns bool
    if not IsTerrainPathable(this.x, this.y, PATHING_TYPE_FLYABILITY)
        return false
    else if IsTerrainPathable(this.x, this.y, PATHING_TYPE_FLOATABILITY)
        return false
    return true
But always returns me false and I don't know why, what's wrong?
 

Wrda

Spell Reviewer
Level 26
Joined
Nov 18, 2012
Messages
1,891
If I remember correctly, IsTerrainPathable always returns the opposite of what you expect. So adding "not" should solve it.

 
Level 24
Joined
Jun 26, 2020
Messages
1,853
If I remember correctly, IsTerrainPathable always returns the opposite of what you expect. So adding "not" should solve it.

I tried that and now always returns true.
Wurst:
function vec2.isPathGood() returns bool
    if IsTerrainPathable(this.x, this.y, PATHING_TYPE_FLYABILITY)
        return false
    else if not IsTerrainPathable(this.x, this.y, PATHING_TYPE_FLOATABILITY)
        return false
    return true
I put a lot of air path blockers and "fake water" paths (because I'm creating the water with doodads) like this:
Wurst:
init
    EnumDestructablesInRect(bj_mapInitialPlayableArea, null, () -> begin
        if GetEnumDestructable().getTypeId() == 'B00L'
            SetTerrainPathable(GetEnumDestructable().getX(), GetEnumDestructable().getY(), PATHING_TYPE_FLOATABILITY, true)
    end)
But the first function doesn't considers them.
 
Level 24
Joined
Jun 26, 2020
Messages
1,853
Welp, at the end I checked if there is those blockers nearby, only left checking if the terrain is limit of map, I tried with not IsTerrainPathable(this.x, this.y, PATHING_TYPE_ANY), but is very inconsistent:
Wurst:
function destructable.isBlocker() returns bool
    if not this.isAliveTrick()
        return false
    
    let typ = this.getTypeId()
    if typ == 'YTab'
        return true
    else if typ == 'YTac'
        return true
    else if typ == 'YTfb'
        return true
    else if typ == 'YTfc'
        return true
    else if typ == 'B00L'
        return true
    return false

function vec2.isPathGood() returns bool
    let check = new Reference(false)
    forDestructablesInRange(this, 64., d -> begin
        if d.isBlocker()
            check.val = true
    end)
    if check.into()
        return false
    //else if not IsTerrainPathable(this.x, this.y, PATHING_TYPE_ANY)
        //return false
    return true
 
 
Level 24
Joined
Jun 26, 2020
Messages
1,853
That could work, but I have to translate it to Wurst, thank you.

Edit: Here it is:

Wurst:
package PathingLib

import UnitObjEditing
import ObjectIdGenerator
import ObjectIds
import Annotations

let PATH_CHECKER = compiletime(UNIT_ID_GEN.next())
let FLY_CHECKER = compiletime(UNIT_ID_GEN.next())

unit pathChecker

public function vec2.isFlyable() returns bool
    return IssueBuildOrderById(pathChecker, FLY_CHECKER, this.x, this.y)

init
    pathChecker = createUnit(DUMMY_PLAYER, PATH_CHECKER)
        ..removeAbility('Amov')
        ..hide()
    if localPlayer == DUMMY_PLAYER
        FogEnable(false)

function UnitDefinition.general()
    this
        ..setAttacksEnabled(0)
        ..setDeathType(0)
        ..setCategorizationSpecial(true)
        ..setSightRadiusDay(0)
        ..setSightRadiusNight(0)
        ..setFoodCost(0)
        ..setLumberCost(0)
        ..setGoldCost(0)
        ..setIsaBuilding(false)
        ..setHideMinimapDisplay(true)
        ..setCanFlee(false)
        ..setRace(Race.Unknown)
        ..setPointValue(0)
        ..setAnimationBlendTimeseconds(0)
        ..setModelFile("dummy.mdl")
        ..setSelectionScale(0)
        ..setIconGameInterface("")
        ..setShadowImageUnit("")
        ..setMaximumPitchAngledegrees(0)
        ..setMaximumRollAngledegrees(0)
        ..setNormalAbilities(LOCUST_ID.toRawCode())
        ..setUpgradesUsed("")
        ..setUnitSoundSet("")
        ..setHotkey("")
        ..setTooltipBasic("")
        ..setTooltipExtended("")
        ..setName("")

@compiletime function gen()
    new UnitDefinition(PATH_CHECKER, 'hpea')
        ..general()
        ..setMovementType(MovementType.Foot)
        ..setStructuresBuilt(commaList(FLY_CHECKER))
        ..setCollisionSize(0.)
        ..setNameEditorSuffix("PathChecker")
    
    new UnitDefinition(FLY_CHECKER, 'hgry')
        ..general()
        ..setMovementType(MovementType.Fly)
        ..setCollisionSize(1.)
        ..setNameEditorSuffix("FlyChecker")
 
Last edited:
Status
Not open for further replies.
Top