From adb4befcdfe87ef735b4f8fd5b7a1371dacbe805 Mon Sep 17 00:00:00 2001 From: FlightControl_Master Date: Wed, 13 Sep 2017 07:07:07 +0200 Subject: [PATCH] Updates --- Moose Development/Moose/Core/Point.lua | 5 +- Moose Development/Moose/Core/Set.lua | 106 +++++++++++++++++- .../Moose/Functional/Detection.lua | 2 + Moose Development/Moose/Tasking/Task.lua | 39 ++++++- Moose Development/Moose/Tasking/Task_A2G.lua | 54 ++++----- 5 files changed, 169 insertions(+), 37 deletions(-) diff --git a/Moose Development/Moose/Core/Point.lua b/Moose Development/Moose/Core/Point.lua index 334d6850f..014422de0 100644 --- a/Moose Development/Moose/Core/Point.lua +++ b/Moose Development/Moose/Core/Point.lua @@ -485,12 +485,11 @@ do -- COORDINATE -- @param #COORDINATE self -- @return #string Heading text. function COORDINATE:GetHeadingText( Settings ) - local Heading = self.Heading - local Settings = Settings or _SETTINGS + local Heading = self:GetHeading() if Heading then return string.format( " heading %3.2f °", Heading ) else - return "" + return " heading cannot be determined" end end diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index 8ccb7611f..84d0763dd 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -217,7 +217,6 @@ function SET_BASE:Count() end - --- Copies the Filter criteria from a given Set (for rebuilding a new Set based on an existing Set). -- @param #SET_BASE self -- @param #SET_BASE BaseSet @@ -1803,6 +1802,111 @@ function SET_UNIT:CalculateThreatLevelA2G() end +--- Get the center coordinate of the SET_UNIT. +-- @param #SET_UNIT self +-- @return Core.Point#COORDINATE The center coordinate of all the units in the set, including heading in degrees and speed in mps in case of moving units. +function SET_UNIT:GetCoordinate() + + local Coordinate = self:GetFirst():GetCoordinate() + + local x1 = Coordinate.x + local x2 = Coordinate.x + local y1 = Coordinate.y + local y2 = Coordinate.y + local z1 = Coordinate.z + local z2 = Coordinate.z + local MaxVelocity = 0 + local AvgHeading = nil + local MovingCount = 0 + + for UnitName, UnitData in pairs( self:GetSet() ) do + + local Unit = UnitData -- Wrapper.Unit#UNIT + local Coordinate = Unit:GetCoordinate() + + x1 = ( Coordinate.x < x1 ) and Coordinate.x or x1 + x2 = ( Coordinate.x > x2 ) and Coordinate.x or x2 + y1 = ( Coordinate.y < y1 ) and Coordinate.y or y1 + y2 = ( Coordinate.y > y2 ) and Coordinate.y or y2 + z1 = ( Coordinate.y < z1 ) and Coordinate.z or z1 + z2 = ( Coordinate.y > z2 ) and Coordinate.z or z2 + + local Velocity = Coordinate:GetVelocity() + if Velocity ~= 0 then + MaxVelocity = ( MaxVelocity < Velocity ) and Velocity or MaxVelocity + local Heading = Coordinate:GetHeading() + AvgHeading = AvgHeading and ( AvgHeading + Heading ) or Heading + MovingCount = MovingCount + 1 + end + end + + AvgHeading = AvgHeading and ( AvgHeading / MovingCount ) + + Coordinate.x = ( x2 - x1 ) / 2 + x1 + Coordinate.y = ( y2 - y1 ) / 2 + y1 + Coordinate.z = ( z2 - z1 ) / 2 + z1 + Coordinate:SetHeading( AvgHeading ) + Coordinate:SetVelocity( MaxVelocity ) + + self:F( { Coordinate = Coordinate } ) + return Coordinate + +end + +--- Get the maximum velocity of the SET_UNIT. +-- @param #SET_UNIT self +-- @return #number The speed in mps in case of moving units. +function SET_UNIT:GetVelocity() + + local Coordinate = self:GetFirst():GetCoordinate() + + local MaxVelocity = 0 + + for UnitName, UnitData in pairs( self:GetSet() ) do + + local Unit = UnitData -- Wrapper.Unit#UNIT + local Coordinate = Unit:GetCoordinate() + + local Velocity = Coordinate:GetVelocity() + if Velocity ~= 0 then + MaxVelocity = ( MaxVelocity < Velocity ) and Velocity or MaxVelocity + end + end + + self:F( { MaxVelocity = MaxVelocity } ) + return MaxVelocity + +end + +--- Get the average heading of the SET_UNIT. +-- @param #SET_UNIT self +-- @return #number Heading Heading in degrees and speed in mps in case of moving units. +function SET_UNIT:GetHeading() + + local AvgHeading = nil + local MovingCount = 0 + + for UnitName, UnitData in pairs( self:GetSet() ) do + + local Unit = UnitData -- Wrapper.Unit#UNIT + local Coordinate = Unit:GetCoordinate() + + local Velocity = Coordinate:GetVelocity() + if Velocity ~= 0 then + local Heading = Coordinate:GetHeading() + AvgHeading = AvgHeading and ( AvgHeading + Heading ) or Heading + MovingCount = MovingCount + 1 + end + end + + AvgHeading = AvgHeading and ( AvgHeading / MovingCount ) + + self:F( { AvgHeading = AvgHeading } ) + return AvgHeading + +end + + --- Returns if the @{Set} has targets having a radar (of a given type). -- @param #SET_UNIT self diff --git a/Moose Development/Moose/Functional/Detection.lua b/Moose Development/Moose/Functional/Detection.lua index 729be5f40..45bdc0b77 100644 --- a/Moose Development/Moose/Functional/Detection.lua +++ b/Moose Development/Moose/Functional/Detection.lua @@ -1436,6 +1436,8 @@ do -- DETECTION_BASE else return "Unknown" end + else + return "Unknown" end else return "Dead:" .. DetectedUnit:GetName() diff --git a/Moose Development/Moose/Tasking/Task.lua b/Moose Development/Moose/Tasking/Task.lua index 07904d069..03e7107f5 100644 --- a/Moose Development/Moose/Tasking/Task.lua +++ b/Moose Development/Moose/Tasking/Task.lua @@ -867,13 +867,46 @@ function TASK:MenuMarkToGroup( TaskGroup ) self:E( "Mark Task menu selected") self:UpdateTaskInfo() + + local Report = REPORT:New():SetIndent( 0 ) + + -- List the name of the Task. + local Name = self:GetName() + Report:Add( Name .. ": " .. self:GetTaskBriefing() ) + + for TaskInfoID, TaskInfo in pairs( self.TaskInfo, function( t, a, b ) return t[a].TaskInfoOrder < t[b].TaskInfoOrder end ) do + + local TaskInfoIDText = "" --string.format( "%s: ", TaskInfoID ) + + if type( TaskInfo.TaskInfoText ) == "string" then + Report:Add( TaskInfoIDText .. TaskInfo.TaskInfoText ) + elseif type(TaskInfo) == "table" then + if TaskInfoID == "Coordinates" then + local ToCoordinate = TaskInfo.TaskInfoText -- Core.Point#COORDINATE + Report:Add( TaskInfoIDText .. ToCoordinate:ToString() ) + else + end + end + + end + + self:E("ok5") local Coordinate = self:GetInfo( "Coordinates" ) -- Core.Point#COORDINATE - local Briefing = self:GetTaskBriefing() - self:F( { Briefing = Briefing, Coordinate = Coordinate } ) + local Velocity = self.TargetSetUnit:GetVelocity() + local Heading = self.TargetSetUnit:GetHeading() - Coordinate:MarkToGroup( Briefing, TaskGroup ) + Coordinate:SetHeading( Heading ) + Coordinate:SetVelocity( Velocity ) + + Report:Add( "Targets are" .. Coordinate:GetMovingText() .. "." ) + + local MarkText = Report:Text( ", " ) + + self:F( { Coordinate = Coordinate, MarkText = MarkText } ) + + Coordinate:MarkToGroup( MarkText, TaskGroup ) --Coordinate:MarkToAll( Briefing ) end diff --git a/Moose Development/Moose/Tasking/Task_A2G.lua b/Moose Development/Moose/Tasking/Task_A2G.lua index 8c9a7b5be..5b00b1b0d 100644 --- a/Moose Development/Moose/Tasking/Task_A2G.lua +++ b/Moose Development/Moose/Tasking/Task_A2G.lua @@ -323,16 +323,9 @@ do -- TASK_A2G_SEAD Mission:AddTask( self ) - self:UpdateTaskInfo() - - local ThreatLevel, ThreatText = TargetSetUnit:CalculateThreatLevelA2G() - local TargetUnit = TargetSetUnit:GetFirst() - local TargetCoord = TargetUnit:GetCoordinate() -- Core.Point#COORDINATE - self:SetBriefing( TaskBriefing or - "Execute a Suppression of Enemy Air Defenses. " .. - ThreatText .. " targets to be expected. Target is" .. TargetCoord:GetMovingText() .. "." + "Execute a Suppression of Enemy Air Defenses." ) return self @@ -344,7 +337,13 @@ do -- TASK_A2G_SEAD local TargetCoordinate = self.Detection and self.Detection:GetDetectedItemCoordinate( self.DetectedItemIndex ) or self.TargetSetUnit:GetFirst():GetCoordinate() self:SetInfo( "Coordinates", TargetCoordinate, 0 ) - self:SetInfo( "Threat", "[" .. string.rep( "■", self.Detection and self.Detection:GetDetectedItemThreatLevel( self.DetectedItemIndex ) or self.TargetSetUnit:CalculateThreatLevelA2G() ) .. "]", 11 ) + local ThreatLevel, ThreatText + if self.Detection then + ThreatLevel, ThreatText = self.Detection:GetDetectedItemThreatLevel( self.DetectedItemIndex ) + else + ThreatLevel, ThreatText = self.TargetSetUnit:CalculateThreatLevelA2G() + end + self:SetInfo( "Threat", ThreatText .. " [" .. string.rep( "■", ThreatLevel ) .. "]", 11 ) if self.Detection then local DetectedItemsCount = self.TargetSetUnit:Count() @@ -471,16 +470,9 @@ do -- TASK_A2G_BAI Mission:AddTask( self ) - self:UpdateTaskInfo() - - local ThreatLevel, ThreatText = TargetSetUnit:CalculateThreatLevelA2G() - local TargetUnit = TargetSetUnit:GetFirst() - local TargetCoord = TargetUnit:GetCoordinate() -- Core.Point#COORDINATE - self:SetBriefing( TaskBriefing or - "Execute a Battlefield Air Interdiction of a group of enemy targets. " .. - ThreatText .. " targets to be expected. Target is" .. TargetCoord:GetMovingText() .. "." + "Execute a Battlefield Air Interdiction of a group of enemy targets." ) return self @@ -493,7 +485,13 @@ do -- TASK_A2G_BAI local TargetCoordinate = self.Detection and self.Detection:GetDetectedItemCoordinate( self.DetectedItemIndex ) or self.TargetSetUnit:GetFirst():GetCoordinate() self:SetInfo( "Coordinates", TargetCoordinate, 0 ) - self:SetInfo( "Threat", "[" .. string.rep( "■", self.Detection and self.Detection:GetDetectedItemThreatLevel( self.DetectedItemIndex ) or self.TargetSetUnit:CalculateThreatLevelA2G() ) .. "]", 11 ) + local ThreatLevel, ThreatText + if self.Detection then + ThreatLevel, ThreatText = self.Detection:GetDetectedItemThreatLevel( self.DetectedItemIndex ) + else + ThreatLevel, ThreatText = self.TargetSetUnit:CalculateThreatLevelA2G() + end + self:SetInfo( "Threat", ThreatText .. " [" .. string.rep( "■", ThreatLevel ) .. "]", 11 ) if self.Detection then local DetectedItemsCount = self.TargetSetUnit:Count() @@ -620,18 +618,10 @@ do -- TASK_A2G_CAS Mission:AddTask( self ) - self:UpdateTaskInfo() - - local ThreatLevel, ThreatText = TargetSetUnit:CalculateThreatLevelA2G() - local TargetUnit = TargetSetUnit:GetFirst() - local TargetCoord = TargetUnit:GetCoordinate() -- Core.Point#COORDINATE - self:SetBriefing( TaskBriefing or "Execute a Close Air Support for a group of enemy targets. " .. - "Beware of friendlies at the vicinity! " .. - ThreatText .. " targets to be expected. Target is" .. TargetCoord:GetMovingText() .. "." - + "Beware of friendlies at the vicinity! " ) @@ -643,9 +633,13 @@ do -- TASK_A2G_CAS local TargetCoordinate = self.Detection and self.Detection:GetDetectedItemCoordinate( self.DetectedItemIndex ) or self.TargetSetUnit:GetFirst():GetCoordinate() self:SetInfo( "Coordinates", TargetCoordinate, 0 ) - local ThreatLevel = self.Detection and self.Detection:GetDetectedItemThreatLevel( self.DetectedItemIndex ) or self.TargetSetUnit:CalculateThreatLevelA2G() - - self:SetInfo( "Threat", "[" .. string.rep( "■", ThreatLevel ) .. "]", 11 ) + local ThreatLevel, ThreatText + if self.Detection then + ThreatLevel, ThreatText = self.Detection:GetDetectedItemThreatLevel( self.DetectedItemIndex ) + else + ThreatLevel, ThreatText = self.TargetSetUnit:CalculateThreatLevelA2G() + end + self:SetInfo( "Threat", ThreatText .. " [" .. string.rep( "■", ThreatLevel ) .. "]", 11 ) if self.Detection then local DetectedItemsCount = self.TargetSetUnit:Count()