| 04-11-2009, 02:08 PM | #1 |
So I'm making a map heavily based on dummy units. I want to keep the amount of dummies constant so the game won't get sudden shocks of shitloads of dummies being created. Now, I know xe has a dummy recycler, and I know moyack made one, but I'd like to make my own. So therefore I'm asking you: what would be the most efficient and overall the best way to recycle dummy units? My idea was to create maybe like 500 dummy units at map init and then create a function to return the unit... bla bla, let me illustrate it: JASS:library DummyUtils initializer Init globals private constant integer DUMMY_CODE = 'hdum' //* Raw code of the dummy unit private constant integer HEIGHT_ENABLER = 'Amrf' //* Raw code of Medivh's Raven Form ability private constant integer INITIALIZED_DUMMIES = 500 //* Number of initialized dummy units private constant location CREATION_LOC = Location(3250, -3300) //* Location on the map to create the dummies private constant player OWNING_PLAYER = Player(15) //* Owner of the dummies private constant integer OFFSET = 0x100000 //* H2I - OFFSET private unit array Dummy private boolean array InUse private integer DummyCount = 0 endglobals private function H2I takes handle h returns integer return h return 0 endfunction function CreateDummy takes player p, real x, real y, real f returns unit local integer i = H2I(Dummy[DummyCount]) - OFFSET set DummyCount = DummyCount + 1 if not InUse[i] then call SetUnitOwner(Dummy[i], p, true) call SetUnitX(Dummy[i], x) call SetUnitY(Dummy[i], y) call SetUnitFacing(Dummy[i], f) call ShowUnit(Dummy[i], true) set InUse[i] = true return Dummy[i] else set DummyCount = DummyCount - 1 debug call BJDebugMsg("Warning: something has certainly fucked up") return null endif if i > INITIALIZED_DUMMIES then debug call BJDebugMsg("Warning: number of used dummies exceeded the number of initialized dummy units - creating new dummy unit") set Dummy[i] = CreateUnit(p, DUMMY_CODE, x, y, f) call UnitAddAbility(Dummy[i], HEIGHT_ENABLER) call UnitRemoveAbility(Dummy[i], HEIGHT_ENABLER) set InUse[i] = true return Dummy[i] endif return null endfunction function RemoveDummy takes unit u returns nothing local integer i = H2I(u) - OFFSET if InUse[i] then set DummyCount = i call SetUnitOwner(u, OWNING_PLAYER, false) call SetUnitPositionLoc(u, CREATION_LOC) call ShowUnit(u, false) set InUse[i] = false else debug call BJDebugMsg("Warning: the dummy is either already removed, has never been created or hasn't been created through the use of CreateDummy") endif endfunction private function Init takes nothing returns nothing local integer i = 0 loop exitwhen i == INITIALIZED_DUMMIES + 1 set Dummy[i] = CreateUnitAtLoc(OWNING_PLAYER, DUMMY_CODE, CREATION_LOC, 0) call UnitAddAbility(Dummy[i], HEIGHT_ENABLER) call UnitRemoveAbility(Dummy[i], HEIGHT_ENABLER) call ShowUnit(Dummy[i], false) set InUse[i] = false set i = i + 1 endloop endfunction endlibrary Will that work? If not, any help? |
| 04-11-2009, 02:26 PM | #2 |
take a look at xe's xecast or xefx... |
| 04-11-2009, 02:31 PM | #3 | |
Quote:
I did, didn't really help me. |
| 04-11-2009, 02:33 PM | #4 |
What are you going to do with the dummies? Missile system - stack, create if stack empty, linked list Cast without DoT - single caster Cast with DoT - caster for each player |
| 04-11-2009, 02:47 PM | #5 | |
Quote:
Most of them are just used as projectiles, but some of them (very few) are used as dummies for 'attaching' lightning to and some for facing (SetUnitLookAt) |
| 04-12-2009, 08:39 PM | #6 |
So called a dummy recycling system...I made one, thats very easy weesy to use ;) JASS:library Dummy globals private group F = CreateGroup() private group All = CreateGroup() unit TEMP_DUMMY endglobals function ReleaseDummy takes unit u returns nothing if IsUnitInGroup(u,All) and GetUnitAbilityLevel(u,'Aloc') < 0 then call SetUnitScale(u,1,1,1) call SetUnitVertexColor(u,255,255,255,0) call GroupAddUnit(F,u) call ShowUnit(u,false) return endif call ShowUnit(u,false) call SetUnitExploded(u,true) call KillUnit(u) endfunction function CreateDummy takes real x, real y, player p returns unit local unit u = FirstOfGroup(F) if u == null then set u = CreateUnit(p,DummyId,x,y,0) call GroupAddUnit(All,u) else call GroupRemoveUnit(F,u) call ShowUnit(u,true) call SetUnitX(u,x) call SetUnitY(u,y) call SetUnitOwner(u,p,true) endif return u endfunction endlibrary It uses a similar algorithm to all other recycling systems like TimerUtils, but with the postivie thing called group ;) mybe, i have to add something like a group refresher or so^^ and mybe some day, I'll gotta add a function which checks if the released dummy is still a usable dummy ;) to cusomize it a bit^^ Greez |
