- Joined
- Nov 18, 2007
- Messages
- 1,084
This snippet is intended to allow different unit-type dummy units to be recycled.
The documentation is inside the code. A test-map is also attached with a simple spell showing the recycling in action.
Additional Credits:
The documentation is inside the code. A test-map is also attached with a simple spell showing the recycling in action.
JASS:
//==========================================================================================
// DummyReuser v2.01 by watermelon_1234
//******************************************************************************************
// A textmacro for structs designed to reuse/recycle dummy units of any type.
//
// This is mostly aimed for reusing dummy units with models that can play multiple animations,
// allowing a specific animation to be played unlike special effects which can only play
// birth, standing, or death animations consistently.
//##########################################################################################
//
// Instructions:
// To first use this, you must declare some kind of struct. Once you've declared the struct,
// just add the following line:
//
// //! runtextmacro DummyReuser("DUMMY_UNIT_TYPEID")
//
// where DUMMY_UNIT_TYPEID is the unit-type id of the dummy.
//
// API:
// * static method get takes player owner, real x, real y, real facing returns unit *
// Returns a dummy unit that you can use for a player at map coordinates x and y.
// Note that facing is in degrees like CreateUnit.
//
// * static method release takes unit u returns nothing *
// Releases a dummy unit for recycling.
//
//##########################################################################################
//
// Importing:
// 1. Copy this trigger.
// 2. Configure the system to your liking
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Credits:
// - azlier for improvements on my earlier code
// - Bribe for more improvements
// - PurgeandFire111 for showing me how to make structs efficient, though it no longer applies
// - Anachron for CustomAura which gave me an idea to use a textmacro for this
//
//==========================================================================================
library DummyReuser
globals
// The owner for the dummy unit when it's in storage
private constant player DUMMY_STORAGE_OWNER = Player(15)
// Max number of dummies to be stored
private constant integer DUMMY_MAX_COUNT = 18
endglobals
//==========================================================================================
// END OF CONFIGURATION
//==========================================================================================
// Prepares a dummy unit for use and returns it
public function Get takes unit u, player owner, real x, real y, real facing returns unit
call SetUnitOwner(u, owner, true)
call SetUnitFacing(u, facing)
call PauseUnit(u, false)
call ShowUnit(u, true)
if UnitRemoveAbility(u, 'Aloc') then
call UnitAddAbility(u, 'Aloc')
endif
call SetUnitX(u, x)
call SetUnitY(u, y)
return u
endfunction
// Returns true if a dummy unit was stored
public function Store takes unit u, integer id, integer count returns boolean
// Safety check to prevent silly mistakes
if not IsUnitType(u, UNIT_TYPE_DEAD) and GetUnitTypeId(u) == id and count < DUMMY_MAX_COUNT then
call ShowUnit(u, false) // Using ShowUnit as that's the most consistent way of hiding any dummy unit
call SetUnitOwner(u, DUMMY_STORAGE_OWNER, false)
call PauseUnit(u, true)
return true
endif
debug call BJDebugMsg("DummyReuser: Removed dummy unit either due to max limit or wrong dummy unit")
call RemoveUnit(u)
return false
endfunction
endlibrary
//! textmacro DummyReuser takes DUMMY_UNIT_TYPEID
private static unit array dr_stack
private static integer dr_count = 0
static method get takes player owner, real x, real y, real facing returns unit
if dr_count == 0 then
return CreateUnit(owner, $DUMMY_UNIT_TYPEID$, x, y, facing)
endif
set dr_count = dr_count - 1 // The stack is zero-based
return DummyReuser_Get(dr_stack[dr_count], owner, x, y, facing)
endmethod
static method release takes unit u returns nothing
if DummyReuser_Store(u, $DUMMY_UNIT_TYPEID$, dr_count) then
set dr_stack[dr_count] = u
set dr_count = dr_count + 1
endif
endmethod
//! endtextmacro
v2.01
v2.00
v1.01b
v1.01a
v1.01
v1.00
- Made the textmacro produce less code
- No longer stores dummy in a different place
- Globals are no longer public
- Added constant that can specify a max number of dummy units that can be recycled
- Supports dummy units with Locust (again)
v2.00
- New way of getting and recycling dummy units.
- No longer supports dummy units that don't have Locust.
- Updated test map to use xemissile instead of xeprojectile.
- No longer uses UnitAlive.
v1.01b
- Used a more efficient way of allocating and deallocating the struct.
v1.01a
- No longer uses onDestroy.
- Macro uses static if for locust.
v1.01
- Changed system to template for structs recycling dummy units.
v1.00
- Released.
Additional Credits:
- Vexorian for xe system, TimerUtils, and BoundSentinel
- EotA by DarnYak whose spell inspired the test-map one.
Attachments
Last edited: