FG/FC v0.2.4

This commit is contained in:
Frank
2020-01-27 00:09:35 +01:00
parent 43034ed0ad
commit aaabf5220e
4 changed files with 74 additions and 94 deletions
+6 -2
View File
@@ -250,12 +250,16 @@ end
--- Adds a Airbase based on the Airbase Name in the DATABASE.
-- @param #DATABASE self
-- @param #string AirbaseName The name of the airbase
-- @param #string AirbaseName The name of the airbase.
-- @return Wrapper.Airbase#AIRBASE The AIRBASE object.
function DATABASE:AddAirbase( AirbaseName )
if not self.AIRBASES[AirbaseName] then
self.AIRBASES[AirbaseName] = AIRBASE:Register( AirbaseName )
self:I(string.format("Adding airbase %s with %d parking spots", tostring(self.AIRBASES[AirbaseName].AirbaseName), tonumber(#self.AIRBASES[AirbaseName].parking)))
end
return self.AIRBASES[AirbaseName]
end
@@ -903,7 +907,7 @@ function DATABASE:_RegisterAirbases()
local DCSAirbaseName = DCSAirbase:getName()
self:T( { "Register Airbase:", DCSAirbaseName, DCSAirbase:getID() } )
self:AddAirbase( DCSAirbaseName )
local airbase=self:AddAirbase( DCSAirbaseName )
end
end
+16 -75
View File
@@ -119,7 +119,7 @@ FLIGHTCONTROL = {
--- FlightControl class version.
-- @field #string version
FLIGHTCONTROL.version="0.1.6"
FLIGHTCONTROL.version="0.2.4"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO list
@@ -1193,6 +1193,11 @@ end
-- @return #string Name of element or nil.
function FLIGHTCONTROL:IsParkingReserved(spot)
local park=self.parking[spot.TerminalID] --Wrapper.Airbase#AIRBASE.ParkingSpot
if park.Reserved then
return tostring(park.Reserved)
end
-- Init all elements as NOT parking anywhere.
for _,_flight in pairs(self.flights) do
local flight=_flight --Ops.FlightGroup#FLIGHTGROUP
@@ -1215,7 +1220,7 @@ end
-- @param #number terminaltype (Optional) Check only this terminal type.
-- @param #boolean free (Optional) If true, check only free spots.
-- @return Wrapper.Airbase#AIRBASE.ParkingSpot Closest parking spot.
function FLIGHTCONTROL:GetClosestParkingSpot(coord, terminaltype, free)
function FLIGHTCONTROL:GetClosestParkingSpot(coordinate, terminaltype, free)
local distmin=math.huge
local spotmin=nil
@@ -1227,7 +1232,7 @@ function FLIGHTCONTROL:GetClosestParkingSpot(coord, terminaltype, free)
if terminaltype==nil or terminaltype==spot.TerminalType then
-- Get distance from coordinate to spot.
local dist=coord:Get2DDistance(spot.Coordinate)
local dist=coordinate:Get2DDistance(spot.Coordinate)
-- Check if distance is smaller.
if dist<distmin then
@@ -1591,14 +1596,15 @@ end
-- @param Ops.FlightGroup#FLIGHTGROUP flight The flight to be removed.
function FLIGHTCONTROL:_RemoveFlight(flight)
self:_RemoveFlightFromQueue(self.Qinbound, flight, "inbound")
self:_RemoveFlightFromQueue(self.Qholding, flight, "holding")
self:_RemoveFlightFromQueue(self.Qlanding, flight, "landing")
self:_RemoveFlightFromQueue(self.Qtaxiinb, flight, "taxiINB")
self:_RemoveFlightFromQueue(self.Qarrived, flight, "arrived")
self:_RemoveFlightFromQueue(self.Qparking, flight, "parking")
self:_RemoveFlightFromQueue(self.Qtaxiout, flight, "taxiOUT")
self:_RemoveFlightFromQueue(self.Qreadyto, flight, "readyTO")
self:_RemoveFlightFromQueue(self.Qtakeoff, flight, "takeoff")
self:_RemoveFlightFromQueue(self.Qarrived, flight, "arrived")
self:_RemoveFlightFromQueue(self.flights, flight, "flights")
end
@@ -1700,11 +1706,11 @@ function FLIGHTCONTROL:_CheckParking()
if spot.MarkerID then
spot.Coordinate:RemoveMark(spot.MarkerID)
end
spot.MarkerID=spot.Coordinate:MarkToCoalition(string.format("Parking reserved for %s", tostring(spot.Reserved)), self.airbase:GetCoalition())
spot.MarkerID=spot.Coordinate:MarkToCoalition(string.format("Parking reserved for %s", tostring(spot.Reserved)), self:GetCoalition())
end
-- First remove all dead flights.
for i=#self.flights,1,-1 do
for i=1,#self.flights do
local flight=self.flights[i] --Ops.FlightGroup#FLIGHTGROUP
for _,_element in pairs(flight.elements) do
local element=_element --Ops.FlightGroup#FLIGHTGROUP.Element
@@ -1712,7 +1718,7 @@ function FLIGHTCONTROL:_CheckParking()
if spot.MarkerID then
spot.Coordinate:RemoveMark(spot.MarkerID)
end
spot.MarkerID=spot.Coordinate:MarkToCoalition(string.format("Parking spot occupied by %s", tostring(element.name)), self.airbase:GetCoalition())
spot.MarkerID=spot.Coordinate:MarkToCoalition(string.format("Parking spot occupied by %s", tostring(element.name)), self:GetCoalition())
end
end
end
@@ -1780,72 +1786,6 @@ function FLIGHTCONTROL:_CheckAirbase()
return su,setstatic
end
--- Scan airbase zone and find new flights.
-- @param #FLIGHTCONTROL self
-- @param Core.Set#SET_UNIT unitset Set of units.
function FLIGHTCONTROL:_CheckACstatus(unitset)
-- Make a table with all groups currently in the CCA zone.
local insideZone={}
for _,_unit in pairs(unitset:GetSetObjects()) do
local unit=_unit --Wrapper.Unit#UNIT
-- Necessary conditions to be met:
local aircraft=unit:IsAir()
local inzone=unit:IsInZone(self.zoneAirbase)
local friendly=self:GetCoalition()==unit:GetCoalition()
-- Check if this an aircraft and that it is inside the airbase zone and friendly.
if aircraft and inzone then
local group=unit:GetGroup()
local groupname=group:GetName()
-- Add group to table.
if insideZone[groupname]==nil then
insideZone[groupname]=groupname
end
end
end
-- Find new flights that are inside the airbase zone.
for groupname,_ in pairs(insideZone) do
local flight=_DATABASE:GetFlightGroup(groupname)
if flight then
for _,_element in pairs(flight.elements) do
local element=_element --Ops.FlightGroup#FLIGHTGROUP.Element
local unit=element.unit
if unit and unit:IsAlive() then
if unit:InAir() then
else
if element.status==FLIGHTGROUP.ElementStatus.PARKING then
if element.parking then
end
end
end
end
end
end
end
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Routing Functions
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -1906,14 +1846,15 @@ function FLIGHTCONTROL:_LandAI(flight, parking)
Template.route.points=wp
for i,unit in pairs(Template.units) do
local spot=parking[i] --Ops.FlightControl#FLIGHTCONTROL.ParkingSpot
local spot=parking[i] --Wrapper.Airbase#AIRBASE.ParkingSpot
local element=flight:GetElementByName(unit.name)
if element then
element.parking=spot
--element.parking=spot
unit.parking_landing=spot.TerminalID
local text=string.format("FF Reserving parking spot %d for unit %s", spot.TerminalID, tostring(unit.name))
self:I(self.lid..text)
self.parking[spot.TerminalID].Reserved=element.name
else
env.info("FF error could not get element to assign parking!")
end
+44 -15
View File
@@ -263,7 +263,7 @@ FLIGHTGROUP.TaskType={
--- FLIGHTGROUP class version.
-- @field #string version
FLIGHTGROUP.version="0.2.3"
FLIGHTGROUP.version="0.2.4"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO list
@@ -1264,7 +1264,8 @@ function FLIGHTGROUP:onafterElementSpawned(From, Event, To, Element)
self:_UpdateStatus(Element, FLIGHTGROUP.ElementStatus.SPAWNED)
if Element.unit:InAir() then
self:ElementAirborne(Element)
-- Trigger ElementAirborne event. Add a little delay because spawn is also delayed!
self:__ElementAirborne(0.11, Element)
else
-- Get parking spot.
@@ -1272,10 +1273,11 @@ function FLIGHTGROUP:onafterElementSpawned(From, Event, To, Element)
if spot then
-- Set
Element.parking=spot
self:ElementParking(Element)
-- Trigger ElementParking event. Add a little delay because spawn is also delayed!
self:__ElementParking(0.11, Element)
else
self:E(self.lid..string.format("Element spawned not in air but not on any parking spot."))
end
@@ -1289,7 +1291,7 @@ end
-- @param #string To To state.
-- @param #FLIGHTGROUP.Element Element The flight group element.
function FLIGHTGROUP:onafterElementParking(From, Event, To, Element)
self:T(self.lid..string.format("Element parking %s at spot %s.", Element.name, tostring(Element.parking.TerminalID)))
self:I(self.lid..string.format("Element parking %s at spot %s", Element.name, tostring(Element.parking.TerminalID)))
-- Set element status.
@@ -1303,13 +1305,15 @@ end
-- @param #string To To state.
-- @param #FLIGHTGROUP.Element Element The flight group element.
function FLIGHTGROUP:onafterElementTaxiing(From, Event, To, Element)
local TerminalID="N/A"
if Element.parking then
if Element.parking.MarkerID then
Element.parking.Coordinate:RemoveMark(Element.parking.MarkerID)
end
Element.parking.Reserved=nil
local TerminalID="N/A"
-- Remove marker.
if self.flightcontrol and Element.parking then
TerminalID=tostring(Element.parking.TerminalID)
local parking=self.flightcontrol.parking[Element.parking.TerminalID] --Wrapper.Airbase#AIRBASE.ParkingSpot
if parking and parking.MarkerID then
parking.Coordinate:RemoveMark(parking.MarkerID)
end
end
self:I(self.lid..string.format("Element taxiing %s. Parking spot %s is now free", Element.name, TerminalID))
@@ -1372,7 +1376,23 @@ end
-- @param #string To To state.
-- @param #FLIGHTGROUP.Element Element The flight group element.
function FLIGHTGROUP:onafterElementArrived(From, Event, To, Element)
self:T2(self.lid..string.format("Element arrived %s.", Element.name))
-- Get parking spot
local parking=self:GetParkingSpot(Element, 10, self.flightcontrol and self.flightcontrol.airbase or nil)
if parking then
if self.flightcontrol then
local spot=self.flightcontrol.parking[parking.TerminalID] --Wrapper.Airbase#AIRBASE.ParkingSpot
self:I(self.lid..string.format("Element arrived %s at %s on parking spot %s reserved for %s", Element.name, parking.AirbaseName, parking.TerminalID, tostring(spot.Reserved)))
if spot.Reserved then
if spot.Reserved==Element.name then
spot.Reserved=nil
else
self:E(self.lid..string.format("WARNING: Parking spot was not reserved for this element!"))
end
end
end
end
-- Set element status.
self:_UpdateStatus(Element, FLIGHTGROUP.ElementStatus.ARRIVED)
@@ -3404,14 +3424,15 @@ end
-- @param #FLIGHTGROUP self
-- @param #FLIGHTGROUP.Element element Element of the flight group.
-- @param #number maxdist Distance threshold in meters. Default 5 m.
-- @param Wrapper.Airbase#AIRBASE airbase (Optional) The airbase to check for parking. Default is closest airbase to the element.
-- @return Wrapper.Airbase#AIRBASE.ParkingSpot Parking spot or nil if no spot is within distance threshold.
function FLIGHTGROUP:GetParkingSpot(element, maxdist)
function FLIGHTGROUP:GetParkingSpot(element, maxdist, airbase)
local coord=element.unit:GetCoordinate()
local ab=coord:GetClosestAirbase(nil, self:GetCoalition())
airbase=airbase or coord:GetClosestAirbase(nil, self:GetCoalition())
local _,_,dist,spot=coord:GetClosestParkingSpot(ab)
local _,_,dist,spot=coord:GetClosestParkingSpot(airbase)
if dist<=maxdist and not element.unit:InAir() then
return spot
@@ -3597,6 +3618,14 @@ function FLIGHTGROUP:GetParking(airbase)
end
end
-- Check flightcontrol data.
if self.flightcontrol and self.flightcontrol.airbasename==airbase:GetName() then
local problem=self.flightcontrol:IsParkingReserved(parkingspot)
if problem then
free=false
end
end
-- Check if spot is free
if free then
+8 -2
View File
@@ -15,7 +15,10 @@
--- @type AIRBASE
-- @field #string ClassName Name of the class, i.e. "AIRBASE".
-- @field #table CategoryName Names of airbase categories.
-- @field #string AirbaseName Name of the airbase.
-- @field Core.Zone#ZONE_RADIUS Zone around the airbase.
-- @field #number activerwyno Active runway number (forced).
-- @field #table parking Table of parking spots.
-- @extends Wrapper.Positionable#POSITIONABLE
--- Wrapper class to handle the DCS Airbase objects:
@@ -57,7 +60,10 @@ AIRBASE = {
[Airbase.Category.HELIPAD] = "Helipad",
[Airbase.Category.SHIP] = "Ship",
},
AirbaseName=nil,
AirbaseZone=nil,
activerwyno=nil,
parking={},
}
--- Enumeration to identify the airbases in the Caucasus region.
@@ -346,10 +352,10 @@ AIRBASE.TerminalType = {
-- @param #string AirbaseName The name of the airbase.
-- @return Wrapper.Airbase#AIRBASE
function AIRBASE:Register( AirbaseName )
local self = BASE:Inherit( self, POSITIONABLE:New( AirbaseName ) )
local self = BASE:Inherit( self, POSITIONABLE:New( AirbaseName ) ) --#AIRBASE
self.AirbaseName = AirbaseName
self.AirbaseZone = ZONE_RADIUS:New( AirbaseName, self:GetVec2(), 2500 )
self.parking=self:GetParkingSpotsTable()
return self
end