diff --git a/Moose Development/Moose/Ops/Auftrag.lua b/Moose Development/Moose/Ops/Auftrag.lua index d5e62aab1..fa2d49679 100644 --- a/Moose Development/Moose/Ops/Auftrag.lua +++ b/Moose Development/Moose/Ops/Auftrag.lua @@ -1312,6 +1312,62 @@ function AUFTRAG:NewCAP(ZoneCAP, Altitude, Speed, Coordinate, Heading, Leg, Targ return mission end +--- **[AIRPANE]** Create a CAP on group mission. +-- @param #AUFTRAG self +-- @param Wrapper.Group#GROUP group. +-- @param #number Altitude Orbit altitude in feet. Default is 6,000 ft. +-- @param #number Speed Orbit speed in knots. Default 250 KIAS. +-- @param #number Leg Length of race-track in NM. Default 14 NM. +-- @param #number RelHeading Relative heading [0, 360) of race-track pattern in degrees wrt heading of the carrier. Default is heading of the carrier. +-- @param #number OffsetDist Relative distance of the first race-track point wrt to the carrier. Default 6 NM. +-- @param #number OffsetAngle Relative angle of the first race-track point wrt. to the carrier. Default 180 (behind the boat). +-- @param #number UpdateDistance Threshold distance in NM before orbit pattern is updated. Default 5 NM. +-- @param #table TargetTypes (Optional) Table of target types. Default `{"Helicopters", "Ground Units", "Light armed ships"}`. +-- @param #number EngageRange Max range in nautical miles that the escort group(s) will engage enemies. Default 32 NM (60 km). +-- @return #AUFTRAG self +function AUFTRAG:NewCAPGROUP(Grp, Altitude, Speed, RelHeading, Leg, OffsetDist, OffsetAngle, UpdateDistance, TargetTypes, EngageRange) + + -- Ensure given TargetTypes parameter is a table. + if TargetTypes then + if type(TargetTypes)~="table" then + TargetTypes={TargetTypes} + end + end + -- Six NM astern. + local OffsetVec2={r=OffsetDist or 6, phi=OffsetAngle or 180} + + -- Default leg. + Leg=Leg or 14 + + local Heading=nil + if RelHeading then + Heading=-math.abs(RelHeading) + end + + -- Create orbit mission. + local mission=AUFTRAG:NewORBIT_GROUP(Grp, Altitude, Speed, Leg, Heading, OffsetVec2, UpdateDistance) + -- Mission type CAP. + mission.type=AUFTRAG.Type.CAP + mission:_SetLogID() + + -- DCS task parameters: + local engage = EngageRange or 32 + local zoneCAPGroup = ZONE_GROUP:New("CAPGroup", Grp, UTILS.NMToMeters(engage)) + mission.engageZone=zoneCAPGroup + mission.engageTargetTypes=TargetTypes or {"Air"} + + -- Mission options: + mission.missionTask=ENUMS.MissionTask.CAP + mission.optionROE=ENUMS.ROE.OpenFire + mission.optionROT=ENUMS.ROT.EvadeFire + + mission.categories={AUFTRAG.Category.AIRCRAFT} + + mission.DCStask=mission:GetDCSMissionTask() + + return mission +end + --- **[AIR]** Create a CAS mission. -- @param #AUFTRAG self -- @param Core.Zone#ZONE_RADIUS ZoneCAS Circular CAS zone. Detected targets in this zone will be engaged. diff --git a/Moose Development/Moose/Ops/Chief.lua b/Moose Development/Moose/Ops/Chief.lua index fe60fed48..4f9d6216b 100644 --- a/Moose Development/Moose/Ops/Chief.lua +++ b/Moose Development/Moose/Ops/Chief.lua @@ -413,6 +413,8 @@ function CHIEF:New(Coalition, AgentSet, Alias) self:AddTransition("*", "DefconChange", "*") -- Change defence condition. self:AddTransition("*", "StrategyChange", "*") -- Change strategy condition. + self:AddTransition("*", "LegionLost", "*") -- Out of our legions was lost to the enemy. + ------------------------ --- Pseudo Functions --- ------------------------ @@ -647,6 +649,33 @@ function CHIEF:New(Coalition, AgentSet, Alias) -- @param #string To To state. -- @param Ops.OpsZone#OPSZONE OpsZone Zone that is being attacked. + + --- Triggers the FSM event "LegionLost". + -- @function [parent=#CHIEF] LegionLost + -- @param #CHIEF self + -- @param Ops.Legion#LEGION Legion The legion that was lost. + -- @param DCS#coalition.side Coalition which captured the warehouse. + -- @param DCS#country.id Country which has captured the warehouse. + + --- Triggers the FSM event "LegionLost". + -- @function [parent=#CHIEF] __LegionLost + -- @param #CHIEF self + -- @param #number delay Delay in seconds. + -- @param Ops.Legion#LEGION Legion The legion that was lost. + -- @param DCS#coalition.side Coalition which captured the warehouse. + -- @param DCS#country.id Country which has captured the warehouse. + + --- On after "LegionLost" event. + -- @function [parent=#CHIEF] OnAfterLegionLost + -- @param #CHIEF self + -- @param #string From From state. + -- @param #string Event Event. + -- @param #string To To state. + -- @param Ops.Legion#LEGION Legion The legion that was lost. + -- @param DCS#coalition.side Coalition which captured the warehouse. + -- @param DCS#country.id Country which has captured the warehouse. + + return self end @@ -1115,6 +1144,21 @@ function CHIEF:AddLegion(Legion) return self end +--- Remove a LEGION to the chief's commander. +-- @param #CHIEF self +-- @param Ops.Legion#LEGION Legion The legion to add. +-- @return #CHIEF self +function CHIEF:RemoveLegion(Legion) + + -- Set chief of the legion. + Legion.chief=nil + + -- Add legion to the commander. + self.commander:RemoveLegion(Legion) + + return self +end + --- Add mission to mission queue of the COMMANDER. -- @param #CHIEF self diff --git a/Moose Development/Moose/Ops/Commander.lua b/Moose Development/Moose/Ops/Commander.lua index 022fc2678..2126a90de 100644 --- a/Moose Development/Moose/Ops/Commander.lua +++ b/Moose Development/Moose/Ops/Commander.lua @@ -209,6 +209,8 @@ function COMMANDER:New(Coalition, Alias) self:AddTransition("*", "TransportCancel", "*") -- COMMANDER cancels a Transport. self:AddTransition("*", "OpsOnMission", "*") -- An OPSGROUP was send on a Mission (AUFTRAG). + + self:AddTransition("*", "LegionLost", "*") -- Out of our legions was lost to the enemy. ------------------------ --- Pseudo Functions --- @@ -351,6 +353,32 @@ function COMMANDER:New(Coalition, Alias) -- @param Ops.OpsGroup#OPSGROUP OpsGroup The OPS group on mission. -- @param Ops.Auftrag#AUFTRAG Mission The mission. + + --- Triggers the FSM event "LegionLost". + -- @function [parent=#COMMANDER] LegionLost + -- @param #COMMANDER self + -- @param Ops.Legion#LEGION Legion The legion that was lost. + -- @param DCS#coalition.side Coalition which captured the warehouse. + -- @param DCS#country.id Country which has captured the warehouse. + + --- Triggers the FSM event "LegionLost". + -- @function [parent=#COMMANDER] __LegionLost + -- @param #COMMANDER self + -- @param #number delay Delay in seconds. + -- @param Ops.Legion#LEGION Legion The legion that was lost. + -- @param DCS#coalition.side Coalition which captured the warehouse. + -- @param DCS#country.id Country which has captured the warehouse. + + --- On after "LegionLost" event. + -- @function [parent=#COMMANDER] OnAfterLegionLost + -- @param #COMMANDER self + -- @param #string From From state. + -- @param #string Event Event. + -- @param #string To To state. + -- @param Ops.Legion#LEGION Legion The legion that was lost. + -- @param DCS#coalition.side Coalition which captured the warehouse. + -- @param DCS#country.id Country which has captured the warehouse. + return self end @@ -442,6 +470,23 @@ function COMMANDER:AddLegion(Legion) return self end +--- Remove a LEGION to the commander. +-- @param #COMMANDER self +-- @param Ops.Legion#LEGION Legion The legion to be removed. +-- @return #COMMANDER self +function COMMANDER:RemoveLegion(Legion) + + for i,_legion in pairs(self.legions) do + local legion=_legion --Ops.Legion#LEGION + if legion.alias==Legion.alias then + table.remove(self.legions, i) + Legion.commander=nil + end + end + + return self +end + --- Add mission to mission queue. -- @param #COMMANDER self -- @param Ops.Auftrag#AUFTRAG Mission Mission to be added. diff --git a/Moose Development/Moose/Ops/FlightGroup.lua b/Moose Development/Moose/Ops/FlightGroup.lua index 3d43ee67f..3087195f6 100644 --- a/Moose Development/Moose/Ops/FlightGroup.lua +++ b/Moose Development/Moose/Ops/FlightGroup.lua @@ -908,7 +908,7 @@ function FLIGHTGROUP:Status() if mission and mission.updateDCSTask then -- Orbit missions might need updates. - if (mission:GetType()==AUFTRAG.Type.ORBIT or mission:GetType()==AUFTRAG.Type.RECOVERYTANKER) and mission.orbitVec2 then + if (mission:GetType()==AUFTRAG.Type.ORBIT or mission:GetType()==AUFTRAG.Type.RECOVERYTANKER or mission:GetType()==AUFTRAG.Type.CAP) and mission.orbitVec2 then -- Get 2D vector of orbit target. local vec2=mission:GetTargetVec2() diff --git a/Moose Development/Moose/Ops/Legion.lua b/Moose Development/Moose/Ops/Legion.lua index 80fdf1e9e..76e0f641f 100644 --- a/Moose Development/Moose/Ops/Legion.lua +++ b/Moose Development/Moose/Ops/Legion.lua @@ -553,6 +553,13 @@ function LEGION:IsCohort(CohortName) return false end +--- Get name of legion. This is the alias of the warehouse. +-- @param #LEGION self +-- @return #string Name of legion. +function LEGION:GetName() + return self.alias +end + --- Get cohort of an asset. -- @param #LEGION self -- @param Functional.Warehouse#WAREHOUSE.Assetitem Asset The asset. @@ -1631,6 +1638,34 @@ function LEGION:onafterRequestSpawned(From, Event, To, Request, CargoGroupSet, T end +--- On after "Captured" event. +-- @param #LEGION self +-- @param #string From From state. +-- @param #string Event Event. +-- @param #string To To state. +-- @param DCS#coalition.side Coalition which captured the warehouse. +-- @param DCS#country.id Country which has captured the warehouse. +function LEGION:onafterCaptured(From, Event, To, Coalition, Country) + + -- Call parent warehouse function. + self:GetParent(self, LEGION).onafterCaptured(self, From, Event, To, Coalition, Country) + + + if self.chief then + -- Trigger event for chief and commander. + self.chief.commander:LegionLost(self, Coalition, Country) + self.chief:LegionLost(self, Coalition, Country) + -- Remove legion from chief and commander. + self.chief:RemoveLegion(self) + elseif self.commander then + -- Trigger event. + self.commander:LegionLost(self, Coalition,Country) + -- Remove legion from commander. + self.commander:RemoveLegion(self) + end + +end + ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- Mission Functions -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------