This commit is contained in:
Frank
2019-09-06 22:23:52 +02:00
parent 553f14d2ea
commit af3bf7dece
4 changed files with 161 additions and 202 deletions
+4 -1
View File
@@ -420,6 +420,7 @@ end
BEACON = { BEACON = {
ClassName = "BEACON", ClassName = "BEACON",
Positionable = nil, Positionable = nil,
name=nil,
} }
--- Beacon types supported by DCS. --- Beacon types supported by DCS.
@@ -496,6 +497,8 @@ function BEACON:New(Positionable)
-- Set positionable. -- Set positionable.
if Positionable:GetPointVec2() then -- It's stupid, but the only way I found to make sure positionable is valid if Positionable:GetPointVec2() then -- It's stupid, but the only way I found to make sure positionable is valid
self.Positionable = Positionable self.Positionable = Positionable
self.name=Positionable:GetName()
self:I(string.format("New BEACON %s", tostring(self.name)))
return self return self
end end
@@ -550,7 +553,7 @@ function BEACON:ActivateTACAN(Channel, Mode, Message, Bearing, Duration)
local UnitID=self.Positionable:GetID() local UnitID=self.Positionable:GetID()
-- Debug. -- Debug.
self:T({"TACAN BEACON started!"}) self:I({string.format("BEACON Activating TACAN %s: Channel=%d%s, Morse=%s, Bearing=%s, Duration=%s!", tostring(self.name), Channel, Mode, Message, tostring(Bearing), tostring(Duration))})
-- Start beacon. -- Start beacon.
self.Positionable:CommandActivateBeacon(Type, System, Frequency, UnitID, Channel, Mode, AA, Message, Bearing) self.Positionable:CommandActivateBeacon(Type, System, Frequency, UnitID, Channel, Mode, AA, Message, Bearing)
+26 -120
View File
@@ -63,46 +63,6 @@ FLIGHTCONTROL = {
activerwyno = 1, activerwyno = 1,
} }
--- Parameters of a flight group.
-- @type FLIGHTCONTROL.FlightGroup
-- @field #string groupname Name of the group.
-- @field Wrapper.Group#GROUP group Flight group.
-- @field #number nunits Number of units in group.
-- @field #number time Timestamp in seconds of timer.getAbsTime() of the last important event, e.g. added to the queue.
-- @field #number dist0 Distance in meters when group was first detected.
-- @field #number flag Flag value describing the current stack.
-- @field #boolean ai If true, flight is purly AI.
-- @field #string actype Aircraft type name.
-- @field #table onboardnumbers Onboard numbers of aircraft in the group.
-- @field #string onboard Onboard number of player or first unit in group.
-- @field #boolean holding If true, flight is in holding zone.
-- @field #boolean inzone If true, flight is inside airbase zone.
-- @field #table elements Flight group elements.
--- Parameters of an element in a flight group.
-- @type FLIGHTCONTROL.FlightElement
-- @field #string unitname Name of the unit.
-- @field Wrapper.Unit#UNIT unit Aircraft unit.
-- @field #boolean ai If true, AI sits inside. If false, human player is flying.
-- @field #string onboard Onboard number of the aircraft.
-- @field #boolean recovered If true, element was successfully recovered.
-- @field #boolean tookoff If true, element took off.
-- @field #boolean parking If true, element is parking.
-- @field #number sizemax Max size (length or width) of aircraft in meters.
--- Parameters of an element in a flight group.
-- @type FLIGHTCONTROL.FlightState
-- @field #string LANDED
-- @field #string PARKED
-- @field #string HOLDING
-- @field #string TAXIING
FLIGHTCONTROL.FlightState={
LANDED="Landed",
PARKED="Parked",
HOLDING="Holding",
TAXIING="Taxiing",
}
--- Holding point --- Holding point
-- @type FLIGHTCONTROL.HoldingPoint -- @type FLIGHTCONTROL.HoldingPoint
-- @field Core.Point#COORDINATE pos0 First poosition of racetrack holding point. -- @field Core.Point#COORDINATE pos0 First poosition of racetrack holding point.
@@ -130,7 +90,7 @@ FLIGHTCONTROL.FlightState={
--- FlightControl class version. --- FlightControl class version.
-- @field #string version -- @field #string version
FLIGHTCONTROL.version="0.0.4" FLIGHTCONTROL.version="0.0.5"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO list -- TODO list
@@ -142,6 +102,7 @@ FLIGHTCONTROL.version="0.0.4"
-- TODO: ATIS option. -- TODO: ATIS option.
-- TODO: ATC voice overs. -- TODO: ATC voice overs.
-- TODO: Check runways and clean up. -- TODO: Check runways and clean up.
-- TODO: Interface with FLIGHTGROUP
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Constructor -- Constructor
@@ -317,7 +278,7 @@ function FLIGHTCONTROL:_InitRunwayData()
local hdg=c1:HeadingTo(c2) local hdg=c1:HeadingTo(c2)
-- Debug info. -- Debug info.
self:T(self.lid..string.format("Runway %d heading=%03d", j, hdg)) self:T(self.lid..string.format("Runway %d heading=%03d", j, hdg))
-- Runway table. -- Runway table.
local runway={} --#FLIGHTCONTROL.Runway local runway={} --#FLIGHTCONTROL.Runway
@@ -474,44 +435,6 @@ function FLIGHTCONTROL:OnEventLand(EventData)
self:T2(self.lid..string.format("LAND: unit = %s", tostring(EventData.IniUnitName))) self:T2(self.lid..string.format("LAND: unit = %s", tostring(EventData.IniUnitName)))
self:T2(self.lid..string.format("LAND: group = %s", tostring(EventData.IniGroupName))) self:T2(self.lid..string.format("LAND: group = %s", tostring(EventData.IniGroupName)))
-- This would be the closest airbase.
local airbase=EventData.Place
-- Nil check for airbase. Crashed as player gave me no airbase.
if airbase==nil then
return
end
-- Get airbase name.
local airbasename=tostring(airbase:GetName())
-- Check if landed at this airbase.
if airbasename==self.airbasename then
-- AI always lands ==> remove unit from flight group and queues.
local flight=self:_ElementRecovered(EventData.IniUnit)
if flight then
-- Check if everybody is home.
local recovered=true
for _,_elem in pairs(flight.elements) do
local element=_elem --#FLIGHTCONTROL.FlightElement
if not element.recovered then
recovered=false
end
end
-- Remove flight.
if recovered then
self:_RemoveFlightFromQueue(self.Qlanding, flight)
end
end
end
end end
--- Event handler for event takeoff. --- Event handler for event takeoff.
@@ -688,10 +611,11 @@ function FLIGHTCONTROL:_CheckParking()
-- Loop over all flights. -- Loop over all flights.
for _,_flight in pairs(self.flights) do for _,_flight in pairs(self.flights) do
local flight=_flight --Ops.FlightGroup#FLIGHTGROUP
-- Loop over all elements. -- Loop over all elements.
for _,_element in pairs(_flight.elements) do for _,_element in pairs(_flight.elements) do
local element=_element --#FLIGHTCONTROL.FlightElement local element=_element --Ops.FlightGroup#FLIGHTGROUP.Element
local unit=element.unit local unit=element.unit
@@ -720,12 +644,12 @@ end
--- Get next flight waiting for landing clearance. --- Get next flight waiting for landing clearance.
-- @param #FLIGHTCONTROL self -- @param #FLIGHTCONTROL self
-- @return #FLIGHTCONTROL.FlightGroup Marshal flight next in line and ready to enter the pattern. Or nil if no flight is ready. -- @return Ops.FlightGroup#FLIGHTGROUP Marshal flight next in line and ready to enter the pattern. Or nil if no flight is ready.
function FLIGHTCONTROL:_GetNextWaitingFight() function FLIGHTCONTROL:_GetNextWaitingFight()
-- Loop over all marshal flights. -- Loop over all marshal flights.
for _,_flight in pairs(self.Qwaiting) do for _,_flight in pairs(self.Qwaiting) do
local flight=_flight --#FLIGHTCONTROL.FlightGroup local flight=_flight --Ops.FlightGroup#FLIGHTGROUP
-- Current stack. -- Current stack.
local stack=flight.flag local stack=flight.flag
@@ -760,7 +684,7 @@ function FLIGHTCONTROL:_PrintQueue(queue, name)
-- Loop over all flights in queue. -- Loop over all flights in queue.
for i,_flight in ipairs(queue) do for i,_flight in ipairs(queue) do
local flight=_flight --#FLIGHTCONTROL.FlightGroup local flight=_flight --Ops.FlightGroup#FLIGHTGROUP
-- Gather info. -- Gather info.
local clock=UTILS.SecondsToClock(timer.getAbsTime()-flight.time) local clock=UTILS.SecondsToClock(timer.getAbsTime()-flight.time)
@@ -792,14 +716,14 @@ end
--- Remove a flight group from a queue. --- Remove a flight group from a queue.
-- @param #FLIGHTCONTROL self -- @param #FLIGHTCONTROL self
-- @param #table queue The queue from which the group will be removed. -- @param #table queue The queue from which the group will be removed.
-- @param #FLIGHTCONTROL.FlightGroup flight Flight group that will be removed from queue. -- @param Ops.FlightGroup#FLIGHTGROUP flight Flight group that will be removed from queue.
-- @return #boolean True, flight was in Queue and removed. False otherwise. -- @return #boolean True, flight was in Queue and removed. False otherwise.
-- @return #number Table index of removed queue element or nil. -- @return #number Table index of removed queue element or nil.
function FLIGHTCONTROL:_RemoveFlightFromQueue(queue, flight) function FLIGHTCONTROL:_RemoveFlightFromQueue(queue, flight)
-- Loop over all flights in group. -- Loop over all flights in group.
for i,_flight in pairs(queue) do for i,_flight in pairs(queue) do
local qflight=_flight --#FLIGHTCONTROL.FlightGroup local qflight=_flight --Ops.FlightGroup#FLIGHTGROUP
-- Check for name. -- Check for name.
if qflight.groupname==flight.groupname then if qflight.groupname==flight.groupname then
@@ -812,28 +736,10 @@ function FLIGHTCONTROL:_RemoveFlightFromQueue(queue, flight)
return false, nil return false, nil
end end
--- Sets flag recovered=true and tookoff=false for a flight element, which was successfully recovered (landed).
-- @param #FLIGHTCONTROL self
-- @param Wrapper.Unit#UNIT unit The aircraft unit that was recovered.
-- @return #FLIGHTCONTROL.FlightGroup Flight group of element.
function FLIGHTCONTROL:_ElementRecovered(unit)
-- Get element of flight.
local element, idx, flight=self:_GetFlightElement(unit:GetName()) --#FLIGHTCONTROL.FlightElement
-- Nil check. Could be if a helo landed or something else we dont know!
if element then
element.recovered=true
element.tookoff=false
end
return flight
end
--- Set tookoff to true for the flight element. --- Set tookoff to true for the flight element.
-- @param #FLIGHTCONTROL self -- @param #FLIGHTCONTROL self
-- @param Wrapper.Unit#UNIT unit The aircraft unit that was recovered. -- @param Wrapper.Unit#UNIT unit The aircraft unit that was recovered.
-- @return #FLIGHTCONTROL.FlightGroup Flight group of element. -- @return Ops.FlightGroup#FLIGHTGROUP Flight group of element.
function FLIGHTCONTROL:_ElementTookOff(unit) function FLIGHTCONTROL:_ElementTookOff(unit)
-- Get element of flight. -- Get element of flight.
@@ -849,7 +755,7 @@ end
--- Add flight to landing queue and set recovered to false for all elements of the flight and its section members. --- Add flight to landing queue and set recovered to false for all elements of the flight and its section members.
-- @param #FLIGHTCONTROL self -- @param #FLIGHTCONTROL self
-- @param #FLIGHTCONTROL.FlightGroup flight Flight group of element. -- @param Ops.FlightGroup#FLIGHTGROUP flight Flight group of element.
function FLIGHTCONTROL:_AddFlightToLandingQueue(flight) function FLIGHTCONTROL:_AddFlightToLandingQueue(flight)
-- Add flight to table. -- Add flight to table.
@@ -871,7 +777,7 @@ end
--- Add flight to takeoff queue. --- Add flight to takeoff queue.
-- @param #FLIGHTCONTROL self -- @param #FLIGHTCONTROL self
-- @param #FLIGHTCONTROL.FlightGroup flight Flight group of element. -- @param Ops.FlightGroup#FLIGHTGROUP flight Flight group of element.
function FLIGHTCONTROL:_AddFlightToTakeoffQueue(flight) function FLIGHTCONTROL:_AddFlightToTakeoffQueue(flight)
-- Check if already in queue. -- Check if already in queue.
@@ -904,7 +810,7 @@ end
function FLIGHTCONTROL:_InQueue(queue, group) function FLIGHTCONTROL:_InQueue(queue, group)
local name=group:GetName() local name=group:GetName()
for _,_flight in pairs(queue) do for _,_flight in pairs(queue) do
local flight=_flight --#FLIGHTCONTROL.FlightGroup local flight=_flight --Ops.FlightGroup#FLIGHTGROUP
if name==flight.groupname then if name==flight.groupname then
return true return true
end end
@@ -919,7 +825,7 @@ end
--- Create a new flight group. Usually when a flight appears in the CCA. --- Create a new flight group. Usually when a flight appears in the CCA.
-- @param #FLIGHTCONTROL self -- @param #FLIGHTCONTROL self
-- @param Wrapper.Group#GROUP group Aircraft group. -- @param Wrapper.Group#GROUP group Aircraft group.
-- @return #FLIGHTCONTROL.FlightGroup Flight group. -- @return Ops.FlightGroup#FLIGHTGROUP Flight group.
function FLIGHTCONTROL:_CreateFlightGroup(group) function FLIGHTCONTROL:_CreateFlightGroup(group)
-- Check if not already in flights -- Check if not already in flights
@@ -931,7 +837,7 @@ function FLIGHTCONTROL:_CreateFlightGroup(group)
self:T(self.lid..string.format("Creating new flight for group %s of aircraft type %s.", group:GetName(), group:GetTypeName())) self:T(self.lid..string.format("Creating new flight for group %s of aircraft type %s.", group:GetName(), group:GetTypeName()))
-- New flight. -- New flight.
local flight={} --#FLIGHTCONTROL.FlightGroup local flight={} --Ops.FlightGroup#FLIGHTGROUP
-- Flight group name -- Flight group name
local groupname=group:GetName() local groupname=group:GetName()
@@ -991,7 +897,7 @@ end
-- @param #FLIGHTCONTROL self -- @param #FLIGHTCONTROL self
-- @param Wrapper.Group#GROUP group Group that will be removed from queue. -- @param Wrapper.Group#GROUP group Group that will be removed from queue.
-- @param #table queue The queue from which the group will be removed. -- @param #table queue The queue from which the group will be removed.
-- @return #FLIGHTCONTROL.FlightGroup Flight group or nil. -- @return Ops.FlightGroup#FLIGHTGROUP Flight group or nil.
-- @return #number Queue index or nil. -- @return #number Queue index or nil.
function FLIGHTCONTROL:_GetFlightFromGroup(group) function FLIGHTCONTROL:_GetFlightFromGroup(group)
@@ -1002,7 +908,7 @@ function FLIGHTCONTROL:_GetFlightFromGroup(group)
-- Loop over all flight groups in queue -- Loop over all flight groups in queue
for i,_flight in pairs(self.flights) do for i,_flight in pairs(self.flights) do
local flight=_flight --#FLIGHTCONTROL.FlightGroup local flight=_flight --Ops.FlightGroup#FLIGHTGROUP
if flight.groupname==name then if flight.groupname==name then
return flight, i return flight, i
@@ -1021,7 +927,7 @@ end
-- @param #string unitname Name of the unit. -- @param #string unitname Name of the unit.
-- @return #FLIGHTCONTROL.FlightElement Element of the flight or nil. -- @return #FLIGHTCONTROL.FlightElement Element of the flight or nil.
-- @return #number Element index or nil. -- @return #number Element index or nil.
-- @return #FLIGHTCONTROL.FlightGroup The Flight group or nil. -- @return Ops.FlightGroup#FLIGHTGROUP The Flight group or nil.
function FLIGHTCONTROL:_GetFlightElement(unitname) function FLIGHTCONTROL:_GetFlightElement(unitname)
-- Get the unit. -- Get the unit.
@@ -1072,7 +978,7 @@ end
--- Get parking spot of flight element. --- Get parking spot of flight element.
-- @param #FLIGHTCONTROL self -- @param #FLIGHTCONTROL self
-- @param #FLIGHTCONTROL.FlightElement element Element of flight group. -- @param Ops.FlightGroup#FLIGHTGROUP.Element element Element of flight group.
-- @return #FLIGHTCONTROL.ParkingSpot Parking spot of flight element or nil. -- @return #FLIGHTCONTROL.ParkingSpot Parking spot of flight element or nil.
function FLIGHTCONTROL:_GetElementParkingSpot(element) function FLIGHTCONTROL:_GetElementParkingSpot(element)
@@ -1159,7 +1065,7 @@ function FLIGHTCONTROL:_CheckInbound()
end end
for _,_flight in pairs(self.flights) do for _,_flight in pairs(self.flights) do
local flight=_flight --#FLIGHTCONTROL.FlightGroup local flight=_flight --Ops.FlightGroup#FLIGHTGROUP
local inzone=flight.group:IsCompletelyInZone(self.zoneAirbase) local inzone=flight.group:IsCompletelyInZone(self.zoneAirbase)
@@ -1174,7 +1080,7 @@ function FLIGHTCONTROL:_CheckInbound()
for _,_flight in pairs(self.flights) do for _,_flight in pairs(self.flights) do
local flight=_flight --#FLIGHTCONTROL.FlightGroup local flight=_flight --Ops.FlightGroup#FLIGHTGROUP
--TODO: Check if aircraft has a landing waypoint for this airbase. --TODO: Check if aircraft has a landing waypoint for this airbase.
@@ -1207,7 +1113,7 @@ end
--- Command AI flight to orbit. --- Command AI flight to orbit.
-- @param #FLIGHTCONTROL self -- @param #FLIGHTCONTROL self
-- @param #FLIGHTCONTROL.FlightGroup flight Flight group. -- @param Ops.FlightGroup#FLIGHTGROUP flight Flight group.
-- @param #number stack Holding stack. -- @param #number stack Holding stack.
-- @param #boolean respawn If true respawn the group. Otherwise reset the mission task with new waypoints. -- @param #boolean respawn If true respawn the group. Otherwise reset the mission task with new waypoints.
function FLIGHTCONTROL:_WaitAI(flight, stack, respawn) function FLIGHTCONTROL:_WaitAI(flight, stack, respawn)
@@ -1290,7 +1196,7 @@ end
--- Tell AI to land at the airbase. Flight is added to the landing queue. --- Tell AI to land at the airbase. Flight is added to the landing queue.
-- @param #FLIGHTCONTROL self -- @param #FLIGHTCONTROL self
-- @param #FLIGHTCONTROL.FlightGroup flight Flight group. -- @param Ops.FlightGroup#FLIGHTGROUP flight Flight group.
function FLIGHTCONTROL:_LandAI(flight) function FLIGHTCONTROL:_LandAI(flight)
-- Debug info. -- Debug info.
@@ -1340,7 +1246,7 @@ end
--- Function called when a group has reached the holding zone. --- Function called when a group has reached the holding zone.
--@param Wrapper.Group#GROUP group Group that reached the holding zone. --@param Wrapper.Group#GROUP group Group that reached the holding zone.
--@param #FLIGHTCONTROL flightcontrol Flightcontrol object. --@param #FLIGHTCONTROL flightcontrol Flightcontrol object.
--@param #FLIGHTCONTROL.FlightGroup flight Flight group that has reached the holding zone. --@param Ops.FlightGroup#FLIGHTGROUP flight Flight group that has reached the holding zone.
function FLIGHTCONTROL._ReachedHoldingZone(group, flightcontrol, flight) function FLIGHTCONTROL._ReachedHoldingZone(group, flightcontrol, flight)
-- Debug message. -- Debug message.
@@ -1362,7 +1268,7 @@ end
--- Get holding point. --- Get holding point.
-- @param #FLIGHTCONTROL self -- @param #FLIGHTCONTROL self
-- @param #FLIGHTCONTROL.FlightGroup flight Flight group. -- @param Ops.FlightGroup#FLIGHTGROUP flight Flight group.
-- @return #FLIGHTCONTROL.HoldingPoint Holding point. -- @return #FLIGHTCONTROL.HoldingPoint Holding point.
function FLIGHTCONTROL:_GetHoldingpoint(flight) function FLIGHTCONTROL:_GetHoldingpoint(flight)
+124 -79
View File
@@ -21,9 +21,9 @@
-- @field #boolean Debug Debug mode. Messages to all about status. -- @field #boolean Debug Debug mode. Messages to all about status.
-- @field #string sid Class id string for output to DCS log file. -- @field #string sid Class id string for output to DCS log file.
-- @field #string groupname Name of flight group. -- @field #string groupname Name of flight group.
-- @field Wrapper.Group#GROUP flightgroup Flight group object. -- @field Wrapper.Group#GROUP group Flight group object.
-- @field #string type Aircraft type of flight group. -- @field #string type Aircraft type of flight group.
-- @field #table element Table of elements, i.e. units of the group. -- @field #table elements Table of elements, i.e. units of the group.
-- @field #table waypoints Table of waypoints. -- @field #table waypoints Table of waypoints.
-- @field #table coordinates Table of waypoint coordinates. -- @field #table coordinates Table of waypoint coordinates.
-- @field #table taskqueue Queue of tasks. -- @field #table taskqueue Queue of tasks.
@@ -63,7 +63,7 @@ FLIGHTGROUP = {
type = nil, type = nil,
waypoints = {}, waypoints = {},
coordinates = {}, coordinates = {},
element = {}, elements = {},
taskqueue = {}, taskqueue = {},
taskcounter = nil, taskcounter = nil,
taskcurrent = nil, taskcurrent = nil,
@@ -207,7 +207,7 @@ function FLIGHTGROUP:New(groupname)
-- Inherit everything from WAREHOUSE class. -- Inherit everything from WAREHOUSE class.
local self=BASE:Inherit(self, FSM:New()) -- #FLIGHTGROUP local self=BASE:Inherit(self, FSM:New()) -- #FLIGHTGROUP
--self.flightgroup=AIGroup --self.group=AIGroup
self.groupname=tostring(groupname) self.groupname=tostring(groupname)
-- Set some string id for output to DCS.log file. -- Set some string id for output to DCS.log file.
@@ -459,14 +459,14 @@ end
-- @param #FLIGHTGROUP self -- @param #FLIGHTGROUP self
-- @return Wrapper.Group#GROUP Moose group object. -- @return Wrapper.Group#GROUP Moose group object.
function FLIGHTGROUP:GetGroup() function FLIGHTGROUP:GetGroup()
return self.flightgroup return self.group
end end
--- Get flight group name. --- Get flight group name.
-- @param #FLIGHTGROUP self -- @param #FLIGHTGROUP self
-- @return #string Group name. -- @return #string Group name.
function FLIGHTGROUP:GetName() function FLIGHTGROUP:GetName()
return self.flightgroup:GetName() return self.group:GetName()
end end
--- Get waypoint. --- Get waypoint.
@@ -567,7 +567,7 @@ function FLIGHTGROUP:onafterStart(From, Event, To)
-- Check if the group is already alive and if so, add its elements. -- Check if the group is already alive and if so, add its elements.
local group=GROUP:FindByName(self.groupname) local group=GROUP:FindByName(self.groupname)
if group and group:IsAlive() then if group and group:IsAlive() then
self.flightgroup=group self.group=group
local units=group:GetUnits() local units=group:GetUnits()
for _,_unit in pairs(units) do for _,_unit in pairs(units) do
local unit=_unit --Wrapper.Unit#UNIT local unit=_unit --Wrapper.Unit#UNIT
@@ -593,39 +593,6 @@ function FLIGHTGROUP:onafterStart(From, Event, To)
self:__FlightStatus(-1) self:__FlightStatus(-1)
end end
--- On after "FlightSpawned" event. Sets the template, initializes the waypoints.
-- @param #FLIGHTGROUP self
-- @param Wrapper.Group#GROUP Group Flight group.
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
-- @param Wrapper.Group#GROUP Group The group object.
function FLIGHTGROUP:onafterFlightSpawned(From, Event, To, Group)
-- Get template of group.
self.template=self.flightgroup:GetTemplate()
-- Init waypoints.
self:_InitWaypoints()
-- Route flight group but now with passing waypoint tasks.
self.flightgroup:Route(self.waypoints)
end
--- On after "FlightAirborne" event.
-- @param #FLIGHTGROUP self
-- @param Wrapper.Group#GROUP Group Flight group.
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
-- @param Wrapper.Group#GROUP Group The group object.
function FLIGHTGROUP:onafterFlightAirborne(From, Event, To, Group)
-- Update
self:__QueueUpdate(-1)
end
--- On after "FlightStatus" event. --- On after "FlightStatus" event.
-- @param #FLIGHTGROUP self -- @param #FLIGHTGROUP self
-- @param Wrapper.Group#GROUP Group Flight group. -- @param Wrapper.Group#GROUP Group Flight group.
@@ -641,13 +608,13 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To)
self:_CheckDetectedUnits() self:_CheckDetectedUnits()
-- Short info. -- Short info.
local text=string.format("Flight status %s [%d/%d]. Task=%d/%d. Waypoint=%d/%d. Detected=%d", fsmstate, #self.element, #self.element, self.taskcurrent, #self.taskqueue, self.currentwp or 0, #self.waypoints or 0, self.detectedunits:Count()) local text=string.format("Flight status %s [%d/%d]. Task=%d/%d. Waypoint=%d/%d. Detected=%d", fsmstate, #self.elements, #self.elements, self.taskcurrent, #self.taskqueue, self.currentwp or 0, #self.waypoints or 0, self.detectedunits:Count())
self:I(self.sid..text) self:I(self.sid..text)
-- Element status. -- Element status.
text="Elements:" text="Elements:"
local fuelmin=999999 local fuelmin=999999
for i,_element in pairs(self.element) do for i,_element in pairs(self.elements) do
local element=_element --#FLIGHTGROUP.Element local element=_element --#FLIGHTGROUP.Element
local name=element.name local name=element.name
local status=element.status local status=element.status
@@ -677,7 +644,7 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To)
-- Output text for element. -- Output text for element.
text=text..string.format("\n[%d] %s: status=%s, fuel=%.1f, life=%.1f, shells=%d, rockets=%d, bombs=%d, missiles=%d", i, name, status, fuel*100, life*100, nshells, nrockets, nbombs, nmissiles) text=text..string.format("\n[%d] %s: status=%s, fuel=%.1f, life=%.1f, shells=%d, rockets=%d, bombs=%d, missiles=%d", i, name, status, fuel*100, life*100, nshells, nrockets, nbombs, nmissiles)
end end
if #self.element==0 then if #self.elements==0 then
text=text.." none!" text=text.." none!"
end end
self:I(self.sid..text) self:I(self.sid..text)
@@ -780,7 +747,7 @@ function FLIGHTGROUP:OnEventBirth(EventData)
local unitname=EventData.IniUnitName local unitname=EventData.IniUnitName
-- Set group. -- Set group.
self.flightgroup=self.flightgroup or EventData.IniGroup self.group=self.group or EventData.IniGroup
-- Set homebase if not already set. -- Set homebase if not already set.
if EventData.Place then if EventData.Place then
@@ -1032,6 +999,60 @@ function FLIGHTGROUP:onafterElementArrived(From, Event, To, Element)
end end
--- On after "FlightSpawned" event. Sets the template, initializes the waypoints.
-- @param #FLIGHTGROUP self
-- @param Wrapper.Group#GROUP Group Flight group.
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
-- @param Wrapper.Group#GROUP Group The group object.
function FLIGHTGROUP:onafterFlightSpawned(From, Event, To, Group)
-- Get template of group.
self.template=self.group:GetTemplate()
-- Init waypoints.
self:_InitWaypoints()
-- Route flight group but now with passing waypoint tasks.
self.group:Route(self.waypoints)
end
--- On after "FlightAirborne" event.
-- @param #FLIGHTGROUP self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
-- @param Wrapper.Airbase#AIRBASE airbase The airbase the flight landed.
function FLIGHTGROUP:onafterFlightAirborne(From, Event, To, airbase)
self:I(self.sid..string.format("Flight airborne %s.", self.groupname))
if self.flightcontrol and airbase and self.flightcontrol.airbasename==airbase:GetName() then
self.flightcontrol:_RemoveFlightFromQueue(self.flightcontrol.Qtakeoff, self)
end
-- Update
self:__QueueUpdate(-1)
end
--- On after "FlightLanded" event.
-- @param #FLIGHTGROUP self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
-- @param Wrapper.Airbase#AIRBASE airbase The airbase the flight landed.
function FLIGHTGROUP:onafterFlightLanded(From, Event, To, airbase)
self:I(self.sid..string.format("Flight landed %s.", self.groupname))
if self.flightcontrol and airbase and self.flightcontrol.airbasename==airbase:GetName() then
self.flightcontrol:_RemoveFlightFromQueue(self.flightcontrol.Qlanding, self)
end
end
--- On after "PassingWaypoint" event. --- On after "PassingWaypoint" event.
-- @param #FLIGHTGROUP self -- @param #FLIGHTGROUP self
-- @param #string From From state. -- @param #string From From state.
@@ -1125,9 +1146,33 @@ function FLIGHTGROUP:onafterOrbit(From, Event, To, Coord, Altitude, Speed)
MESSAGE:New(text, 10, "DEBUG"):ToAllIf(self.Debug) MESSAGE:New(text, 10, "DEBUG"):ToAllIf(self.Debug)
self:I(self.sid..text) self:I(self.sid..text)
local TaskOrbit=self.flightgroup:TaskOrbit(Coord, Altitude, UTILS.KmphToMps(Speed)) --TODO: set ROE passive. introduce roe event/state/variable.
local TaskOrbit=self.group:TaskOrbit(Coord, Altitude, UTILS.KmphToMps(Speed))
self.flightgroup:SetTask(TaskOrbit) self.group:SetTask(TaskOrbit)
end
--- On after "Hold" event.
-- @param #FLIGHTGROUP self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
-- @param Core.Point#COORDINATE Coord Coordinate where to orbit.
-- @param #number Altitude Altitude in meters.
-- @param #number Speed Speed in km/h.
function FLIGHTGROUP:onafterHold(From, Event, To, Coord, Altitude, Speed)
-- Debug message.
local text=string.format("Flight group set to hold at altitude %d m and speed %.1f km/h", Altitude, Speed)
MESSAGE:New(text, 10, "DEBUG"):ToAllIf(self.Debug)
self:I(self.sid..text)
self.group:ClearTasks()
local TaskOrbit=self.group:TaskOrbit(Coord, Altitude, UTILS.KmphToMps(Speed))
self.group:SetTask(TaskOrbit)
end end
--- On after TaskExecute event. --- On after TaskExecute event.
@@ -1156,16 +1201,16 @@ function FLIGHTGROUP:onafterTaskExecute(From, Event, To, Task)
if Task.type==FLIGHTGROUP.TaskType.SCHEDULED then if Task.type==FLIGHTGROUP.TaskType.SCHEDULED then
-- Clear all tasks. -- Clear all tasks.
self.flightgroup:ClearTasks() self.group:ClearTasks()
-- Task done. -- Task done.
local TaskDone=self.flightgroup:TaskFunction("FLIGHTGROUP._TaskDone", self, Task) local TaskDone=self.group:TaskFunction("FLIGHTGROUP._TaskDone", self, Task)
-- Combo task. -- Combo task.
local TaskCombo=self.flightgroup:TaskCombo({Task.dcstask, TaskDone}) local TaskCombo=self.group:TaskCombo({Task.dcstask, TaskDone})
-- Set task for group. -- Set task for group.
self.flightgroup:SetTask(TaskCombo) self.group:SetTask(TaskCombo)
end end
@@ -1183,7 +1228,7 @@ function FLIGHTGROUP:onafterTaskPause(From, Event, To, Task)
if self.taskcurrent>0 then if self.taskcurrent>0 then
-- Clear all tasks. -- Clear all tasks.
self.flightgroup:ClearTasks() self.group:ClearTasks()
-- Task status executing. -- Task status executing.
Task.status=1 --FLIGHTGROUP.TaskStatus.PAUSED Task.status=1 --FLIGHTGROUP.TaskStatus.PAUSED
@@ -1208,7 +1253,7 @@ function FLIGHTGROUP:onafterTaskCancel(From, Event, To)
MESSAGE:New(text, 10, "DEBUG"):ToAllIf(self.Debug) MESSAGE:New(text, 10, "DEBUG"):ToAllIf(self.Debug)
self:I(self.sid..text) self:I(self.sid..text)
-- Clear tasks. -- Clear tasks.
self.flightgroup:ClearTasks() self.group:ClearTasks()
self:TaskDone(task) self:TaskDone(task)
else else
local text=string.format("WARNING: No current task to cancel!") local text=string.format("WARNING: No current task to cancel!")
@@ -1386,10 +1431,10 @@ end
function FLIGHTGROUP:RouteRTB(RTBAirbase, Speed, Altitude) function FLIGHTGROUP:RouteRTB(RTBAirbase, Speed, Altitude)
-- If speed is not given take 80% of max speed. -- If speed is not given take 80% of max speed.
local Speed=Speed or self.flightgroup:GetSpeedMax()*0.8 local Speed=Speed or self.group:GetSpeedMax()*0.8
-- Curent (from) waypoint. -- Curent (from) waypoint.
local coord=self.flightgroup:GetCoordinate() local coord=self.group:GetCoordinate()
if Altitude then if Altitude then
coord:SetAltitude(Altitude) coord:SetAltitude(Altitude)
@@ -1408,17 +1453,17 @@ function FLIGHTGROUP:RouteRTB(RTBAirbase, Speed, Altitude)
local Points={PointFrom, PointOverhead, PointLanding} local Points={PointFrom, PointOverhead, PointLanding}
-- Get group template. -- Get group template.
local Template=self.flightgroup:GetTemplate() local Template=self.group:GetTemplate()
-- Set route points. -- Set route points.
Template.route.points=Points Template.route.points=Points
-- Respawn the group. -- Respawn the group.
self.flightgroup=self.flightgroup:Respawn(Template, true) self.group=self.group:Respawn(Template, true)
-- Route the group or this will not work. -- Route the group or this will not work.
self.flightgroup:Route(Points, 1) self.group:Route(Points, 1)
end end
@@ -1432,7 +1477,7 @@ end
function FLIGHTGROUP:RouteOrbit(CoordOrbit, Speed, Altitude, CoordRaceTrack) function FLIGHTGROUP:RouteOrbit(CoordOrbit, Speed, Altitude, CoordRaceTrack)
-- If speed is not given take 80% of max speed. -- If speed is not given take 80% of max speed.
local Speed=Speed or self.flightgroup:GetSpeedMax()*0.6 local Speed=Speed or self.group:GetSpeedMax()*0.6
-- Altitude. -- Altitude.
local altitude=Altitude or UTILS.FeetToMeters(10000) local altitude=Altitude or UTILS.FeetToMeters(10000)
@@ -1441,23 +1486,23 @@ function FLIGHTGROUP:RouteOrbit(CoordOrbit, Speed, Altitude, CoordRaceTrack)
local wp={} local wp={}
-- Current coordinate. -- Current coordinate.
wp[1]=self.flightgroup:GetCoordinate():SetAltitude(altitude):WaypointAirTurningPoint(nil, Speed, {}, "Current") wp[1]=self.group:GetCoordinate():SetAltitude(altitude):WaypointAirTurningPoint(nil, Speed, {}, "Current")
-- Orbit -- Orbit
wp[2]=CoordOrbit:SetAltitude(altitude):WaypointAirTurningPoint(nil, Speed, {}, "Orbit") wp[2]=CoordOrbit:SetAltitude(altitude):WaypointAirTurningPoint(nil, Speed, {}, "Orbit")
local TaskOrbit=self.flightgroup:TaskOrbit(CoordOrbit, altitude, Speed, CoordRaceTrack) local TaskOrbit=self.group:TaskOrbit(CoordOrbit, altitude, Speed, CoordRaceTrack)
local TaskRoute=self.flightgroup:TaskRoute(wp) local TaskRoute=self.group:TaskRoute(wp)
--local TaskCondi=self.flightgroup:TaskCondition(time,userFlag,userFlagValue,condition,duration,lastWayPoint) --local TaskCondi=self.group:TaskCondition(time,userFlag,userFlagValue,condition,duration,lastWayPoint)
local TaskCombo=self.flightgroup:TaskControlled(TaskRoute, TaskOrbit) local TaskCombo=self.group:TaskControlled(TaskRoute, TaskOrbit)
self.flightgroup:SetTask(TaskCombo, 1) self.group:SetTask(TaskCombo, 1)
-- Route the group or this will not work. -- Route the group or this will not work.
--self.flightgroup:Route(wp, 1) --self.group:Route(wp, 1)
end end
@@ -1497,7 +1542,7 @@ function FLIGHTGROUP:AddElementByName(unitname)
end end
table.insert(self.element, element) table.insert(self.elements, element)
return element return element
end end
@@ -1511,7 +1556,7 @@ end
-- @return #FLIGHTGROUP.Element The element. -- @return #FLIGHTGROUP.Element The element.
function FLIGHTGROUP:GetElementByName(unitname) function FLIGHTGROUP:GetElementByName(unitname)
for _,_element in pairs(self.element) do for _,_element in pairs(self.elements) do
local element=_element --#FLIGHTGROUP.Element local element=_element --#FLIGHTGROUP.Element
if element.name==unitname then if element.name==unitname then
@@ -1644,7 +1689,7 @@ function FLIGHTGROUP:_UpdateRoute(n)
if #wp>0 then if #wp>0 then
-- Route group to all defined waypoints remaining. -- Route group to all defined waypoints remaining.
self.flightgroup:Route(wp, 1) self.group:Route(wp, 1)
else else
@@ -1664,7 +1709,7 @@ function FLIGHTGROUP:_UpdateRoute(n)
self:RTB(airbase) self:RTB(airbase)
else else
-- Let flight orbit. -- Let flight orbit.
--self:Orbit(self.flightgroup:GetCoordinate(), UTILS.FeetToMeters(20000), self.flightgroup:GetSpeedMax()*0.4) --self:Orbit(self.group:GetCoordinate(), UTILS.FeetToMeters(20000), self.group:GetSpeedMax()*0.4)
end end
end end
@@ -1684,7 +1729,7 @@ function FLIGHTGROUP:_UpdateWaypointTasks()
local taskswp={} local taskswp={}
-- At each waypoint report passing. -- At each waypoint report passing.
local TaskPassingWaypoint=self.flightgroup:TaskFunction("FLIGHTGROUP._PassingWaypoint", self, i) local TaskPassingWaypoint=self.group:TaskFunction("FLIGHTGROUP._PassingWaypoint", self, i)
table.insert(taskswp, TaskPassingWaypoint) table.insert(taskswp, TaskPassingWaypoint)
@@ -1696,18 +1741,18 @@ function FLIGHTGROUP:_UpdateWaypointTasks()
local Task=task --#FLIGHTGROUP.Task local Task=task --#FLIGHTGROUP.Task
-- Add task execute. -- Add task execute.
table.insert(taskswp, self.flightgroup:TaskFunction("FLIGHTGROUP._TaskExecute", self, Task)) table.insert(taskswp, self.group:TaskFunction("FLIGHTGROUP._TaskExecute", self, Task))
-- Add task itself. -- Add task itself.
table.insert(taskswp, Task.dcstask) table.insert(taskswp, Task.dcstask)
-- Add task done. -- Add task done.
table.insert(taskswp, self.flightgroup:TaskFunction("FLIGHTGROUP._TaskDone", self, Task)) table.insert(taskswp, self.group:TaskFunction("FLIGHTGROUP._TaskDone", self, Task))
end end
end end
-- Waypoint task combo. -- Waypoint task combo.
wp.task=self.flightgroup:TaskCombo(taskswp) wp.task=self.group:TaskCombo(taskswp)
-- Debug info. -- Debug info.
self:T3({wptask=taskswp}) self:T3({wptask=taskswp})
@@ -1721,7 +1766,7 @@ end
function FLIGHTGROUP:_InitWaypoints() function FLIGHTGROUP:_InitWaypoints()
-- Waypoints of group as defined in the ME. -- Waypoints of group as defined in the ME.
self.waypoints=self.flightgroup:GetTemplateRoutePoints() self.waypoints=self.group:GetTemplateRoutePoints()
-- Update waypoint tasks. -- Update waypoint tasks.
self:_UpdateWaypointTasks() self:_UpdateWaypointTasks()
@@ -1797,7 +1842,7 @@ end
-- @return #boolean If true, unit is element of the flight group or false if otherwise. -- @return #boolean If true, unit is element of the flight group or false if otherwise.
function FLIGHTGROUP:_IsElement(unitname) function FLIGHTGROUP:_IsElement(unitname)
for _,_element in pairs(self.element) do for _,_element in pairs(self.elements) do
local element=_element --#FLIGHTGROUP.Element local element=_element --#FLIGHTGROUP.Element
if element.name==unitname then if element.name==unitname then
@@ -1814,7 +1859,7 @@ end
-- @param #string unitname Name of unit. -- @param #string unitname Name of unit.
function FLIGHTGROUP:_AllSameStatus(status) function FLIGHTGROUP:_AllSameStatus(status)
for _,_element in pairs(self.element) do for _,_element in pairs(self.elements) do
local element=_element --#FLIGHTGROUP.Element local element=_element --#FLIGHTGROUP.Element
if element.status==FLIGHTGROUP.ElementStatus.DEAD then if element.status==FLIGHTGROUP.ElementStatus.DEAD then
@@ -1837,7 +1882,7 @@ function FLIGHTGROUP:_AllSimilarStatus(status)
local similar=true local similar=true
for _,_element in pairs(self.element) do for _,_element in pairs(self.elements) do
local element=_element --#FLIGHTGROUP.Element local element=_element --#FLIGHTGROUP.Element
-- Dead units dont count. -- Dead units dont count.
@@ -2020,10 +2065,10 @@ end
-- @param #FLIGHTGROUP self -- @param #FLIGHTGROUP self
function FLIGHTGROUP:_CheckDetectedUnits() function FLIGHTGROUP:_CheckDetectedUnits()
if self.flightgroup and not self:IsDead() then if self.group and not self:IsDead() then
-- Get detected DCS units. -- Get detected DCS units.
local detectedtargets=self.flightgroup:GetDetectedTargets() local detectedtargets=self.group:GetDetectedTargets()
local detected={} local detected={}
for DetectionObjectID, Detection in pairs(detectedtargets or {}) do for DetectionObjectID, Detection in pairs(detectedtargets or {}) do
+7 -2
View File
@@ -961,9 +961,14 @@ function UTILS.FileExists(file)
end end
--- Checks the current memory usage collectgarbage("count"). Info is printed to the DCS log file. Time stamp is the current mission runtime. --- Checks the current memory usage collectgarbage("count"). Info is printed to the DCS log file. Time stamp is the current mission runtime.
function UTILS.CheckMemory() -- @param #boolean output If true, print to DCS log file.
-- @return #number Memory usage in kByte.
function UTILS.CheckMemory(output)
local time=timer.getTime() local time=timer.getTime()
local clock=UTILS.SecondsToClock(time) local clock=UTILS.SecondsToClock(time)
local mem=collectgarbage("count") local mem=collectgarbage("count")
env.info(string.format("T=%s Memory usage %d kByte = %.2f MByte", clock, mem, mem/1024)) if output then
env.info(string.format("T=%s Memory usage %d kByte = %.2f MByte", clock, mem, mem/1024))
end
return mem
end end