Working INTERCEPT!

This commit is contained in:
FlightControl 2017-05-23 11:50:28 +02:00
parent 220edef653
commit 96f7a79f3a
7 changed files with 94 additions and 34 deletions

View File

@ -640,7 +640,6 @@ end
-- @param #BASE self
-- @param Object The object that holds the Value set by the Key.
-- @param Key The key that is used to retrieve the value. Note that the key can be a #string, but it can also be any other type!
-- @param Value The value to is stored in the Object.
-- @return The Value retrieved.
function BASE:GetState( Object, Key )

View File

@ -1072,8 +1072,15 @@ do -- DETECTION_BASE
-- @return #boolean trhe if there are friendlies nearby
function DETECTION_BASE:IsFriendliesNearBy( DetectedItem )
self:T3( DetectedItem.FriendliesNearBy )
return DetectedItem.FriendliesNearBy or false
return DetectedItem.FriendliesNearBy ~= nil or false
end
--- Returns friendly units nearby the FAC units ...
-- @param #DETECTION_BASE self
-- @return #map<#string,Wrapper.Unit#UNIT> The map of Friendly UNITs.
function DETECTION_BASE:GetFriendliesNearBy( DetectedItem )
return DetectedItem.FriendliesNearBy
end
--- Background worker function to determine if there are friendlies nearby ...
@ -1085,7 +1092,7 @@ do -- DETECTION_BASE
local DetectedSet = ReportGroupData.DetectedItem.Set
local DetectedUnit = DetectedSet:GetFirst()
DetectedItem.FriendliesNearBy = false
DetectedItem.FriendliesNearBy = nil
if DetectedUnit then
@ -1120,7 +1127,8 @@ do -- DETECTION_BASE
self:T3( { "Friendlies search:", FoundUnitName, FoundUnitCoalition, EnemyUnitName, EnemyCoalition, FoundUnitInReportSetGroup } )
if FoundUnitCoalition ~= EnemyCoalition and FoundUnitInReportSetGroup == false then
DetectedItem.FriendliesNearBy = true
DetectedItem.FriendliesNearBy = DetectedItem.FriendliesNearBy or {}
DetectedItem.FriendliesNearBy[FoundUnitName] = UNIT:Find( FoundDCSUnit )
return false
end
@ -2107,16 +2115,6 @@ do -- DETECTION_AREAS
end
--- Returns if there are friendlies nearby the FAC units ...
-- @param #DETECTION_AREAS self
-- @return #boolean trhe if there are friendlies nearby
function DETECTION_AREAS:IsFriendliesNearBy( DetectedItem )
self:T3( DetectedItem.FriendliesNearBy )
return DetectedItem.FriendliesNearBy or false
end
--- Calculate the maxium A2G threat level of the DetectedItem.
-- @param #DETECTION_AREAS self
-- @param #DETECTION_BASE.DetectedItem DetectedItem

View File

@ -26,6 +26,8 @@ function REPORT:New( Title )
if Title then
self.Title = Title
end
self:SetIndent( 3 )
return self
end

View File

@ -769,7 +769,7 @@ end
--- Create a overview report of the Mission (multiple lines).
-- @param #MISSION self
-- @return #string
function MISSION:ReportOverview( TaskStatus )
function MISSION:ReportOverview( ReportGroup, TaskStatus )
local Report = REPORT:New()
@ -787,7 +787,7 @@ function MISSION:ReportOverview( TaskStatus )
for TaskID, Task in pairs( self:GetTasks() ) do
local Task = Task -- Tasking.Task#TASK
if Task:Is( TaskStatus ) then
Report:Add( "\n - " .. Task:ReportOverview() )
Report:Add( "\n - " .. Task:ReportOverview( ReportGroup ) )
end
end
@ -852,7 +852,7 @@ end
-- @param Wrapper.Group#GROUP ReportGroup
function MISSION:MenuReportOverview( ReportGroup, TaskStatus )
local Report = self:ReportOverview( TaskStatus )
local Report = self:ReportOverview( ReportGroup, TaskStatus )
self:GetCommandCenter():MessageToGroup( Report, ReportGroup )
end

View File

@ -1307,21 +1307,35 @@ end
-- List the Task Name and Status
-- @param #TASK self
-- @return #string
function TASK:ReportOverview() --R2.1 fixed report. Now nicely formatted and contains the info required.
function TASK:ReportOverview( ReportGroup ) --R2.1 fixed report. Now nicely formatted and contains the info required.
local Report = REPORT:New()
-- List the name of the Task.
local Name = self:GetName()
local Report = REPORT:New( "Task " .. Name )
-- Determine the status of the Task.
local State = self:GetState()
local Detection = self.TaskInfo["Detection"] and " - " .. self.TaskInfo["Detection"] or ""
Report:Add( "Task " .. Name .. Detection )
for TaskInfoID, TaskInfo in pairs( self.TaskInfo ) do
return Report:Text()
local TaskInfoIDText = string.format( " - %s: ", TaskInfoID )
if type(TaskInfo) == "string" then
Report:Add( TaskInfoIDText .. TaskInfo )
elseif type(TaskInfo) == "table" then
if TaskInfoID == "Coordinates" then
local FromCoordinate = ReportGroup:GetUnit(1):GetCoordinate()
local ToCoordinate = TaskInfo -- Core.Point#COORDINATE
Report:Add( TaskInfoIDText )
Report:AddIndent( ToCoordinate:ToStringBRA( FromCoordinate ) .. ", " .. TaskInfo:ToStringAspect( FromCoordinate ) )
--Report:AddIndent( ToCoordinate:ToStringBULLS( ReportGroup:GetCoalition() ) )
else
end
end
end
return Report:Text( ", ")
end
--- Create a count of the players in the Task.

