package CreepRespawn
import LinkedList
import LinkedListModule
import TimerUtils
import MapBounds
import Table
player target = players[0] //respawns preplaces units by player red
real radius = 300
real respawnTime = 2
LinkedList<group> camps = new LinkedList<group>()
Table hash = new Table()
class Creep
use LinkedListModule
vec2 pos
angle a
integer id
unit creep
player p
LinkedList<Creep> camp
construct(unit u, LinkedList<Creep> memberOf)
creep = u
id = creep.getTypeId()
pos = creep.getPos()
a = creep.getFacingAngle()
p= creep.getOwner()
camp = memberOf
function onDeathFilter() returns boolean
return GetTriggerUnit().getOwner() == target
function isCampDead(LinkedList<Creep> camp) returns boolean
boolean check = true
for Creep c in camp
if(c.creep.isAlive())
check = false
break
return check
function unit.getCreep() returns Creep
Creep current = Creep.first
while(current.next != null and current.creep != this)
current = current.next
if(current.creep != this)
current = null
return current
function onDeath()
Creep c = GetTriggerUnit().getCreep()
if(isCampDead(c.camp))
timer t = getTimer()
hash.saveUnit(t.getHandleId(), c.creep)
t.start(respawnTime, function onExpire)
function onExpire()
timer t = GetExpiredTimer()
integer h = t.getHandleId()
unit u = hash.loadUnit(h)
Creep c = u.getCreep()
hash.flush()
t.release()
for creep in c.camp
creep.creep = createUnit(creep.p, creep.id, creep.pos, creep.a)
function onEnter()
unit u = GetTriggerUnit()
if(u.getOwner() == target and u.getCreep() == null)
location loc = GetUnitLoc(u)
group detected = GetUnitsInRangeOfLocAll(radius, loc)
for unit found in detected
Creep c = found.getCreep()
if(c != null)
c.camp.push(new Creep(u, c.camp))
break
function sortCreeps()
group targets = GetUnitsOfPlayerAll(target)
for unit first in targets
if(first.getCreep() == null)
location loc = GetUnitLoc(first)
group detected = GetUnitsInRangeOfLocAll(radius, loc)
LinkedList<Creep> camp = new LinkedList<Creep>()
for unit found in detected
if(found.getCreep() == null)
camp.push(new Creep(found, camp))
else
detected.removeUnit(found)
RemoveLocation(loc)
detected.destr()
targets.destr()
init
sortCreeps()
trigger t = CreateTrigger()
t.registerAnyUnitEvent(EVENT_PLAYER_UNIT_DEATH)
t.addCondition(Condition(function onDeathFilter))
t.addAction(function onDeath)
CreateTrigger()
..registerEnterRegion(playableMapRegion, null)
..addAction(function onEnter)