Snippet library Pathable

Troll-Brain

You can change this now in User CP.
Reaction score
85
This is just a library with thee functions to apply a pathing for a rect, a circle and a disk.
I don't think i need to comment because it's quite obvious how to use it, but if i must, then simply say it.
And if you don't know how to use them i add a demo map.

You need jasshelper.

PS : Don't try it for a too big circle/rect/disk because you may reach the limit op, and so make stopped your trigger which you called the function.
And don't try to add cells that are outside the map or warcraft will crash.

Sorry, let's explain what these three functions do so.



JASS:
function RectPathing takes rect r , pathingtype t , boolean b returns boolean


It apply the pathing t for the rect r.
b = true -> turn on the pathing
b = false -> turn off the pathing

It returns true if the pathing was done completely, and false if not.

For example :

JASS:
call RectPathing(Rect(0.0,20.0,40.0,60.0),PATHING_TYPE_WALKABILITY,false)

will avoid walking unit to going in this rect.

JASS:
function DiskPathing takes real xc,real yc,real radius,pathingtype t,boolean b returns

xc -> the x coordinate of disk center.
yc -> the y coordinate of disk center
radius -> the radius of the disk
b -> same comments.

JASS:
function CirclePathing takes real xc,real yc,real radius,pathingtype t,boolean b returns boolean

Exactly the same comments to the DiskPathing except this is a circle, not a disk.

JASS:
library Pathable

globals
    private constant real R= SquareRoot(2.0)/2.0
    private real Xmax
    private real Ymax
    private real Xmin
    private real Ymin
    private real Xmax2
    private real Ymax2
    private real Xmin2
    private real Ymin2
endglobals

private function R32 takes real r returns real //must be an inlined function or it will be so slow ...
    return 32.0*R2I(r/32.0)                              
endfunction

//! textmacro Pathable_loop
    set x= xMin
    loop
    exitwhen y== yMax
    set y= y+32.0
    
        loop
        exitwhen x== xMax
        set x= x+32.0
        
            call SetTerrainPathable(x,y,t,b)
            
        endloop
        
        set x= xMin
        
    endloop
//! endtextmacro

//! textmacro Pathable_loopif
    set x= xMin
    loop
    exitwhen y== yMax
    set y= y+32.0
    
        loop
        exitwhen x== xMax
        set x= x+32.0
        
            if (x-xc)*(x-xc)+(y-yc)*(y-yc) < r2 then
                call SetTerrainPathable(x,y,t,b)
            endif
            
        endloop
        
        set x= xMin
        
    endloop
//! endtextmacro

//! textmacro Pathable_loopfill
    loop
    exitwhen r== 0.0
    set r= r-32.0
             
        call SetTerrainPathable(x-32.0,r+rel,t,b)
            
    endloop
//! endtextmacro                                               

function RectPathing takes rect r , pathingtype t , boolean b returns boolean

    local real xMin
    local real xMax
    local real yMax
    local real x
    local real y

    if r== null then
        debug call BJDebugMsg("the rect is null")
        return false
    elseif t== null then
        debug call BJDebugMsg("the pathingtype is null")
        return false
    endif

    set xMin= R32(GetRectMinX(r))-32.0
    set y= R32(GetRectMinY(r))-32.0
    set xMax= R32(GetRectMaxX(r))
    set yMax= R32(GetRectMaxY(r))
    set x= xMin

    //! runtextmacro Pathable_loop()
    
    return true

endfunction

