From 50b61ea09462f811c323cd930e0874914ca9f2c9 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 12 Nov 2019 20:10:15 +0100 Subject: [PATCH] Ops --- Moose Development/Moose/Ops/FlightControl.lua | 27 +++++++++++--- Moose Development/Moose/Ops/FlightGroup.lua | 37 ++++++++++++++----- 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/Moose Development/Moose/Ops/FlightControl.lua b/Moose Development/Moose/Ops/FlightControl.lua index b8528bd2c..09a619b69 100644 --- a/Moose Development/Moose/Ops/FlightControl.lua +++ b/Moose Development/Moose/Ops/FlightControl.lua @@ -93,6 +93,7 @@ FLIGHTCONTROL = { -- @field #boolean free If true, spot is free. -- @field #number drunway Distance to runway. -- @field #boolean reserved If true, reserved. +-- @field #string reserved4 Flight group the spot is reserved for. Applies only to landing. -- @field #number markerid ID of the marker. --- Runway data. @@ -104,7 +105,7 @@ FLIGHTCONTROL = { --- FlightControl class version. -- @field #string version -FLIGHTCONTROL.version="0.0.7" +FLIGHTCONTROL.version="0.0.8" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO list @@ -265,6 +266,8 @@ function FLIGHTCONTROL:onafterStatus() -- Check parking spots. self:_CheckParking() + + -- Update parking spots. self:_UpdateParkingSpots() -- Check waiting and landing queue. @@ -594,9 +597,22 @@ function FLIGHTCONTROL:_PrintQueue(queue, name) local fuel=flight.group:GetFuelMin()*100 local ai=tostring(flight.ai) local actype=tostring(flight.actype) + env.info("FF") + self:I({holding=flight.Tholding}) + self:I({parking=flight.Tparking}) local holding=flight.Tholding and UTILS.SecondsToClock(flight.Tholding-time, true) or "X" local parking=flight.Tparking and UTILS.SecondsToClock(flight.Tparking-time, true) or "X" + local holding=flight:GetHoldingTime() + if holding>=0 then + holding=UTILS.SecondsToClock(holding, true) + end + local parking=flight:GetParkingTime() + if parking>=0 then + parking=UTILS.SecondsToClock(parking, true) + end + + local nunits=flight.nunits or 1 -- Main info. @@ -772,6 +788,7 @@ function FLIGHTCONTROL:_InitParkingSpots() -- Parking spots of airbase. local parkingdata=self.airbase:GetParkingSpotsTable() + -- Init parking spots table. self.parking={} for _,_spot in pairs(parkingdata) do @@ -785,6 +802,7 @@ function FLIGHTCONTROL:_InitParkingSpots() parking.id=spot.TerminalID parking.free=spot.Free parking.reserved=spot.TOAC + parking.reserved4="none" -- Mark position. local text=string.format("ID=%d, Terminal=%d, Free=%s, Reserved=%s, Dist=%.1f", parking.id, parking.terminal, tostring(parking.free), tostring(parking.reserved), parking.drunway) @@ -858,7 +876,7 @@ function FLIGHTCONTROL:_GetFreeParkingSpots(terminal) for _,_parking in pairs(self.parking) do local parking=_parking --#FLIGHTCONTROL.ParkingSpot - if parking.free then + if parking.free and parking.reserved4=="none" then if terminal==nil or terminal==parking.terminal then n=n+1 table.insert(freespots, parking) @@ -897,9 +915,9 @@ function FLIGHTCONTROL:_UpdateParkingSpots() parking.position:RemoveMark(parking.markerid) end - local text=string.format("ID=%d, Terminal=%d, Free=%s, Reserved=%s, Dist=%.1f", parking.id, parking.terminal, tostring(parking.free), tostring(parking.reserved), parking.drunway) + local text=string.format("ID=%03d, Terminal=%03d, Free=%s, Reserved=%s, reserved4=%s, Dist=%.1f", parking.id, parking.terminal, tostring(parking.free), tostring(parking.reserved), parking.reserved4, parking.drunway) message=message.."\n"..text - if parking.free==false or parking.reserved then + if parking.free==false or parking.reserved or parking.reserved4~="none" then parking.markerid=parking.position:MarkToAll(text) end @@ -1334,7 +1352,6 @@ function FLIGHTCONTROL:_LandAI(flight) self:I(self.lid..string.format("Landing AI flight %s.", flight.groupname)) -- Add flight to landing queue. - --table.insert(self.Qlanding, flight) self:_AddFlightToLandingQueue(flight) -- Give signal to land. diff --git a/Moose Development/Moose/Ops/FlightGroup.lua b/Moose Development/Moose/Ops/FlightGroup.lua index 4101e1ea9..c86a5ec1a 100644 --- a/Moose Development/Moose/Ops/FlightGroup.lua +++ b/Moose Development/Moose/Ops/FlightGroup.lua @@ -1242,6 +1242,7 @@ end -- @param #string Event Event. -- @param #string To To state. function FLIGHTGROUP:onafterFlightParking(From, Event, To) + self:I(self.sid..string.format("Flight is parking %s.", self.groupname)) local airbase=self.group:GetCoordinate():GetClosestAirbase() @@ -1596,7 +1597,7 @@ function FLIGHTGROUP:onafterHold(From, Event, To, airbase, SpeedTo, SpeedHold, S wp[#wp+1]=pland:WaypointAirLanding(UTILS.KnotsToKmph(SpeedLand), airbase, {}, "Landing") - + -- Respawn? local respawn=true if respawn then @@ -1607,6 +1608,25 @@ function FLIGHTGROUP:onafterHold(From, Event, To, airbase, SpeedTo, SpeedHold, S -- Set route points. Template.route.points=wp + if fc then + local n,parking=fc:_GetFreeParkingSpots() + -- TODO: getsize + if n>=1 then + for i,unit in pairs(Template.units) do + local spot=parking[i] --Ops.FlightControl#FLIGHTCONTROL.ParkingSpot + spot.reserved4=unit.name + unit.parking_landing=spot.id + local text=string.format("FF Reserving parking spot %d for unit %s", spot.id, tostring(unit.name)) + env.info(text) + end + --[[ + for _,_spot in pairs(parking) do + local spot=_spot --Ops.FlightControl#FLIGHTCONTROL.ParkingSpot + end + ]] + end + end + MESSAGE:New("Respawning group"):ToAll() --Respawn the group. @@ -1887,11 +1907,10 @@ function FLIGHTGROUP._PassingWaypoint(group, flightgroup, i) if flightgroup.Debug then local pos=group:GetCoordinate() --pos:SmokeRed() - local MarkerID=pos:MarkToAll(string.format("Group %s reached waypoint %d", group:GetName(), i)) + --local MarkerID=pos:MarkToAll(string.format("Group %s reached waypoint %d", group:GetName(), i)) end -- Debug message. - --MESSAGE:New(text,10):ToAllIf(flightgroup.Debug) flightgroup:T3(flightgroup.sid..text) -- Set current waypoint. @@ -1910,7 +1929,7 @@ end -- @param Wrapper.Group#GROUP group Group object. -- @param #FLIGHTGROUP flightgroup Flight group object. function FLIGHTGROUP._ReachedHolding(group, flightgroup) - env.info(string.format("FF group %s reached holding point", group:GetName())) + flightgroup:T(flightgroup.sid..string.format("Group %s reached holding point", group:GetName())) if flightgroup.Debug then group:GetCoordinate():MarkToAll("Holding Point Reached") @@ -2261,7 +2280,7 @@ function FLIGHTGROUP:_UpdateRoute(n) for i=n, #self.waypoints do local w=self.waypoints[i] if self.Debug then - self:GetWaypointCoordinate(w):MarkToAll(string.format("UpdateRoute Waypoint %d", i)) + --self:GetWaypointCoordinate(w):MarkToAll(string.format("UpdateRoute Waypoint %d", i)) end table.insert(wp, w) end @@ -3070,24 +3089,24 @@ end --- Get holding time. -- @param #FLIGHTGROUP self --- @return #number Holding time in seconds or 0 if flight is not holding. +-- @return #number Holding time in seconds or -1 if flight is not holding. function FLIGHTGROUP:GetHoldingTime() if self.Tholding then return timer.getAbsTime()-self.Tholding end - return 0 + return -1 end --- Get parking time. -- @param #FLIGHTGROUP self --- @return #number Holding time in seconds or 0 if flight is not holding. +-- @return #number Holding time in seconds or -1 if flight is not holding. function FLIGHTGROUP:GetParkingTime() if self.Tparking then return timer.getAbsTime()-self.Tparking end - return 0 + return -1 end