- Joined
- Oct 17, 2013
- Messages
- 29
JASS:
library IndexSystem initializer Init
/*========================== Adds Index to units in the Map======================================*/
/*================API===========================================================================================*/
/*=============function IsUnitIndexed takes unit u returns boolean ====================================*/
/*============= -Tells Whether a unit is Indexed ====================================*/
/*============= ====================================*/
/*=============function GetIndexCount takes nothing returns integer ====================================*/
/*=============function GetUndexCount takes nothing returns integer ====================================*/
/*============= -Gets the Trigger Units Count ====================================*/
/*=============function IndexUnit takes unit u returns nothing ====================================*/
/*=============function IndexUnit takes unit u returns nothing ====================================*/
/*============= -Adds Index to the Unit ====================================*/
/*=============function UndexUnit takes unit u returns nothing ====================================*/
/*============= -Adds Undex to the Unit ====================================*/
/*============= -Undexed units won't be indexed ====================================*/
/*=============function DeUndexUnit takes unit u returns nothing ====================================*/
/*============= -Removes Undex to the Unit ====================================*/
/*============= -Be Sure to Remove the Display actions once done testing ====================================*/
/*============= Details not updated.(Later) ====================================*/
/*==============================================================================================================*/
/*==============================================================================================================*/
globals
private boolean array Indexed
private boolean array Dead
private boolean array Undexed
private group IndexUnits = null
endglobals
function IsUnitIndexed takes unit u returns boolean
return Indexed[GetUnitUserData(u)]
endfunction
function GetUnitIndex takes unit u returns integer
return GetUnitUserData(u)
endfunction
private function IndexCountTargets takes nothing returns boolean
return IsUnitAliveBJ(GetFilterUnit()) and Indexed[GetUnitIndex(GetFilterUnit())] and not Undexed[GetUnitIndex(GetFilterUnit())]
endfunction
function GetIndexCount takes nothing returns integer
local group g = GetUnitsInRectMatching(GetPlayableMapRect(),Condition(function IndexCountTargets))
local integer i = CountUnitsInGroup(g)
call DestroyGroup(g)
set g = null
return i
endfunction
private function UndexCountTargets takes nothing returns boolean
return IsUnitAliveBJ(GetFilterUnit()) and not Indexed[GetUnitIndex(GetFilterUnit())] and Undexed[GetUnitIndex(GetFilterUnit())]
endfunction
function GetUndexCount takes nothing returns integer
local group g = GetUnitsInRectMatching(GetPlayableMapRect(),Condition(function IndexCountTargets))
local integer i = CountUnitsInGroup(g)
call DestroyGroup(g)
set g = null
return i
endfunction
private function IndexTargets takes unit u returns boolean
return IsUnitAliveBJ(u) and not Indexed[GetUnitIndex(u)] and not Undexed[GetUnitIndex(u)]
endfunction
private function IndexCheckTargets takes nothing returns boolean
return Dead[GetUnitIndex(GetFilterUnit())]
endfunction
function IndexUnit takes unit u returns nothing
local boolean b = false
local integer i = GetIndexCount()
local integer Di = 0
loop
if Dead[i] == true then
set b = true
set Di = i
endif
exitwhen i == 0
set i = i - 1
endloop
if b == true then
call SetUnitUserData(u,Di)
set Dead[Di] = false
else
call SetUnitUserData(u,GetIndexCount() + 1)
endif
set Indexed[GetUnitIndex(u)] = true
//test
call DisplayTextToPlayer(Player(0),0.00,0.00,GetUnitName(u) + " = " + I2S(GetUnitIndex(u)) )
//test end
endfunction
private function IndexGroup takes nothing returns nothing
if IndexTargets(FirstOfGroup(IndexUnits)) then
call IndexUnit(FirstOfGroup(IndexUnits))
call GroupRemoveUnit(IndexUnits,FirstOfGroup(IndexUnits))
endif
endfunction
private function IndexAllUnits takes nothing returns nothing
set IndexUnits = GetUnitsInRectAll(GetPlayableMapRect())
call ForGroup(IndexUnits,function IndexGroup)
call DestroyGroup(IndexUnits)
set IndexUnits = null
endfunction
function DeUndexUnit takes unit u returns nothing
set Indexed[GetUnitIndex(u)] = false
set Undexed[GetUnitIndex(u)] = true
endfunction
function UndexUnit takes unit u returns nothing
set Indexed[GetUnitIndex(u)] = false
set Undexed[GetUnitIndex(u)] = true
endfunction
private function AddIndexEnteringUnit takes nothing returns nothing
if IndexTargets(GetEnteringUnit()) then
call IndexUnit(GetEnteringUnit())
endif
endfunction
private function RemoveIndex takes nothing returns nothing
set Indexed[GetUnitIndex(GetDyingUnit())] = false
set Dead[GetUnitIndex(GetDyingUnit())] = true
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterEnterRectSimple( t, bj_mapInitialPlayableArea )
call TriggerAddAction(t, function AddIndexEnteringUnit)
set t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddAction(t, function RemoveIndex)
call IndexAllUnits()
endfunction
endlibrary
-Need Suggestions.

.......
Attachments
Last edited by a moderator: