Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement