function Trig_Unit_Dies_Conditions takes nothing returns boolean
return GetUnitUserData(GetTriggerUnit())>0
endfunction
function Trig_Unit_Dies_DeathDamage takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer TimerId = GetTimerId(t)
local unit U = udg_AV_Units[TimerId]
local integer Class = GetUnitClass(U)
local real X = GetUnitX(U)
local real Y = GetUnitY(U)
call MoveLocation(udg_tempLoc,X,Y)
call DoAOEDamage(U, GetOwningPlayer(U), udg_classDeathDmg[Class], udg_classDeathDmgAOE[Class], X, Y, GetUnitFlyHeight(U)+GetLocationZ(udg_tempLoc)+udg_classCollisionZOffset[Class], false,0)
call ReleaseTimer(t)
set U = null
endfunction
function Trig_Unit_Dies_RemovePlatform takes unit U returns nothing
local integer Id = GetUnitUserData(U)
local group G
local unit EnumU
local integer EnumId
local real X = GetUnitX(U)
local real Y = GetUnitY(U)
local real EnumX
local real EnumY
local real ZBefore
local boolean wasStackBase
local real ZAfter
local integer Squares
call MoveLocation(udg_tempLoc,X,Y)
set ZBefore = GetLocationZ(udg_tempLoc)
call RemoveDestructable(udg_unitLinkedDestructable[Id])
set udg_unitLinkedDestructable[Id] = null
call SetRect(udg_tempRect,X-256,Y-256,X+256,Y+256)
call UpdateTerrainPathing(udg_tempRect,false)
call MoveLocation(udg_tempLoc,X,Y)
set ZAfter = GetLocationZ(udg_tempLoc)
set wasStackBase = ZBefore<=ZAfter+.1
set G = NewGroup()
call GroupEnumUnitsInRect(G,udg_tempRect,null)
loop
set EnumU = FirstOfGroup(G)
exitwhen EnumU==null
if IsUnitType(EnumU, UNIT_TYPE_STRUCTURE)==true then
set EnumId = GetUnitUserData(EnumU)
if EnumId>0 then
set EnumX = GetUnitX(EnumU)
set EnumY = GetUnitY(EnumU)
set Squares = udg_classBuildingSquares[udg_unitClass[EnumId]]
if GetUnitTypeId(EnumU)=='h034' then
if wasStackBase and RAbsBJ(EnumX-X)-160<Squares*32. and RAbsBJ(EnumY-Y)-160<Squares*32. then
call KillUnit(EnumU)
endif
elseif not IsTerrainBlockPathable(EnumX-Squares*32.,EnumY-Squares*32.,EnumX+Squares*32.,EnumY+Squares*32.) then
call KillUnit(EnumU)
else
call SetUnitPosition(EnumU,X,Y)
endif
endif
endif
call GroupRemoveUnit(G,EnumU)
endloop
call ReleaseGroup(G)
endfunction
function Trig_Unit_Dies_Actions takes nothing returns nothing
local timer t
local unit U = GetTriggerUnit()
local player p = GetOwningPlayer(U)
local integer i = GetPlayerId(p)
local integer Id = GetUnitUserData(U)
local integer Class = udg_unitClass[Id]
local unit EnumUnit
local real SpeedX = udg_unitSpeedX[Id]
local real SpeedY = udg_unitSpeedY[Id]
local real SpeedZ = udg_unitSpeedZ[Id]
local real X = GetUnitX(U)
local real Y = GetUnitY(U)
local boolean Constructed = udg_unitConstructionState[Id]>10
local integer TransportId
local effect E = null
call UnitAddKill(udg_DamageSource)
call SetUnitInGroup(U,udg_groupAutoFire,false)
call SetUnitInGroup(U,udg_groupRessOnlyIncome,false)
call SetUnitInGroup(U,udg_groupRessIncomeWithFee,false)
call SetUnitInGroup(U,udg_groupRessUpgradeAndTrain,false)
call SetUnitInGroup(U,udg_groupRessUse,false)
call SetUnitInGroup(U,udg_groupMeasureSpeed,false)
call SetUnitInGroup(U,udg_groupCapturedUnits,false)
call SetUnitInGroup(U,udg_groupBigColliders,false)
set udg_unitCaptureState[Id] = 0
if udg_unitCaptureTag[Id]!=null then
call DestroyTextTag(udg_unitCaptureTag[Id])
set udg_unitCaptureTag[Id] = null
endif
if udg_unitTransportedUnits[Id]!=null then
loop
set EnumUnit = FirstOfGroup(udg_unitTransportedUnits[Id])
exitwhen EnumUnit==null
set udg_unitTransportedBy[GetUnitUserData(EnumUnit)] = null
call GroupRemoveUnit(udg_unitTransportedUnits[Id],EnumUnit)
endloop
call ReleaseGroup(udg_unitTransportedUnits[Id])
set udg_unitTransportedUnits[Id] = null
endif
if udg_unitTransportedBy[Id]!=null then
set TransportId = GetUnitUserData(udg_unitTransportedBy[Id])
if udg_unitTransportedUnits[TransportId]!=null then
call GroupRemoveUnit(udg_unitTransportedUnits[TransportId], U)
if FirstOfGroup(udg_unitTransportedUnits[TransportId])==null then
call ReleaseGroup(udg_unitTransportedUnits[TransportId])
set udg_unitTransportedUnits[TransportId] = null
endif
endif
set udg_unitTransportedBy[Id] = null
call GroupRemoveUnit(udg_groupTransportedUnits, U)
endif
if udg_unitSupporters[Id]!=null then
loop
set EnumUnit = FirstOfGroup(udg_unitSupporters[Id])
exitwhen EnumUnit==null
set udg_unitSupportsUnit[GetUnitUserData(EnumUnit)] = null
call GroupRemoveUnit(udg_unitSupporters[Id],EnumUnit)
endloop
call ReleaseGroup(udg_unitSupporters[Id])
set udg_unitSupporters[Id] = null
endif
if udg_unitUsedMass[Id]!=0 then
set udg_playerMass[i] = udg_playerMass[i]+udg_unitUsedMass[Id]
endif
if udg_unitUsedEnergy[Id]!=0 then
set udg_playerEnergy[i] = udg_playerEnergy[i]+udg_unitUsedEnergy[Id]
endif
set udg_unitProducesUnitState[Id] = 0
set udg_unitRangeDisplay[Id]=false
set udg_unitEcoDisplay[Id]=false
if GetUnitAbilityLevel(U,'Apiv')!=0 then
call UnitRemoveAbility(U,'Apiv')
call SetUnitInGroup(U,udg_groupStealth,false)
endif
if udg_unitLinkedDestructable[Id]!=null then
call Trig_Unit_Dies_RemovePlatform(U)
endif
call UnitRefreshColor(U)
call UnitRemoveWeapons(Id)
set udg_unitStackN=udg_unitStackN+1
set udg_unitStack[udg_unitStackN] = Id
call SetUnitUserData(U,0)
call DisableShield(U)
if UnitProvidesAdjecency(U) then
set udg_calculateAdjecency = true
endif
if udg_classStorageMass[Class]!=0 or udg_classStorageEnergy[Class]!=0 then
set udg_calculateRessourceCaps = true
endif
set i = 0
loop
exitwhen i > 5
if UnitItemInSlot(U,i)!=null then
call RemoveItem(UnitItemInSlot(U,i))
endif
set i = i + 1
endloop
if Constructed then
if GetUnitTypeId(U)=='H00C' then
call MoveLocation(udg_tempLoc,X,Y)
call Nuke(U,p,X,Y,GetUnitFlyHeight(U)+GetLocationZ(udg_tempLoc)+200,3500,2500)
elseif GetUnitTypeId(U)=='h01L' then
call MoveLocation(udg_tempLoc,X,Y)
call Nuke(U,p,X,Y,GetUnitFlyHeight(U)+GetLocationZ(udg_tempLoc)+200,1000,2500)
elseif GetUnitTypeId(U)=='h020' then
call MoveLocation(udg_tempLoc,X,Y)
call Nuke(U,p,X,Y,GetUnitFlyHeight(U)+GetLocationZ(udg_tempLoc)+200,35000,2500)
endif
endif
if GetUnitFlyHeight(U)>100 then
call AirCrash(U,SpeedX,SpeedY,SpeedZ)
call AddScaledEffectWithFlyHeight("war3mapImported\\Flash2.mdx",udg_classCollisionRadius[Class]/128,X,Y,GetUnitFlyHeight(U)+udg_classCollisionZOffset[Class])
else
if udg_classDeathDmgAOE[Class]>0 then
call MoveLocation(udg_tempLoc,X,Y)
if udg_classBigExplosion[Class] then
call CreateExplosionEffect(X,Y,GetUnitFlyHeight(U)+udg_classCollisionZOffset[Class]+GetLocationZ(udg_tempLoc),udg_classDeathDmgAOE[Class])
endif
if Constructed and udg_classDeathDmg[Class]!=0 then
set t = NewTimer()
set udg_AV_Units[GetTimerId(t)] = U
call TimerStart(t,0.4,false,function Trig_Unit_Dies_DeathDamage)
endif
endif
call MoveLocation(udg_tempLoc,X,Y)
if GetRandomInt(0,2)==0 and GetLocationZ(udg_tempLoc)>udg_waterHeight then
if GetRandomReal(.4,1)*udg_classCollisionRadius[Class]<50 then
set E = AddSpecialEffect("Environment\\SmallBuildingFire\\SmallBuildingFire2.mdl",X,Y)
else
set E = AddSpecialEffect("Environment\\LargeBuildingFire\\LargeBuildingFire2.mdl",X,Y)
endif
endif
endif
if GetUnitTypeId(U)=='h036' then
call ShowUnit(U,false)
endif
set U = null
call CheckPlayerDefeat(p,X,Y)
if E!=null then
call TriggerSleepAction( GetRandomReal(1,3) )
call DestroyEffect(E)
set E = null
endif
endfunction
//===========================================================================
function InitTrig_Unit_Dies takes nothing returns nothing
set gg_trg_Unit_Dies = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Unit_Dies, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( gg_trg_Unit_Dies, Condition( function Trig_Unit_Dies_Conditions ) )
call TriggerAddAction( gg_trg_Unit_Dies, function Trig_Unit_Dies_Actions )
endfunction