This commit is contained in:
FlightControl_Master 2017-09-13 07:07:07 +02:00
parent 5d62125245
commit adb4befcdf
5 changed files with 169 additions and 37 deletions

View File

@ -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

View File

@ -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

View File

@ -1436,6 +1436,8 @@ do -- DETECTION_BASE
else
return "Unknown"
end
else
return "Unknown"
end
else
return "Dead:" .. DetectedUnit:GetName()

View File

@ -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

View File

@ -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()