mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-07-23 08:29:30 +00:00
Ops
This commit is contained in:
@@ -462,7 +462,31 @@ do -- COORDINATE
|
||||
end
|
||||
|
||||
return set
|
||||
end
|
||||
|
||||
--- Find the closest unit to the COORDINATE within a certain radius.
|
||||
-- @param #COORDINATE self
|
||||
-- @param #number radius Scan radius in meters. Default 100 m.
|
||||
-- @return Wrapper.Unit#UNIT The closest unit or #nil if no unit is inside the given radius.
|
||||
function COORDINATE:FindClosestUnit(radius)
|
||||
|
||||
local units=self:ScanUnits(radius)
|
||||
|
||||
local umin=nil --Wrapper.Unit#UNIT
|
||||
local dmin=math.huge
|
||||
for _,_unit in pairs(units.Set) do
|
||||
local unit=_unit --Wrapper.Unit#UNIT
|
||||
local coordinate=unit:GetCoordinate()
|
||||
local d=self:Get2DDistance(coordinate)
|
||||
if d<dmin then
|
||||
dmin=d
|
||||
umin=unit
|
||||
end
|
||||
end
|
||||
|
||||
return umin
|
||||
end
|
||||
|
||||
|
||||
--- Calculate the distance from a reference @{#COORDINATE}.
|
||||
-- @param #COORDINATE self
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
-- @field #number activerwyno Number of active runway.
|
||||
-- @field #number atcfreq ATC radio frequency.
|
||||
-- @field Core.RadioQueue#RADIOQUEUE atcradio ATC radio queue.
|
||||
-- @field #table playermenu Player Menu.
|
||||
-- @field #number Nlanding Max number of aircraft groups in the landing pattern.
|
||||
-- @field #number dTlanding Time interval in seconds between landing clearance.
|
||||
-- @field #number Nparkingspots Total number of parking spots.
|
||||
@@ -87,7 +86,6 @@ FLIGHTCONTROL = {
|
||||
atcfreq = nil,
|
||||
atcradio = nil,
|
||||
atcradiounitname = nil,
|
||||
playermenu = nil,
|
||||
Nlanding = nil,
|
||||
dTlanding = nil,
|
||||
Nparkingspots = nil,
|
||||
@@ -155,12 +153,13 @@ FLIGHTCONTROL.Sound = {
|
||||
|
||||
--- FlightControl class version.
|
||||
-- @field #string version
|
||||
FLIGHTCONTROL.version="0.3.0"
|
||||
FLIGHTCONTROL.version="0.4.0"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- TODO list
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- DONE: Add parking guard.
|
||||
-- TODO: Accept and forbit parking spots.
|
||||
-- NOGO: Add FARPS?
|
||||
-- TODO: Add helos.
|
||||
@@ -213,7 +212,7 @@ function FLIGHTCONTROL:New(airbasename)
|
||||
-- 5 NM zone around the airbase.
|
||||
self.zoneAirbase=ZONE_RADIUS:New("FC", self:GetCoordinate():GetVec2(), UTILS.NMToMeters(5))
|
||||
|
||||
-- Defaults
|
||||
-- Defaults:
|
||||
self:SetLandingMax()
|
||||
self:SetLandingInterval()
|
||||
|
||||
@@ -221,11 +220,6 @@ function FLIGHTCONTROL:New(airbasename)
|
||||
-- Init runways.
|
||||
self:_InitRunwayData()
|
||||
|
||||
-- Init parking spots.
|
||||
self:_InitParkingSpots()
|
||||
|
||||
self.playermenu={}
|
||||
|
||||
-- Start State.
|
||||
self:SetStartState("Stopped")
|
||||
|
||||
@@ -333,6 +327,9 @@ function FLIGHTCONTROL:onafterStart()
|
||||
|
||||
-- Events are handled my MOOSE.
|
||||
self:I(self.lid..string.format("Starting FLIGHTCONTROL v%s for airbase %s of type %d on map %s", FLIGHTCONTROL.version, self.airbasename, self.airbasetype, self.theatre))
|
||||
|
||||
-- Init parking spots.
|
||||
self:_InitParkingSpots()
|
||||
|
||||
-- Handle events.
|
||||
self:HandleEvent(EVENTS.Birth)
|
||||
@@ -387,7 +384,7 @@ function FLIGHTCONTROL:onafterStatus()
|
||||
local Nresv=self:CountParking(AIRBASE.SpotStatus.RESERVED)
|
||||
|
||||
if Nfree+Noccu+Nresv~=self.Nparkingspots then
|
||||
self:E(self.lid..string.format("WARNING: Number of parking spots does not match! Nfree=%d, Noccu=%d, Nreserved=%d %d != %d total"), Nfree, Noccu, Nresv, self.Nparkingspots)
|
||||
self:E(self.lid..string.format("WARNING: Number of parking spots does not match! Nfree=%d, Noccu=%d, Nreserved=%d != %d total", Nfree, Noccu, Nresv, self.Nparkingspots))
|
||||
end
|
||||
|
||||
-- Info text.
|
||||
@@ -444,7 +441,7 @@ function FLIGHTCONTROL:OnEventBirth(EventData)
|
||||
-- Coordinate.
|
||||
local coordinate=unit:GetCoordinate()
|
||||
|
||||
self:ScheduleOnce(0.1, self._CreateFlightGroup, self, EventData.IniGroup)
|
||||
self:ScheduleOnce(0.5, self._CreateFlightGroup, self, EventData.IniGroup)
|
||||
|
||||
self:SpawnParkingGuard(unit)
|
||||
|
||||
@@ -777,6 +774,7 @@ end
|
||||
-- @return Ops.FlightGroup#FLIGHTGROUP Marshal flight next in line and ready to enter the pattern. Or nil if no flight is ready.
|
||||
function FLIGHTCONTROL:_GetNextFightParking()
|
||||
|
||||
-- Get flights taxiing to runway for takeoff.
|
||||
local Qtaxiout=self:GetFlights(FLIGHTCONTROL.FlightStatus.TAXIOUT)
|
||||
|
||||
-- First check human players.
|
||||
@@ -786,10 +784,9 @@ function FLIGHTCONTROL:_GetNextFightParking()
|
||||
-- First come, first serve.
|
||||
return Qtaxiout[1]
|
||||
|
||||
else
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Get flights parking.
|
||||
local Qparking=self:GetFlights(FLIGHTCONTROL.FlightStatus.PARKING)
|
||||
|
||||
-- Check special cases where only up to one flight is waiting for takeoff.
|
||||
@@ -1065,15 +1062,22 @@ function FLIGHTCONTROL:_InitParkingSpots()
|
||||
-- Add to table.
|
||||
self.parking[spot.TerminalID]=spot
|
||||
|
||||
spot.Marker=MARKER:New(spot.Coordinate, "Spot"):ReadOnly()
|
||||
spot.Marker.tocoaliton=true
|
||||
spot.Marker.coalition=self:GetCoalition()
|
||||
|
||||
-- Set spot to occupied.
|
||||
if spot.Free then
|
||||
self:SetParkingFree(spot)
|
||||
else
|
||||
self:SetParkingOccupied(spot, "unknown")
|
||||
local unit=spot.Coordinate:FindClosestUnit(20)
|
||||
if unit and unit:IsAlive() then
|
||||
local unitname=unit and unit:GetName() or "unknown"
|
||||
self:SetParkingOccupied(spot, unitname)
|
||||
self:SpawnParkingGuard(unit)
|
||||
end
|
||||
end
|
||||
|
||||
--TODO: scan spot for objects.
|
||||
|
||||
|
||||
-- Increase counter
|
||||
self.Nparkingspots=self.Nparkingspots+1
|
||||
end
|
||||
@@ -1319,7 +1323,7 @@ function FLIGHTCONTROL:_CreatePlayerMenu(flight, atcmenu)
|
||||
local groupname=flight.groupname
|
||||
local gid=group:GetID()
|
||||
|
||||
self:I(self.lid..string.format("Creating ATC player menu for flight group %s (ID=%d)", tostring(flight.groupname), gid))
|
||||
self:I(self.lid..string.format("Creating ATC player menu for flight group %s (ID=%d) in state=%s", tostring(flight.groupname), gid, flight:GetState()))
|
||||
|
||||
|
||||
local airbasename=self.airbasename
|
||||
@@ -1352,7 +1356,7 @@ function FLIGHTCONTROL:_CreatePlayerMenu(flight, atcmenu)
|
||||
elseif flight:IsAirborne() then
|
||||
end
|
||||
|
||||
if flight:IsInbound() or flight:IsHolding() or flight:IsLanding() or flight:IsLanded() or true then
|
||||
if flight:IsInbound() or flight:IsHolding() or flight:IsLanding() or flight:IsLanded() then
|
||||
MENU_GROUP_COMMAND_DELAYED:New(group, "Request Parking", rootmenu, self._PlayerRequestParking, self, groupname):SetTime(Tnow):SetTag(Tag)
|
||||
end
|
||||
else
|
||||
@@ -1600,7 +1604,11 @@ function FLIGHTCONTROL:_PlayerRequestTaxi(groupname)
|
||||
|
||||
for _,_element in pairs(flight.elements) do
|
||||
local element=_element --Ops.FlightGroup#FLIGHTGROUP.Element
|
||||
flight:ElementTaxiing(element)
|
||||
if element.parking then
|
||||
local spot=self:GetParkingSpotByID(element.parking.TerminalID)
|
||||
self:RemoveParkingGuard(spot)
|
||||
end
|
||||
flight:ElementTaxiing(element)
|
||||
end
|
||||
|
||||
else
|
||||
@@ -1954,6 +1962,7 @@ function FLIGHTCONTROL:SpawnParkingGuard(unit)
|
||||
|
||||
if unit and self.parkingGuard then
|
||||
|
||||
-- Position of the unit.
|
||||
local coordinate=unit:GetCoordinate()
|
||||
|
||||
-- Parking spot.
|
||||
@@ -1963,10 +1972,12 @@ function FLIGHTCONTROL:SpawnParkingGuard(unit)
|
||||
local heading=unit:GetHeading()
|
||||
|
||||
-- Length of the unit + 3 meters.
|
||||
local _,distance=unit:GetObjectSize()+3
|
||||
local size, x, y, z=unit:GetObjectSize()
|
||||
|
||||
self:I(self.lid..string.format("Parking guard for %s: heading=%d, distance size=%s x=%s y=%s z=%s", unit:GetName(), heading, tostring(size), tostring(x), tostring(y), tostring(z)))
|
||||
|
||||
-- Coordinate for the guard.
|
||||
local Coordinate=coordinate:Translate(distance, heading)
|
||||
local Coordinate=coordinate:Translate(x+3, heading)
|
||||
|
||||
-- Let him face the aircraft.
|
||||
local lookat=heading-180
|
||||
|
||||
@@ -850,7 +850,7 @@ function FLIGHTGROUP:SetFlightControl(flightcontrol)
|
||||
|
||||
-- Update flight's F10 menu.
|
||||
if self.ai==false then
|
||||
self:_UpdateMenu()
|
||||
self:_UpdateMenu(0.5)
|
||||
end
|
||||
|
||||
return self
|
||||
@@ -2395,9 +2395,6 @@ function FLIGHTGROUP:onafterFlightSpawned(From, Event, To)
|
||||
else
|
||||
|
||||
-- F10 other menu.
|
||||
self.menu=self.menu or {}
|
||||
self.menu.atc=self.menu.atc or {}
|
||||
self.menu.atc.root=self.menu.atc.root or MENU_GROUP:New(self.group, "ATC")
|
||||
self:_UpdateMenu()
|
||||
|
||||
end
|
||||
@@ -2410,7 +2407,7 @@ end
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
function FLIGHTGROUP:onafterFlightParking(From, Event, To)
|
||||
self:T(self.lid..string.format("Flight is parking"))
|
||||
self:I(self.lid..string.format("Flight is parking"))
|
||||
|
||||
local airbase=self.group:GetCoordinate():GetClosestAirbase()
|
||||
|
||||
@@ -2431,6 +2428,11 @@ function FLIGHTGROUP:onafterFlightParking(From, Event, To)
|
||||
|
||||
-- Set flight status.
|
||||
self.flightcontrol:SetFlightStatus(self, FLIGHTCONTROL.FlightStatus.PARKING)
|
||||
|
||||
-- Update player menu.
|
||||
if not self.ai then
|
||||
self:_UpdateMenu(0.5)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -4297,6 +4299,14 @@ function FLIGHTGROUP:_InitGroup()
|
||||
end
|
||||
end
|
||||
|
||||
self.ai=not self:_IsHuman(self.group)
|
||||
|
||||
if not self.ai then
|
||||
self.menu=self.menu or {}
|
||||
self.menu.atc=self.menu.atc or {}
|
||||
self.menu.atc.root=self.menu.atc.root or MENU_GROUP:New(self.group, "ATC")
|
||||
end
|
||||
|
||||
self:SwitchFormation(self.formationDefault)
|
||||
|
||||
-- Get first unit. This is used to extract other parameters.
|
||||
@@ -4314,8 +4324,6 @@ function FLIGHTGROUP:_InitGroup()
|
||||
|
||||
self.tankertype=select(2, unit:IsTanker())
|
||||
self.refueltype=select(2, unit:IsRefuelable())
|
||||
|
||||
self.ai=not self:_IsHuman(self.group)
|
||||
|
||||
-- Init waypoints.
|
||||
if not self.waypoints then
|
||||
@@ -6371,45 +6379,52 @@ end
|
||||
|
||||
--- Get the proper terminal type based on generalized attribute of the group.
|
||||
--@param #FLIGHTGROUP self
|
||||
function FLIGHTGROUP:_UpdateMenu()
|
||||
self:I(self.lid.."FF updating menu")
|
||||
--@param #number delay Delay in seconds.
|
||||
function FLIGHTGROUP:_UpdateMenu(delay)
|
||||
|
||||
-- Get current position of group.
|
||||
local position=self.group:GetCoordinate()
|
||||
if delay and delay>0 then
|
||||
self:ScheduleOnce(delay, FLIGHTGROUP._UpdateMenu, self)
|
||||
else
|
||||
|
||||
-- Get all FLIGHTCONTROLS
|
||||
local fc={}
|
||||
for airbasename,_flightcontrol in pairs(_DATABASE.FLIGHTCONTROLS) do
|
||||
|
||||
local airbase=AIRBASE:FindByName(airbasename)
|
||||
self:I(self.lid.."FF updating menu")
|
||||
|
||||
local coord=airbase:GetCoordinate()
|
||||
|
||||
local dist=coord:Get2DDistance(position)
|
||||
|
||||
local fcitem={airbasename=airbasename, dist=dist}
|
||||
|
||||
table.insert(fc, fcitem)
|
||||
end
|
||||
-- Get current position of group.
|
||||
local position=self.group:GetCoordinate()
|
||||
|
||||
-- Sort table wrt distance to airbases.
|
||||
local function _sort(a,b)
|
||||
return a.dist<b.dist
|
||||
end
|
||||
table.sort(fc, _sort)
|
||||
-- Get all FLIGHTCONTROLS
|
||||
local fc={}
|
||||
for airbasename,_flightcontrol in pairs(_DATABASE.FLIGHTCONTROLS) do
|
||||
|
||||
local airbase=AIRBASE:FindByName(airbasename)
|
||||
|
||||
-- If there is a designated FC, we put it first.
|
||||
local N=8
|
||||
if self.flightcontrol then
|
||||
self.flightcontrol:_CreatePlayerMenu(self, self.menu.atc)
|
||||
N=7
|
||||
end
|
||||
|
||||
-- Max 8 entries in F10 menu.
|
||||
for i=1,math.min(#fc,N) do
|
||||
local airbasename=fc[i].airbasename
|
||||
local flightcontrol=_DATABASE:GetFlightControl(airbasename)
|
||||
flightcontrol:_CreatePlayerMenu(self, self.menu.atc)
|
||||
local coord=airbase:GetCoordinate()
|
||||
|
||||
local dist=coord:Get2DDistance(position)
|
||||
|
||||
local fcitem={airbasename=airbasename, dist=dist}
|
||||
|
||||
table.insert(fc, fcitem)
|
||||
end
|
||||
|
||||
-- Sort table wrt distance to airbases.
|
||||
local function _sort(a,b)
|
||||
return a.dist<b.dist
|
||||
end
|
||||
table.sort(fc, _sort)
|
||||
|
||||
-- If there is a designated FC, we put it first.
|
||||
local N=8
|
||||
if self.flightcontrol then
|
||||
self.flightcontrol:_CreatePlayerMenu(self, self.menu.atc)
|
||||
N=7
|
||||
end
|
||||
|
||||
-- Max 8 entries in F10 menu.
|
||||
for i=1,math.min(#fc,N) do
|
||||
local airbasename=fc[i].airbasename
|
||||
local flightcontrol=_DATABASE:GetFlightControl(airbasename)
|
||||
flightcontrol:_CreatePlayerMenu(self, self.menu.atc)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -552,7 +552,7 @@ end
|
||||
|
||||
--- Remove a marker.
|
||||
-- @param #MARKER self
|
||||
-- @param #number Delay (Optional) Delay in seconds, before the marker is created.
|
||||
-- @param #number Delay (Optional) Delay in seconds, before the marker is removed.
|
||||
-- @return #MARKER self
|
||||
function MARKER:Remove(Delay)
|
||||
|
||||
@@ -560,8 +560,12 @@ function MARKER:Remove(Delay)
|
||||
self:ScheduleOnce(Delay, MARKER.Remove, self)
|
||||
else
|
||||
|
||||
-- Call DCS function.
|
||||
trigger.action.removeMark(self.mid)
|
||||
if self.shown then
|
||||
|
||||
-- Call DCS function.
|
||||
trigger.action.removeMark(self.mid)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -587,7 +591,7 @@ end
|
||||
-- @param #string Text Marker text.
|
||||
-- @return #MARKER self
|
||||
function MARKER:SetText(Text)
|
||||
self.text=tostring(Text)
|
||||
self.text=Text and tostring(Text) or ""
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user