View File

@ -348,7 +348,9 @@ do -- TASK_INTERCEPT
TASK_INTERCEPT = {
ClassName = "TASK_INTERCEPT",
}
--- Instantiates a new TASK_INTERCEPT.
-- @param #TASK_INTERCEPT self
-- @param Tasking.Mission#MISSION Mission

View File

@ -104,10 +104,7 @@ do -- TASK_A2A_DISPATCHER
local DetectedSet = DetectedItem.Set
local DetectedZone = DetectedItem.Zone
-- Put here the intercept logic....
local FriendliesNearBy = self.Detection:IsFriendliesNearBy( DetectedItem )
if not FriendliesNearBy == true then
if true then
-- Here we're doing something advanced... We're copying the DetectedSet, but making a new Set only with SEADable Radar units in it.
local TargetSetUnit = SET_UNIT:New()
@ -119,6 +116,7 @@ do -- TASK_A2A_DISPATCHER
return nil
end
--- Evaluates the removal of the Task from the Mission.
@ -133,9 +131,9 @@ do -- TASK_A2A_DISPATCHER
if Task then
local FriendliesNearBy = self.Detection:IsFriendliesNearBy( DetectedItem )
if Task:IsStatePlanned() and DetectedItemChanged == true and FriendliesNearBy then
local TaskName = Task:GetName()
if Task:IsStatePlanned() and DetectedItemChanged == true then
self:E( "Removing Tasking: " .. Task:GetTaskName() )
Mission:RemoveTask( Task )
self.Tasks[DetectedItemID] = nil
@ -144,7 +142,50 @@ do -- TASK_A2A_DISPATCHER
return Task
end
--- Calculates which friendlies are nearby the area
-- @param #TASK_A2A_DISPATCHER self
-- @param DetectedItem
-- @return #number, Core.CommandCenter#REPORT
function TASK_A2A_DISPATCHER:GetFriendliesNearBy( DetectedItem )
local DetectedSet = DetectedItem.Set
local FriendlyUnitsNearBy = self.Detection:GetFriendliesNearBy( DetectedItem )
local FriendlyTypes = {}
local FriendliesCount = 0
if FriendlyUnitsNearBy then
local DetectedTreatLevel = DetectedSet:CalculateThreatLevelA2G()
for FriendlyUnitName, FriendlyUnitData in pairs( FriendlyUnitsNearBy ) do
local FriendlyUnit = FriendlyUnitData -- Wrapper.Unit#UNIT
if FriendlyUnit:IsAirPlane() then
local FriendlyUnitThreatLevel = FriendlyUnit:GetThreatLevel()
FriendliesCount = FriendliesCount + 1
local FriendlyType = FriendlyUnit:GetTypeName()
FriendlyTypes[FriendlyType] = FriendlyTypes[FriendlyType] and ( FriendlyTypes[FriendlyType] + 1 ) or 1
if DetectedTreatLevel < FriendlyUnitThreatLevel + 2 then
end
end
end
end
self:E( { FriendliesCount = FriendliesCount } )
local FriendlyTypesReport = REPORT:New()
if FriendliesCount > 0 then
for FriendlyType, FriendlyTypeCount in pairs( FriendlyTypes ) do
FriendlyTypesReport:Add( string.format("%d of %s", FriendlyTypeCount, FriendlyType ) )
end
else
FriendlyTypesReport:Add( "-" )
end
return FriendliesCount, FriendlyTypesReport
end
--- Assigns tasks in relation to the detected items to the @{Set#SET_GROUP}.
-- @param #TASK_A2A_DISPATCHER self
@ -181,9 +222,10 @@ do -- TASK_A2A_DISPATCHER
-- Evaluate INTERCEPT
if not Task then
local TaskName = string.format( "INTERCEPT.%03d", DetectedID )
local TargetSetUnit = self:EvaluateINTERCEPT( DetectedItem ) -- Returns a SetUnit if there are targets to be INTERCEPTed...
if TargetSetUnit then
Task = TASK_INTERCEPT:New( Mission, self.SetGroup, string.format( "INTERCEPT.%03d", DetectedID ), TargetSetUnit )
Task = TASK_INTERCEPT:New( Mission, self.SetGroup, TaskName, TargetSetUnit )
end
if Task then
@ -191,13 +233,16 @@ do -- TASK_A2A_DISPATCHER
Task:SetTargetZone( DetectedZone, DetectedSet:GetFirst():GetAltitude(), DetectedSet:GetFirst():GetHeading() )
Task:SetDispatcher( self )
Mission:AddTask( Task )
TaskReport:Add( Task:GetName() )
else
self:E("This should not happen")
end
end
TaskReport:Add( Task:GetName() )
local FriendliesCount, FriendliesReport = self:GetFriendliesNearBy( DetectedItem )
Task:SetInfo( "Friendlies", string.format( "%d ( %s )", FriendliesCount, FriendliesReport:Text( "," ) ) )
-- OK, so the tasking has been done, now delete the changes reported for the area.
Detection:AcceptChanges( DetectedItem )