System 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", "PathTextures\\2x2Default.tga")
        //! i makechange(current, "ushb", "")
        //! i makechange(current, "uubs", "")
        //! i makechange(current, "uabr", "0")
        //! i makechange(current, "uabt", "")
        //! i makechange(current, "ucol", "0")
        //! i makechange(current, "usid", "")
        //! i makechange(current, "usin", "")
        //! i makechange(current, "usca", ".01")
        //! i makechange(current, "uabi", "Avul")
        //! 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.2.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)
*
************************************************************************************
*
*   */uses/*
*
*       */ WorldBounds /*           hiveworkshop.com/forums/jass-functions-413/snippet-worldbounds-180494/
*       */ optional UnitIndexer /*  hiveworkshop.com/forums/jass-resources-412/system-unit-indexer-172090/
*
************************************************************************************
*
*   SETTINGS
*/
    globals
        /*
            Enables the 1024 path checking for warcraft 3 (100% accurate path checking)
            The 1024 case is a very rare case and may not be present in the map
            Only enable this if it is truly needed (major performance hit).
        */
        private constant boolean SAFE_PATHING = false
    endglobals
/*
************************************************************************************
*
*   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 GetPathingUnit takes integer pt returns unit
        return u[pt]
    endfunction
    function IsPathable takes integer x, integer y, integer p returns boolean
        local boolean b                                     //was point pathable?
        
        call SetUnitPosition(u[p],x,y)                      //use SetUnitPosition to determine if point is pathable
        set b=GetUnitX(u[p])==x and GetUnitY(u[p])==y       //if coordinates are identical, coordinate *may* be
                                                            //pathable
                                                            
        static if SAFE_PATHING then
            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+32                      //go out by 32
                call SetUnitPosition(u[p],x,y)  //set unit to new position
                set b=GetUnitX(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=GetUnitX(u[p+6])<x
                    call SetUnitX(u[p+6],WorldBounds.minX)
                    call SetUnitY(u[p+6],WorldBounds.minY)
                endif
            endif
        endif
        call SetUnitX(u[p],WorldBounds.minX)
        call SetUnitY(u[p],WorldBounds.minY)
        return b
    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
            
            static if LIBRARY_UnitIndexer then
                set UnitIndexer.enabled = false
            endif
            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)
            static if LIBRARY_UnitIndexer then
                set UnitIndexer.enabled = true
            endif
            
            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
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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