- Joined
- May 16, 2012
- Messages
- 644
Hey guys, so, in my map i've created a spawn system that spawns 5 units of a given type and then 5 more of another type at 8 different locations (center of regions), which i assinged to a region vector. I loop through them checking which types of units should spawn (like in X Hero Siege fo eg) code below:
As you can see, i've created i little function called "CreateNUnitsLoc()" to aid me in this task, because i didn't want to use CreateNUnitsAtLoc(), i think its a bad BJ that calls 3 more functions to spawn the units, and since i cant use CreateUnitAtLoc() to create more than 1 unit, i decided to create my own, with 2 less functions calls than the BJ one. code below:
Again, as you can see, i've created a local location to get rid of that nasty location leak and things were going well until i decided to go back in my Spawn code and do the same. i've create my locals to do so, but when i tried to do:
Only the first 5 units were being created. I realized that the leak was already being removed inside my "CreateNUnitsLoc()", finally, my question is: by removing the location leak at my created function, do i remove all the possible location leaks in my Spawn code?
JASS:
private function Actions takes nothing returns nothing
local integer i
local location c
set c = Location(GetRectCenterX(gg_rct_Castle), GetRectCenterY(gg_rct_Castle))
if ( udg_Race_Turn == 0 ) then
set i = 0
loop
exitwhen i > (udg_NumberOfPlayers_Integer - 1)
call CreateNUnitsLoc((5 * udg_Portal_Vector[i]), 'hfoo', Player(10), Location(GetRectCenterX(udg_Spawn_Region_Vector[i]), GetRectCenterY(udg_Spawn_Region_Vector[i])), 0.00)
call GroupPointOrderLoc(bj_lastCreatedGroup, "attack", c)
call CreateNUnitsLoc((5 * udg_Portal_Vector[i]), 'hrif', Player(11), Location(GetRectCenterX(udg_Spawn_Region_Vector[i]), GetRectCenterY(udg_Spawn_Region_Vector[i])), 0.00)
call GroupPointOrderLoc(bj_lastCreatedGroup, "attack", c)
set i = i + 1
endloop
set udg_Race_Turn = 1
else
if ( udg_Race_Turn == 1 ) then
set i = 0
loop
exitwhen i > ( udg_NumberOfPlayers_Integer - 1 )
call CreateNUnitsLoc((5 * udg_Portal_Vector[i]), 'ogru', Player(10), Location(GetRectCenterX(udg_Spawn_Region_Vector[i]), GetRectCenterY(udg_Spawn_Region_Vector[i])), 0.00)
call GroupPointOrderLoc(bj_lastCreatedGroup, "attack", c)
call CreateNUnitsLoc((5 * udg_Portal_Vector[i]), 'ohun', Player(11), Location(GetRectCenterX(udg_Spawn_Region_Vector[i]), GetRectCenterY(udg_Spawn_Region_Vector[i])), 0.00)
call GroupPointOrderLoc(bj_lastCreatedGroup, "attack", c)
set i = i + 1
endloop
set udg_Race_Turn = 2
else
if ( udg_Race_Turn == 2 ) then
set i = 0
loop
exitwhen i > ( udg_NumberOfPlayers_Integer - 1 )
call CreateNUnitsLoc((5 * udg_Portal_Vector[i]), 'ugho', Player(10), Location(GetRectCenterX(udg_Spawn_Region_Vector[i]), GetRectCenterY(udg_Spawn_Region_Vector[i])), 0.00)
call GroupPointOrderLoc(bj_lastCreatedGroup, "attack", c)
call CreateNUnitsLoc((5 * udg_Portal_Vector[i]), 'ucry', Player(11), Location(GetRectCenterX(udg_Spawn_Region_Vector[i]), GetRectCenterY(udg_Spawn_Region_Vector[i])), 0.00)
call GroupPointOrderLoc(bj_lastCreatedGroup, "attack", c)
set i = i + 1
endloop
set udg_Race_Turn = 3
else
if ( udg_Race_Turn == 3 ) then
set i = 0
loop
exitwhen i > ( udg_NumberOfPlayers_Integer - 1 )
call CreateNUnitsLoc((5 * udg_Portal_Vector[i]), 'esen', Player(10), Location(GetRectCenterX(udg_Spawn_Region_Vector[i]), GetRectCenterY(udg_Spawn_Region_Vector[i])), 0.00)
call GroupPointOrderLoc(bj_lastCreatedGroup, "attack", c)
call CreateNUnitsLoc((5 * udg_Portal_Vector[i]), 'earc', Player(11), Location(GetRectCenterX(udg_Spawn_Region_Vector[i]), GetRectCenterY(udg_Spawn_Region_Vector[i])), 0.00)
call GroupPointOrderLoc(bj_lastCreatedGroup, "attack", c)
set i = i + 1
endloop
set udg_Race_Turn = 0
else
endif
endif
endif
endif
call RemoveLocation(c)
set c = null
endfunction
As you can see, i've created i little function called "CreateNUnitsLoc()" to aid me in this task, because i didn't want to use CreateNUnitsAtLoc(), i think its a bad BJ that calls 3 more functions to spawn the units, and since i cant use CreateUnitAtLoc() to create more than 1 unit, i decided to create my own, with 2 less functions calls than the BJ one. code below:
JASS:
function CreateNUnitsLoc takes integer count, integer unitid, player whichPlayer, location whichLoc, real face returns group
local location l
call GroupClear(bj_lastCreatedGroup)
set l = whichLoc
loop
set count = count - 1
exitwhen count < 0
set bj_lastCreatedUnit = CreateUnitAtLoc(whichPlayer, unitid, l, face)
call RemoveGuardPosition(bj_lastCreatedUnit)
call GroupAddUnit(bj_lastCreatedGroup, bj_lastCreatedUnit)
endloop
call RemoveLocation(l)
set l = null
return bj_lastCreatedGroup
endfunction
Again, as you can see, i've created a local location to get rid of that nasty location leak and things were going well until i decided to go back in my Spawn code and do the same. i've create my locals to do so, but when i tried to do:
JASS:
local location l
local location c
local integer i
set c = Location(GetRectCenterX(gg_rct_Castle), GetRectCenterY(gg_rct_Castle))
if ( udg_Race_Turn == 0 ) then
set i = 0
loop
exitwhen i > (udg_NumberOfPlayers_Integer - 1)
set l = Location(GetRectCenterX(udg_Spawn_Region_Vector[i]), GetRectCenterY(udg_Spawn_Region_Vector[i]))
call CreateNUnitsLoc((5 * udg_Portal_Vector[i]), 'hfoo', Player(10), l, 0.00)
call GroupPointOrderLoc(bj_lastCreatedGroup, "attack", c)
call CreateNUnitsLoc((5 * udg_Portal_Vector[i]), 'hrif', Player(11), l, 0.00)
call GroupPointOrderLoc(bj_lastCreatedGroup, "attack", c)
call RemoveLocation(l)
set i = i + 1
endloop
set l = null
set udg_Race_Turn = 1
else
Only the first 5 units were being created. I realized that the leak was already being removed inside my "CreateNUnitsLoc()", finally, my question is: by removing the location leak at my created function, do i remove all the possible location leaks in my Spawn code?
Last edited: