From 7961ae90f4ae93cb168a4b35202897e3751669ff Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sun, 23 Apr 2017 08:48:30 +0200 Subject: [PATCH 1/4] Progress --- Moose Development/Moose/AI/AI_Designate.lua | 192 ++++++++++++------ Moose Development/Moose/Core/Spot.lua | 4 +- .../Moose/Wrapper/Positionable.lua | 24 +++ 3 files changed, 156 insertions(+), 64 deletions(-) diff --git a/Moose Development/Moose/AI/AI_Designate.lua b/Moose Development/Moose/AI/AI_Designate.lua index 4ca683974..ec4a26a1e 100644 --- a/Moose Development/Moose/AI/AI_Designate.lua +++ b/Moose Development/Moose/AI/AI_Designate.lua @@ -122,9 +122,9 @@ do -- AI_DESIGNATE --- AI_DESIGNATE Constructor. This class is an abstract class and should not be instantiated. -- @param #AI_DESIGNATE self -- @param Functional.Detection#DETECTION_BASE Detection - -- @param Core.Set#SET_GROUP GroupSet The set of groups to designate for. + -- @param Core.Set#SET_GROUP AttackSet The Attack collection of GROUP objects to designate and report for. -- @return #AI_DESIGNATE - function AI_DESIGNATE:New( Detection, GroupSet ) + function AI_DESIGNATE:New( Detection, AttackSet ) local self = BASE:Inherit( self, FSM:New() ) -- #AI_DESIGNATE self:F( { Detection } ) @@ -295,18 +295,22 @@ do -- AI_DESIGNATE -- @param #number Delay self.Detection = Detection - self.GroupSet = GroupSet + self.AttackSet = AttackSet self.RecceSet = Detection:GetDetectionSetGroup() self.Spots = {} self.Designating = {} - self:SetLaserCodes( 1688 ) + self.LaseDuration = 60 + + self:SetLaserCodes( 1688 ) -- set self.LaserCodes + self:SetAutoLase( false ) -- set self.Autolase self.LaserCodesUsed = {} self.Detection:__Start( 2 ) - + + self:SetDesignateMenu() return self end @@ -327,6 +331,29 @@ do -- AI_DESIGNATE return self end + --- Set auto lase. + -- Auto lase will start lasing targets immediately when these are in range. + -- @param #AI_DESIGNATE self + -- @param #boolean AutoLase + -- @return #AI_DESIGNATE + function AI_DESIGNATE:SetAutoLase( AutoLase ) + + self.AutoLase = AutoLase + + local AutoLaseOnOff = ( AutoLase == true ) and "On" or "Off" + + local Recce = self.RecceSet:GetFirst() + + if Recce then + Recce:MessageToSetGroup( "Auto Lase " .. AutoLaseOnOff .. ".", 15, self.AttackSet ) + end + + self:ActivateAutoLase() + self:SetDesignateMenu() + + return self + end + --- -- @param #AI_DESIGNATE self @@ -335,7 +362,11 @@ do -- AI_DESIGNATE self:__Detect( -60 ) + self:ActivateAutoLase() + self:SendStatus() + + self:SetDesignateMenu() return self @@ -357,11 +388,32 @@ do -- AI_DESIGNATE local RecceLeader = self.RecceSet:GetFirst() -- Wrapper.Group#GROUP - self.GroupSet:ForEachGroup( + RecceLeader:MessageToSetGroup( DetectedReport:Text( "\n" ), 15, self.AttackSet ) + + return self + end + + --- Coordinates the Auto Lase. + -- @param #AI_DESIGNATE self + -- @return #AI_DESIGNATE + function AI_DESIGNATE:ActivateAutoLase() + + self.AttackSet:Flush() + + self.AttackSet:ForEachGroup( --- @param Wrapper.Group#GROUP GroupReport function( AttackGroup ) - RecceLeader:MessageToGroup( DetectedReport:Text( "\n" ), 15, AttackGroup ) + + local DetectedItems = self.Detection:GetDetectedItems() + + for Index, DetectedItemData in pairs( DetectedItems ) do + if self.AutoLase then + if not self.Designating[Index] then + self:LaseOn( Index, self.LaseDuration ) + end + end + end end ) @@ -373,9 +425,9 @@ do -- AI_DESIGNATE -- @return #AI_DESIGNATE function AI_DESIGNATE:SetDesignateMenu() - self.GroupSet:Flush() + self.AttackSet:Flush() - self.GroupSet:ForEachGroup( + self.AttackSet:ForEachGroup( --- @param Wrapper.Group#GROUP GroupReport function( AttackGroup ) @@ -389,6 +441,13 @@ do -- AI_DESIGNATE self:E(DesignateMenu) AttackGroup:SetState( AttackGroup, "DesignateMenu", DesignateMenu ) + -- Set Menu option for auto lase + + if self.AutoLase then + MENU_GROUP_COMMAND:New( AttackGroup, "Auto Lase Off", DesignateMenu, self.MenuAutoLase, self, false ) + else + MENU_GROUP_COMMAND:New( AttackGroup, "Auto Lase On", DesignateMenu, self.MenuAutoLase, self, true ) + end local DetectedItems = self.Detection:GetDetectedItems() @@ -398,14 +457,14 @@ do -- AI_DESIGNATE if not self.Designating[Index] then local DetectedMenu = MENU_GROUP:New( AttackGroup, Report, DesignateMenu ) - MENU_GROUP_COMMAND:New( AttackGroup, "Lase target 60 secs", DetectedMenu, self.MenuLaseOn, self, AttackGroup, Index, 60 ) - MENU_GROUP_COMMAND:New( AttackGroup, "Lase target 120 secs", DetectedMenu, self.MenuLaseOn, self,AttackGroup, Index, 120 ) - MENU_GROUP_COMMAND:New( AttackGroup, "Smoke red", DetectedMenu, self.MenuSmoke, self, AttackGroup, Index, SMOKECOLOR.Red ) - MENU_GROUP_COMMAND:New( AttackGroup, "Smoke blue", DetectedMenu, self.MenuSmoke, self, AttackGroup, Index, SMOKECOLOR.Blue ) - MENU_GROUP_COMMAND:New( AttackGroup, "Smoke green", DetectedMenu, self.MenuSmoke, self, AttackGroup, Index, SMOKECOLOR.Green ) - MENU_GROUP_COMMAND:New( AttackGroup, "Smoke white", DetectedMenu, self.MenuSmoke, self, AttackGroup, Index, SMOKECOLOR.White ) - MENU_GROUP_COMMAND:New( AttackGroup, "Smoke orange", DetectedMenu, self.MenuSmoke, self, AttackGroup, Index, SMOKECOLOR.Orange ) - MENU_GROUP_COMMAND:New( AttackGroup, "Illuminate", DetectedMenu, self.MenuIlluminate, self, AttackGroup, Index ) + MENU_GROUP_COMMAND:New( AttackGroup, "Lase target 60 secs", DetectedMenu, self.MenuLaseOn, self, Index, 60 ) + MENU_GROUP_COMMAND:New( AttackGroup, "Lase target 120 secs", DetectedMenu, self.MenuLaseOn, self, Index, 120 ) + MENU_GROUP_COMMAND:New( AttackGroup, "Smoke red", DetectedMenu, self.MenuSmoke, self, Index, SMOKECOLOR.Red ) + MENU_GROUP_COMMAND:New( AttackGroup, "Smoke blue", DetectedMenu, self.MenuSmoke, self, Index, SMOKECOLOR.Blue ) + MENU_GROUP_COMMAND:New( AttackGroup, "Smoke green", DetectedMenu, self.MenuSmoke, self, Index, SMOKECOLOR.Green ) + MENU_GROUP_COMMAND:New( AttackGroup, "Smoke white", DetectedMenu, self.MenuSmoke, self, Index, SMOKECOLOR.White ) + MENU_GROUP_COMMAND:New( AttackGroup, "Smoke orange", DetectedMenu, self.MenuSmoke, self, Index, SMOKECOLOR.Orange ) + MENU_GROUP_COMMAND:New( AttackGroup, "Illuminate", DetectedMenu, self.MenuIlluminate, self, Index ) else if self.Designating[Index] == "Laser" then Report = "Lasing " .. Report @@ -416,7 +475,7 @@ do -- AI_DESIGNATE end local DetectedMenu = MENU_GROUP:New( AttackGroup, Report, DesignateMenu ) if self.Designating[Index] == "Laser" then - MENU_GROUP_COMMAND:New( AttackGroup, "Stop lasing", DetectedMenu, self.MenuLaseOff, self, AttackGroup, Index ) + MENU_GROUP_COMMAND:New( AttackGroup, "Stop lasing", DetectedMenu, self.MenuLaseOff, self, Index ) else end end @@ -429,59 +488,66 @@ do -- AI_DESIGNATE --- -- @param #AI_DESIGNATE self - function AI_DESIGNATE:MenuSmoke( AttackGroup, Index, Color ) + function AI_DESIGNATE:MenuAutoLase( AutoLase ) - self:E("Designate through Smoke") + self:E("AutoLase") - self.Designating[Index] = "Smoke" - self:__Smoke( 1, AttackGroup, Index, Color ) + self:SetAutoLase( AutoLase ) end --- -- @param #AI_DESIGNATE self - function AI_DESIGNATE:MenuIlluminate( AttackGroup, Index ) + function AI_DESIGNATE:MenuSmoke( Index, Color ) + + self:E("Designate through Smoke") + + self.Designating[Index] = "Smoke" + self:__Smoke( 1, Index, Color ) + end + + --- + -- @param #AI_DESIGNATE self + function AI_DESIGNATE:MenuIlluminate( Index ) self:E("Designate through Illumination") self.Designating[Index] = "Illuminate" - self:__Illuminate( 1, AttackGroup, Index ) + self:__Illuminate( 1, Index ) end --- -- @param #AI_DESIGNATE self - function AI_DESIGNATE:MenuLaseOn( AttackGroup, Index, Duration ) + function AI_DESIGNATE:MenuLaseOn( Index, Duration ) self:E("Designate through Lase") - self.Designating[Index] = "Laser" - self:__LaseOn( 1, AttackGroup, Index, Duration ) + self:__LaseOn( 1, Index, Duration ) end --- -- @param #AI_DESIGNATE self - function AI_DESIGNATE:MenuLaseOff( AttackGroup, Index, Duration ) + function AI_DESIGNATE:MenuLaseOff( Index, Duration ) self:E("Lasing off") self.Designating[Index] = nil - self:__LaseOff( 1, AttackGroup, Index ) + self:__LaseOff( 1, Index ) end --- -- @param #AI_DESIGNATE self - -- @return #AI_DESIGNATE - function AI_DESIGNATE:onafterLaseOn( From, Event, To, AttackGroup, Index, Duration ) - - self:__Lasing( 5, AttackGroup, Index, Duration ) + function AI_DESIGNATE:onafterLaseOn( From, Event, To, Index, Duration ) + self.Designating[Index] = "Laser" + self:Lasing( Index, Duration ) end --- -- @param #AI_DESIGNATE self -- @return #AI_DESIGNATE - function AI_DESIGNATE:onafterLasing( From, Event, To, AttackGroup, Index, Duration ) + function AI_DESIGNATE:onafterLasing( From, Event, To, Index, Duration ) local TargetSetUnit = self.Detection:GetDetectedSet( Index ) @@ -496,8 +562,6 @@ do -- AI_DESIGNATE end end - local MoreTargets = false - TargetSetUnit:ForEachUnit( --- @param Wrapper.Unit#UNIT SmokeUnit function( TargetUnit ) @@ -518,10 +582,10 @@ do -- AI_DESIGNATE local Spot = RecceUnit:LaseUnit( TargetUnit, LaserCode, Duration ) function Spot:OnAfterDestroyed( From, Event, To ) self:E( "Destroyed Message" ) - self.Recce:MessageToGroup( "Target " .. TargetUnit:GetTypeName() .. " destroyed." .. TargetSetUnit:Count() .. " targets left.", 5, AttackGroup ) + self.Recce:MessageToSetGroup( "Target " .. TargetUnit:GetTypeName() .. " destroyed." .. TargetSetUnit:Count() .. " targets left.", 15, self.AttackSet ) end self.Spots[TargetUnit] = Spot - RecceUnit:MessageToGroup( "Lasing " .. TargetUnit:GetTypeName() .. " for " .. Duration .. "s, code: " .. Spot.LaserCode, 5, AttackGroup ) + RecceUnit:MessageToSetGroup( "Lasing " .. TargetUnit:GetTypeName() .. " for " .. Duration .. "s, code: " .. Spot.LaserCode, 5, self.AttackSet ) break end end @@ -531,7 +595,7 @@ do -- AI_DESIGNATE local Spot = self.Spots[TargetUnit] -- Core.Spot#SPOT if Spot then Spot.Recce:LaseOff() - Spot.Recce:MessageToGroup( "Target " .. TargetUnit:GetTypeName() "out of LOS. Cancelling lase!", 5, AttackGroup ) + Spot.Recce:MessageToGroup( "Target " .. TargetUnit:GetTypeName() "out of LOS. Cancelling lase!", 5, self.AttackSet ) end end end @@ -540,7 +604,7 @@ do -- AI_DESIGNATE else MoreTargets = true local RecceUnit = Spot.Recce - RecceUnit:MessageToGroup( "Lasing " .. TargetUnit:GetTypeName() .. ", code " .. Spot.LaserCode, 5, AttackGroup ) + RecceUnit:MessageToSetGroup( "Lasing " .. TargetUnit:GetTypeName() .. ", code " .. Spot.LaserCode, 5, self.AttackSet ) end else self.Spots[TargetUnit] = nil @@ -548,11 +612,7 @@ do -- AI_DESIGNATE end ) - if MoreTargets == true then - self:__Lasing( 30, AttackGroup, Index, Duration ) - else - self:__LaseOff( 1, AttackGroup, Index ) - end + self:__Lasing( 15, Index, Duration ) self:SetDesignateMenu() @@ -561,9 +621,13 @@ do -- AI_DESIGNATE --- -- @param #AI_DESIGNATE self -- @return #AI_DESIGNATE - function AI_DESIGNATE:onafterLaseOff( From, Event, To, AttackGroup, Index ) + function AI_DESIGNATE:onafterLaseOff( From, Event, To, Index ) - self.RecceSet:GetFirst():MessageToGroup( "Stopped lasing.", 15, AttackGroup ) + local Recce = self.RecceSet:GetFirst() + + if Recce then + Recce:MessageToSetGroup( "Stopped lasing.", 15, self.AttackSet ) + end local TargetSetUnit = self.Detection:GetDetectedSet( Index ) @@ -571,7 +635,7 @@ do -- AI_DESIGNATE for SpotID, SpotData in pairs( Spots ) do local Spot = SpotData -- Core.Spot#SPOT - Spot.Recce:MessageToGroup( "Stopped lasing " .. Spot.Target:GetTypeName() .. ".", 15, AttackGroup ) + Spot.Recce:MessageToSetGroup( "Stopped lasing " .. Spot.Target:GetTypeName() .. ".", 15, self.AttackSet ) Spot:LaseOff() end @@ -586,7 +650,7 @@ do -- AI_DESIGNATE --- -- @param #AI_DESIGNATE self -- @return #AI_DESIGNATE - function AI_DESIGNATE:onafterSmoke( From, Event, To, AttackGroup, Index, Color ) + function AI_DESIGNATE:onafterSmoke( From, Event, To, Index, Color ) local TargetSetUnit = self.Detection:GetDetectedSet( Index ) @@ -599,15 +663,17 @@ do -- AI_DESIGNATE if math.random( 1, TargetSetUnitCount ) == math.random( 1, TargetSetUnitCount ) then local RecceGroup = self.RecceSet:FindNearestGroupFromPointVec2(SmokeUnit:GetPointVec2()) local RecceUnit = RecceGroup:GetUnit( 1 ) - RecceUnit:MessageToGroup( "Smoking " .. SmokeUnit:GetTypeName() .. ".", 5, AttackGroup ) - SCHEDULER:New( self, - function() - if SmokeUnit:IsAlive() then - SmokeUnit:Smoke( Color, 150 ) - end - self:Done( Index ) - end, {}, math.random( 5, 20 ) - ) + if RecceUnit then + RecceUnit:MessageToSetGroup( "Smoking " .. SmokeUnit:GetTypeName() .. ".", 5, self.AttackSet ) + SCHEDULER:New( self, + function() + if SmokeUnit:IsAlive() then + SmokeUnit:Smoke( Color, 150 ) + end + self:Done( Index ) + end, {}, math.random( 5, 20 ) + ) + end end end ) @@ -618,16 +684,17 @@ do -- AI_DESIGNATE --- Illuminating -- @param #AI_DESIGNATE self -- @return #AI_DESIGNATE - function AI_DESIGNATE:onafterIlluminate( From, Event, To, AttackGroup, Index ) + function AI_DESIGNATE:onafterIlluminate( From, Event, To, Index ) local TargetSetUnit = self.Detection:GetDetectedSet( Index ) local TargetUnit = TargetSetUnit:GetFirst() if TargetUnit then - local RecceGroup = self.RecceSet:FindNearestGroupFromPointVec2(TargetUnit:GetPointVec2()) - local RecceUnit = RecceGroup:GetUnit( 1 ) - RecceUnit:MessageToGroup( "Illuminating " .. TargetUnit:GetTypeName() .. ".", 5, AttackGroup ) + local RecceGroup = self.RecceSet:FindNearestGroupFromPointVec2(TargetUnit:GetPointVec2()) + local RecceUnit = RecceGroup:GetUnit( 1 ) + if RecceUnit then + RecceUnit:MessageToGroup( "Illuminating " .. TargetUnit:GetTypeName() .. ".", 5, self.AttackSet ) SCHEDULER:New( self, function() if TargetUnit:IsAlive() then @@ -636,6 +703,7 @@ do -- AI_DESIGNATE self:Done( Index ) end, {}, math.random( 5, 20 ) ) + end end end diff --git a/Moose Development/Moose/Core/Spot.lua b/Moose Development/Moose/Core/Spot.lua index 18ba85400..7177cbde8 100644 --- a/Moose Development/Moose/Core/Spot.lua +++ b/Moose Development/Moose/Core/Spot.lua @@ -196,9 +196,9 @@ do function SPOT:onafterLasing( From, Event, To ) if self.Target:IsAlive() then - self.SpotIR:setPoint( self.Target:GetPointVec3():AddY(1):GetVec3() ) + self.SpotIR:setPoint( self.Target:GetPointVec3():AddY(1):AddY(math.random(-100,100)/100):AddX(math.random(-100,100)/100):GetVec3() ) self.SpotLaser:setPoint( self.Target:GetPointVec3():AddY(1):GetVec3() ) - self:__Lasing( -0.2 ) + self:__Lasing( -0.05 ) else self:E( { "Target is not alive", self.Target:IsAlive() } ) end diff --git a/Moose Development/Moose/Wrapper/Positionable.lua b/Moose Development/Moose/Wrapper/Positionable.lua index c04d1cc06..7ebdb3979 100644 --- a/Moose Development/Moose/Wrapper/Positionable.lua +++ b/Moose Development/Moose/Wrapper/Positionable.lua @@ -426,6 +426,30 @@ function POSITIONABLE:MessageToGroup( Message, Duration, MessageGroup, Name ) return nil end +--- (R2.1) Send a message to a @{Set#SET_GROUP}. +-- The message will appear in the message area. The message will begin with the callsign of the group and the type of the first unit sending the message. +-- @param #POSITIONABLE self +-- @param #string Message The message text +-- @param Dcs.DCSTypes#Duration Duration The duration of the message. +-- @param Core.Set#SET_GROUP MessageSetGroup The SET_GROUP collection receiving the message. +-- @param #string Name (optional) The Name of the sender. If not provided, the Name is the type of the Positionable. +function POSITIONABLE:MessageToSetGroup( Message, Duration, MessageSetGroup, Name ) + self:F2( { Message, Duration } ) + + local DCSObject = self:GetDCSObject() + if DCSObject then + if DCSObject:isExist() then + MessageSetGroup:ForEachGroup( + function( MessageGroup ) + self:GetMessage( Message, Duration, Name ):ToGroup( MessageGroup ) + end + ) + end + end + + return nil +end + --- Send a message to the players in the @{Group}. -- The message will appear in the message area. The message will begin with the callsign of the group and the type of the first unit sending the message. -- @param #POSITIONABLE self From 1cc89942d12e8cf86522e15d7348bbe46d1e7a86 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sun, 23 Apr 2017 08:49:12 +0200 Subject: [PATCH 2/4] Progress --- Moose Mission Setup/Moose.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Moose Mission Setup/Moose.lua b/Moose Mission Setup/Moose.lua index 07c8fc12b..3fb8251c1 100644 --- a/Moose Mission Setup/Moose.lua +++ b/Moose Mission Setup/Moose.lua @@ -1,5 +1,5 @@ env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' ) -env.info( 'Moose Generation Timestamp: 20170422_1159' ) +env.info( 'Moose Generation Timestamp: 20170423_0705' ) local base = _G From 8a5a33d191b8cc1aaf2cec8994e8d21bfc74386c Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sun, 23 Apr 2017 10:04:11 +0200 Subject: [PATCH 3/4] Progress --- Moose Development/Moose/AI/AI_Designate.lua | 50 +++++++++---------- .../Moose/Wrapper/Positionable.lua | 8 +++ 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/Moose Development/Moose/AI/AI_Designate.lua b/Moose Development/Moose/AI/AI_Designate.lua index ec4a26a1e..dee4153ab 100644 --- a/Moose Development/Moose/AI/AI_Designate.lua +++ b/Moose Development/Moose/AI/AI_Designate.lua @@ -297,7 +297,7 @@ do -- AI_DESIGNATE self.Detection = Detection self.AttackSet = AttackSet self.RecceSet = Detection:GetDetectionSetGroup() - self.Spots = {} + self.Recces = {} self.Designating = {} self.LaseDuration = 60 @@ -553,12 +553,12 @@ do -- AI_DESIGNATE TargetSetUnit:Flush() - 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). + for TargetUnit, RecceData in pairs( self.Recces ) do + local Recce = RecceData -- Wrapper.Unit#UNIT + if not Recce:IsLasing() then + local LaserCode = self.LaserCodesUsed[Recce] --(Not deleted when stopping with lasing). self.LaserCodesUsed[LaserCode] = nil - self.Spots[TargetUnit] = nil + self.Recces[TargetUnit] = nil end end @@ -567,8 +567,8 @@ do -- AI_DESIGNATE function( TargetUnit ) self:E("In procedure") if TargetUnit:IsAlive() then - local Spot = self.Spots[TargetUnit] - if (not Spot) or ( Spot and Spot:IsLasing() == false ) then + local Recce = self.Recces[TargetUnit] + if (not Recce) or ( Recce and Recce:IsLasing() == false ) then for RecceGroupID, RecceGroup in pairs( self.RecceSet:GetSet() ) do for UnitID, UnitData in pairs( RecceGroup:GetUnits() or {} ) do local RecceUnit = UnitData -- Wrapper.Unit#UNIT @@ -577,37 +577,35 @@ do -- AI_DESIGNATE 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 ) function Spot:OnAfterDestroyed( From, Event, To ) self:E( "Destroyed Message" ) self.Recce:MessageToSetGroup( "Target " .. TargetUnit:GetTypeName() .. " destroyed." .. TargetSetUnit:Count() .. " targets left.", 15, self.AttackSet ) end - self.Spots[TargetUnit] = Spot - RecceUnit:MessageToSetGroup( "Lasing " .. TargetUnit:GetTypeName() .. " for " .. Duration .. "s, code: " .. Spot.LaserCode, 5, self.AttackSet ) + self.Recces[TargetUnit] = RecceUnit + RecceUnit:MessageToSetGroup( "Lasing " .. TargetUnit:GetTypeName() .. " for " .. Duration .. "s, code: " .. RecceUnit:GetSpot().LaserCode, 5, self.AttackSet ) break end end else -- The Recce is lasing, but the Target is not detected or within LOS. So stop lasing and send a report. if not RecceUnit:IsDetected( TargetUnit ) or not RecceUnit:IsLOS( TargetUnit ) then - local Spot = self.Spots[TargetUnit] -- Core.Spot#SPOT - if Spot then - Spot.Recce:LaseOff() - Spot.Recce:MessageToGroup( "Target " .. TargetUnit:GetTypeName() "out of LOS. Cancelling lase!", 5, self.AttackSet ) + local Recce = self.Recces[TargetUnit] -- Wrapper.Unit#UNIT + if Recce then + Recce:LaseOff() + Recce:MessageToGroup( "Target " .. TargetUnit:GetTypeName() "out of LOS. Cancelling lase!", 5, self.AttackSet ) end end end end end else - MoreTargets = true - local RecceUnit = Spot.Recce - RecceUnit:MessageToSetGroup( "Lasing " .. TargetUnit:GetTypeName() .. ", code " .. Spot.LaserCode, 5, self.AttackSet ) + local RecceUnit = Recce.Recce + RecceUnit:MessageToSetGroup( "Lasing " .. TargetUnit:GetTypeName() .. ", code " .. Recce.LaserCode, 5, self.AttackSet ) end else - self.Spots[TargetUnit] = nil + self.Recces[TargetUnit] = nil end end ) @@ -631,16 +629,16 @@ do -- AI_DESIGNATE local TargetSetUnit = self.Detection:GetDetectedSet( Index ) - local Spots = self.Spots + local Recces = self.Recces - for SpotID, SpotData in pairs( Spots ) do - local Spot = SpotData -- Core.Spot#SPOT - Spot.Recce:MessageToSetGroup( "Stopped lasing " .. Spot.Target:GetTypeName() .. ".", 15, self.AttackSet ) - Spot:LaseOff() + for TargetID, RecceData in pairs( Recces ) do + local Recce = RecceData -- Wrapper.Unit#UNIT + Recce:MessageToSetGroup( "Stopped lasing " .. Recce:GetSpot().Target:GetTypeName() .. ".", 15, self.AttackSet ) + Recce:LaseOff() end - Spots = nil - self.Spots = {} + Recces = nil + self.Recces = {} self.LaserCodesUsed = {} self:SetDesignateMenu() diff --git a/Moose Development/Moose/Wrapper/Positionable.lua b/Moose Development/Moose/Wrapper/Positionable.lua index 7ebdb3979..3157d8bbc 100644 --- a/Moose Development/Moose/Wrapper/Positionable.lua +++ b/Moose Development/Moose/Wrapper/Positionable.lua @@ -534,3 +534,11 @@ function POSITIONABLE:IsLasing() return Lasing end + +--- (R2.1) Get the Spot +-- @param #POSITIONABLE self +-- @return Core.Spot#SPOT The Spot +function POSITIONABLE:GetSpot() + + return self.Spot +end From 20b4ebfb2b88be56180963b8229607154656e7b0 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sun, 23 Apr 2017 13:49:32 +0200 Subject: [PATCH 4/4] Improvements --- Moose Development/Moose/AI/AI_Designate.lua | 39 +++++++++++++++---- Moose Development/Moose/Core/Spot.lua | 20 +++++----- .../Moose/Wrapper/Positionable.lua | 11 ++++++ 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/Moose Development/Moose/AI/AI_Designate.lua b/Moose Development/Moose/AI/AI_Designate.lua index dee4153ab..5d725e623 100644 --- a/Moose Development/Moose/AI/AI_Designate.lua +++ b/Moose Development/Moose/AI/AI_Designate.lua @@ -448,6 +448,8 @@ do -- AI_DESIGNATE else MENU_GROUP_COMMAND:New( AttackGroup, "Auto Lase On", DesignateMenu, self.MenuAutoLase, self, true ) end + + MENU_GROUP_COMMAND:New( AttackGroup, "Report Designation Status", DesignateMenu, self.MenuStatus, self, AttackGroup ) local DetectedItems = self.Detection:GetDetectedItems() @@ -485,6 +487,27 @@ do -- AI_DESIGNATE return self end + + --- + -- @param #AI_DESIGNATE self + function AI_DESIGNATE:MenuStatus( AttackGroup ) + + self:E("Status") + + self.RecceSet:ForEachGroup( + function( RecceGroup ) + local RecceUnits = RecceGroup:GetUnits() + for UnitID, RecceData in pairs( RecceUnits ) do + local Recce = RecceData -- Wrapper.Unit#UNIT + if Recce:IsLasing() then + Recce:MessageToGroup( "Marking " .. Recce:GetSpot().Target:GetTypeName() .. " with laser " .. Recce:GetSpot().LaserCode .. ".", 5, AttackGroup ) + end + end + end + ) + + end + --- -- @param #AI_DESIGNATE self @@ -556,7 +579,7 @@ do -- AI_DESIGNATE for TargetUnit, RecceData in pairs( self.Recces ) do local Recce = RecceData -- Wrapper.Unit#UNIT if not Recce:IsLasing() then - local LaserCode = self.LaserCodesUsed[Recce] --(Not deleted when stopping with lasing). + local LaserCode = Recce:GetLaserCode() --(Not deleted when stopping with lasing). self.LaserCodesUsed[LaserCode] = nil self.Recces[TargetUnit] = nil end @@ -568,7 +591,7 @@ do -- AI_DESIGNATE self:E("In procedure") if TargetUnit:IsAlive() then local Recce = self.Recces[TargetUnit] - if (not Recce) or ( Recce and Recce:IsLasing() == false ) then + if not Recce then for RecceGroupID, RecceGroup in pairs( self.RecceSet:GetSet() ) do for UnitID, UnitData in pairs( RecceGroup:GetUnits() or {} ) do local RecceUnit = UnitData -- Wrapper.Unit#UNIT @@ -579,14 +602,17 @@ do -- AI_DESIGNATE if not self.LaserCodesUsed[LaserCode] then self.LaserCodesUsed[LaserCode] = LaserCodeIndex local Spot = RecceUnit:LaseUnit( TargetUnit, LaserCode, Duration ) + local AttackSet = self.AttackSet function Spot:OnAfterDestroyed( From, Event, To ) self:E( "Destroyed Message" ) - self.Recce:MessageToSetGroup( "Target " .. TargetUnit:GetTypeName() .. " destroyed." .. TargetSetUnit:Count() .. " targets left.", 15, self.AttackSet ) + self.Recce:MessageToSetGroup( "Target " .. TargetUnit:GetTypeName() .. " destroyed." .. TargetSetUnit:Count() .. " targets left.", 15, AttackSet ) end self.Recces[TargetUnit] = RecceUnit - RecceUnit:MessageToSetGroup( "Lasing " .. TargetUnit:GetTypeName() .. " for " .. Duration .. "s, code: " .. RecceUnit:GetSpot().LaserCode, 5, self.AttackSet ) + RecceUnit:MessageToSetGroup( "Marking " .. TargetUnit:GetTypeName() .. " with laser " .. RecceUnit:GetSpot().LaserCode .. " for " .. Duration .. "s.", 5, self.AttackSet ) break end + else + RecceUnit:MessageToSetGroup( "Can't lase " .. TargetUnit:GetTypeName(), 5, self.AttackSet ) end else -- The Recce is lasing, but the Target is not detected or within LOS. So stop lasing and send a report. @@ -601,11 +627,8 @@ do -- AI_DESIGNATE end end else - local RecceUnit = Recce.Recce - RecceUnit:MessageToSetGroup( "Lasing " .. TargetUnit:GetTypeName() .. ", code " .. Recce.LaserCode, 5, self.AttackSet ) + Recce:MessageToSetGroup( "Marking " .. TargetUnit:GetTypeName() .. " with laser " .. Recce.LaserCode .. ".", 5, self.AttackSet ) end - else - self.Recces[TargetUnit] = nil end end ) diff --git a/Moose Development/Moose/Core/Spot.lua b/Moose Development/Moose/Core/Spot.lua index 7177cbde8..b925af8a4 100644 --- a/Moose Development/Moose/Core/Spot.lua +++ b/Moose Development/Moose/Core/Spot.lua @@ -141,6 +141,8 @@ do self.LaseScheduler = SCHEDULER:New( self ) self:SetEventPriority( 5 ) + + self.Lasing = false return self end @@ -162,6 +164,8 @@ do self.Target = Target self.LaserCode = LaserCode + self.Lasing = true + local RecceDcsUnit = self.Recce:GetDCSObject() self.SpotIR = Spot.createInfraRed( RecceDcsUnit, { x = 0, y = 2, z = 0 }, Target:GetPointVec3():AddY(1):GetVec3() ) @@ -184,7 +188,7 @@ do if EventData.IniDCSUnitName == self.Target:GetName() then self:E( {"Target dead ", self.Target:GetName() } ) self:Destroyed() - self:LaseOff( 0.1 ) + self:LaseOff() end end end @@ -198,7 +202,7 @@ do if self.Target:IsAlive() then self.SpotIR:setPoint( self.Target:GetPointVec3():AddY(1):AddY(math.random(-100,100)/100):AddX(math.random(-100,100)/100):GetVec3() ) self.SpotLaser:setPoint( self.Target:GetPointVec3():AddY(1):GetVec3() ) - self:__Lasing( -0.05 ) + self:__Lasing( -0.2 ) else self:E( { "Target is not alive", self.Target:IsAlive() } ) end @@ -214,6 +218,8 @@ do self:E( {"Stopped lasing for ", self.Target:GetName() , SpotIR = self.SportIR, SpotLaser = self.SpotLaser } ) + self.Lasing = false + self.SpotIR:destroy() self.SpotLaser:destroy() @@ -234,15 +240,7 @@ do -- @param #SPOT self -- @return #boolean true if it is lasing function SPOT:IsLasing() - self:F2() - - local Lasing = false - - if self.SpotIR then - Lasing = true - end - - return Lasing + return self.Lasing end end \ No newline at end of file diff --git a/Moose Development/Moose/Wrapper/Positionable.lua b/Moose Development/Moose/Wrapper/Positionable.lua index 3157d8bbc..5b3d2339c 100644 --- a/Moose Development/Moose/Wrapper/Positionable.lua +++ b/Moose Development/Moose/Wrapper/Positionable.lua @@ -29,6 +29,8 @@ -- @type POSITIONABLE -- @extends Wrapper.Identifiable#IDENTIFIABLE -- @field #string PositionableName The name of the measurable. +-- @field Core.Spot#SPOT Spot The laser Spot. +-- @field #number LaserCode The last assigned laser code. POSITIONABLE = { ClassName = "POSITIONABLE", PositionableName = "", @@ -501,6 +503,7 @@ function POSITIONABLE:LaseUnit( Target, LaserCode, Duration ) self:E("bulding spot") self.Spot = SPOT:New( self ) -- Core.Spot#SPOT self.Spot:LaseOn( Target, LaserCode, Duration) + self.LaserCode = LaserCode return self.Spot @@ -542,3 +545,11 @@ function POSITIONABLE:GetSpot() return self.Spot end + +--- (R2.1) Get the last assigned laser code +-- @param #POSITIONABLE self +-- @return #number The laser code +function POSITIONABLE:GetLaserCode() + + return self.LaserCode +end