- Joined
- May 26, 2017
- Messages
- 444
Hi!
I am not sure if the following code (from one of my AIs) leaks memory or not:
I am just curious about unit pointers. The created group is at least destroyed properly.
I am not sure if the following code (from one of my AIs) leaks memory or not:
JASS:
function AttackAssignment takes nothing returns nothing
local boolean AttackSuccess = false
local integer WaitTime1 = 240 + ((3 - difficulty) * 60) //Wait 6/5/4 minutes before the first attack on EASY/NORMAL/HARD
local integer WaitTime2 = 600 + ((3 - difficulty) * 60) //Wait 12/11/10 minutes before other attacks on EASY/NORMAL/HARD
local integer currentWaitLimit = 0
local integer wait_seconds = 0
local boolean LaunchAttack = false
local unit base = null
local integer greatDenCount = 0
local group g = null
local integer id
local unit u = null
loop
loop
//Wait until smg_custom_integer (in common.ai) is 1 and Player 1 has built Great Den
loop
set greatDenCount = GetPlayerUnitTypeCount(Player(0), GREAT_DEN)
exitwhen smg_custom_integer == 1 and greatDenCount > 0
call Sleep(5)
endloop
//Let's find the Great Den
set g = CreateGroup()
call GroupEnumUnitsOfPlayer(g, Player(0), null)
set u = FirstOfGroup(g)
loop
exitwhen u == null
set id = GetUnitTypeId(u)
if(id == GREAT_DEN) then
set base = u
endif
call GroupRemoveUnit(g, u)
set u = FirstOfGroup(g)
endloop
call DestroyGroup(g)
exitwhen base != null
call DebugText("Base is null")
call Sleep(5)
endloop
call DebugText("Attacking against base!")
//Let's wait WaitTime seconds before launching an attack
//We'll do this also before the first attack
set wait_seconds = 0
if attack_wave == 1 then
set currentWaitLimit = WaitTime1
else
set currentWaitLimit = WaitTime2
endif
loop
if ( HaveMinimumAttackers() and not CaptainRetreating() and not CaptainInCombat(true) and not TownThreatened()) then
if wait_seconds >= currentWaitLimit then
set LaunchAttack = true
else
//Wait WaitTime seconds before launching the attack
call Sleep( 3 )
set wait_seconds = wait_seconds + 3
call DebugText("Waited " + Int2Str(wait_seconds) + " seconds before attack. Needs to wait " + Int2Str(currentWaitLimit) + " seconds.")
endif
else
//Wait until the conditions have been satisfied
call Sleep( 3 )
call DebugText("Waited 3 seconds to have minimum attackers etc.")
endif
exitwhen LaunchAttack == true
endloop
//Reset the variable
set LaunchAttack = false
if base != null and UnitAlive(base) then
//Launch Attack
call PrepareAttackGroup( )
//Start building the next wave
set attack_wave = attack_wave + 1
call InitBuildArray()
call InitAssaultGroup()
call BuildPriorities()
//Attack target
set AttackSuccess = AttackPlayerBase(base)
endif
call Sleep(3)
endloop
endfunction
I am just curious about unit pointers. The created group is at least destroyed properly.