- Joined
- Apr 27, 2011
- Messages
- 272
I'll just leave this here to get some constructive criticisms.
JASS:
library DummyStack
//===========================================================================
// Dummy Stack by Alain.Mark
//
// -How to Use-
// *GetDummyId(u) - retrieves the assigned id of the dummy.
// *GetNewDummy(pl,x,y,f) - returns a new dummy to be used.
// *RecycleDummy(u)
//
//===========================================================================
globals
private integer I =-1
private integer Id=-1
private unit array StackedDummies
endglobals
//===========================================================================
private function Pop takes nothing returns unit
local integer i=I
local unit u
set u=StackedDummies[0]
set StackedDummies[0]=StackedDummies[i]
set I=i-1
return u
endfunction
//===========================================================================
private function Push takes unit u returns nothing
local integer i=I+1
set StackedDummies[i]=u
set I=i
endfunction
//===========================================================================
private function StackEmpty takes nothing returns boolean
return StackedDummies[0]==null
endfunction
//===========================================================================
private function IndexDummy takes unit u returns nothing
local integer i=Id+1
call SetUnitUserData(u,i)
set Id=i
endfunction
//===========================================================================
function GetDummyId takes unit u returns integer
return GetUnitUserData(u)
endfunction
//===========================================================================
function GetNewDummy takes player pl, real x, real y, real f returns unit
local unit u
if(StackEmpty())then
set u=CreateUnit(pl,SPELLCRAFT_DUMMY,x,y,f)
call IndexDummy(u)
else
set u=Pop()
call SetUnitOwner(u,pl,false)
call SetUnitX(u,x)
call SetUnitY(u,y)
call SetUnitFacing(u,f)
call PauseUnit(u,false)
endif
return u
endfunction
//===========================================================================
function RecycleDummy takes unit u returns nothing
call Push(u)
call SetUnitOwner(u,Player(15),false)
call PauseUnit(u,true)
endfunction
//===========================================================================
endlibrary
Last edited: