From e76c26ff5979c6645a89b6f92051eac8bc6ee8c6 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 3 Aug 2023 00:41:34 +0200 Subject: [PATCH] FLIGHTPLAN --- .../Moose/Navigation/FlightPlan.lua | 94 +++++++++++++++++-- Moose Development/Moose/Navigation/NavFix.lua | 16 ++++ Moose Development/Moose/Ops/FlightControl.lua | 7 ++ Moose Development/Moose/Ops/FlightGroup.lua | 71 +++++++++++++- 4 files changed, 178 insertions(+), 10 deletions(-) diff --git a/Moose Development/Moose/Navigation/FlightPlan.lua b/Moose Development/Moose/Navigation/FlightPlan.lua index 425603a45..345a0b7dd 100644 --- a/Moose Development/Moose/Navigation/FlightPlan.lua +++ b/Moose Development/Moose/Navigation/FlightPlan.lua @@ -24,6 +24,11 @@ -- @type FLIGHTPLAN -- @field #string ClassName Name of the class. -- @field #number verbose Verbosity of output. +-- @field #table fixes Navigation fixes. +-- @field Wrapper.Airbase#AIRBASE departureAirbase Departure airbase. +-- @field Wrapper.Airbase#AIRBASE destinationAirbase Destination airbase. +-- @field #number altitudeCruiseMin Minimum cruise altitude in feet MSL. +-- @field #number altitudeCruiseMax Maximum cruise altitude in feet MSL. -- @extends Core.Base#BASE --- *A fleet of British ships at war are the best negotiators.* -- Horatio Nelson @@ -39,7 +44,7 @@ -- A new `FLIGHTPLAN` object can be created with the @{#FLIGHTPLAN.New}(`WarehouseName`, `FleetName`) function, where `WarehouseName` is the name of the static or unit object hosting the fleet -- and `FleetName` is the name you want to give the fleet. This must be *unique*! -- --- myFleet=FLIGHTPLAN:New("myWarehouseName", "1st Fleet") +-- myFlightplan=FLIGHTPLAN:New("Plan A") -- myFleet:SetPortZone(ZonePort1stFleet) -- myFleet:Start() -- @@ -51,6 +56,7 @@ FLIGHTPLAN = { ClassName = "FLIGHTPLAN", verbose = 0, + fixes = {} } --- Type of navaid @@ -78,11 +84,9 @@ FLIGHTPLAN.version="0.0.1" -- Constructor ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---- Create a new FLIGHTPLAN class instance. +--- Create a new FLIGHTPLAN instance. -- @param #FLIGHTPLAN self --- @param #string ZoneName Name of the zone to scan the scenery. --- @param #string SceneryName Name of the scenery object. --- @param #string Type Type of Navaid. +-- @param #string Name Name of this flight plan. -- @return #FLIGHTPLAN self function FLIGHTPLAN:New(Name) @@ -101,22 +105,94 @@ function FLIGHTPLAN:New(Name) return self end +--- Create a new FLIGHTPLAN instance from another FLIGHTPLAN acting as blue print. +-- The newly created flight plan is deep copied from the given one. +-- @param #FLIGHTPLAN self +-- @param #FLIGHTPLAN FlightPlan Blue print of the flight plan to copy. +-- @return #FLIGHTPLAN self +function FLIGHTPLAN:NewFromFlightPlan(FlightPlan) + self=UTILS.DeepCopy(FlightPlan) + return self +end + ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- User Functions ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---- Set frequency. +--- Add navigation fix to the flight plan. -- @param #FLIGHTPLAN self --- @param #number Frequency Frequency in Hz. +-- @param Navigation.NavFix#NAVFIX NavFix The nav fix. -- @return #FLIGHTPLAN self -function FLIGHTPLAN:SetFrequency(Frequency) +function FLIGHTPLAN:AddNavFix(NavFix) - self.frequency=Frequency + table.insert(self.fixes, NavFix) return self end +--- Set depature airbase. +-- @param #FLIGHTPLAN self +-- @param #string AirbaseName Name of the airbase or AIRBASE object. +-- @return #FLIGHTPLAN self +function FLIGHTPLAN:SetDepartureAirbase(AirbaseName) + + self.departureAirbase=AIRBASE:FindByName(AirbaseName) + + return self +end + +--- Set destination airbase. +-- @param #FLIGHTPLAN self +-- @param #string AirbaseName Name of the airbase or AIRBASE object. +-- @return #FLIGHTPLAN self +function FLIGHTPLAN:SetDestinationAirbase(AirbaseName) + + self.destinationAirbase=AIRBASE:FindByName(AirbaseName) + + return self +end + + +--- Set cruise altitude. +-- @param #FLIGHTPLAN self +-- @param #number AltMin Minimum altitude in feet MSL. +-- @param #number AltMax Maximum altitude in feet MSL. Default is `AltMin`. +-- @return #FLIGHTPLAN self +function FLIGHTPLAN:SetCruiseAltitude(AltMin, AltMax) + + self.altitudeCruiseMin=AltMin + self.altitudeCruiseMax=AltMax or self.altitudeCruiseMin + + return self +end + + +--- Get the name of this flight plan. +-- @param #FLIGHTPLAN self +-- @return #string The name. +function FLIGHTPLAN:GetName() + return self.alias +end + + +--- Get cruise altitude. This returns a random altitude between the set min/max cruise altitudes. +-- @param #FLIGHTPLAN self +-- @return #number Cruise altitude in feet MSL. +function FLIGHTPLAN:GetCruiseAltitude() + + local alt=10000 + if self.altitudeCruiseMin and self.altitudeCruiseMax then + alt=math.random(self.altitudeCruiseMin, self.altitudeCruiseMax) + elseif self.altitudeCruiseMin then + alt=self.altitudeCruiseMin + elseif self.altitudeCruiseMax then + alt=self.altitudeCruiseMax + end + + return alt +end + ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- Private Functions ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/Moose Development/Moose/Navigation/NavFix.lua b/Moose Development/Moose/Navigation/NavFix.lua index 7ebdee888..45e387094 100644 --- a/Moose Development/Moose/Navigation/NavFix.lua +++ b/Moose Development/Moose/Navigation/NavFix.lua @@ -160,6 +160,22 @@ function NAVFIX:SetInitialApproachFix(IntermediateFix) return self end +--- Get the altitude in feet MSL. +-- @param #NAVFIX self +-- @return #number Altitude in feet MSL. Can be `#nil` +function NAVFIX:GetAltitude() + + local alt=nil + if self.altMin and self.altMax then + alt=math.random(self.altMin, self.altMax) + elseif self.altMin then + alt=self.altMin + elseif self.altMax then + alt=self.altMax + end + + return alt +end ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- Private Functions diff --git a/Moose Development/Moose/Ops/FlightControl.lua b/Moose Development/Moose/Ops/FlightControl.lua index 23e147c1f..852e646d3 100644 --- a/Moose Development/Moose/Ops/FlightControl.lua +++ b/Moose Development/Moose/Ops/FlightControl.lua @@ -332,6 +332,13 @@ FLIGHTCONTROL.version="0.7.3" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO list +-- TODO: Ground control for takeoff and taxi. +-- TODO: Improve approach pattern with new NAVIGATION classes. +-- TODO: SID procedure for departures. +-- TODO: STAR procedure for arrivals. +-- TODO: Holding positions for runways. +-- TODO: Taxi ways. +-- TODO: Better phrasiology. -- TODO: Switch to enable/disable AI messages. -- TODO: Talk me down option. -- TODO: Check runways and clean up. diff --git a/Moose Development/Moose/Ops/FlightGroup.lua b/Moose Development/Moose/Ops/FlightGroup.lua index 126705e2f..0d0f23e07 100644 --- a/Moose Development/Moose/Ops/FlightGroup.lua +++ b/Moose Development/Moose/Ops/FlightGroup.lua @@ -59,6 +59,8 @@ -- @field #boolean prohibitAB Disallow (true) or allow (false) AI to use the afterburner. -- @field #boolean jettisonEmptyTanks Allow (true) or disallow (false) AI to jettison empty fuel tanks. -- @field #boolean jettisonWeapons Allow (true) or disallow (false) AI to jettison weapons if in danger. +-- @field #table flightplans Flight plans for this group. +-- @field Navigation.FlightPlan#FLIGHTPLAN flightplan Currently active flight plan. -- -- @extends Ops.OpsGroup#OPSGROUP @@ -150,7 +152,8 @@ FLIGHTGROUP = { playerWarnings = {}, prohibitAB = false, jettisonEmptyTanks = true, - jettisonWeapons = true, -- that's actually a negative option like prohibitAB + jettisonWeapons = true, -- that's actually a negative option like prohibitAB + flightplans = {}, } @@ -647,6 +650,18 @@ function FLIGHTGROUP:SetDespawnAfterHolding() return self end +--- Add flightplan. +-- @param #FLIGHTGROUP self +-- @param Navigation.FlightPlan#FLIGHTPLAN FlightPlan The flight plan. +-- @return #FLIGHTGROUP self +function FLIGHTGROUP:AddFlightPlan(FlightPlan) + + self:T(self.lid..string.format("Adding flight plan %s", FlightPlan:GetName() )) + table.insert(self.flightplans, FlightPlan) + + return self +end + --- Check if flight is parking. -- @param #FLIGHTGROUP self @@ -1305,6 +1320,10 @@ function FLIGHTGROUP:Status() -- Current mission. local mission=self:GetMissionCurrent() + + if not (self.cargoTransport or mission) then + self:_CheckFlightPlans() + end end @@ -3353,6 +3372,56 @@ function FLIGHTGROUP:onafterFuelCritical(From, Event, To) end end +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +-- Flightplan Functions +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +--- Check flightplans. +-- @param #FLIGHTGROUP self +-- @param Navigation.FlightPlan#FLIGHTPLAN FlightPlan Flight plan. +-- @return #FLIGHTGROUP self +function FLIGHTGROUP:_SetFlightPlan(FlightPlan) + + self.flightplan=FlightPlan + + for i,_fix in pairs(FlightPlan.fixes) do + local fix=_fix --Navigation.NavFix#NAVFIX + + --fix.coordinate + + local speed=fix.altMin + + local altitude=(fix.altMin or fix.altMax)~=nil and fix:GetAltitude() or FlightPlan:GetCruiseAltitude() + + local wp=self:AddWaypoint(fix.coordinate, Speed, AfterWaypointWithID, altitude or 10000, false) + + end + +end + +--- Check flightplans. +-- @param #FLIGHTGROUP self +-- @return #FLIGHTGROUP self +function FLIGHTGROUP:_CheckFlightPlans() + + if self.flightplan then + return + end + + + for i,_flightplan in pairs(self.flightplans) do + local flightplan=_flightplan --Navigation.FlightPlan#FLIGHTPLAN + + if flightplan then + + self:_SetFlightPlan(flightplan) + + break + end + end + +end + ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- Task functions -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------