Fixed #517 - When detected set is empty, script fails when lasing is activated.

Now, when there is no target detected and lase is activated, the system
does not crash.
This commit is contained in:
FlightControl 2017-05-15 12:40:32 +02:00
parent 9053f99960
commit cc4a6a5f01

View File

@ -1611,29 +1611,33 @@ function SET_UNIT:ForEachUnitPerThreatLevel( FromThreatLevel, ToThreatLevel, Ite
local ThreatLevelSet = {} local ThreatLevelSet = {}
for UnitName, UnitObject in pairs( self.Set ) do if self:Count() ~= 0 then
local Unit = UnitObject -- Wrapper.Unit#UNIT for UnitName, UnitObject in pairs( self.Set ) do
local Unit = UnitObject -- Wrapper.Unit#UNIT
local ThreatLevel = Unit:GetThreatLevel()
ThreatLevelSet[ThreatLevel] = ThreatLevelSet[ThreatLevel] or {} local ThreatLevel = Unit:GetThreatLevel()
ThreatLevelSet[ThreatLevel].Set = ThreatLevelSet[ThreatLevel].Set or {} ThreatLevelSet[ThreatLevel] = ThreatLevelSet[ThreatLevel] or {}
ThreatLevelSet[ThreatLevel].Set[UnitName] = UnitObject ThreatLevelSet[ThreatLevel].Set = ThreatLevelSet[ThreatLevel].Set or {}
self:E( { ThreatLevel = ThreatLevel, ThreatLevelSet = ThreatLevelSet[ThreatLevel].Set } ) ThreatLevelSet[ThreatLevel].Set[UnitName] = UnitObject
end self:E( { ThreatLevel = ThreatLevel, ThreatLevelSet = ThreatLevelSet[ThreatLevel].Set } )
end
local ThreatLevelIncrement = FromThreatLevel <= ToThreatLevel and 1 or -1
local ThreatLevelIncrement = FromThreatLevel <= ToThreatLevel and 1 or -1
for ThreatLevel = FromThreatLevel, ToThreatLevel, ThreatLevelIncrement do
self:E( { ThreatLevel = ThreatLevel } ) for ThreatLevel = FromThreatLevel, ToThreatLevel, ThreatLevelIncrement do
local ThreatLevelItem = ThreatLevelSet[ThreatLevel] self:E( { ThreatLevel = ThreatLevel } )
if ThreatLevelItem then local ThreatLevelItem = ThreatLevelSet[ThreatLevel]
self:ForEach( IteratorFunction, arg, ThreatLevelItem.Set ) if ThreatLevelItem then
self:ForEach( IteratorFunction, arg, ThreatLevelItem.Set )
end
end end
end end
return self return self
end end
--- Iterate the SET_UNIT and call an iterator function for each **alive** UNIT presence completely in a @{Zone}, providing the UNIT and optional parameters to the called function. --- Iterate the SET_UNIT and call an iterator function for each **alive** UNIT presence completely in a @{Zone}, providing the UNIT and optional parameters to the called function.
-- @param #SET_UNIT self -- @param #SET_UNIT self
-- @param Core.Zone#ZONE ZoneObject The Zone to be tested for. -- @param Core.Zone#ZONE ZoneObject The Zone to be tested for.