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.
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 :
will avoid walking unit to going in this rect.
xc -> the x coordinate of disk center.
yc -> the y coordinate of disk center
radius -> the radius of the disk
b -> same comments.
Exactly the same comments to the DiskPathing except this is a circle, not 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:
constant pathingtype PATHING_TYPE_ANY = ConvertPathingType(0)
constant pathingtype PATHING_TYPE_WALKABILITY = ConvertPathingType(1)
constant pathingtype PATHING_TYPE_FLYABILITY = ConvertPathingType(2)
constant pathingtype PATHING_TYPE_BUILDABILITY = ConvertPathingType(3)
constant pathingtype PATHING_TYPE_PEONHARVESTPATHING = ConvertPathingType(4)
constant pathingtype PATHING_TYPE_BLIGHTPATHING = ConvertPathingType(5)
constant pathingtype PATHING_TYPE_FLOATABILITY = ConvertPathingType(6)
constant pathingtype PATHING_TYPE_AMPHIBIOUSPATHING = ConvertPathingType(7)
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:
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