mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
atc2
This commit is contained in:
parent
43cbc93a96
commit
c1f884d024
@ -439,6 +439,11 @@ function RAT:New(groupname, alias)
|
|||||||
-- Get all airports of current map (Caucasus, NTTR, Normandy, ...).
|
-- Get all airports of current map (Caucasus, NTTR, Normandy, ...).
|
||||||
self:_GetAirportsOfMap()
|
self:_GetAirportsOfMap()
|
||||||
|
|
||||||
|
-- Init RAT ATC if not already done.
|
||||||
|
if not RAT.ATC.init then
|
||||||
|
RAT:ATC_Init(self.airports_map)
|
||||||
|
end
|
||||||
|
|
||||||
-- Create F10 main menu if it does not exists yet.
|
-- Create F10 main menu if it does not exists yet.
|
||||||
if self.f10menu and not RAT.MenuF10 then
|
if self.f10menu and not RAT.MenuF10 then
|
||||||
RAT.MenuF10 = MENU_MISSION:New("RAT")
|
RAT.MenuF10 = MENU_MISSION:New("RAT")
|
||||||
@ -993,6 +998,9 @@ function RAT:_SpawnWithRoute(_departure, _destination)
|
|||||||
local group=self:SpawnWithIndex(self.SpawnIndex) -- Wrapper.Group#GROUP
|
local group=self:SpawnWithIndex(self.SpawnIndex) -- Wrapper.Group#GROUP
|
||||||
self.alive=self.alive+1
|
self.alive=self.alive+1
|
||||||
|
|
||||||
|
-- ATC is monitoring this flight.
|
||||||
|
RAT:ATC_AddAircraft(group:GetName(), destination:GetName())
|
||||||
|
|
||||||
-- Set ROE, default is "weapon hold".
|
-- Set ROE, default is "weapon hold".
|
||||||
self:_SetROE(group, self.roe)
|
self:_SetROE(group, self.roe)
|
||||||
|
|
||||||
@ -2772,53 +2780,77 @@ function RAT:_ModifySpawnTemplate(waypoints)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- @module Atc
|
RAT.ATC={
|
||||||
--
|
init=false,
|
||||||
--- ATC class
|
flight={},
|
||||||
-- @type ATC
|
airport={},
|
||||||
ATC={
|
|
||||||
aircraft={},
|
|
||||||
waypoints={},
|
|
||||||
departures={},
|
|
||||||
destinations={},
|
|
||||||
holding={},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function RAT:ATC_Init(airports_map)
|
||||||
function ATC:Add(index, group, wp, departure, destination)
|
if not RAT.ATC.init then
|
||||||
self.aircraft[index]=group
|
env.info("Starting RAT ATC")
|
||||||
self.waypoints[index]=wp
|
RAT.ATC.init=true
|
||||||
self.departures[index]=departure
|
for _,name in pairs(airports_map) do
|
||||||
self.destinations[index]=destination
|
RAT.ATC.airport[name]={}
|
||||||
|
RAT.ATC.airport[name].busy=false
|
||||||
|
end
|
||||||
|
SCHEDULER:New(nil, RAT.ATC_Status, {self}, 5, 30)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ATC:Status(airports)
|
function RAT:ATC_del(t,entry)
|
||||||
local function tally(t)
|
--print(dump(t))
|
||||||
local freq = {}
|
for k,_ in pairs(t) do
|
||||||
for _, v in pairs(t) do
|
if k==entry then
|
||||||
freq[v] = (freq[v] or 0) + 1
|
t[entry]=nil
|
||||||
end
|
end
|
||||||
return freq
|
|
||||||
end
|
end
|
||||||
|
--print(dump(t))
|
||||||
|
end
|
||||||
|
|
||||||
local _destinations=tally(self.sestinations)
|
function RAT:ATC_AddAircraft(name, dest)
|
||||||
for k,v in pairs(_destinations) do
|
env.info(string.format("ATC: Adding flight %s with destination %s.", name, dest))
|
||||||
local text=string.format("Destination %s: %d",k,v)
|
RAT.ATC.flight[name]={}
|
||||||
env.info(text)
|
RAT.ATC.flight[name].destination=dest
|
||||||
end
|
RAT.ATC.flight[name].holding=0
|
||||||
|
end
|
||||||
|
|
||||||
|
function RAT:ATC_AircraftLanded(name)
|
||||||
|
-- airport is not busy any more.
|
||||||
|
local dest=RAT.ATC.flight[name].destination
|
||||||
|
|
||||||
for i,aircraft in pairs(self.aircraft) do
|
env.info(string.format("ATC: Flight %s landed at %s", name, dest))
|
||||||
local hp=self.waypoints[i][5]
|
|
||||||
local hc={hp.x,hp.alt,hp.y}
|
RAT.ATC.airport[dest].busy=false
|
||||||
local z=ZONE_RADIUS:New("holding", hc:GetVec2(), 3000)
|
|
||||||
local group=aircraft --Wrapper.Group#GROUP
|
RAT.ATC.del(RAT.ATC.flight, name)
|
||||||
local holding=group:IsCompletelyInZone(z)
|
end
|
||||||
if holding then
|
|
||||||
table.insert(self.holding[self.destination], group)
|
function RAT:ATC_Status()
|
||||||
|
|
||||||
|
for name,_ in pairs(RAT.ATC.flight) do
|
||||||
|
|
||||||
|
local hold=RAT.ATC.flight[name].holding
|
||||||
|
local dest=RAT.ATC.flight[name].destination
|
||||||
|
|
||||||
|
if hold >= 0 then
|
||||||
|
env.info(string.format("ATC: Flight %s is holding for %d at %s", name, hold, dest))
|
||||||
|
|
||||||
|
-- check if dest is busy
|
||||||
|
if RAT.ATC.airport[dest].busy then
|
||||||
|
env.info("ATC: Airport is busy, increase holding time and move on. No landing clearance!")
|
||||||
|
RAT.ATC.flight[name].holding=RAT.ATC.flight[name].holding+30
|
||||||
|
else
|
||||||
|
env.info("ATC: Airport is free. Set holding time to -100. Push landing task. Set airport to busy.")
|
||||||
|
RAT.ATC.airport[dest].busy=true
|
||||||
|
RAT.ATC.flight[name].holding=-100
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif hold==-100 then
|
||||||
|
print(string.format("ATC: Flight %s was cleared for landing at %s. Waiting for landing event.", name, dest))
|
||||||
|
else
|
||||||
|
print(string.format("ATC: Flight %s is not holding %d", name, hold))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' )
|
env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' )
|
||||||
env.info( 'Moose Generation Timestamp: 20170917_2338' )
|
env.info( 'Moose Generation Timestamp: 20170920_1942' )
|
||||||
|
|
||||||
local base = _G
|
local base = _G
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user