library WardsSystem uses HeroAI
globals
private constant integer ITEM_ID = 'I001'
private constant real RADIUS = 800
private hashtable ht = InitHashtable()
private real array obsX[8194]
private real array obsY[8194]
private integer MAX_OBS = 0
endglobals
private function Filt takes nothing returns boolean
return HaveSavedInteger(ht,GetUnitTypeId(GetFilterUnit()),0)
endfunction
function CheckWard takes unit hero, boolean move returns boolean
local unit obs
local real hx = GetUnitX(hero)
local real hy = GetUnitY(hero)
local boolean cast = false
local integer i = 0
local item it = GetItemOfTypeFromUnitBJ(hero,ITEM_ID)
if null != it then
loop
exitwhen i >= MAX_OBS
set obs = GetClosestUnitInRange(obsX[i],obsY[i],RADIUS,Filter(function Filt))
if null == obs then
set cast = UnitUseItemPoint(hero,it,obsX[i],obsY[i])
set i = MAX_OBS + 1
set it = null
set obs = null
return true
endif
set i = i + 1
endloop
endif
if move then
call IssuePointOrder(hero,"attack",hx + GetRandomReal(-HeroAI_MOVE_DIST, HeroAI_MOVE_DIST), hy + GetRandomReal(-HeroAI_MOVE_DIST, HeroAI_MOVE_DIST))
endif
set it = null
set obs = null
return false
endfunction
function RegisterWardPoints takes real x, real y returns nothing
set obsX[MAX_OBS] = x
set obsY[MAX_OBS] = y
set MAX_OBS = MAX_OBS + 1
endfunction
private module M
static method onInit takes nothing returns nothing
call SaveInteger(ht,'o003',0,1)
set obsX[MAX_OBS] = -601
set obsY[MAX_OBS] = -1719
set MAX_OBS = MAX_OBS + 1
endmethod
endmodule
private struct S extends array
implement M
endstruct
endlibrary