• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Is Point Pathable

Status
Not open for further replies.
Please excuse me for not linking the original, but here's IsTerrrainWalkable from one of my maps -

JASS:
//Thanks to anitarf and Vexorian @ wc3c.net for this library, it makes things easier.

library IsTerrainWalkable initializer Init
    globals
        // this value is how far from a point the item may end up for the point to be considered pathable
        private constant real MAX_RANGE=10.
        // the following two variables are set to the position of the item after each pathing check
        // that way, if a point isn't pathable, these will be the coordinates of the nearest point that is
        public real X=0.
        public real Y=0.
        private rect r
        private item check
        private item array hidden
        private integer hiddenMax=0
    endglobals

    private function Init takes nothing returns nothing
        set check=CreateItem('ciri',0,0)
        call SetItemVisible(check,false)
        set r=Rect(0.0,0.0,128.0,128.0)
    endfunction

    private function HideBothersomeItem takes nothing returns nothing
        if IsItemVisible(GetEnumItem()) then
            set hidden[hiddenMax]=GetEnumItem()
            call SetItemVisible(hidden[hiddenMax],false)
            set hiddenMax=hiddenMax+1
        endif
    endfunction

    function IsTerrainWalkable takes real x, real y returns boolean
        // first, hide any items in the area so they don't get in the way of our item
        call MoveRectTo(r,x,y)
        call EnumItemsInRect(r,null,function HideBothersomeItem)
        // try to move the check item and get it's coordinates
        call SetItemPosition(check,x,y)//this unhides the item...
        set X=GetItemX(check)
        set Y=GetItemY(check)
        call SetItemVisible(check,false)//...so we must hide it again
        // before returning, unhide any items that got hidden at the start
        loop
            exitwhen hiddenMax<=0
            set hiddenMax=hiddenMax-1
            call SetItemVisible(hidden[hiddenMax],true)
            set hidden[hiddenMax]=null
        endloop
        // return pathability status
        return (x-X)*(x-X)+(y-Y)*(y-Y)<MAX_RANGE*MAX_RANGE
    endfunction
endlibrary
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
Please excuse me for not linking the original, but here's IsTerrrainWalkable from one of my maps -

JASS:
//Thanks to anitarf and Vexorian @ wc3c.net for this library, it makes things easier.

library IsTerrainWalkable initializer Init
    globals
        // this value is how far from a point the item may end up for the point to be considered pathable
        private constant real MAX_RANGE=10.
        // the following two variables are set to the position of the item after each pathing check
        // that way, if a point isn't pathable, these will be the coordinates of the nearest point that is
        public real X=0.
        public real Y=0.
        private rect r
        private item check
        private item array hidden
        private integer hiddenMax=0
    endglobals

    private function Init takes nothing returns nothing
        set check=CreateItem('ciri',0,0)
        call SetItemVisible(check,false)
        set r=Rect(0.0,0.0,128.0,128.0)
    endfunction

    private function HideBothersomeItem takes nothing returns nothing
        if IsItemVisible(GetEnumItem()) then
            set hidden[hiddenMax]=GetEnumItem()
            call SetItemVisible(hidden[hiddenMax],false)
            set hiddenMax=hiddenMax+1
        endif
    endfunction

    function IsTerrainWalkable takes real x, real y returns boolean
        // first, hide any items in the area so they don't get in the way of our item
        call MoveRectTo(r,x,y)
        call EnumItemsInRect(r,null,function HideBothersomeItem)
        // try to move the check item and get it's coordinates
        call SetItemPosition(check,x,y)//this unhides the item...
        set X=GetItemX(check)
        set Y=GetItemY(check)
        call SetItemVisible(check,false)//...so we must hide it again
        // before returning, unhide any items that got hidden at the start
        loop
            exitwhen hiddenMax<=0
            set hiddenMax=hiddenMax-1
            call SetItemVisible(hidden[hiddenMax],true)
            set hidden[hiddenMax]=null
        endloop
        // return pathability status
        return (x-X)*(x-X)+(y-Y)*(y-Y)<MAX_RANGE*MAX_RANGE
    endfunction
endlibrary

getting error : Undeclared Function IsTerrainWalkable from this if (IsTerrainWalkable(GetLocationX(udg_TempLoc), GetLocationY(udg_TempLoc))) then < -.- i have that snippet in map why is it not work
 
Last edited:
Level 19
Joined
Aug 8, 2007
Messages
2,765
Try removing the library/endlibrary lines, then change the function Init's name to InitTrig_TerrainWalkable, then put it in the Map header.

private outside lbrary/scope definition. Im having this trouble (undeclared function) with another function too, i dont understand why!
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
If you're getting that error, sounds like you DO have JNGP.

What was the error with the first script? before doing what magtheridon said, that is.

Ya think? lol. The error with the first script, after importing it, was "Undeclared Function : IsTerrainWalkable"
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
After importing it? Just put it in an empty trigger called "IsTerrainWalkable".

Then use IsTerrainWalkable(x,y) as a custom script elsewhere.

