From a0befeb34f9c068a507a6bbd807c6bc6eab34fa5 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Tue, 11 Jul 2017 16:20:15 +0200 Subject: [PATCH] Fixed a bug in the removal of GROUP objects in SET_GROUP Upon a DEAD or CRASH event processing in a SET_GROUP, the GROUP object would be removed regardless of how many UNITs are still in the GROUP object. The fix is that upon a DEAD or CRASH event in a SET_GROUP, it will be checked if there is only one UNIT left in the GROUP, and only then the GROUP will be removed from the SET_GROUP. --- Moose Development/Moose/Core/Set.lua | 17 +++++++++++++++++ Moose Mission Setup/Moose.lua | 19 ++++++++++++++++++- Moose.lua | 21 +++++++++++++++++++-- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index a5dbf70a1..f67ca53af 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -871,6 +871,23 @@ function SET_GROUP:FilterStart() return self end +--- Handles the OnDead or OnCrash event for alive groups set. +-- Note: The GROUP object in the SET_GROUP collection will only be removed if the last unit is destroyed of the GROUP. +-- @param #SET_GROUP self +-- @param Core.Event#EVENTDATA Event +function SET_GROUP:_EventOnDeadOrCrash( Event ) + self:F3( { Event } ) + + if Event.IniDCSUnit then + local ObjectName, Object = self:FindInDatabase( Event ) + if ObjectName then + if Event.IniDCSGroup:getSize() == 1 then -- Only remove if the last unit of the group was destroyed. + self:Remove( ObjectName ) + end + end + end +end + --- Handles the Database to check on an event (birth) that the Object was added in the Database. -- This is required, because sometimes the _DATABASE birth event gets called later than the SET_BASE birth event! -- @param #SET_GROUP self diff --git a/Moose Mission Setup/Moose.lua b/Moose Mission Setup/Moose.lua index fae94236f..36ac8aa6c 100644 --- a/Moose Mission Setup/Moose.lua +++ b/Moose Mission Setup/Moose.lua @@ -1,5 +1,5 @@ env.info( '*** MOOSE STATIC INCLUDE START *** ' ) -env.info( 'Moose Generation Timestamp: 20170618_0858' ) +env.info( 'Moose Generation Timestamp: 20170711_1616' ) --- Various routines -- @module routines @@ -9278,6 +9278,23 @@ function SET_GROUP:FilterStart() return self end +--- Handles the OnDead or OnCrash event for alive groups set. +-- Note: The GROUP object in the SET_GROUP collection will only be removed if the last unit is destroyed of the GROUP. +-- @param #SET_GROUP self +-- @param Core.Event#EVENTDATA Event +function SET_GROUP:_EventOnDeadOrCrash( Event ) + self:F3( { Event } ) + + if Event.IniDCSUnit then + local ObjectName, Object = self:FindInDatabase( Event ) + if ObjectName then + if Event.IniDCSGroup:getSize() == 1 then -- Only remove if the last unit of the group was destroyed. + self:Remove( ObjectName ) + end + end + end +end + --- Handles the Database to check on an event (birth) that the Object was added in the Database. -- This is required, because sometimes the _DATABASE birth event gets called later than the SET_BASE birth event! -- @param #SET_GROUP self diff --git a/Moose.lua b/Moose.lua index e39cd3f7a..36ac8aa6c 100644 --- a/Moose.lua +++ b/Moose.lua @@ -1,5 +1,5 @@ env.info( '*** MOOSE STATIC INCLUDE START *** ' ) -env.info( 'Moose Generation Timestamp: 20170518_2056' ) +env.info( 'Moose Generation Timestamp: 20170711_1616' ) --- Various routines -- @module routines @@ -5070,7 +5070,7 @@ function EVENT:onEvent( Event ) Event.IniUnitName = Event.IniDCSUnitName Event.IniUnit = SCENERY:Register( Event.IniDCSUnitName, Event.initiator ) Event.IniCategory = Event.IniDCSUnit:getDesc().category - Event.IniTypeName = Event.IniDCSUnit:getTypeName() + Event.IniTypeName = Event.initiator:isExist() and Event.IniDCSUnit:getTypeName() or "SCENERY" -- TODO: Bug fix for 2.1! end end @@ -9278,6 +9278,23 @@ function SET_GROUP:FilterStart() return self end +--- Handles the OnDead or OnCrash event for alive groups set. +-- Note: The GROUP object in the SET_GROUP collection will only be removed if the last unit is destroyed of the GROUP. +-- @param #SET_GROUP self +-- @param Core.Event#EVENTDATA Event +function SET_GROUP:_EventOnDeadOrCrash( Event ) + self:F3( { Event } ) + + if Event.IniDCSUnit then + local ObjectName, Object = self:FindInDatabase( Event ) + if ObjectName then + if Event.IniDCSGroup:getSize() == 1 then -- Only remove if the last unit of the group was destroyed. + self:Remove( ObjectName ) + end + end + end +end + --- Handles the Database to check on an event (birth) that the Object was added in the Database. -- This is required, because sometimes the _DATABASE birth event gets called later than the SET_BASE birth event! -- @param #SET_GROUP self