function DiskPathing takes real xc,real yc,real radius,pathingtype t,boolean b returns boolean

    local real xMax
    local real yMax
    local real xMin
    local real yMin
    local real x= R*radius
    local real y
    local real r2= radius*radius
    local real rel
    
    if t==null then
        debug call BJDebugMsg("the pathingtype is null")
        return false
    elseif radius<0.0 then
        debug call BJDebugMsg("a negative radius o_0")
        return false
    endif
    
    set Xmax= R32(xc+radius)
    set Ymax= R32(yc+radius)
    set Xmin= R32(xc-radius)-32.0
    set Ymin= R32(yc-radius)-32.0
    
    set Xmax2= R32(xc+x)
    set Ymax2= R32(yc+x)
    set Xmin2= R32(xc-x)-32.0
    set Ymin2= R32(yc-x)-32.0
    
    set xMax= Xmax2
    set yMax= Ymax2
    set xMin= Xmin2
    set y= Ymin2
    //! runtextmacro Pathable_loop()
    set xMax= Xmax
    set yMax= Ymax2
    set xMin= Xmax2
    set y= Ymin2
    //! runtextmacro Pathable_loopif()
    set xMax= Xmax2
    set yMax= Ymax
    set xMin= Xmin2
    set y= Ymax2
    //! runtextmacro Pathable_loopif()
    set xMax= Xmin
    set yMax= Ymax2
    set xMin= Xmin
    set y= Ymin2
    //! runtextmacro Pathable_loopif()
    set xMax= Xmax2
    set yMax= Ymin2
    set xMin= Xmin2
    set y= Ymin   
    //! runtextmacro Pathable_loopif()    

    return true
    
endfunction

function CirclePathing takes real xc,real yc,real radius,pathingtype t,boolean b returns boolean
    
    local real xMax= R32(xc+radius)-32.0
    local real x= R32(xc-radius)
    local real r
    local real r1
    local real r2
    local real r3
    local real r4
    local real rel

        if radius<0.0 then
            debug call BJDebugMsg("a negative radius o_0")
            return false
        endif
    
        set radius= radius*radius
        
        set r= SquareRoot( radius - (x-xc)*(x-xc) )
        set r1= R32(yc-r)
        set r2= R32(yc+r)
        call SetTerrainPathable(x,r1,t,b)
        call SetTerrainPathable(x,r2,t,b)
        set rel= r1
        set r= r2-r1
        //! runtextmacro Pathable_loopfill()
        if xMax< x then
            return true
        endif
        
        loop
        exitwhen x== xMax
        set x= x+32.0
         
            set r= SquareRoot( radius - (x-xc)*(x-xc) )
            set r3= R32(yc-r)
            set r4= R32(yc+r)
            call SetTerrainPathable(x,r3,t,b)
            call SetTerrainPathable(x,r4,t,b)
            
            if r3>r1 then
                set r= r3-r1
                set rel= r1
            else
                set r= r1-r3
                set rel= r3
            endif
            //! runtextmacro Pathable_loopfill()
            
            if r4>r2 then
                set r= r4-r2
                set rel= r2
            else
                set r= r2-r4
                set rel= r4
            endif
            //! runtextmacro Pathable_loopfill()
            
            set r1=r3
            set r2=r4
         
        endloop
        
        set r= SquareRoot( radius - (x-xc)*(x-xc) )
        set r1= R32(yc-r)
        set r2= R32(yc+r)
        call SetTerrainPathable(x,r1,t,b)
        call SetTerrainPathable(x,r2,t,b)
        set rel= r1
        set r= r2-r1
        //! runtextmacro Pathable_loopfill()
        set x= x+32.0
        if r3>r1 then
            set r= r3-r1
            set rel= r1
        else
            set r= r1-r3
            set rel= r3
        endif
        //! runtextmacro Pathable_loopfill()
            
        if r4>r2 then
            set r= r4-r2
            set rel= r2
        else
            set r= r2-r4
            set rel= r4
        endif
        //! runtextmacro Pathable_loopfill()
            
        return true
    endfunction

endlibrary
 

Attachments

  • LibraryPathable.w3x
    22.3 KB · Views: 117

Romek

Super Moderator
Reaction score
964
I think you should explain what this does and how to use it a bit more. :D
With examples.

Indeed it looks like it works in a simple way, though it also looks like it'd hit the op limit very easily (as you said). Maybe splitting it up, and using .execute would help with that.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
For the op limit i don't think someone will reach it, i mean i can't imagine the use of a big form.
But if i'm wrong and someone reach it (and use it :p), i will use .execute.
 

Romek

Super Moderator
Reaction score
964
I merged your explanation with the first post, it'd probably be better there.
Well, I think it's better to anticipate that people would use this for large areas.

Anyway, it seems quite useful. :)
 

Builder Bob

Live free or don't
Reaction score
249
How is the disk different from a circle? Does the circle function only change pathing at the circular outline?
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
yes it is, if i wasn't so bad to create nice effects i would already had submit a such spell ^^
Even if it could be very unbalanced :p
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • 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 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