Nope.

i put it in a trigger called IsTerrainWalkable and did
if ( IsTerrainWalkable(GetLocationX(udg_TempLoc) , GetLocationY(udg_TempLoc)) ) == true then

and it still says Undeclared Function IsTerrainWalkable
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
You should be writing jass triggers, not using custom scripts

You can convert this library to non-vJass but the effort is not worth it.

You have JNGP. You obviously have at least a beginner's knowledge of jass.

It's time to switch. PM me if you want help.

What? the trigger thats using that function is in JASS not GUI, i have no idea what your talking about.
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
JASS:
library GetPathablePoint
function GetPathablePointInRect takes rect r returns nothing
    set udg_TempInt = 1
    loop
        exitwhen udg_TempInt > 10
        set udg_TempLoc = GetRandomLocInRect(r)
        if (IsTerrainWalkable(GetLocationX(udg_TempLoc), GetLocationY(udg_TempLoc))) == true then
            set udg_TempInt = 10
        else
            set udg_TempInt = 1
        endif
        set udg_TempInt = udg_TempInt + 1
    endloop
endfunction
endlibrary
 
JASS:
library GetPathablePoint requires IsTerrainWalkable
    function GetPathablePointInRect takes rect r returns location
        local location loc
        local real randX=GetRectCenterX(r)
        local real randY=GetRectCenterY(r)
        loop
            exitwhen IsTerrainWalkable(randX,randY)
            set randX=GetRandomReal(GetRectMinX(r),GetRectMaxX(r))
            set randY=GetRandomReal(GetRectMinY(r),GetRectMaxY(r))
        endloop
        set Loc=Location(loc,randX,randY)
        return loc
    endfunction
endlibrary

NB: If the given rect contains no walkable points, the thread will crash.
 
Last edited:
Level 19
Joined
Aug 8, 2007
Messages
2,765
JASS:
library GetPathablePoint requires IsTerrainWalkable
    function GetPathablePointInRect takes rect r returns location
        local location loc
        local real randX=GetRectCenterX(r)
        local real randY=GetRectCenterY(r)
        loop
            exitwhen IsTerrainWalkable(randX,randY)
            set randX=GetRandomReal(GetRectMinX(r),GetRectMaxX(r))
            set randY=GetRandomReal(GetRectMinY(r),GetRectMaxY(r))
        endloop
        set Loc=Location(loc,randX,randY)
        return loc
    endfunction
endlibrary

NB: If the given rect contains no walkable points, the thread will crash.

Now im suspicous....

Undeclared Variable Loc

um..? all i did was remove the Loc, from Set Loc=Location(randX,randY)
 
Awww, but I just finished writing a vanilla Jass version of the script so you can paste it in the map header :(

JASS:
    // Required Globals
    // Create these globals using the variable editor
   
    //real         TW_MAX_RANGE
    //real         TW_X
    //real         TW_Y
    //rect         TW_r
    //item         TW_check
    //item array   TW_hidden
    //integer      TW_hiddenMax
                
    function HideBothersomeItem takes nothing returns nothing
        if IsItemVisible(GetEnumItem()) then
            set udg_TW_hidden[udg_TW_hiddenMax] = GetEnumItem()
            call SetItemVisible(udg_TW_hidden[udg_TW_hiddenMax], false)
            set udg_TW_hiddenMax = udg_TW_hiddenMax + 1
        endif
    endfunction

    function IsTerrainWalkable takes real x, real y returns boolean
        
        call MoveRectTo(udg_TW_r, x, y)
        call EnumItemsInRect(udg_TW_r, null, function HideBothersomeItem)

        call SetItemPosition(udg_TW_check, x, y)//this unhides the item...
        set udg_TW_X=GetItemX(udg_TW_check)
        set udg_TW_Y=GetItemY(udg_TW_check)
        call SetItemVisible(udg_TW_check, false)//...so we must hide it again
        
        loop
            exitwhen udg_TW_hiddenMax <= 0
            set udg_TW_hiddenMax = udg_TW_hiddenMax - 1
            call SetItemVisible(udg_TW_hidden[udg_TW_hiddenMax], true)
            set udg_TW_hidden[udg_TW_hiddenMax] = null
        endloop
        
        return (x - udg_TW_X) * (x - udg_TW_X) + (y - udg_TW_Y) * (y - udg_TW_Y) < udg_TW_MAX_RANGE * udg_TW_MAX_RANGE
    endfunction
    
    function InitTrig_initTerrainWalk takes nothing returns nothing
        set udg_TW_MAX_RANGE = 10
        set udg_TW_X = 0
        set udg_TW_Y = 0
        set udg_TW_r = Rect(0, 0, 128, 128)
        set udg_TW_check = CreateItem('ciri', 0, 0)
        call SetItemVisible(udg_TW_check, false)
        set udg_TW_hiddenMax = 0 
    endfunction
 
vanilla jass

1879f18e_e542_e1c6.jpg
 
Status
Not open for further replies.
Top