mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Working INTERCEPT!
This commit is contained in:
parent
220edef653
commit
96f7a79f3a
@ -640,7 +640,6 @@ end
|
|||||||
-- @param #BASE self
|
-- @param #BASE self
|
||||||
-- @param Object The object that holds the Value set by the Key.
|
-- @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 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.
|
-- @return The Value retrieved.
|
||||||
function BASE:GetState( Object, Key )
|
function BASE:GetState( Object, Key )
|
||||||
|
|
||||||
|
|||||||
@ -1072,8 +1072,15 @@ do -- DETECTION_BASE
|
|||||||
-- @return #boolean trhe if there are friendlies nearby
|
-- @return #boolean trhe if there are friendlies nearby
|
||||||
function DETECTION_BASE:IsFriendliesNearBy( DetectedItem )
|
function DETECTION_BASE:IsFriendliesNearBy( DetectedItem )
|
||||||
|
|
||||||
self:T3( DetectedItem.FriendliesNearBy )
|
return DetectedItem.FriendliesNearBy ~= nil or false
|
||||||
return DetectedItem.FriendliesNearBy 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
|
end
|
||||||
|
|
||||||
--- Background worker function to determine if there are friendlies nearby ...
|
--- Background worker function to determine if there are friendlies nearby ...
|
||||||
@ -1085,7 +1092,7 @@ do -- DETECTION_BASE
|
|||||||
local DetectedSet = ReportGroupData.DetectedItem.Set
|
local DetectedSet = ReportGroupData.DetectedItem.Set
|
||||||
local DetectedUnit = DetectedSet:GetFirst()
|
local DetectedUnit = DetectedSet:GetFirst()
|
||||||
|
|
||||||
DetectedItem.FriendliesNearBy = false
|
DetectedItem.FriendliesNearBy = nil
|
||||||
|
|
||||||
if DetectedUnit then
|
if DetectedUnit then
|
||||||
|
|
||||||
@ -1120,7 +1127,8 @@ do -- DETECTION_BASE
|
|||||||
self:T3( { "Friendlies search:", FoundUnitName, FoundUnitCoalition, EnemyUnitName, EnemyCoalition, FoundUnitInReportSetGroup } )
|
self:T3( { "Friendlies search:", FoundUnitName, FoundUnitCoalition, EnemyUnitName, EnemyCoalition, FoundUnitInReportSetGroup } )
|
||||||
|
|
||||||
if FoundUnitCoalition ~= EnemyCoalition and FoundUnitInReportSetGroup == false then
|
if FoundUnitCoalition ~= EnemyCoalition and FoundUnitInReportSetGroup == false then
|
||||||
DetectedItem.FriendliesNearBy = true
|
DetectedItem.FriendliesNearBy = DetectedItem.FriendliesNearBy or {}
|
||||||
|
DetectedItem.FriendliesNearBy[FoundUnitName] = UNIT:Find( FoundDCSUnit )
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -2107,16 +2115,6 @@ do -- DETECTION_AREAS
|
|||||||
end
|
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.
|
--- Calculate the maxium A2G threat level of the DetectedItem.
|
||||||
-- @param #DETECTION_AREAS self
|
-- @param #DETECTION_AREAS self
|
||||||
-- @param #DETECTION_BASE.DetectedItem DetectedItem
|
-- @param #DETECTION_BASE.DetectedItem DetectedItem
|
||||||
|
|||||||
@ -27,6 +27,8 @@ function REPORT:New( Title )
|
|||||||
self.Title = Title
|
self.Title = Title
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self:SetIndent( 3 )
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -769,7 +769,7 @@ end
|
|||||||
--- Create a overview report of the Mission (multiple lines).
|
--- Create a overview report of the Mission (multiple lines).
|
||||||
-- @param #MISSION self
|
-- @param #MISSION self
|
||||||
-- @return #string
|
-- @return #string
|
||||||
function MISSION:ReportOverview( TaskStatus )
|
function MISSION:ReportOverview( ReportGroup, TaskStatus )
|
||||||
|
|
||||||
local Report = REPORT:New()
|
local Report = REPORT:New()
|
||||||
|
|
||||||
@ -787,7 +787,7 @@ function MISSION:ReportOverview( TaskStatus )
|
|||||||
for TaskID, Task in pairs( self:GetTasks() ) do
|
for TaskID, Task in pairs( self:GetTasks() ) do
|
||||||
local Task = Task -- Tasking.Task#TASK
|
local Task = Task -- Tasking.Task#TASK
|
||||||
if Task:Is( TaskStatus ) then
|
if Task:Is( TaskStatus ) then
|
||||||
Report:Add( "\n - " .. Task:ReportOverview() )
|
Report:Add( "\n - " .. Task:ReportOverview( ReportGroup ) )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -852,7 +852,7 @@ end
|
|||||||
-- @param Wrapper.Group#GROUP ReportGroup
|
-- @param Wrapper.Group#GROUP ReportGroup
|
||||||
function MISSION:MenuReportOverview( ReportGroup, TaskStatus )
|
function MISSION:MenuReportOverview( ReportGroup, TaskStatus )
|
||||||
|
|
||||||
local Report = self:ReportOverview( TaskStatus )
|
local Report = self:ReportOverview( ReportGroup, TaskStatus )
|
||||||
|
|
||||||
self:GetCommandCenter():MessageToGroup( Report, ReportGroup )
|
self:GetCommandCenter():MessageToGroup( Report, ReportGroup )
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1307,21 +1307,35 @@ end
|
|||||||
-- List the Task Name and Status
|
-- List the Task Name and Status
|
||||||
-- @param #TASK self
|
-- @param #TASK self
|
||||||
-- @return #string
|
-- @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.
|
-- List the name of the Task.
|
||||||
local Name = self:GetName()
|
local Name = self:GetName()
|
||||||
|
local Report = REPORT:New( "Task " .. Name )
|
||||||
|
|
||||||
-- Determine the status of the Task.
|
-- Determine the status of the Task.
|
||||||
local State = self:GetState()
|
local State = self:GetState()
|
||||||
|
|
||||||
local Detection = self.TaskInfo["Detection"] and " - " .. self.TaskInfo["Detection"] or ""
|
for TaskInfoID, TaskInfo in pairs( self.TaskInfo ) do
|
||||||
|
|
||||||
Report:Add( "Task " .. Name .. Detection )
|
local TaskInfoIDText = string.format( " - %s: ", TaskInfoID )
|
||||||
|
|
||||||
return Report:Text()
|
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
|
end
|
||||||
|
|
||||||
--- Create a count of the players in the Task.
|
--- Create a count of the players in the Task.
|
||||||
|
|||||||
@ -349,6 +349,8 @@ do -- TASK_INTERCEPT
|
|||||||
ClassName = "TASK_INTERCEPT",
|
ClassName = "TASK_INTERCEPT",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- Instantiates a new TASK_INTERCEPT.
|
--- Instantiates a new TASK_INTERCEPT.
|
||||||
-- @param #TASK_INTERCEPT self
|
-- @param #TASK_INTERCEPT self
|
||||||
-- @param Tasking.Mission#MISSION Mission
|
-- @param Tasking.Mission#MISSION Mission
|
||||||
|
|||||||
@ -104,10 +104,7 @@ do -- TASK_A2A_DISPATCHER
|
|||||||
local DetectedSet = DetectedItem.Set
|
local DetectedSet = DetectedItem.Set
|
||||||
local DetectedZone = DetectedItem.Zone
|
local DetectedZone = DetectedItem.Zone
|
||||||
|
|
||||||
-- Put here the intercept logic....
|
if true then
|
||||||
local FriendliesNearBy = self.Detection:IsFriendliesNearBy( DetectedItem )
|
|
||||||
|
|
||||||
if not FriendliesNearBy == 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.
|
-- 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()
|
local TargetSetUnit = SET_UNIT:New()
|
||||||
@ -121,6 +118,7 @@ do -- TASK_A2A_DISPATCHER
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- Evaluates the removal of the Task from the Mission.
|
--- Evaluates the removal of the Task from the Mission.
|
||||||
-- Can only occur when the DetectedItem is Changed AND the state of the Task is "Planned".
|
-- Can only occur when the DetectedItem is Changed AND the state of the Task is "Planned".
|
||||||
-- @param #TASK_A2A_DISPATCHER self
|
-- @param #TASK_A2A_DISPATCHER self
|
||||||
@ -133,9 +131,9 @@ do -- TASK_A2A_DISPATCHER
|
|||||||
|
|
||||||
|
|
||||||
if Task then
|
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() )
|
self:E( "Removing Tasking: " .. Task:GetTaskName() )
|
||||||
Mission:RemoveTask( Task )
|
Mission:RemoveTask( Task )
|
||||||
self.Tasks[DetectedItemID] = nil
|
self.Tasks[DetectedItemID] = nil
|
||||||
@ -145,6 +143,49 @@ do -- TASK_A2A_DISPATCHER
|
|||||||
return Task
|
return Task
|
||||||
end
|
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}.
|
--- Assigns tasks in relation to the detected items to the @{Set#SET_GROUP}.
|
||||||
-- @param #TASK_A2A_DISPATCHER self
|
-- @param #TASK_A2A_DISPATCHER self
|
||||||
@ -181,9 +222,10 @@ do -- TASK_A2A_DISPATCHER
|
|||||||
|
|
||||||
-- Evaluate INTERCEPT
|
-- Evaluate INTERCEPT
|
||||||
if not Task then
|
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...
|
local TargetSetUnit = self:EvaluateINTERCEPT( DetectedItem ) -- Returns a SetUnit if there are targets to be INTERCEPTed...
|
||||||
if TargetSetUnit then
|
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
|
end
|
||||||
|
|
||||||
if Task then
|
if Task then
|
||||||
@ -191,13 +233,16 @@ do -- TASK_A2A_DISPATCHER
|
|||||||
Task:SetTargetZone( DetectedZone, DetectedSet:GetFirst():GetAltitude(), DetectedSet:GetFirst():GetHeading() )
|
Task:SetTargetZone( DetectedZone, DetectedSet:GetFirst():GetAltitude(), DetectedSet:GetFirst():GetHeading() )
|
||||||
Task:SetDispatcher( self )
|
Task:SetDispatcher( self )
|
||||||
Mission:AddTask( Task )
|
Mission:AddTask( Task )
|
||||||
|
|
||||||
|
TaskReport:Add( Task:GetName() )
|
||||||
else
|
else
|
||||||
self:E("This should not happen")
|
self:E("This should not happen")
|
||||||
end
|
end
|
||||||
|
|
||||||
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.
|
-- OK, so the tasking has been done, now delete the changes reported for the area.
|
||||||
Detection:AcceptChanges( DetectedItem )
|
Detection:AcceptChanges( DetectedItem )
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user