mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Update FlightControl.lua
This commit is contained in:
parent
69175e1b19
commit
8c573c65d4
@ -16,7 +16,7 @@
|
|||||||
--- FLIGHTCONTROL class.
|
--- FLIGHTCONTROL class.
|
||||||
-- @type FLIGHTCONTROL
|
-- @type FLIGHTCONTROL
|
||||||
-- @field #string ClassName Name of the class.
|
-- @field #string ClassName Name of the class.
|
||||||
-- @field #boolean Debug Debug mode. Messages to all about status.
|
-- @field #number verbose Verbosity level.
|
||||||
-- @field #string theatre The DCS map used in the mission.
|
-- @field #string theatre The DCS map used in the mission.
|
||||||
-- @field #string lid Class id string for output to DCS log file.
|
-- @field #string lid Class id string for output to DCS log file.
|
||||||
-- @field #string airbasename Name of airbase.
|
-- @field #string airbasename Name of airbase.
|
||||||
@ -52,7 +52,7 @@
|
|||||||
-- @field #FLIGHTCONTROL
|
-- @field #FLIGHTCONTROL
|
||||||
FLIGHTCONTROL = {
|
FLIGHTCONTROL = {
|
||||||
ClassName = "FLIGHTCONTROL",
|
ClassName = "FLIGHTCONTROL",
|
||||||
Debug = false,
|
verbose = 3,
|
||||||
lid = nil,
|
lid = nil,
|
||||||
theatre = nil,
|
theatre = nil,
|
||||||
airbasename = nil,
|
airbasename = nil,
|
||||||
@ -135,16 +135,14 @@ FLIGHTCONTROL.Sound = {
|
|||||||
|
|
||||||
--- FlightControl class version.
|
--- FlightControl class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
FLIGHTCONTROL.version="0.4.0"
|
FLIGHTCONTROL.version="0.5.0"
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- TODO list
|
-- TODO list
|
||||||
--
|
|
||||||
-- TODO: Define holding zone
|
|
||||||
-- TODO:
|
|
||||||
--
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- TODO: Runway destroyed.
|
||||||
|
-- TODO: Define holding zone
|
||||||
-- DONE: Add parking guard.
|
-- DONE: Add parking guard.
|
||||||
-- TODO: Accept and forbit parking spots.
|
-- TODO: Accept and forbit parking spots.
|
||||||
-- NOGO: Add FARPS?
|
-- NOGO: Add FARPS?
|
||||||
@ -214,14 +212,6 @@ function FLIGHTCONTROL:New(airbasename)
|
|||||||
self:AddTransition("Stopped", "Start", "Running") -- Start FSM.
|
self:AddTransition("Stopped", "Start", "Running") -- Start FSM.
|
||||||
self:AddTransition("*", "Status", "*") -- Update status.
|
self:AddTransition("*", "Status", "*") -- Update status.
|
||||||
|
|
||||||
-- Debug trace.
|
|
||||||
if false then
|
|
||||||
self.Debug=true
|
|
||||||
BASE:TraceOnOff(true)
|
|
||||||
BASE:TraceClass(self.ClassName)
|
|
||||||
BASE:TraceLevel(1)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Add to data base.
|
-- Add to data base.
|
||||||
_DATABASE:AddFlightControl(self)
|
_DATABASE:AddFlightControl(self)
|
||||||
|
|
||||||
@ -379,9 +369,10 @@ function FLIGHTCONTROL:onafterStatus()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Info text.
|
-- Info text.
|
||||||
local text=string.format("State %s - Runway %s - Parking F=%d/O=%d/R=%d of %d - Flights=%s: Qpark=%d Qtxout=%d Qready=%d Qto=%d | Qinbound=%d Qhold=%d Qland=%d Qtxinb=%d Qarr=%d",
|
if self.verbose>0 then
|
||||||
self:GetState(), runway.idx, Nfree, Noccu, Nresv, self.Nparkingspots, Nflights, NQparking, NQtaxiout, NQreadyto, NQtakeoff, NQinbound, NQholding, NQlanding, NQtaxiinb, NQarrived)
|
local text=string.format("State %s - Runway %s - Parking F=%d/O=%d/R=%d of %d - Flights=%s", self:GetState(), runway.idx, Nfree, Noccu, Nresv, self.Nparkingspots, Nflights)
|
||||||
self:I(self.lid..text)
|
self:I(self.lid..text)
|
||||||
|
end
|
||||||
|
|
||||||
if Nflights==Nqueues then
|
if Nflights==Nqueues then
|
||||||
--Check!
|
--Check!
|
||||||
@ -389,6 +380,24 @@ function FLIGHTCONTROL:onafterStatus()
|
|||||||
self:E(string.format("WARNING: Number of total flights %d!=%d number of flights in all queues!", Nflights, Nqueues))
|
self:E(string.format("WARNING: Number of total flights %d!=%d number of flights in all queues!", Nflights, Nqueues))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if self.verbose>1 then
|
||||||
|
local text="Queue:"
|
||||||
|
text=text..string.format("\n- Flights = %d", Nflights)
|
||||||
|
text=text..string.format("\n---------------------------------------------")
|
||||||
|
text=text..string.format("\n- Parking = %d", NQparking)
|
||||||
|
text=text..string.format("\n- Taxi Out = %d", NQtaxiout)
|
||||||
|
text=text..string.format("\n- Ready TO = %d", NQreadyto)
|
||||||
|
text=text..string.format("\n- Take off = %d", NQtakeoff)
|
||||||
|
text=text..string.format("\n---------------------------------------------")
|
||||||
|
text=text..string.format("\n- Inbound = %d", NQinbound)
|
||||||
|
text=text..string.format("\n- Holding = %d", NQholding)
|
||||||
|
text=text..string.format("\n- Landing = %d", NQlanding)
|
||||||
|
text=text..string.format("\n- Taxi Inb = %d", NQtaxiinb)
|
||||||
|
text=text..string.format("\n- Arrived = %d", NQarrived)
|
||||||
|
text=text..string.format("\n---------------------------------------------")
|
||||||
|
self:I(self.lid..text)
|
||||||
|
end
|
||||||
|
|
||||||
-- Next status update in ~30 seconds.
|
-- Next status update in ~30 seconds.
|
||||||
self:__Status(-20)
|
self:__Status(-20)
|
||||||
end
|
end
|
||||||
@ -420,30 +429,30 @@ function FLIGHTCONTROL:OnEventBirth(EventData)
|
|||||||
|
|
||||||
if EventData and EventData.IniGroupName and EventData.IniUnit then
|
if EventData and EventData.IniGroupName and EventData.IniUnit then
|
||||||
|
|
||||||
self:I(self.lid..string.format("BIRTH: unit = %s", tostring(EventData.IniUnitName)))
|
-- Debug
|
||||||
|
self:T2(self.lid..string.format("BIRTH: unit = %s", tostring(EventData.IniUnitName)))
|
||||||
self:T2(self.lid..string.format("BIRTH: group = %s", tostring(EventData.IniGroupName)))
|
self:T2(self.lid..string.format("BIRTH: group = %s", tostring(EventData.IniGroupName)))
|
||||||
|
|
||||||
-- Unit that was born.
|
-- Unit that was born.
|
||||||
local unit=EventData.IniUnit
|
local unit=EventData.IniUnit
|
||||||
|
|
||||||
-- We delay this, to have all elements of the group in the game.
|
-- Check if birth took place at this airfield.
|
||||||
if unit:IsAir() then
|
|
||||||
|
|
||||||
local bornhere=EventData.Place and EventData.Place:GetName()==self.airbasename or false
|
local bornhere=EventData.Place and EventData.Place:GetName()==self.airbasename or false
|
||||||
env.info("FF born here ".. tostring(bornhere))
|
|
||||||
|
-- We delay this, to have all elements of the group in the game.
|
||||||
|
if unit:IsAir() and bornhere then
|
||||||
|
|
||||||
-- We got a player?
|
-- We got a player?
|
||||||
local playerunit, playername=self:_GetPlayerUnitAndName(EventData.IniUnitName)
|
local playerunit, playername=self:_GetPlayerUnitAndName(EventData.IniUnitName)
|
||||||
|
|
||||||
if playername or bornhere then
|
-- Create flight group.
|
||||||
|
if playername then
|
||||||
|
--self:ScheduleOnce(0.5, self._CreateFlightGroup, self, EventData.IniGroup)
|
||||||
|
end
|
||||||
self:ScheduleOnce(0.5, self._CreateFlightGroup, self, EventData.IniGroup)
|
self:ScheduleOnce(0.5, self._CreateFlightGroup, self, EventData.IniGroup)
|
||||||
|
|
||||||
end
|
-- Spawn parking guard.
|
||||||
|
|
||||||
if bornhere then
|
|
||||||
self:SpawnParkingGuard(unit)
|
self:SpawnParkingGuard(unit)
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -933,10 +942,16 @@ end
|
|||||||
-- @param #FLIGHTCONTROL self
|
-- @param #FLIGHTCONTROL self
|
||||||
-- @param Ops.FlightGroup#FLIGHTGROUP flight Flight group.
|
-- @param Ops.FlightGroup#FLIGHTGROUP flight Flight group.
|
||||||
-- @param #string status New status.
|
-- @param #string status New status.
|
||||||
|
-- @param #FLIGHTCONTROL self
|
||||||
function FLIGHTCONTROL:SetFlightStatus(flight, status)
|
function FLIGHTCONTROL:SetFlightStatus(flight, status)
|
||||||
|
|
||||||
|
-- Debug info.
|
||||||
|
self:I(self.lid..string.format("New Flight Status for %s [%s]: %s-->%s", flight:GetName(), flight:GetState(), tostring(flight.controlstatus), status))
|
||||||
|
|
||||||
|
-- Set control status
|
||||||
flight.controlstatus=status
|
flight.controlstatus=status
|
||||||
|
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get flight status.
|
--- Get flight status.
|
||||||
@ -955,16 +970,12 @@ end
|
|||||||
--- Check if FC has control over this flight.
|
--- Check if FC has control over this flight.
|
||||||
-- @param #FLIGHTCONTROL self
|
-- @param #FLIGHTCONTROL self
|
||||||
-- @param Ops.FlightGroup#FLIGHTGROUP flight Flight group.
|
-- @param Ops.FlightGroup#FLIGHTGROUP flight Flight group.
|
||||||
-- @return #boolean
|
-- @return #boolean If true, this FC is controlling this flight group.
|
||||||
function FLIGHTCONTROL:IsControlling(flight)
|
function FLIGHTCONTROL:IsControlling(flight)
|
||||||
|
|
||||||
return flight.flightcontrol and flight.flightcontrol.airbasename==self.airbasename or false
|
return flight.flightcontrol and flight.flightcontrol.airbasename==self.airbasename or false
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- Check if a group is in a queue.
|
--- Check if a group is in a queue.
|
||||||
-- @param #FLIGHTCONTROL self
|
-- @param #FLIGHTCONTROL self
|
||||||
-- @param #table queue The queue to check.
|
-- @param #table queue The queue to check.
|
||||||
@ -1158,6 +1169,9 @@ function FLIGHTCONTROL:SetParkingFree(spot)
|
|||||||
|
|
||||||
local spot=self:GetParkingSpotByID(spot.TerminalID)
|
local spot=self:GetParkingSpotByID(spot.TerminalID)
|
||||||
|
|
||||||
|
-- Debug info.
|
||||||
|
self:I(self.lid..string.format("Parking spot %d: %s-->%s", spot.TerminalID, tostring(spot.Status), AIRBASE.SpotStatus.FREE))
|
||||||
|
|
||||||
spot.Status=AIRBASE.SpotStatus.FREE
|
spot.Status=AIRBASE.SpotStatus.FREE
|
||||||
spot.OccupiedBy=nil
|
spot.OccupiedBy=nil
|
||||||
spot.ReservedBy=nil
|
spot.ReservedBy=nil
|
||||||
@ -1174,6 +1188,9 @@ function FLIGHTCONTROL:SetParkingReserved(spot, unitname)
|
|||||||
|
|
||||||
local spot=self:GetParkingSpotByID(spot.TerminalID)
|
local spot=self:GetParkingSpotByID(spot.TerminalID)
|
||||||
|
|
||||||
|
-- Debug info.
|
||||||
|
self:I(self.lid..string.format("Parking spot %d: %s-->%s", spot.TerminalID, tostring(spot.Status), AIRBASE.SpotStatus.RESERVED))
|
||||||
|
|
||||||
spot.Status=AIRBASE.SpotStatus.RESERVED
|
spot.Status=AIRBASE.SpotStatus.RESERVED
|
||||||
spot.ReservedBy=unitname or "unknown"
|
spot.ReservedBy=unitname or "unknown"
|
||||||
|
|
||||||
@ -1189,6 +1206,9 @@ function FLIGHTCONTROL:SetParkingOccupied(spot, unitname)
|
|||||||
|
|
||||||
local spot=self:GetParkingSpotByID(spot.TerminalID)
|
local spot=self:GetParkingSpotByID(spot.TerminalID)
|
||||||
|
|
||||||
|
-- Debug info.
|
||||||
|
self:I(self.lid..string.format("Parking spot %d: %s-->%s", spot.TerminalID, tostring(spot.Status), AIRBASE.SpotStatus.OCCUPIED))
|
||||||
|
|
||||||
spot.Status=AIRBASE.SpotStatus.OCCUPIED
|
spot.Status=AIRBASE.SpotStatus.OCCUPIED
|
||||||
spot.OccupiedBy=unitname or "unknown"
|
spot.OccupiedBy=unitname or "unknown"
|
||||||
|
|
||||||
@ -1203,7 +1223,7 @@ function FLIGHTCONTROL:UpdateParkingMarker(spot)
|
|||||||
|
|
||||||
local spot=self:GetParkingSpotByID(spot.TerminalID)
|
local spot=self:GetParkingSpotByID(spot.TerminalID)
|
||||||
|
|
||||||
env.info(string.format("FF updateing spot %d status=%s", spot.TerminalID, spot.Status))
|
--env.info(string.format("FF updateing spot %d status=%s", spot.TerminalID, spot.Status))
|
||||||
|
|
||||||
-- Only mark OCCUPIED and RESERVED spots.
|
-- Only mark OCCUPIED and RESERVED spots.
|
||||||
if spot.Status==AIRBASE.SpotStatus.FREE then
|
if spot.Status==AIRBASE.SpotStatus.FREE then
|
||||||
@ -1852,6 +1872,8 @@ function FLIGHTCONTROL:_CreateFlightGroup(group)
|
|||||||
flight:SetFlightControl(self)
|
flight:SetFlightControl(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
flight:SetVerbosity(2)
|
||||||
|
|
||||||
return flight
|
return flight
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user