function CreepRespawn_CampLength takes nothing returns real
????return 500.0
endfunction
function CreepRespawn_WaitTime takes nothing returns real
????return 60.0
endfunction
function CreepRespawn takes nothing returns gamecache
????return InitGameCache("CreepRespawn.c")
endfunction
function CreepRespawn_H2I takes handle h returns integer
????return h
????return 0
endfunction
function CreepRespawn_GetCamp takes gamecache g, string k returns group
????return GetStoredInteger(g,k,"camp")
????return null
endfunction
function RespawnCreepCamp takes nothing returns nothing
????local unit u=GetTriggerUnit()
????local string k=I2S(CreepRespawn_H2I(u))
????local integer typeid = GetUnitTypeId(u)
????local gamecache g=CreepRespawn()
????local group camp=CreepRespawn_GetCamp(g,k)
????local real x=GetStoredReal(g,k,"sx")
????local real y=GetStoredReal(g,k,"sy")
????local real f=GetStoredReal(g,k,"sf")
????local rect r=bj_mapInitialPlayableArea
????if not( HaveStoredReal(g,k,"sx") ) then
????else
????????call GroupRemoveUnit(camp,u)
????????loop
????????????exitwhen FirstOfGroup(camp)==null
????????????call TriggerSleepAction(1)
????????endloop
????????call PolledWait(CreepRespawn_WaitTime())
????????if IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) then
????????????call SetUnitOwner( u, Player(1), false)
????????????call ReviveHero( u, x, y, true)
????????????call SetUnitOwner( u, Player(12), false)
????????????call GroupAddUnit(camp,u)
????????else
????????????call FlushStoredMission(g,k)
????????????set u=CreateUnit( Player(12), typeid, x,y,f )
????????????set k=I2S(CreepRespawn_H2I(u))
????????????call DestroyEffect( AddSpecialEffectTarget( "Abilities\\Spells\\Human\\MassTeleport\\MassTeleportCaster.mdl", u, "origin"))
????????????call StoreReal( g ,k,"sx", x )
????????????call StoreReal( g ,k,"sy", y )
????????????call StoreReal( g ,k,"sf", f )
????????????call StoreInteger(g,k,"camp",CreepRespawn_H2I(camp) )
????????????call GroupAddUnit(camp,u)
????????endif
????endif
????set camp=null
????set u=null
????set g=null
????set r=null
endfunction
function StartCreepCampRespawn_Filter takes nothing returns boolean
????return IsUnitOwnedByPlayer( GetFilterUnit(), Player(12) ) and IsUnitInGroup(GetFilterUnit(),bj_groupRemoveGroupDest)
endfunction
function StartCreepCampRespawn takes nothing returns trigger
????local trigger t = CreateTrigger()
????local gamecache g=CreepRespawn()
????local boolexpr B=Condition(function StartCreepCampRespawn_Filter)
????local group r=CreateGroup()
????local group aux=CreateGroup()
????local group aux2=CreateGroup()
????local group c
????local unit u
????local string k
????call GroupEnumUnitsOfPlayer(r,Player(12), null)
????set bj_groupRemoveGroupDest=r
????loop
????????set u=FirstOfGroup(r)
????????exitwhen u==null
????????call GroupRemoveUnit(r,u)
????????set c=CreateGroup()
????????set bj_groupAddGroupDest=c
????????call GroupClear(aux)
????????loop
????????????call GroupClear(aux2)
????????????call GroupEnumUnitsInRange(aux2,GetUnitX(u),GetUnitY(u),CreepRespawn_CampLength(),B)
????????????call GroupAddGroup(aux2,aux)
????????????call GroupRemoveUnit(aux,u)
????????????call GroupRemoveUnit(r,u)
????????????call GroupAddUnit(c,u)
????????????set k=I2S(CreepRespawn_H2I(u))
????????????call StoreReal( g ,k,"sx", GetUnitX(u) )
????????????call StoreReal( g ,k,"sy", GetUnitY(u) )
????????????call StoreReal( g ,k,"sf", GetUnitFacing(u) )
????????????call StoreInteger(g,k,"camp",CreepRespawn_H2I(c) )
????????????set u=FirstOfGroup(aux)
????????????exitwhen u==null
????????endloop
????endloop
????call DestroyGroup(r)
????call DestroyGroup(aux)
????call DestroyGroup(aux2)
????call DestroyBoolExpr(B)
????set B=null
????set r=null
????set aux=null
????set aux2=null
????call TriggerRegisterPlayerUnitEvent( t, Player(12), EVENT_PLAYER_UNIT_DEATH,null )
????call TriggerAddAction( t, function RespawnCreepCamp )
????return t
endfunction