Name | Type | is_array | initial_value |
happy | boolean | No | true |
p | location | No |
//TESH.scrollpos=0
//TESH.alwaysfold=0
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
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_test_Actions takes nothing returns nothing
if IsWayWalkable(gg_rct_Start,gg_rct_Finish) then
call DisplayTimedTextToPlayer(Player(0),0,0,1,"Everything is ok. You aren't blocking!!")
else
call DisplayTimedTextToPlayer(Player(0),0,0,1,"You are blocking!!")
endif
endfunction
//===========================================================================
function InitTrig_Player_tests takes nothing returns nothing
set gg_trg_Player_tests = CreateTrigger( )
call TriggerRegisterPlayerEventEndCinematic( gg_trg_Player_tests, Player(0) )
call TriggerAddAction( gg_trg_Player_tests, function Trig_test_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_Units_Actions takes nothing returns nothing
local unit u
local location p = GetRectCenter(gg_rct_Finish)
if IsWayWalkable(gg_rct_Start,gg_rct_Finish) or not udg_happy then
set u = CreateUnit( Player(8), 'hfoo', GetRectCenterX(gg_rct_Start),GetRectCenterY(gg_rct_Start), bj_UNIT_FACING )
call IssuePointOrderLoc( u, "attack", p )
else
set udg_happy = false
call DisplayTimedTextToPlayer(Player(0),0,0,3,"You blocked the way of the army!! Now they will slaughter your people!")
call SetPlayerAllianceStateBJ( Player(8), Player(1), bj_ALLIANCE_UNALLIED )
set u = CreateUnit( Player(8), 'hfoo', GetRectCenterX(gg_rct_Start),GetRectCenterY(gg_rct_Start), bj_UNIT_FACING )
call IssuePointOrderLoc( u, "attack", p )
set u = CreateUnit( Player(8), 'hfoo', GetRectCenterX(gg_rct_Start),GetRectCenterY(gg_rct_Start), bj_UNIT_FACING )
call IssuePointOrderLoc( u, "attack", p )
set u = CreateUnit( Player(8), 'hfoo', GetRectCenterX(gg_rct_Start),GetRectCenterY(gg_rct_Start), bj_UNIT_FACING )
call IssuePointOrderLoc( u, "attack", p )
set u = CreateUnit( Player(8), 'hfoo', GetRectCenterX(gg_rct_Start),GetRectCenterY(gg_rct_Start), bj_UNIT_FACING )
call IssuePointOrderLoc( u, "attack", p )
set u = CreateUnit( Player(8), 'hfoo', GetRectCenterX(gg_rct_Start),GetRectCenterY(gg_rct_Start), bj_UNIT_FACING )
call IssuePointOrderLoc( u, "attack", p )
set u = CreateUnit( Player(8), 'hfoo', GetRectCenterX(gg_rct_Start),GetRectCenterY(gg_rct_Start), bj_UNIT_FACING )
call IssuePointOrderLoc( u, "attack", p )
set u = CreateUnit( Player(8), 'hfoo', GetRectCenterX(gg_rct_Start),GetRectCenterY(gg_rct_Start), bj_UNIT_FACING )
call IssuePointOrderLoc( u, "attack", p )
set u = CreateUnit( Player(8), 'hfoo', GetRectCenterX(gg_rct_Start),GetRectCenterY(gg_rct_Start), bj_UNIT_FACING )
call IssuePointOrderLoc( u, "attack", p )
set u = CreateUnit( Player(8), 'hfoo', GetRectCenterX(gg_rct_Start),GetRectCenterY(gg_rct_Start), bj_UNIT_FACING )
call IssuePointOrderLoc( u, "attack", p )
set u = CreateUnit( Player(8), 'hfoo', GetRectCenterX(gg_rct_Start),GetRectCenterY(gg_rct_Start), bj_UNIT_FACING )
call IssuePointOrderLoc( u, "attack", p )
call EnableTrigger(gg_trg_Army_is_happy)
endif
call RemoveLocation(p)
set p = null
set u = null
endfunction
//===========================================================================
function InitTrig_Spawn_the_army takes nothing returns nothing
set gg_trg_Spawn_the_army = CreateTrigger( )
call TriggerRegisterTimerEventPeriodic( gg_trg_Spawn_the_army, 5.00 )
call TriggerAddAction( gg_trg_Spawn_the_army, function Trig_Units_Actions )
endfunction