Snippet IsPathable

Nestharus

o-o
Reaction score
84
Is Point Pathable

Not to be confused with IsTerrainPathable, this script will check to see if a point is currently pathable given a pathing type. For example, it will be able to detect if a building is at that point, unlike IsTerrainPathable, which only checks the terrains pathability (including doodads and what not).

This takes advantage of SetUnitPosition in order to determine whether a point is pathable or not. However, SetUnitPosition may bug in cases where the closest pathable point is at least 1024 units away (in which case the unit is just placed at the original point regardless as to whether it was pathable or not). This avoid that bug with a special algorithm that no other is pathable resource has.

Installation Script
JASS:

//! externalblock extension=lua ObjectMerger $FILENAME$
    //! runtextmacro LUA_FILE_HEADER()
    //! i dofile("GetVarObject")
    
    //! i local function create(id,pt)
        //! i createobject("hwtw", id)
        //! i makechange(current, "unsf", "( " .. pt .. " )")
        //! i makechange(current, "upat", "")
        //! i makechange(current, "ushb", "")
        //! i makechange(current, "uubs", "")
        //! i makechange(current, "uabr", "0")
        //! i makechange(current, "uabt", "")
        //! i makechange(current, "ucol", "16")
        //! i makechange(current, "usid", "")
        //! i makechange(current, "usin", "")
        //! i if (pt~="blighted") then
            //! i makechange(current, "upap", pt)
        //! i else
            //! i makechange(current, "upar", pt)
            //! i makechange(current, "upap", "")
        //! i end
        //! i if (pt=="unflyable") then
            //! i makechange(current, "umvt", "fly")
        //! i elseif (pt=="unamph") then
            //! i makechange(current, "umvt", "amph")
        //! i elseif (pt=="unfloat") then
            //! i makechange(current, "umvt", "float")
        //! i else
            //! i makechange(current, "umvt", "foot")
        //! i end
    //! i end
    //! i create(getvarobject("hwtw", "units", "UNITS_PATH_" .. "unflyable", true),"unflyable")
    //! i create(getvarobject("hwtw", "units", "UNITS_PATH_" .. "unamph", true),"unamph")
    //! i create(getvarobject("hwtw", "units", "UNITS_PATH_" .. "unbuildable", true),"unbuildable")
    //! i create(getvarobject("hwtw", "units", "UNITS_PATH_" .. "unwalkable", true),"unwalkable")
    //! i create(getvarobject("hwtw", "units", "UNITS_PATH_" .. "unfloat", true),"unfloat")
    //! i create(getvarobject("hwtw", "units", "UNITS_PATH_" .. "blighted", true),"blighted")
    
    //! i updateobjects()
//! endexternalblock


Script
JASS:

