- Joined
- Apr 5, 2011
- Messages
- 245
There is a lot of unit indexers, but no markers found :/
Few words about this:
- Marker does not really register units, but only marks them
- Use GetUnitUserData to get unit state:
>0 - alive
=0 - dead
<0 - decaying)
- Marker recycles dead units periodically (each dead unit has minimum of RECYCLE_TIME before gets recycled)
Few words about this:
- Marker does not really register units, but only marks them
- Use GetUnitUserData to get unit state:
>0 - alive
=0 - dead
<0 - decaying)
- Marker recycles dead units periodically (each dead unit has minimum of RECYCLE_TIME before gets recycled)
JASS:
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//-=-=-=-] Supermarker [-=-=-=-
//-=-=-=-=-= v0.900 -=-=-=-=-=-
/*******************************************************
* function InitSupermarker takes nothing returns nothing
* (Starts supermarker wonderwork)
*******************************************************/
library Supermarker requires Support
//-=-=-=- Settings -=-=-=-
globals
private constant real RECYCLE_TIME = 20
//-=-=-=-==-=-=-=-=-=-=-=-
private trigger EnterTrigger = CreateTrigger()
private trigger DeathTrigger = CreateTrigger()
private integer IndexCount = 0
private integer FreeindexCount = 0
private integer array Freeindex
private group Bathroom = CreateGroup()
endglobals
private function Mark takes nothing returns boolean
set Support.workUnit = GetFilterUnit()
if FreeindexCount == 0 then
set IndexCount = IndexCount + 1
call SetUnitUserData(Support.workUnit, IndexCount)
else
set FreeindexCount = FreeindexCount - 1
call SetUnitUserData(Support.workUnit, Freeindex[FreeindexCount])
endif
return false
endfunction
private function Wash takes nothing returns boolean
call GroupAddUnit(Bathroom, GetTriggerUnit())
return false
endfunction
private function Grab takes nothing returns nothing
loop
set Support.workUnit = FirstOfGroup(Bathroom)
exitwhen Support.workUnit == null
set Support.workInteger = GetUnitUserData(Support.workUnit)
if Support.workInteger > 0 then
call SetUnitUserData(Support.workUnit, -Support.workInteger)
else
call GroupRemoveUnit(Bathroom, Support.workUnit)
set Support.workInteger = -Support.workInteger
if Support.workInteger == IndexCount then
set IndexCount = IndexCount - 1
endif
set Freeindex[FreeindexCount] = Support.workInteger
set FreeindexCount = FreeindexCount + 1
endif
endloop
endfunction
function InitSupermarker takes nothing returns nothing
local region R = CreateRegion()
set Support.workRect = GetWorldBounds()
call RegionAddRect(R, Support.workRect)
call GroupEnumUnitsInRect(Support.workGroup, Support.workRect, Condition(function Mark))
call TriggerRegisterEnterRegion(EnterTrigger, R, Condition(function Mark))
set R = null
//! runtextmacro TriggerRegisterAnyUnitEvent("DeathTrigger")
call TriggerAddCondition(DeathTrigger, Condition(function Wash))
call TimerStart(CreateTimer(), RECYCLE_TIME, true, function Grab)
endfunction
endlibrary
Last edited: