afisakov
You can change this now in User CP.
- Reaction score
- 37
My tower defense map starts encountering serious lag toward end of game, and I cannot tell f from memory leaks or just because of shear # of towers. This does not happen on easy mode so I doubt it is from enemy spawn or pathing triggers.
This trigger intended to deal damage in 2 areas (full and half radius) to target attacked by tower, and runs very often so I want to make sure it is leak-proof.
I removed some redundancies to make it easier to see and cleaned up all the leaks I knew of.
The part I am most worried about is
needed to prevent domino-effect of wiping out a wave because trigger-damage kill does not use up unit attack- resulting in instant re-attack
This trigger intended to deal damage in 2 areas (full and half radius) to target attacked by tower, and runs very often so I want to make sure it is leak-proof.
I removed some redundancies to make it easier to see and cleaned up all the leaks I knew of.
Code:
function CD_atk takes unit u returns nothing
call GroupAddUnitSimple(u, udg_CoolingDown)
call PolledWait(0.3)
call GroupRemoveUnitSimple(u, udg_CoolingDown)
endfunction
function Trig_Thunder_Conditions takes nothing returns boolean
local integer uid=GetUnitTypeId(GetAttacker())
local integer Lp1=1
if IsUnitInGroup(GetAttacker(),udg_CoolingDown) then
return false
endif
loop
exitwhen Lp1>15
if uid == udg_Dmg_tower[Lp1] then
return true
endif
set Lp1=Lp1+1
endloop
return false
endfunction
function gendenemy takes nothing returns boolean
if IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(udg_attacker)) and GetUnitState(GetFilterUnit(),UNIT_STATE_LIFE)>0.405 then
call UnitDamageTarget(udg_attacker,GetFilterUnit(),udg_damage,true,false,udg_atktype,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
endif
return false
endfunction
function Trig_Thunder_Actions takes nothing returns nothing
local location tp1
local group tg
local real cx
local integer uid
local integer pn
set udg_attacker=GetAttacker()
set uid=GetUnitTypeId(GetAttacker())
set pn=1+GetPlayerId(GetOwningPlayer(udg_attacker))
set tp1=GetUnitLoc(GetTriggerUnit())
if ( uid == 'o00K' ) then
set udg_damage=GetRandomInt(200,550)*udg_abp[pn]
set cx=120*udg_abp[pn]
set udg_atktype = ATTACK_TYPE_PIERCE
elseif ( uid == 'o01G' ) then
set udg_damage=2000*udg_abp[pn]
set cx=300*udg_abp[pn]
set udg_atktype = ATTACK_TYPE_CHAOS
call AddSpecialEffectLocBJ( tp1, "Abilities\\Spells\\Undead\\AnimateDead\\AnimateDeadTarget.mdl" )
call DestroyEffect(GetLastCreatedEffectBJ())
-more elseif's of similar type
endif
if (GetUnitAbilityLevel(udg_attacker,'B00B')>0) then
set udg_damage=udg_damage*1.5*udg_abp[pn]
endif
set tg=GetUnitsInRangeOfLocMatching(cx*2.,tp1,Condition(function gendenemy))
call DestroyGroup(tg)
set tg=GetUnitsInRangeOfLocMatching(cx,tp1,Condition(function gendenemy))
call DestroyGroup(tg)
call RemoveLocation (tp1)
call CD_atk(GetAttacker())
set udg_attacker=null
set tg=null
set tp1=null
endfunction
//===========================================================================
function InitTrig_Thunder takes nothing returns nothing
set gg_trg_Thunder = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( gg_trg_Thunder, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddCondition( gg_trg_Thunder, Condition(function Trig_Thunder_Conditions) )
call TriggerAddAction( gg_trg_Thunder, function Trig_Thunder_Actions )
endfunction
Code:
function CD_atk takes unit u returns nothing
call GroupAddUnitSimple(u, udg_CoolingDown)
call PolledWait(0.3)
call GroupRemoveUnitSimple(u, udg_CoolingDown)
endfunction