library IsPathable /* v1.0.1.2
*************************************************************************************
*
*   The IsTerrainPathable native does not work.
*
*   This library will also check if a point is currently pathable. Will even be
*   able to detect buildings and large clusters of units (avoids the 1024 warcraft
*   limit to pathing by checking via a loop).
*
************************************************************************************
*
*   */uses/*
*
*       */ WorldBounds /*       hiveworkshop.com/forums/jass-functions-413/snippet-worldbounds-180494/
*
************************************************************************************
*
*   constant integer PATH_TYPE_AMPHIBIOUS
*   constant integer PATH_TYPE_BLIGHT
*   constant integer PATH_TYPE_BUILDABILITY
*   constant integer PATH_TYPE_FLOATABILITY
*   constant integer PATH_TYPE_FLYABILITY
*   constant integer PATH_TYPE_WALKABILITY
*
*   function IsPathable takes integer x, integer y, integer pathingType returns boolean
*       -   i.e. call IsPathable(0,0,PATH_TYPE_AMPHIBIOUS)
*
************************************************************************************/
    globals
        //pathing types
        constant integer PATH_TYPE_AMPHIBIOUS=0
        constant integer PATH_TYPE_BLIGHT=1
        constant integer PATH_TYPE_BUILDABILITY=2
        constant integer PATH_TYPE_FLOATABILITY=3
        constant integer PATH_TYPE_FLYABILITY=4
        constant integer PATH_TYPE_WALKABILITY=5
        
        private pathingtype array pt
        private unit array u                                //unit pathability checkers array
    endglobals
    function IsPathable takes integer x, integer y, integer p returns boolean
        local boolean b                                     //was point pathable?
        
        if (not IsTerrainPathable(x,y,pt[p])) then
            call SetUnitPosition(u[p],x,y)                      //use SetUnitPosition to determine if point is pathable
            set b=GetWidgetX(u[p])==x and GetWidgetY(u[p])==y   //if coordinates are identical, coordinate *may* be
                                                                //pathable
            if (b) then
                //if the point was found as pathable, it may not be pathable
                //units are placed at the original coordinates if the closest pathable point is
                //at least 1024 units out
                set x=x+64                      //go out by 64
                call SetUnitPosition(u[p],x,y)  //set unit to new position
                set b=GetWidgetX(u[p])<x        //check to see if unit shifted towards original position
                //if unit didn't shift towards original position, check second position with another unit
                
                //where all points are not pathable, place a unit at an arbitrary point
                //it will stay at that point even though it isn't pathable
                /*
                    *   *   *   *
                    *   *   *   *
                    *   U   *   *
                    *   *   *   *
                */
                
                //shift the unit over by 1 and see if it doesn't shift
                //if it did shift, then the original position was pathable
                //if it didn't shift, then both positions may or may not be pathable
                /*
                    *   *   *   *
                    *   *   *   *
                    *   *   U   *
                    *   *   *   *
                */
                
                //place a second unit on top of the first unit
                //if it didn't shift left, then the first position was not pathable
                /*
                    *   *   *   *
                    *   *   *   *
                    *   *   <-UU   *
                    *   *   *   *
                    
                    --------------------------
                    *   *   *   *
                    *   *   *   *
                    *   U   U   *
                    *   *   *   *
                */
                //the reason it will shift left is because 64 is only half a square, meaning it
                //will still be closest to the first position
                
                //the reason why two units are required
                /*
                    *   *   *   *
                    *   *   *   *
                    *           *
                    *   *   *   *
                */
                //in this case, both positions are pathable, meaning the unit will not shift
                //it would be identical to this case
                /*
                    *   *   *   *
                    *   *   *   *
                    *   *   *   *
                    *   *   *   *
                */
                //and the reason for moving right is due to this case
                /*
                    *   *   *   *
                    *   *   *   *
                    *       *   *
                    *   *   *   *
                */
                //in this case, a unit placed on top of the original unit will not shift anywhere
                //and nothing is known
                if (not b) then
                    call SetUnitPosition(u[p+6],x-32,y)
                    set b=GetWidgetX(u[p+6])<x
                    call SetUnitX(u[p+6],WorldBounds.minX)
                    call SetUnitY(u[p+6],WorldBounds.minY)
                endif
            endif
            call SetUnitX(u[p],WorldBounds.minX)
            call SetUnitY(u[p],WorldBounds.minY)
            return b
        endif
        return false
    endfunction
    private module N
        private static method onInit takes nothing returns nothing
            local player p=Player(15)
            
            set pt[PATH_TYPE_FLYABILITY]=PATHING_TYPE_FLYABILITY
            set pt[PATH_TYPE_AMPHIBIOUS]=PATHING_TYPE_AMPHIBIOUSPATHING
            set pt[PATH_TYPE_BUILDABILITY]=PATHING_TYPE_BUILDABILITY
            set pt[PATH_TYPE_WALKABILITY]=PATHING_TYPE_WALKABILITY
            set pt[PATH_TYPE_FLOATABILITY]=PATHING_TYPE_FLOATABILITY
            set pt[PATH_TYPE_BLIGHT]=PATHING_TYPE_BLIGHTPATHING
            
            set u[PATH_TYPE_FLYABILITY]=CreateUnit(p,UNITS_PATH_unflyable,0,0,0)
            set u[PATH_TYPE_AMPHIBIOUS]=CreateUnit(p,UNITS_PATH_unamph,0,0,0)
            set u[PATH_TYPE_BUILDABILITY]=CreateUnit(p,UNITS_PATH_unbuildable,0,0,0)
            set u[PATH_TYPE_WALKABILITY]=CreateUnit(p,UNITS_PATH_unwalkable,0,0,0)
            set u[PATH_TYPE_FLOATABILITY]=CreateUnit(p,UNITS_PATH_unfloat,0,0,0)
            set u[PATH_TYPE_BLIGHT]=CreateUnit(p,UNITS_PATH_blighted,0,0,0)
            
            set u[PATH_TYPE_FLYABILITY+6]=CreateUnit(p,UNITS_PATH_unflyable,0,0,0)
            set u[PATH_TYPE_AMPHIBIOUS+6]=CreateUnit(p,UNITS_PATH_unamph,0,0,0)
            set u[PATH_TYPE_BUILDABILITY+6]=CreateUnit(p,UNITS_PATH_unbuildable,0,0,0)
            set u[PATH_TYPE_WALKABILITY+6]=CreateUnit(p,UNITS_PATH_unwalkable,0,0,0)
            set u[PATH_TYPE_FLOATABILITY+6]=CreateUnit(p,UNITS_PATH_unfloat,0,0,0)
            set u[PATH_TYPE_BLIGHT+6]=CreateUnit(p,UNITS_PATH_blighted,0,0,0)
            
            call SetUnitX(u[PATH_TYPE_FLYABILITY],WorldBounds.minX)
            call SetUnitY(u[PATH_TYPE_FLYABILITY],WorldBounds.minY)
            call SetUnitX(u[PATH_TYPE_AMPHIBIOUS],WorldBounds.minX)
            call SetUnitY(u[PATH_TYPE_AMPHIBIOUS],WorldBounds.minY)
            call SetUnitX(u[PATH_TYPE_BUILDABILITY],WorldBounds.minX)
            call SetUnitY(u[PATH_TYPE_BUILDABILITY],WorldBounds.minY)
            call SetUnitX(u[PATH_TYPE_WALKABILITY],WorldBounds.minX)
            call SetUnitY(u[PATH_TYPE_WALKABILITY],WorldBounds.minY)
            call SetUnitX(u[PATH_TYPE_FLOATABILITY],WorldBounds.minX)
            call SetUnitY(u[PATH_TYPE_FLOATABILITY],WorldBounds.minY)
            call SetUnitX(u[PATH_TYPE_BLIGHT],WorldBounds.minX)
            call SetUnitY(u[PATH_TYPE_BLIGHT],WorldBounds.minY)
            
            call SetUnitX(u[PATH_TYPE_FLYABILITY+6],WorldBounds.minX)
            call SetUnitY(u[PATH_TYPE_FLYABILITY+6],WorldBounds.minY)
            call SetUnitX(u[PATH_TYPE_AMPHIBIOUS+6],WorldBounds.minX)
            call SetUnitY(u[PATH_TYPE_AMPHIBIOUS+6],WorldBounds.minY)
            call SetUnitX(u[PATH_TYPE_BUILDABILITY+6],WorldBounds.minX)
            call SetUnitY(u[PATH_TYPE_BUILDABILITY+6],WorldBounds.minY)
            call SetUnitX(u[PATH_TYPE_WALKABILITY+6],WorldBounds.minX)
            call SetUnitY(u[PATH_TYPE_WALKABILITY+6],WorldBounds.minY)
            call SetUnitX(u[PATH_TYPE_FLOATABILITY+6],WorldBounds.minX)
            call SetUnitY(u[PATH_TYPE_FLOATABILITY+6],WorldBounds.minY)
            call SetUnitX(u[PATH_TYPE_BLIGHT+6],WorldBounds.minX)
            call SetUnitY(u[PATH_TYPE_BLIGHT+6],WorldBounds.minY)
            
            set p=null
        endmethod
    endmodule
    private struct I extends array
        implement N
    endstruct
