mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-07-27 00:03:44 +00:00
OPS
This commit is contained in:
@@ -420,6 +420,7 @@ end
|
||||
BEACON = {
|
||||
ClassName = "BEACON",
|
||||
Positionable = nil,
|
||||
name=nil,
|
||||
}
|
||||
|
||||
--- Beacon types supported by DCS.
|
||||
@@ -496,6 +497,8 @@ function BEACON:New(Positionable)
|
||||
-- Set positionable.
|
||||
if Positionable:GetPointVec2() then -- It's stupid, but the only way I found to make sure positionable is valid
|
||||
self.Positionable = Positionable
|
||||
self.name=Positionable:GetName()
|
||||
self:I(string.format("New BEACON %s", tostring(self.name)))
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -550,7 +553,7 @@ function BEACON:ActivateTACAN(Channel, Mode, Message, Bearing, Duration)
|
||||
local UnitID=self.Positionable:GetID()
|
||||
|
||||
-- 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.
|
||||
self.Positionable:CommandActivateBeacon(Type, System, Frequency, UnitID, Channel, Mode, AA, Message, Bearing)
|
||||
|
||||
@@ -63,46 +63,6 @@ FLIGHTCONTROL = {
|
||||
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
|
||||
-- @type FLIGHTCONTROL.HoldingPoint
|
||||
-- @field Core.Point#COORDINATE pos0 First poosition of racetrack holding point.
|
||||
@@ -130,7 +90,7 @@ FLIGHTCONTROL.FlightState={
|
||||
|
||||
--- FlightControl class version.
|
||||
-- @field #string version
|
||||
FLIGHTCONTROL.version="0.0.4"
|
||||
FLIGHTCONTROL.version="0.0.5"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- TODO list
|
||||
@@ -142,6 +102,7 @@ FLIGHTCONTROL.version="0.0.4"
|
||||
-- TODO: ATIS option.
|
||||
-- TODO: ATC voice overs.
|
||||
-- TODO: Check runways and clean up.
|
||||
-- TODO: Interface with FLIGHTGROUP
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Constructor
|
||||
@@ -317,7 +278,7 @@ function FLIGHTCONTROL:_InitRunwayData()
|
||||
local hdg=c1:HeadingTo(c2)
|
||||
|
||||
-- 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.
|
||||
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: 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
|
||||
|
||||
--- Event handler for event takeoff.
|
||||
@@ -688,10 +611,11 @@ function FLIGHTCONTROL:_CheckParking()
|
||||
|
||||
-- Loop over all flights.
|
||||
for _,_flight in pairs(self.flights) do
|
||||
local flight=_flight --Ops.FlightGroup#FLIGHTGROUP
|
||||
|
||||
-- Loop over all elements.
|
||||
for _,_element in pairs(_flight.elements) do
|
||||
local element=_element --#FLIGHTCONTROL.FlightElement
|
||||
local element=_element --Ops.FlightGroup#FLIGHTGROUP.Element
|
||||
|
||||
local unit=element.unit
|
||||
|
||||
@@ -720,12 +644,12 @@ end
|
||||
|
||||
--- Get next flight waiting for landing clearance.
|
||||
-- @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()
|
||||
|
||||
-- Loop over all marshal flights.
|
||||
for _,_flight in pairs(self.Qwaiting) do
|
||||
local flight=_flight --#FLIGHTCONTROL.FlightGroup
|
||||
local flight=_flight --Ops.FlightGroup#FLIGHTGROUP
|
||||
|
||||
-- Current stack.
|
||||
local stack=flight.flag
|
||||
@@ -760,7 +684,7 @@ function FLIGHTCONTROL:_PrintQueue(queue, name)
|
||||
|
||||
-- Loop over all flights in queue.
|
||||
for i,_flight in ipairs(queue) do
|
||||
local flight=_flight --#FLIGHTCONTROL.FlightGroup
|
||||
local flight=_flight --Ops.FlightGroup#FLIGHTGROUP
|
||||
|
||||
-- Gather info.
|
||||
local clock=UTILS.SecondsToClock(timer.getAbsTime()-flight.time)
|
||||
@@ -792,14 +716,14 @@ end
|
||||
--- Remove a flight group from a queue.
|
||||
-- @param #FLIGHTCONTROL self
|
||||
-- @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 #number Table index of removed queue element or nil.
|
||||
function FLIGHTCONTROL:_RemoveFlightFromQueue(queue, flight)
|
||||
|
||||
-- Loop over all flights in group.
|
||||
for i,_flight in pairs(queue) do
|
||||
local qflight=_flight --#FLIGHTCONTROL.FlightGroup
|
||||
local qflight=_flight --Ops.FlightGroup#FLIGHTGROUP
|
||||
|
||||
-- Check for name.
|
||||
if qflight.groupname==flight.groupname then
|
||||
@@ -812,28 +736,10 @@ function FLIGHTCONTROL:_RemoveFlightFromQueue(queue, flight)
|
||||
return false, nil
|
||||
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.
|
||||
-- @param #FLIGHTCONTROL self
|
||||
-- @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)
|
||||
|
||||
-- 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.
|
||||
-- @param #FLIGHTCONTROL self
|
||||
-- @param #FLIGHTCONTROL.FlightGroup flight Flight group of element.
|
||||
-- @param Ops.FlightGroup#FLIGHTGROUP flight Flight group of element.
|
||||
function FLIGHTCONTROL:_AddFlightToLandingQueue(flight)
|
||||
|
||||
-- Add flight to table.
|
||||
@@ -871,7 +777,7 @@ end
|
||||
|
||||
--- Add flight to takeoff queue.
|
||||
-- @param #FLIGHTCONTROL self
|
||||
-- @param #FLIGHTCONTROL.FlightGroup flight Flight group of element.
|
||||
-- @param Ops.FlightGroup#FLIGHTGROUP flight Flight group of element.
|
||||
function FLIGHTCONTROL:_AddFlightToTakeoffQueue(flight)
|
||||
|
||||
-- Check if already in queue.
|
||||
@@ -904,7 +810,7 @@ end
|
||||
function FLIGHTCONTROL:_InQueue(queue, group)
|
||||
local name=group:GetName()
|
||||
for _,_flight in pairs(queue) do
|
||||
local flight=_flight --#FLIGHTCONTROL.FlightGroup
|
||||
local flight=_flight --Ops.FlightGroup#FLIGHTGROUP
|
||||
if name==flight.groupname then
|
||||
return true
|
||||
end
|
||||
@@ -919,7 +825,7 @@ end
|
||||
--- Create a new flight group. Usually when a flight appears in the CCA.
|
||||
-- @param #FLIGHTCONTROL self
|
||||
-- @param Wrapper.Group#GROUP group Aircraft group.
|
||||
-- @return #FLIGHTCONTROL.FlightGroup Flight group.
|
||||
-- @return Ops.FlightGroup#FLIGHTGROUP Flight group.
|
||||
function FLIGHTCONTROL:_CreateFlightGroup(group)
|
||||
|
||||
-- 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()))
|
||||
|
||||
-- New flight.
|
||||
local flight={} --#FLIGHTCONTROL.FlightGroup
|
||||
local flight={} --Ops.FlightGroup#FLIGHTGROUP
|
||||
|
||||
-- Flight group name
|
||||
local groupname=group:GetName()
|
||||
@@ -991,7 +897,7 @@ end
|
||||
-- @param #FLIGHTCONTROL self
|
||||
-- @param Wrapper.Group#GROUP group Group that will be removed from queue.
|
||||
-- @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.
|
||||
function FLIGHTCONTROL:_GetFlightFromGroup(group)
|
||||
|
||||
@@ -1002,7 +908,7 @@ function FLIGHTCONTROL:_GetFlightFromGroup(group)
|
||||
|
||||
-- Loop over all flight groups in queue
|
||||
for i,_flight in pairs(self.flights) do
|
||||
local flight=_flight --#FLIGHTCONTROL.FlightGroup
|
||||
local flight=_flight --Ops.FlightGroup#FLIGHTGROUP
|
||||
|
||||
if flight.groupname==name then
|
||||
return flight, i
|
||||
@@ -1021,7 +927,7 @@ end
|
||||
-- @param #string unitname Name of the unit.
|
||||
-- @return #FLIGHTCONTROL.FlightElement Element of the flight 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)
|
||||
|
||||
-- Get the unit.
|
||||
@@ -1072,7 +978,7 @@ end
|
||||
|
||||
--- Get parking spot of flight element.
|
||||
-- @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.
|
||||
function FLIGHTCONTROL:_GetElementParkingSpot(element)
|
||||
|
||||
@@ -1159,7 +1065,7 @@ function FLIGHTCONTROL:_CheckInbound()
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
@@ -1174,7 +1080,7 @@ function FLIGHTCONTROL:_CheckInbound()
|
||||
|
||||
|
||||
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.
|
||||
|
||||
@@ -1207,7 +1113,7 @@ end
|
||||
|
||||
--- Command AI flight to orbit.
|
||||
-- @param #FLIGHTCONTROL self
|
||||
-- @param #FLIGHTCONTROL.FlightGroup flight Flight group.
|
||||
-- @param Ops.FlightGroup#FLIGHTGROUP flight Flight group.
|
||||
-- @param #number stack Holding stack.
|
||||
-- @param #boolean respawn If true respawn the group. Otherwise reset the mission task with new waypoints.
|
||||
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.
|
||||
-- @param #FLIGHTCONTROL self
|
||||
-- @param #FLIGHTCONTROL.FlightGroup flight Flight group.
|
||||
-- @param Ops.FlightGroup#FLIGHTGROUP flight Flight group.
|
||||
function FLIGHTCONTROL:_LandAI(flight)
|
||||
|
||||
-- Debug info.
|
||||
@@ -1340,7 +1246,7 @@ end
|
||||
--- Function called when a group has reached the holding zone.
|
||||
--@param Wrapper.Group#GROUP group Group that reached the holding zone.
|
||||
--@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)
|
||||
|
||||
-- Debug message.
|
||||
@@ -1362,7 +1268,7 @@ end
|
||||
|
||||
--- Get holding point.
|
||||
-- @param #FLIGHTCONTROL self
|
||||
-- @param #FLIGHTCONTROL.FlightGroup flight Flight group.
|
||||
-- @param Ops.FlightGroup#FLIGHTGROUP flight Flight group.
|
||||
-- @return #FLIGHTCONTROL.HoldingPoint Holding point.
|
||||
function FLIGHTCONTROL:_GetHoldingpoint(flight)
|
||||
|
||||
|
||||
@@ -21,9 +21,9 @@
|
||||
-- @field #boolean Debug Debug mode. Messages to all about status.
|
||||
-- @field #string sid Class id string for output to DCS log file.
|
||||
-- @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 #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 coordinates Table of waypoint coordinates.
|
||||
-- @field #table taskqueue Queue of tasks.
|
||||
@@ -63,7 +63,7 @@ FLIGHTGROUP = {
|
||||
type = nil,
|
||||
waypoints = {},
|
||||
coordinates = {},
|
||||
element = {},
|
||||
elements = {},
|
||||
taskqueue = {},
|
||||
taskcounter = nil,
|
||||
taskcurrent = nil,
|
||||
@@ -207,7 +207,7 @@ function FLIGHTGROUP:New(groupname)
|
||||
-- Inherit everything from WAREHOUSE class.
|
||||
local self=BASE:Inherit(self, FSM:New()) -- #FLIGHTGROUP
|
||||
|
||||
--self.flightgroup=AIGroup
|
||||
--self.group=AIGroup
|
||||
self.groupname=tostring(groupname)
|
||||
|
||||
-- Set some string id for output to DCS.log file.
|
||||
@@ -459,14 +459,14 @@ end
|
||||
-- @param #FLIGHTGROUP self
|
||||
-- @return Wrapper.Group#GROUP Moose group object.
|
||||
function FLIGHTGROUP:GetGroup()
|
||||
return self.flightgroup
|
||||
return self.group
|
||||
end
|
||||
|
||||
--- Get flight group name.
|
||||
-- @param #FLIGHTGROUP self
|
||||
-- @return #string Group name.
|
||||
function FLIGHTGROUP:GetName()
|
||||
return self.flightgroup:GetName()
|
||||
return self.group:GetName()
|
||||
end
|
||||
|
||||
--- 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.
|
||||
local group=GROUP:FindByName(self.groupname)
|
||||
if group and group:IsAlive() then
|
||||
self.flightgroup=group
|
||||
self.group=group
|
||||
local units=group:GetUnits()
|
||||
for _,_unit in pairs(units) do
|
||||
local unit=_unit --Wrapper.Unit#UNIT
|
||||
@@ -593,39 +593,6 @@ function FLIGHTGROUP:onafterStart(From, Event, To)
|
||||
self:__FlightStatus(-1)
|
||||
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.
|
||||
-- @param #FLIGHTGROUP self
|
||||
-- @param Wrapper.Group#GROUP Group Flight group.
|
||||
@@ -641,13 +608,13 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To)
|
||||
self:_CheckDetectedUnits()
|
||||
|
||||
-- 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)
|
||||
|
||||
-- Element status.
|
||||
text="Elements:"
|
||||
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 name=element.name
|
||||
local status=element.status
|
||||
@@ -677,7 +644,7 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To)
|
||||
-- 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)
|
||||
end
|
||||
if #self.element==0 then
|
||||
if #self.elements==0 then
|
||||
text=text.." none!"
|
||||
end
|
||||
self:I(self.sid..text)
|
||||
@@ -780,7 +747,7 @@ function FLIGHTGROUP:OnEventBirth(EventData)
|
||||
local unitname=EventData.IniUnitName
|
||||
|
||||
-- Set group.
|
||||
self.flightgroup=self.flightgroup or EventData.IniGroup
|
||||
self.group=self.group or EventData.IniGroup
|
||||
|
||||
-- Set homebase if not already set.
|
||||
if EventData.Place then
|
||||
@@ -1032,6 +999,60 @@ function FLIGHTGROUP:onafterElementArrived(From, Event, To, Element)
|
||||
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.
|
||||
-- @param #FLIGHTGROUP self
|
||||
-- @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)
|
||||
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
|
||||
|
||||
--- On after TaskExecute event.
|
||||
@@ -1156,16 +1201,16 @@ function FLIGHTGROUP:onafterTaskExecute(From, Event, To, Task)
|
||||
if Task.type==FLIGHTGROUP.TaskType.SCHEDULED then
|
||||
|
||||
-- Clear all tasks.
|
||||
self.flightgroup:ClearTasks()
|
||||
self.group:ClearTasks()
|
||||
|
||||
-- Task done.
|
||||
local TaskDone=self.flightgroup:TaskFunction("FLIGHTGROUP._TaskDone", self, Task)
|
||||
local TaskDone=self.group:TaskFunction("FLIGHTGROUP._TaskDone", self, Task)
|
||||
|
||||
-- Combo task.
|
||||
local TaskCombo=self.flightgroup:TaskCombo({Task.dcstask, TaskDone})
|
||||
local TaskCombo=self.group:TaskCombo({Task.dcstask, TaskDone})
|
||||
|
||||
-- Set task for group.
|
||||
self.flightgroup:SetTask(TaskCombo)
|
||||
self.group:SetTask(TaskCombo)
|
||||
|
||||
end
|
||||
|
||||
@@ -1183,7 +1228,7 @@ function FLIGHTGROUP:onafterTaskPause(From, Event, To, Task)
|
||||
if self.taskcurrent>0 then
|
||||
|
||||
-- Clear all tasks.
|
||||
self.flightgroup:ClearTasks()
|
||||
self.group:ClearTasks()
|
||||
|
||||
-- Task status executing.
|
||||
Task.status=1 --FLIGHTGROUP.TaskStatus.PAUSED
|
||||
@@ -1208,7 +1253,7 @@ function FLIGHTGROUP:onafterTaskCancel(From, Event, To)
|
||||
MESSAGE:New(text, 10, "DEBUG"):ToAllIf(self.Debug)
|
||||
self:I(self.sid..text)
|
||||
-- Clear tasks.
|
||||
self.flightgroup:ClearTasks()
|
||||
self.group:ClearTasks()
|
||||
self:TaskDone(task)
|
||||
else
|
||||
local text=string.format("WARNING: No current task to cancel!")
|
||||
@@ -1386,10 +1431,10 @@ end
|
||||
function FLIGHTGROUP:RouteRTB(RTBAirbase, Speed, Altitude)
|
||||
|
||||
-- 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.
|
||||
local coord=self.flightgroup:GetCoordinate()
|
||||
local coord=self.group:GetCoordinate()
|
||||
|
||||
if Altitude then
|
||||
coord:SetAltitude(Altitude)
|
||||
@@ -1408,17 +1453,17 @@ function FLIGHTGROUP:RouteRTB(RTBAirbase, Speed, Altitude)
|
||||
local Points={PointFrom, PointOverhead, PointLanding}
|
||||
|
||||
-- Get group template.
|
||||
local Template=self.flightgroup:GetTemplate()
|
||||
local Template=self.group:GetTemplate()
|
||||
|
||||
-- Set route points.
|
||||
Template.route.points=Points
|
||||
|
||||
|
||||
-- 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.
|
||||
self.flightgroup:Route(Points, 1)
|
||||
self.group:Route(Points, 1)
|
||||
|
||||
end
|
||||
|
||||
@@ -1432,7 +1477,7 @@ end
|
||||
function FLIGHTGROUP:RouteOrbit(CoordOrbit, Speed, Altitude, CoordRaceTrack)
|
||||
|
||||
-- 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.
|
||||
local altitude=Altitude or UTILS.FeetToMeters(10000)
|
||||
@@ -1441,23 +1486,23 @@ function FLIGHTGROUP:RouteOrbit(CoordOrbit, Speed, Altitude, CoordRaceTrack)
|
||||
local wp={}
|
||||
|
||||
-- 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
|
||||
wp[2]=CoordOrbit:SetAltitude(altitude):WaypointAirTurningPoint(nil, Speed, {}, "Orbit")
|
||||
|
||||
|
||||
local TaskOrbit=self.flightgroup:TaskOrbit(CoordOrbit, altitude, Speed, CoordRaceTrack)
|
||||
local TaskRoute=self.flightgroup:TaskRoute(wp)
|
||||
local TaskOrbit=self.group:TaskOrbit(CoordOrbit, altitude, Speed, CoordRaceTrack)
|
||||
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.
|
||||
--self.flightgroup:Route(wp, 1)
|
||||
--self.group:Route(wp, 1)
|
||||
end
|
||||
|
||||
|
||||
@@ -1497,7 +1542,7 @@ function FLIGHTGROUP:AddElementByName(unitname)
|
||||
end
|
||||
|
||||
|
||||
table.insert(self.element, element)
|
||||
table.insert(self.elements, element)
|
||||
|
||||
return element
|
||||
end
|
||||
@@ -1511,7 +1556,7 @@ end
|
||||
-- @return #FLIGHTGROUP.Element The element.
|
||||
function FLIGHTGROUP:GetElementByName(unitname)
|
||||
|
||||
for _,_element in pairs(self.element) do
|
||||
for _,_element in pairs(self.elements) do
|
||||
local element=_element --#FLIGHTGROUP.Element
|
||||
|
||||
if element.name==unitname then
|
||||
@@ -1644,7 +1689,7 @@ function FLIGHTGROUP:_UpdateRoute(n)
|
||||
if #wp>0 then
|
||||
|
||||
-- Route group to all defined waypoints remaining.
|
||||
self.flightgroup:Route(wp, 1)
|
||||
self.group:Route(wp, 1)
|
||||
|
||||
else
|
||||
|
||||
@@ -1664,7 +1709,7 @@ function FLIGHTGROUP:_UpdateRoute(n)
|
||||
self:RTB(airbase)
|
||||
else
|
||||
-- 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
|
||||
@@ -1684,7 +1729,7 @@ function FLIGHTGROUP:_UpdateWaypointTasks()
|
||||
local taskswp={}
|
||||
|
||||
-- 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)
|
||||
|
||||
@@ -1696,18 +1741,18 @@ function FLIGHTGROUP:_UpdateWaypointTasks()
|
||||
local Task=task --#FLIGHTGROUP.Task
|
||||
|
||||
-- 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.
|
||||
table.insert(taskswp, Task.dcstask)
|
||||
|
||||
-- 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
|
||||
|
||||
-- Waypoint task combo.
|
||||
wp.task=self.flightgroup:TaskCombo(taskswp)
|
||||
wp.task=self.group:TaskCombo(taskswp)
|
||||
|
||||
-- Debug info.
|
||||
self:T3({wptask=taskswp})
|
||||
@@ -1721,7 +1766,7 @@ end
|
||||
function FLIGHTGROUP:_InitWaypoints()
|
||||
|
||||
-- Waypoints of group as defined in the ME.
|
||||
self.waypoints=self.flightgroup:GetTemplateRoutePoints()
|
||||
self.waypoints=self.group:GetTemplateRoutePoints()
|
||||
|
||||
-- Update waypoint tasks.
|
||||
self:_UpdateWaypointTasks()
|
||||
@@ -1797,7 +1842,7 @@ end
|
||||
-- @return #boolean If true, unit is element of the flight group or false if otherwise.
|
||||
function FLIGHTGROUP:_IsElement(unitname)
|
||||
|
||||
for _,_element in pairs(self.element) do
|
||||
for _,_element in pairs(self.elements) do
|
||||
local element=_element --#FLIGHTGROUP.Element
|
||||
|
||||
if element.name==unitname then
|
||||
@@ -1814,7 +1859,7 @@ end
|
||||
-- @param #string unitname Name of unit.
|
||||
function FLIGHTGROUP:_AllSameStatus(status)
|
||||
|
||||
for _,_element in pairs(self.element) do
|
||||
for _,_element in pairs(self.elements) do
|
||||
local element=_element --#FLIGHTGROUP.Element
|
||||
|
||||
if element.status==FLIGHTGROUP.ElementStatus.DEAD then
|
||||
@@ -1837,7 +1882,7 @@ function FLIGHTGROUP:_AllSimilarStatus(status)
|
||||
|
||||
local similar=true
|
||||
|
||||
for _,_element in pairs(self.element) do
|
||||
for _,_element in pairs(self.elements) do
|
||||
local element=_element --#FLIGHTGROUP.Element
|
||||
|
||||
-- Dead units dont count.
|
||||
@@ -2020,10 +2065,10 @@ end
|
||||
-- @param #FLIGHTGROUP self
|
||||
function FLIGHTGROUP:_CheckDetectedUnits()
|
||||
|
||||
if self.flightgroup and not self:IsDead() then
|
||||
if self.group and not self:IsDead() then
|
||||
|
||||
-- Get detected DCS units.
|
||||
local detectedtargets=self.flightgroup:GetDetectedTargets()
|
||||
local detectedtargets=self.group:GetDetectedTargets()
|
||||
|
||||
local detected={}
|
||||
for DetectionObjectID, Detection in pairs(detectedtargets or {}) do
|
||||
|
||||
@@ -961,9 +961,14 @@ function UTILS.FileExists(file)
|
||||
end
|
||||
|
||||
--- 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 clock=UTILS.SecondsToClock(time)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user