diff --git a/Moose Development/Moose/Core/Fsm.lua b/Moose Development/Moose/Core/Fsm.lua index c204ee9a8..831c88209 100644 --- a/Moose Development/Moose/Core/Fsm.lua +++ b/Moose Development/Moose/Core/Fsm.lua @@ -821,6 +821,16 @@ do -- FSM return self._handler( self, EventName, ... ) end end + + --- Clear scheduled FSM event. + -- @param #FSM self + -- @param #string EventName Event name. + function FSM:_ClearFSMEvent( EventName ) + if self._EventSchedules[EventName] then + self.CallScheduler:Remove( self._EventSchedules[EventName] ) + self._EventSchedules[EventName]=nil + end + end --- Go sub. -- @param #FSM self diff --git a/Moose Development/Moose/Ops/Auftrag.lua b/Moose Development/Moose/Ops/Auftrag.lua index 4b49a2842..f219083b2 100644 --- a/Moose Development/Moose/Ops/Auftrag.lua +++ b/Moose Development/Moose/Ops/Auftrag.lua @@ -458,6 +458,7 @@ _AUFTRAGSNR=0 -- @field #string NOTHING Nothing. -- @field #string PATROLRACETRACK Patrol Racetrack. -- @field #string STRAFING Strafing run. +-- @field #string FREIGHTTRANSPORT Freight transport. AUFTRAG.Type={ ANTISHIP="Anti Ship", AWACS="AWACS", @@ -506,6 +507,7 @@ AUFTRAG.Type={ NOTHING="Nothing", PATROLRACETRACK="Patrol Racetrack", STRAFING="Strafing", + FREIGHTTRANSPORT="FREIGHTTRANSPORT", } --- Special task description. @@ -2172,6 +2174,58 @@ function AUFTRAG:NewCARGOTRANSPORT(StaticCargo, DropZone) return mission end +--- **[AIR]** Create a FREIGHT TRANSPORT mission. +-- This mission type can be used to transport cargo items internally via suitable transport aircraft (planes and helicopters), e.g. C-130 or CH-47. +-- It supports transporting one or multiple cargos (weight limits are not checked). +-- @param #AUFTRAG self +-- @param Wrapper.Static#STATIC StaticCargo Static cargo object. Can also be passed as a `SET_STATIC` object. +-- @param Wrapper.Airbase#AIRBASE Destination Destination airbase, where the cargo is unloaded. +-- @return #AUFTRAG self +function AUFTRAG:NewFREIGHTTRANSPORT(StaticCargo, Destination) + + -- Check if Destination is given + if Destination==nil then + self:E(self.lid..string.format("ERROR: Destination is nil for AUFTRAG:NewFREIGHTTRANSPORT! You must specify the destination airbase")) + return nil + elseif type(Destination)=="string" then + Destination=AIRBASE:FindByName(Destination) + end + + -- Check if Cargo is given + if StaticCargo==nil then + self:E(self.lid..string.format("ERROR: StaticCargo is nil for AUFTRAG:NewFREIGHTTRANSPORT! You must specify the static object that represents the cargo")) + return nil + elseif type(StaticCargo)=="string" then + StaticCargo=STATIC:FindByName(StaticCargo) + end + + -- Convert static to a set if necessary + if StaticCargo:IsInstanceOf("STATIC") then + local StaticCargoSet=SET_STATIC:New() --Core.Set#SET_STATIC + StaticCargoSet:AddCargo(StaticCargo) + StaticCargo=StaticCargoSet + end + + local mission=AUFTRAG:New(AUFTRAG.Type.FREIGHTTRANSPORT) + + mission:_TargetFromObject(StaticCargo) + + mission.missionTask=mission:GetMissionTaskforMissionType(AUFTRAG.Type.FREIGHTTRANSPORT) + + -- Set ROE and ROT. + mission.optionROE=ENUMS.ROE.ReturnFire + mission.optionROT=ENUMS.ROT.PassiveDefense + + mission.categories={AUFTRAG.Category.HELICOPTER, AUFTRAG.Category.AIRCRAFT} + + mission.DCStask=mission:GetDCSMissionTask() + + mission.DCStask.params.cargo=StaticCargo + mission.DCStask.params.destination=Destination + + return mission +end + --[[ --- **[AIR, GROUND, NAVAL]** Create a OPS TRANSPORT mission. @@ -6201,8 +6255,9 @@ end --- Get DCS task table for the given mission. -- @param #AUFTRAG self +-- @param Wrapper.Group#GROUP MissionGroup (Optional) Group that is supposed to carry out the mission. This might not exist when the AUFTRAG is created but only when the AUFTRAG is passed to a certain group. -- @return DCS#Task The DCS task table. If multiple tasks are necessary, this is returned as a combo task. -function AUFTRAG:GetDCSMissionTask() +function AUFTRAG:GetDCSMissionTask(MissionGroup) local DCStasks={} @@ -6545,6 +6600,34 @@ function AUFTRAG:GetDCSMissionTask() table.insert(DCStasks, TaskCargoTransportation) + elseif self.type==AUFTRAG.Type.FREIGHTTRANSPORT then + + ------------------------------ + -- FREIGHTTRANSPORT Mission -- + ------------------------------ + + local statics=self.engageTarget:GetObjects() + + for _, StaticObject in pairs(statics) do + local static=StaticObject --Wrapper.Static#STATIC + + self:T(static) + + -- Task to unload the cargo + local TaskCargoUnload={ + ["id"] = "CargoUnloadPlane", + ["params"] = + { + ["groupId"] = static:GetID(), + ["unitId"] = static:GetID(), + } + } + + + table.insert(DCStasks, TaskCargoUnload) + + end + elseif self.type==AUFTRAG.Type.RESCUEHELO then ------------------------- @@ -7109,6 +7192,8 @@ function AUFTRAG:GetMissionTaskforMissionType(MissionType) mtask=ENUMS.MissionTask.TRANSPORT elseif MissionType==AUFTRAG.Type.CARGOTRANSPORT then mtask=ENUMS.MissionTask.TRANSPORT + elseif MissionType==AUFTRAG.Type.FREIGHTTRANSPORT then + mtask=ENUMS.MissionTask.TRANSPORT elseif MissionType==AUFTRAG.Type.ARMORATTACK then mtask=ENUMS.MissionTask.NOTHING elseif MissionType==AUFTRAG.Type.HOVER then diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index 7a1d8d3df..c5617c94c 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -5946,6 +5946,9 @@ function OPSGROUP:RouteToMission(mission, delay) -- Debug info. self:T(self.lid..string.format("Route To Mission")) + + -- Delay in seconds before cruise or updateroute is called. + local delayGo=-1 -- Catch dead or stopped groups. if self:IsDead() or self:IsStopped() then @@ -6150,7 +6153,65 @@ function OPSGROUP:RouteToMission(mission, delay) end end - + + elseif mission.type==AUFTRAG.Type.FREIGHTTRANSPORT then + + --- + -- FREIGHTTRANSPORT + --- + + local destination=mission.DCStask.params.destination + local cargo=mission.DCStask.params.cargo + + -- Set the waypoint coordinate directly above the airbase. + -- The only way to ensure the cargo is delivered there, because when the task is executed, the cargo is delivered to the closest airbase. + -- Hopefully, ED will change the behaviour of this task but at the moment, it is what it is. + waypointcoord=destination:GetCoordinate() + + -- Get additional parameters + mission.DCStask.params.destination=destination --Wrapper.Airbase#AIRBASE + mission.DCStask.params.cargo=cargo --Core.Set#SET_STATIC + + -- Get transport unit + local unit=self.group:GetFirstUnit() + local unitIdTransport=unit:GetID() + local vec2=unit:GetVec2() + + -- Create tasks to load/transport statics cargos + local tasks={} + for StaticName, StaticObject in pairs(cargo:GetSet()) do + local static=StaticObject --Wrapper.Static#STATIC + + -- Task to transport cargo. + local TaskCargoTransportation={ + id = "CargoTransportationPlane", + params = { + x=vec2.x, + y=vec2.y, + unitIdTransport=unitIdTransport, + groupId=static:GetID(), + unitId=static:GetID(), + } + } + + table.insert(tasks, TaskCargoTransportation) + end + + -- If we have multiple tasks, we create a combo task + local TaskCargo=nil + if #tasks==1 then + TaskCargo=tasks[1] + else + TaskCargo=CONTROLLABLE.TaskCombo(nil, tasks) + end + + -- We set the task to load the cargo into the aircraft. + -- We must be careful when calling updateroute because there the task is overwritten. + -- We also clear present "UpdateRoute" FSM events + self:_ClearFSMEvent( "UpdateRoute" ) + delayGo=-30 + self.group:SetTask(TaskCargo) + elseif mission.type==AUFTRAG.Type.ARTY then --- @@ -6309,7 +6370,7 @@ function OPSGROUP:RouteToMission(mission, delay) elseif self:IsNavygroup() then self:Cruise(SpeedToMission) elseif self:IsFlightgroup() then - self:UpdateRoute() + self:__UpdateRoute(delayGo) end end