endlibrary
 

Nestharus

o-o
Reaction score
84
That one's not nearly as good as mine..

plus mine's apparently the only one that doesn't bug up with wc3 pathing limits =).
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Varine Varine:
    I have a bunch of community service I have to do, and I have a feeling there will be a lot of snow shoveling involved now
  • The Helper The Helper:
    don't know why people choose to live in that kind of weather :)
  • Varine Varine:
    Well
  • Varine Varine:
    My job is here
  • Varine Varine:
    I was born here man I didn't choose shit
  • Varine Varine:
    And also, I keep moving away and it doesn't get any better. I moved to San Antonio and shit froze there AND we had blackouts
  • tom_mai78101 tom_mai78101:
    I'm back, suffering from severe jet lag.
  • The Helper The Helper:
    Cold is following your ass around Varine - I just dont think I could handle a snowy winter.
  • The Helper The Helper:
    Welcome Back Tom!
  • The Helper The Helper:
    I hear that taking a Melatonin around your normal bedtime can really fix jet lag
  • tom_mai78101 tom_mai78101:
    Yeah, I also heard about that as well. I think I'm good. I'm just lucky it's the weekend so I have some time to readjust.
    +1
  • Varine Varine:
    It was a fucking blizzard today, shoveling was an effort in futility.
  • Varine Varine:
    Melatonin gives me nightmares
  • Varine Varine:
    They had me shoveling out the parking lot for the jail. Fucking pointless, they need a blow.
  • Varine Varine:
    Well they gave me a snow blower but it was too wet to do much with with other than compact everything. Oh well, the cop cars can get into there now when they arrest people I guess
    +1
  • The Helper The Helper:
    I shit you not we are Number one on Google for Banana Bread Recipe
  • jonas jonas:
    xD
    +1
  • The Helper The Helper:
    Need Web Design Contractor that knows Word Press, Woocommerce and Elementor to help with the company that sponsors this site
  • The Helper The Helper:
  • The Helper The Helper:
    I am going to be AFK most of this weekend has I have a friend coming into town for his company christmas party and I am going to be busy with that this weekend.
    +1
  • The Helper The Helper:
    541 Active Users and this number has been pretty steady give or take some. The bots are hammering us.
  • The Helper The Helper:
    I have been posting a bunch of recipes and Google is loving them. I mean OK my shit is good but how does google know LOL!

    The Helper Discord

    Members online

    No members online now.

    Affiliates

    Hive Workshop NUON Dome World Editor Tutorials

    Network Sponsors

    Apex Steel Pipe - Buys and sells Steel Pipe.
    Top