diff --git a/Moose Development/Moose/AI/AI_Designate.lua b/Moose Development/Moose/AI/AI_Designate.lua index d892da22c..8f64c7b8f 100644 --- a/Moose Development/Moose/AI/AI_Designate.lua +++ b/Moose Development/Moose/AI/AI_Designate.lua @@ -118,6 +118,8 @@ do -- AI_DESIGNATE -- @function [parent=#AI_DESIGNATE] __Detect -- @param #AI_DESIGNATE self -- @param #number Delay + + self:AddTransition( "*", "LaseOn", "Lasing" ) @@ -308,6 +310,8 @@ do -- AI_DESIGNATE -- @return #AI_DESIGNATE function AI_DESIGNATE:SetDesignateMenu() + self.GroupSet:Flush() + self.GroupSet:ForEachGroup( --- @param Wrapper.Group#GROUP GroupReport @@ -426,8 +430,19 @@ do -- AI_DESIGNATE function AI_DESIGNATE:onafterLasing( From, Event, To, AttackGroup, Index, Duration ) local TargetSetUnit = self.Detection:GetDetectedSet( Index ) + + TargetSetUnit:Flush() - local Targets = false + for TargetUnit, SpotData in pairs( self.Spots ) do + local Spot = SpotData -- Core.Spot#SPOT + if not Spot:IsLasing() then + local LaserCode = Spot.LaserCode --(Not deleted when stopping with lasing). + self.LaserCodesUsed[LaserCode] = nil + self.Spots[TargetUnit] = nil + end + end + + local MoreTargets = false TargetSetUnit:ForEachUnit( --- @param Wrapper.Unit#UNIT SmokeUnit @@ -441,17 +456,22 @@ do -- AI_DESIGNATE if NearestRecceGroup then for UnitID, UnitData in pairs( NearestRecceGroup:GetUnits() or {} ) do local RecceUnit = UnitData -- Wrapper.Unit#UNIT - Targets = true if RecceUnit:IsLasing() == false then - local LaserCode = self.LaserCodes[math.random(1, #self.LaserCodes)] - local Spot = RecceUnit:LaseUnit( TargetUnit, LaserCode, Duration ) - self.Spots[TargetUnit] = Spot - RecceUnit:MessageToGroup( "Lasing " .. TargetUnit:GetTypeName() .. " for " .. Duration .. " seconds. Laser Code: " .. Spot.LaserCode, 15, AttackGroup ) - break + local LaserCodeIndex = math.random(1, #self.LaserCodes) + local LaserCode = self.LaserCodes[LaserCodeIndex] + if not self.LaserCodesUsed[LaserCode] then + MoreTargets = true + self.LaserCodesUsed[LaserCode] = LaserCodeIndex + local Spot = RecceUnit:LaseUnit( TargetUnit, LaserCode, Duration ) + self.Spots[TargetUnit] = Spot + RecceUnit:MessageToGroup( "Lasing " .. TargetUnit:GetTypeName() .. " for " .. Duration .. " seconds. Laser Code: " .. Spot.LaserCode, 15, AttackGroup ) + break + end end end end else + MoreTargets = true local RecceUnit = Spot.Recce RecceUnit:MessageToGroup( "Lasing " .. TargetUnit:GetTypeName() .. " for " .. Duration .. " seconds. Laser Code: " .. Spot.LaserCode, 15, AttackGroup ) end @@ -462,12 +482,11 @@ do -- AI_DESIGNATE end ) - if Targets == true then + if MoreTargets == true then self:__Lasing( -30, AttackGroup, Index, Duration ) else - self:__LaseOff( -0.2, AttackGroup, Index ) - end - + self:__LaseOff( 1, AttackGroup, Index ) + end self:SetDesignateMenu() end @@ -477,6 +496,8 @@ do -- AI_DESIGNATE -- @return #AI_DESIGNATE function AI_DESIGNATE:onafterLaseOff( From, Event, To, AttackGroup, Index ) + self.RecceSet:GetFirst():MessageToGroup( "Stopped lasing.", 15, AttackGroup ) + local TargetSetUnit = self.Detection:GetDetectedSet( Index ) local Spots = self.Spots @@ -489,6 +510,7 @@ do -- AI_DESIGNATE Spots = nil self.Spots = {} + self.LaserCodesUsed = {} self:SetDesignateMenu() end diff --git a/Moose Development/Moose/Core/Base.lua b/Moose Development/Moose/Core/Base.lua index 64bcd30d2..8e8bec750 100644 --- a/Moose Development/Moose/Core/Base.lua +++ b/Moose Development/Moose/Core/Base.lua @@ -454,6 +454,12 @@ do -- Event Handling -- @param #BASE self -- @param Core.Event#EVENTDATA EventData The EventData structure. + --- Occurs when an object is dead. + -- initiator : The unit that is dead. + -- @function [parent=#BASE] OnEventDead + -- @param #BASE self + -- @param Core.Event#EVENTDATA EventData The EventData structure. + --- Occurs when an object is completely destroyed. -- initiator : The unit that is was destroyed. -- @function [parent=#BASE] OnEvent diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index bac65d9aa..0087fd667 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -342,6 +342,26 @@ function SET_BASE:_FilterStart() return self end +--- Starts the filtering of the Dead events for the collection. +-- @param #SET_BASE self +-- @return #SET_BASE self +function SET_BASE:FilterDeads() + + self:HandleEvent( EVENTS.Dead, self._EventOnDeadOrCrash ) + + return self +end + +--- Starts the filtering of the Crash events for the collection. +-- @param #SET_BASE self +-- @return #SET_BASE self +function SET_BASE:FilterCrashes() + + self:HandleEvent( EVENTS.Crash, self._EventOnDeadOrCrash ) + + return self +end + --- Stops the filtering for the defined collection. -- @param #SET_BASE self -- @return #SET_BASE self @@ -430,7 +450,7 @@ function SET_BASE:_EventOnDeadOrCrash( Event ) if Event.IniDCSUnit then local ObjectName, Object = self:FindInDatabase( Event ) - if ObjectName and Object ~= nil then + if ObjectName then self:Remove( ObjectName ) end end diff --git a/Moose Development/Moose/Core/Spot.lua b/Moose Development/Moose/Core/Spot.lua index 870a1f3ee..f532ffd15 100644 --- a/Moose Development/Moose/Core/Spot.lua +++ b/Moose Development/Moose/Core/Spot.lua @@ -32,7 +32,11 @@ do --- @type SPOT - -- @extends BASE + -- @extends Core.Base#BASE + + + --- + -- @field #SPOT SPOT = { ClassName = "SPOT", } @@ -50,8 +54,61 @@ do self:SetStartState( "Off" ) self:AddTransition( "Off", "LaseOn", "On" ) + + --- LaseOn Handler OnBefore for SPOT + -- @function [parent=#SPOT] OnBeforeLaseOn + -- @param #SPOT self + -- @param #string From + -- @param #string Event + -- @param #string To + -- @return #boolean + + --- LaseOn Handler OnAfter for SPOT + -- @function [parent=#SPOT] OnAfterLaseOn + -- @param #SPOT self + -- @param #string From + -- @param #string Event + -- @param #string To + + --- LaseOn Trigger for SPOT + -- @function [parent=#SPOT] LaseOn + -- @param #SPOT self + + --- LaseOn Asynchronous Trigger for SPOT + -- @function [parent=#SPOT] __LaseOn + -- @param #SPOT self + -- @param #number Delay + + + self:AddTransition( "On", "Lasing", "On" ) self:AddTransition( "On" , "LaseOff", "Off" ) + + --- LaseOff Handler OnBefore for SPOT + -- @function [parent=#SPOT] OnBeforeLaseOff + -- @param #SPOT self + -- @param #string From + -- @param #string Event + -- @param #string To + -- @return #boolean + + --- LaseOff Handler OnAfter for SPOT + -- @function [parent=#SPOT] OnAfterLaseOff + -- @param #SPOT self + -- @param #string From + -- @param #string Event + -- @param #string To + + --- LaseOff Trigger for SPOT + -- @function [parent=#SPOT] LaseOff + -- @param #SPOT self + + --- LaseOff Asynchronous Trigger for SPOT + -- @function [parent=#SPOT] __LaseOff + -- @param #SPOT self + -- @param #number Delay + + self.Recce = Recce @@ -87,9 +144,22 @@ do self.ScheduleID = self.LaseScheduler:Schedule( self, StopLase, {self}, Duration ) end + self:HandleEvent( EVENTS.Dead ) + self:__Lasing( -0.2 ) end + --- @param #SPOT self + -- @param Core.Event#EVENTDATA EventData + function SPOT:OnEventDead(EventData) + if self.Target then + if EventData.IniDCSUnitName == self.Target:GetName() then + self:E( {"Target dead ", self.Target:GetName() } ) + self:__LaseOff( 0.1 ) + end + end + end + --- @param #SPOT self -- @param From -- @param Event @@ -112,6 +182,7 @@ do -- @return #SPOT function SPOT:onafterLaseOff( From, Event, To ) + self:E( {"Stopped lasing for ", self.Target:GetName() } ) self.Spot:destroy() self.Spot = nil if self.ScheduleID then @@ -120,7 +191,6 @@ do self.ScheduleID = nil self.Target = nil - self.LaserCode = nil return self end diff --git a/Moose Development/Moose/Functional/Detection.lua b/Moose Development/Moose/Functional/Detection.lua index 307cd31bb..f876970b7 100644 --- a/Moose Development/Moose/Functional/Detection.lua +++ b/Moose Development/Moose/Functional/Detection.lua @@ -506,8 +506,6 @@ do -- DETECTION_BASE self.DetectionRun = 0 self:UnIdentifyAllDetectedObjects() -- Resets the DetectedObjectsIdentified table - self.DetectionSetGroup:Flush() - for DetectionGroupID, DetectionGroupData in pairs( self.DetectionSetGroup:GetSet() ) do self:E( {DetectionGroupData}) self:__DetectionGroup( DetectDelay, DetectionGroupData ) -- Process each detection asynchronously. @@ -1132,7 +1130,7 @@ do -- DETECTION_BASE self.DetectedItems[self.DetectedItemCount] = DetectedItem end - DetectedItem.Set = Set or SET_UNIT:New() + DetectedItem.Set = Set or SET_UNIT:New():FilterDeads():FilterCrashes() DetectedItem.ItemID = self.DetectedItemMax DetectedItem.Removed = false diff --git a/Moose Development/Moose/Wrapper/Positionable.lua b/Moose Development/Moose/Wrapper/Positionable.lua index ffef55978..be15b3466 100644 --- a/Moose Development/Moose/Wrapper/Positionable.lua +++ b/Moose Development/Moose/Wrapper/Positionable.lua @@ -475,7 +475,7 @@ function POSITIONABLE:LaseUnit( Target, LaserCode, Duration ) local TargetVec3 = Target:GetVec3() self:E("bulding spot") - self.Spot = SPOT:New( self ) + self.Spot = SPOT:New( self ) -- Core.Spot#SPOT self.Spot:LaseOn( Target, LaserCode, Duration) return self.Spot