library IsWayWalkable initializer Init
// Is Way Walkable system by The_Witcher
//
// well it's a system that checks whether units can walk from a specific rect to another...
//
// FAQ:
// Thats useless!! everyone can let a unit run the way and check whether it reaches the finish or not!!
// - Yes but my system checks within max. 0.3 seconds and it uses no units!!
//
// OK maybe i will use it but for what?
// - Best use is for a TD. It would check whether the creeps can run from spawn to finish
// so you can check whether a player blocks or not...
//
// And how to use it?
// - well just use:
// call IsWayWalkable(spawn, finish) returns a boolean
// rect rect
//
// Ok, ok but how can I import your system??
// - one of the easiest things ever^^
// just copy this trigger in your map and you're done!!
//
// ----- do not edit anything below this line -----
globals
private real MINx
private real MAXx
private real MINy
private real MAXy
private real minx
private real maxx
private real miny
private real maxy
private integer array x
private integer array y
private integer total = 0
private hashtable h = InitHashtable()
private boolean checking = true
private item u
private trigger t = CreateTrigger()
endglobals
private function IsCoordPathable takes real xx, real yy returns boolean
local real xxx
local real yyy
call SetItemVisible(u,true)
call SetItemPosition(u,xx,yy)
set xxx = GetItemX( u ) - xx
set yyy = GetItemY( u ) - yy
call SetItemVisible(u,false)
if xxx < 1 and xxx > -1 and yyy < 1 and yyy > -1 then
return true
endif
return false
endfunction
private function InMapArea takes integer xx, integer yy returns boolean
return (MINx <= xx) and (xx <= MAXx) and (MINy <= yy) and (yy <= MAXy)
endfunction
private function InWinArea takes integer xx, integer yy returns boolean
return (minx <= xx) and (xx <= maxx) and (miny <= yy) and (yy <= maxy)
endfunction
private function IsRunable takes integer xx, integer yy returns boolean
return (not( LoadInteger(h,xx,yy) == 1) and InMapArea(xx,yy) and IsCoordPathable(xx,yy) and checking)
endfunction
private function Check takes nothing returns nothing
local integer AntiLeak = 0
loop
exitwhen total == -1 or checking == false
if InWinArea(x[0],y[0]) then
set checking = false
else
if IsRunable(x[0]+64,y[0]) and not(LoadInteger(h,x[0]+64,y[0]) == 2) then
set total = total + 1
set x[total] = x[0]+64
set y[total] = y[0]
call SaveInteger(h,x[0]+64,y[0],2)
endif
if IsRunable(x[0],y[0]+64) and not(LoadInteger(h,x[0],y[0]+64) == 2) then
set total = total + 1
set x[total] = x[0]
set y[total] = y[0]+64
call SaveInteger(h,x[0],y[0]+64,2)
endif
if IsRunable(x[0],y[0]-64) and not(LoadInteger(h,x[0],y[0]-64) == 2) then
set total = total + 1
set x[total] = x[0]
set y[total] = y[0]-64
call SaveInteger(h,x[0],y[0]-64,2)
endif
if IsRunable(x[0]-64,y[0]) and not(LoadInteger(h,x[0]-64,y[0]) == 2) then
set total = total + 1
set x[total] = x[0]-64
set y[total] = y[0]
call SaveInteger(h,x[0]-64,y[0],2)
endif
call SaveInteger(h,x[0],y[0],1)
loop
exitwhen total == -1 or IsRunable(x[0],y[0])
set x[0] = x[total]
set y[0] = y[total]
set total = total - 1
endloop
endif
set AntiLeak = AntiLeak+1
if AntiLeak > 150 then
call TriggerExecute(t)
set AntiLeak = 0
endif
endloop
endfunction
function IsWayWalkable takes rect spawn, rect finish returns boolean
local integer xx = R2I(GetRectCenterX(spawn))
local integer yy = R2I(GetRectCenterY(spawn))
set maxx = GetRectMaxX(finish)
set minx = GetRectMinX(finish)
set maxy = GetRectMaxY(finish)
set miny = GetRectMinY(finish)
set checking = true
set total = 0
call FlushParentHashtable(h)
set h = InitHashtable()
set x[total] = xx
set y[total] = yy
set total = total + 1
set x[total] = xx+64
set y[total] = yy
set total = total + 1
set x[total] = xx
set y[total] = yy+64
set total = total + 1
set x[total] = xx
set y[total] = yy-64
set total = total + 1
set x[total] = xx-64
set y[total] = yy
call Check()
return not checking
endfunction
private function Init takes nothing returns nothing
local rect r = GetPlayableMapRect()
set MINx = GetRectMinX(r)
set MAXx = GetRectMaxX(r)
set MINy = GetRectMinY(r)
set MAXy = GetRectMaxY(r)
set u = CreateItem( 'wolg', 0,0 )
call SetItemVisible(u,false)
call TriggerAddAction(t,function Check)
endfunction
endlibrary