From d03761486145ce72d8b7e7c1a7b394c7d85adf43 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Mon, 1 Oct 2018 19:47:11 +0200 Subject: [PATCH] Changes. --- Moose Development/Moose/Core/Point.lua | 5 +- Moose Development/Moose/Core/Set.lua | 20 ++++++ Moose Development/Moose/Tasking/Task.lua | 10 +-- Moose Development/Moose/Tasking/TaskInfo.lua | 11 +-- .../Moose/Tasking/Task_Cargo_CSAR.lua | 51 +------------- .../Moose/Tasking/Task_Cargo_Dispatcher.lua | 68 ++++++++++++++++++- Moose Development/Moose/Wrapper/Group.lua | 38 +++++++++++ 7 files changed, 141 insertions(+), 62 deletions(-) diff --git a/Moose Development/Moose/Core/Point.lua b/Moose Development/Moose/Core/Point.lua index 049f9b444..984f6eb5d 100644 --- a/Moose Development/Moose/Core/Point.lua +++ b/Moose Development/Moose/Core/Point.lua @@ -1929,17 +1929,20 @@ do -- COORDINATE -- @param Core.Settings#SETTINGS Settings -- @param Tasking.Task#TASK Task The task for which coordinates need to be calculated. -- @return #string The coordinate Text in the configured coordinate system. - function COORDINATE:ToString( Controllable, Settings, Task ) -- R2.2 + function COORDINATE:ToString( Controllable, Settings, Task ) self:F2( { Controllable = Controllable and Controllable:GetName() } ) local Settings = Settings or ( Controllable and _DATABASE:GetPlayerSettings( Controllable:GetPlayerName() ) ) or _SETTINGS local ModeA2A = false + self:E('A2A false') if Task then + self:E('Task ' .. Task.ClassName ) if Task:IsInstanceOf( TASK_A2A ) then ModeA2A = true + self:E('A2A true') else if Task:IsInstanceOf( TASK_A2G ) then ModeA2A = false diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index 6fa79d6f5..d1a1cc8db 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -3119,6 +3119,26 @@ do -- SET_STATIC end + --- Calculate the maxium A2G threat level of the SET_STATIC. + -- @param #SET_STATIC self + -- @return #number The maximum threatlevel + function SET_STATIC:CalculateThreatLevelA2G() + + local MaxThreatLevelA2G = 0 + local MaxThreatText = "" + for StaticName, StaticData in pairs( self:GetSet() ) do + local ThreatStatic = StaticData -- Wrapper.Static#STATIC + local ThreatLevelA2G, ThreatText = ThreatStatic:GetThreatLevel() + if ThreatLevelA2G > MaxThreatLevelA2G then + MaxThreatLevelA2G = ThreatLevelA2G + MaxThreatText = ThreatText + end + end + + self:F( { MaxThreatLevelA2G = MaxThreatLevelA2G, MaxThreatText = MaxThreatText } ) + return MaxThreatLevelA2G, MaxThreatText + + end --- -- @param #SET_STATIC self diff --git a/Moose Development/Moose/Tasking/Task.lua b/Moose Development/Moose/Tasking/Task.lua index d5361dc17..0f4ec262d 100644 --- a/Moose Development/Moose/Tasking/Task.lua +++ b/Moose Development/Moose/Tasking/Task.lua @@ -1204,7 +1204,7 @@ function TASK:MenuMarkToGroup( TaskGroup ) if TargetCoordinates then for TargetCoordinateID, TargetCoordinate in pairs( TargetCoordinates ) do local Report = REPORT:New():SetIndent( 0 ) - self.TaskInfo:Report( Report, "M", TaskGroup, TargetCoordinateID ) + self.TaskInfo:Report( Report, "M", TaskGroup, self ) local MarkText = Report:Text( ", " ) self:F( { Coordinate = TargetCoordinate, MarkText = MarkText } ) TargetCoordinate:MarkToGroup( MarkText, TaskGroup ) @@ -1214,7 +1214,7 @@ function TASK:MenuMarkToGroup( TaskGroup ) local TargetCoordinate = self.TaskInfo:GetData( "Coordinate" ) -- Core.Point#COORDINATE if TargetCoordinate then local Report = REPORT:New():SetIndent( 0 ) - self.TaskInfo:Report( Report, "M", TaskGroup ) + self.TaskInfo:Report( Report, "M", TaskGroup, self ) local MarkText = Report:Text( ", " ) self:F( { Coordinate = TargetCoordinate, MarkText = MarkText } ) TargetCoordinate:MarkToGroup( MarkText, TaskGroup ) @@ -1751,7 +1751,7 @@ function TASK:ReportSummary( ReportGroup ) -- Determine the status of the Task. Report:Add( "State: <" .. self:GetState() .. ">" ) - self.TaskInfo:Report( Report, "S", ReportGroup ) + self.TaskInfo:Report( Report, "S", ReportGroup, self ) return Report:Text( ', ' ) end @@ -1768,7 +1768,7 @@ function TASK:ReportOverview( ReportGroup ) local TaskName = self:GetName() local Report = REPORT:New() - self.TaskInfo:Report( Report, "O", ReportGroup ) + self.TaskInfo:Report( Report, "O", ReportGroup, self ) return Report:Text() end @@ -1852,7 +1852,7 @@ function TASK:ReportDetails( ReportGroup ) Report:AddIndent( Players ) end - self.TaskInfo:Report( Report, "D", ReportGroup ) + self.TaskInfo:Report( Report, "D", ReportGroup, self ) return Report:Text() end diff --git a/Moose Development/Moose/Tasking/TaskInfo.lua b/Moose Development/Moose/Tasking/TaskInfo.lua index 9a425311a..d3fc88350 100644 --- a/Moose Development/Moose/Tasking/TaskInfo.lua +++ b/Moose Development/Moose/Tasking/TaskInfo.lua @@ -284,8 +284,9 @@ end -- @param Core.Report#REPORT Report -- @param #TASKINFO.Detail Detail The detail Level. -- @param Wrapper.Group#GROUP ReportGroup +-- @param Tasking.Task#TASK Task -- @return #TASKINFO self -function TASKINFO:Report( Report, Detail, ReportGroup ) +function TASKINFO:Report( Report, Detail, ReportGroup, Task ) local Line = 0 local LineReport = REPORT:New() @@ -306,7 +307,7 @@ function TASKINFO:Report( Report, Detail, ReportGroup ) end if Key == "Coordinate" then local Coordinate = Data.Data -- Core.Point#COORDINATE - Text = Coordinate:ToString( ReportGroup:GetUnit(1), nil, self ) + Text = Coordinate:ToString( ReportGroup:GetUnit(1), nil, Task ) end if Key == "Threat" then local DataText = Data.Data -- #string @@ -322,15 +323,15 @@ function TASKINFO:Report( Report, Detail, ReportGroup ) end if Key == "QFE" then local Coordinate = Data.Data -- Core.Point#COORDINATE - Text = Coordinate:ToStringPressure( ReportGroup:GetUnit(1), nil, self ) + Text = Coordinate:ToStringPressure( ReportGroup:GetUnit(1), nil, Task ) end if Key == "Temperature" then local Coordinate = Data.Data -- Core.Point#COORDINATE - Text = Coordinate:ToStringTemperature( ReportGroup:GetUnit(1), nil, self ) + Text = Coordinate:ToStringTemperature( ReportGroup:GetUnit(1), nil, Task ) end if Key == "Wind" then local Coordinate = Data.Data -- Core.Point#COORDINATE - Text = Coordinate:ToStringWind( ReportGroup:GetUnit(1), nil, self ) + Text = Coordinate:ToStringWind( ReportGroup:GetUnit(1), nil, Task ) end if Key == "Cargo" then local DataText = Data.Data -- #string diff --git a/Moose Development/Moose/Tasking/Task_Cargo_CSAR.lua b/Moose Development/Moose/Tasking/Task_Cargo_CSAR.lua index 88cc801cc..7b099980f 100644 --- a/Moose Development/Moose/Tasking/Task_Cargo_CSAR.lua +++ b/Moose Development/Moose/Tasking/Task_Cargo_CSAR.lua @@ -289,16 +289,6 @@ do -- TASK_CARGO_CSAR self:F( { CargoDeployed = self.CargoDeployed ~= nil and "true" or "false" } ) - --- OnBefore Transition Handler for Event CargoPickedUp. - -- @function [parent=#TASK_CARGO_CSAR] OnBeforeCargoPickedUp - -- @param #TASK_CARGO_CSAR self - -- @param #string From The From State string. - -- @param #string Event The Event string. - -- @param #string To The To State string. - -- @param Wrapper.Unit#UNIT TaskUnit The Unit (Client) that PickedUp the cargo. You can use this to retrieve the PlayerName etc. - -- @param Core.Cargo#CARGO Cargo The Cargo that got PickedUp by the TaskUnit. You can use this to check Cargo Status. - -- @return #boolean Return false to cancel Transition. - --- OnAfter Transition Handler for Event CargoPickedUp. -- @function [parent=#TASK_CARGO_CSAR] OnAfterCargoPickedUp -- @param #TASK_CARGO_CSAR self @@ -308,30 +298,6 @@ do -- TASK_CARGO_CSAR -- @param Wrapper.Unit#UNIT TaskUnit The Unit (Client) that PickedUp the cargo. You can use this to retrieve the PlayerName etc. -- @param Core.Cargo#CARGO Cargo The Cargo that got PickedUp by the TaskUnit. You can use this to check Cargo Status. - --- Synchronous Event Trigger for Event CargoPickedUp. - -- @function [parent=#TASK_CARGO_CSAR] CargoPickedUp - -- @param #TASK_CARGO_CSAR self - -- @param Wrapper.Unit#UNIT TaskUnit The Unit (Client) that PickedUp the cargo. You can use this to retrieve the PlayerName etc. - -- @param Core.Cargo#CARGO Cargo The Cargo that got PickedUp by the TaskUnit. You can use this to check Cargo Status. - - --- Asynchronous Event Trigger for Event CargoPickedUp. - -- @function [parent=#TASK_CARGO_CSAR] __CargoPickedUp - -- @param #TASK_CARGO_CSAR self - -- @param #number Delay The delay in seconds. - -- @param Wrapper.Unit#UNIT TaskUnit The Unit (Client) that PickedUp the cargo. You can use this to retrieve the PlayerName etc. - -- @param Core.Cargo#CARGO Cargo The Cargo that got PickedUp by the TaskUnit. You can use this to check Cargo Status. - - --- OnBefore Transition Handler for Event CargoDeployed. - -- @function [parent=#TASK_CARGO_CSAR] OnBeforeCargoDeployed - -- @param #TASK_CARGO_CSAR self - -- @param #string From The From State string. - -- @param #string Event The Event string. - -- @param #string To The To State string. - -- @param Wrapper.Unit#UNIT TaskUnit The Unit (Client) that Deployed the cargo. You can use this to retrieve the PlayerName etc. - -- @param Core.Cargo#CARGO Cargo The Cargo that got PickedUp by the TaskUnit. You can use this to check Cargo Status. - -- @param Core.Zone#ZONE DeployZone The zone where the Cargo got Deployed or UnBoarded. - -- @return #boolean Return false to cancel Transition. - --- OnAfter Transition Handler for Event CargoDeployed. -- @function [parent=#TASK_CARGO_CSAR] OnAfterCargoDeployed -- @param #TASK_CARGO_CSAR self @@ -342,21 +308,6 @@ do -- TASK_CARGO_CSAR -- @param Core.Cargo#CARGO Cargo The Cargo that got PickedUp by the TaskUnit. You can use this to check Cargo Status. -- @param Core.Zone#ZONE DeployZone The zone where the Cargo got Deployed or UnBoarded. - --- Synchronous Event Trigger for Event CargoDeployed. - -- @function [parent=#TASK_CARGO_CSAR] CargoDeployed - -- @param #TASK_CARGO_CSAR self - -- @param Wrapper.Unit#UNIT TaskUnit The Unit (Client) that Deployed the cargo. You can use this to retrieve the PlayerName etc. - -- @param Core.Cargo#CARGO Cargo The Cargo that got PickedUp by the TaskUnit. You can use this to check Cargo Status. - -- @param Core.Zone#ZONE DeployZone The zone where the Cargo got Deployed or UnBoarded. - - --- Asynchronous Event Trigger for Event CargoDeployed. - -- @function [parent=#TASK_CARGO_CSAR] __CargoDeployed - -- @param #TASK_CARGO_CSAR self - -- @param #number Delay The delay in seconds. - -- @param Wrapper.Unit#UNIT TaskUnit The Unit (Client) that Deployed the cargo. You can use this to retrieve the PlayerName etc. - -- @param Core.Cargo#CARGO Cargo The Cargo that got PickedUp by the TaskUnit. You can use this to check Cargo Status. - -- @param Core.Zone#ZONE DeployZone The zone where the Cargo got Deployed or UnBoarded. - local Fsm = self:GetUnitProcess() local CargoReport = REPORT:New( "Rescue a downed pilot from the following position:") @@ -379,6 +330,8 @@ do -- TASK_CARGO_CSAR return self end + + function TASK_CARGO_CSAR:ReportOrder( ReportGroup ) diff --git a/Moose Development/Moose/Tasking/Task_Cargo_Dispatcher.lua b/Moose Development/Moose/Tasking/Task_Cargo_Dispatcher.lua index 9f81a5d79..6833f197c 100644 --- a/Moose Development/Moose/Tasking/Task_Cargo_Dispatcher.lua +++ b/Moose Development/Moose/Tasking/Task_Cargo_Dispatcher.lua @@ -70,6 +70,7 @@ do -- TASK_CARGO_DISPATCHER -- @type TASK_CARGO_DISPATCHER -- @extends Tasking.Task_Manager#TASK_MANAGER -- @field TASK_CARGO_DISPATCHER.CSAR CSAR + -- @field Core.Set#SET_ZONE SetZonesCSAR --- @type TASK_CARGO_DISPATCHER.CSAR -- @field Wrapper.Unit#UNIT PilotUnit @@ -260,6 +261,18 @@ do -- TASK_CARGO_DISPATCHER -- -- Use the @{#TASK_CARGO_DISPATCHER.SetCSARDeployZone}() to setup one deployment zone, and @{#TASK_CARGO_DISPATCHER.SetCSARDeployZones}() to setup multiple default deployment zones in one call. -- + -- ## 4.4. **CSAR ejection zones**. + -- + -- Setup a set of zones where the pilots will only eject and a task is created for CSAR. When such a set of zones is given, any ejection outside those zones will not result in a pilot created for CSAR! + -- + -- Use the @{#TASK_CARGO_DISPATCHER.SetCSARZones}() to setup the set of zones. + -- + -- ## 4.5. **CSAR ejection maximum**. + -- + -- Setup how many pilots will eject the maximum. This to avoid an overload of CSAR tasks being created :-) The default is endless CSAR tasks. + -- + -- Use the @{#TASK_CARGO_DISPATCHER.SetMaxCSAR}() to setup the maximum of pilots that will eject for CSAR. + -- -- -- # 5) Handle cargo task events. -- @@ -395,6 +408,9 @@ do -- TASK_CARGO_DISPATCHER self:SetCSARRadius() self:__StartTasks( 5 ) + self.MaxCSAR = nil + self.CountCSAR = 0 + -- For CSAR missions, we process the event when a pilot ejects. self:HandleEvent( EVENTS.Ejection ) @@ -403,6 +419,47 @@ do -- TASK_CARGO_DISPATCHER end + --- Sets the set of zones were pilots will only be spawned (eject) when the planes crash. + -- Note that because this is a set of zones, the MD can create the zones dynamically within his mission! + -- Just provide a set of zones, see usage, but find the tactical situation here: + -- + -- ![CSAR Zones](../Tasking/CSAR_Zones.JPG) + -- + -- @param #TASK_CARGO_DISPATCHER self + -- @param Core.Set#SET_ZONE SetZonesCSAR The set of zones where pilots will only be spawned for CSAR when they eject. + -- @usage + -- + -- TaskDispatcher = TASK_CARGO_DISPATCHER:New( Mission, AttackGroups ) + -- + -- -- Use this call to pass the set of zones. + -- -- Note that you can create the set of zones inline, because the FilterOnce method (and other SET_ZONE methods return self). + -- -- So here the zones can be created as normal trigger zones (MOOSE creates a collection of ZONE objects when teh mission starts of all trigger zones). + -- -- Just name them as CSAR zones here. + -- TaskDispatcher:SetCSARZones( SET_ZONE:New():FilterPrefixes("CSAR"):FilterOnce() ) + -- + function TASK_CARGO_DISPATCHER:SetCSARZones( SetZonesCSAR ) + + self.SetZonesCSAR = SetZonesCSAR + + end + + + --- Sets the maximum of pilots that will be spawned (eject) when the planes crash. + -- @param #TASK_CARGO_DISPATCHER self + -- @param #number MaxCSAR The maximum of pilots that will eject for CSAR. + -- @usage + -- + -- TaskDispatcher = TASK_CARGO_DISPATCHER:New( Mission, AttackGroups ) + -- + -- -- Use this call to the maximum of CSAR to 10. + -- TaskDispatcher:SetMaxCSAR( 10 ) + -- + function TASK_CARGO_DISPATCHER:SetMaxCSAR( MaxCSAR ) + + self.MaxCSAR = MaxCSAR + + end + --- Handle the event when a pilot ejects. @@ -420,8 +477,15 @@ do -- TASK_CARGO_DISPATCHER -- Only add a CSAR task if the coalition of the mission is equal to the coalition of the ejected unit. if CSARCoalition == self.Mission:GetCommandCenter():GetCoalition() then - local CSARTaskName = self:AddCSARTask( self.CSARTaskName, CSARCoordinate, CSARHeading, CSARCountry, self.CSARBriefing ) - self:SetCSARDeployZones( CSARTaskName, self.CSARDeployZones ) + -- And only add if the eject is in one of the zones, if defined. + if not self.SetZonesCSAR or ( self.SetZonesCSAR and self.SetZonesCSAR:IsCoordinateInZone( CSARCoordinate ) ) then + -- And only if the maximum of pilots is not reached that ejected! + if not self.MaxCSAR or ( self.MaxCSAR and self.CountCSAR < self.MaxCSAR ) then + local CSARTaskName = self:AddCSARTask( self.CSARTaskName, CSARCoordinate, CSARHeading, CSARCountry, self.CSARBriefing ) + self:SetCSARDeployZones( CSARTaskName, self.CSARDeployZones ) + self.CountCSAR = self.CountCSAR + 1 + end + end end end diff --git a/Moose Development/Moose/Wrapper/Group.lua b/Moose Development/Moose/Wrapper/Group.lua index d12f613d0..536d7f8e8 100644 --- a/Moose Development/Moose/Wrapper/Group.lua +++ b/Moose Development/Moose/Wrapper/Group.lua @@ -1217,6 +1217,25 @@ end function GROUP:GetMinHeight() self:F2() + local DCSGroup = self:GetDCSObject() + + if DCSGroup then + local GroupHeightMin = 999999999 + + for Index, UnitData in pairs( DCSGroup:getUnits() ) do + local UnitData = UnitData -- DCS#Unit + + local UnitHeight = UnitData:getPoint() + + if UnitHeight < GroupHeightMin then + GroupHeightMin = UnitHeight + end + end + + return GroupHeightMin + end + + return nil end --- Returns the current maximum height of the group. @@ -1226,6 +1245,25 @@ end function GROUP:GetMaxHeight() self:F2() + local DCSGroup = self:GetDCSObject() + + if DCSGroup then + local GroupHeightMax = -999999999 + + for Index, UnitData in pairs( DCSGroup:getUnits() ) do + local UnitData = UnitData -- DCS#Unit + + local UnitHeight = UnitData:getPoint() + + if UnitHeight > GroupHeightMax then + GroupHeightMax = UnitHeight + end + end + + return GroupHeightMax + end + + return nil end -- RESPAWNING