From 20b4ebfb2b88be56180963b8229607154656e7b0 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sun, 23 Apr 2017 13:49:32 +0200 Subject: [PATCH] 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