Refactoring Ops

This commit is contained in:
Frank
2020-05-14 22:50:27 +02:00
parent a7011e33fa
commit c2f6940c5e
5 changed files with 341 additions and 386 deletions
+2 -1
View File
@@ -74,7 +74,9 @@ __Moose.Include( 'Scripts/Moose/Ops/Airboss.lua' )
__Moose.Include( 'Scripts/Moose/Ops/RecoveryTanker.lua' ) __Moose.Include( 'Scripts/Moose/Ops/RecoveryTanker.lua' )
__Moose.Include( 'Scripts/Moose/Ops/RescueHelo.lua' ) __Moose.Include( 'Scripts/Moose/Ops/RescueHelo.lua' )
__Moose.Include( 'Scripts/Moose/Ops/ATIS.lua' ) __Moose.Include( 'Scripts/Moose/Ops/ATIS.lua' )
__Moose.Include( 'Scripts/Moose/Ops/OpsGroup.lua' )
__Moose.Include( 'Scripts/Moose/Ops/FlightGroup.lua' ) __Moose.Include( 'Scripts/Moose/Ops/FlightGroup.lua' )
__Moose.Include( 'Scripts/Moose/Ops/NavyGroup.lua' )
__Moose.Include( 'Scripts/Moose/Ops/FlightControl.lua' ) __Moose.Include( 'Scripts/Moose/Ops/FlightControl.lua' )
__Moose.Include( 'Scripts/Moose/Ops/Auftrag.lua' ) __Moose.Include( 'Scripts/Moose/Ops/Auftrag.lua' )
__Moose.Include( 'Scripts/Moose/Ops/Squadron.lua' ) __Moose.Include( 'Scripts/Moose/Ops/Squadron.lua' )
@@ -82,7 +84,6 @@ __Moose.Include( 'Scripts/Moose/Ops/AirWing.lua' )
__Moose.Include( 'Scripts/Moose/Ops/Intelligence.lua' ) __Moose.Include( 'Scripts/Moose/Ops/Intelligence.lua' )
__Moose.Include( 'Scripts/Moose/Ops/WingCommander.lua' ) __Moose.Include( 'Scripts/Moose/Ops/WingCommander.lua' )
__Moose.Include( 'Scripts/Moose/Ops/Skipper.lua' ) __Moose.Include( 'Scripts/Moose/Ops/Skipper.lua' )
__Moose.Include( 'Scripts/Moose/Ops/NavyGroup.lua' )
__Moose.Include( 'Scripts/Moose/AI/AI_Balancer.lua' ) __Moose.Include( 'Scripts/Moose/AI/AI_Balancer.lua' )
__Moose.Include( 'Scripts/Moose/AI/AI_Air.lua' ) __Moose.Include( 'Scripts/Moose/AI/AI_Air.lua' )
+24
View File
@@ -205,6 +205,7 @@ _AUFTRAGSNR=0
-- @field #string STRIKE Strike mission. -- @field #string STRIKE Strike mission.
-- @field #string TANKER Tanker mission. -- @field #string TANKER Tanker mission.
-- @field #string TROOPTRANSPORT Troop transport mission. -- @field #string TROOPTRANSPORT Troop transport mission.
-- @field #string ARTY Fire at point.
AUFTRAG.Type={ AUFTRAG.Type={
ANTISHIP="Anti Ship", ANTISHIP="Anti Ship",
AWACS="AWACS", AWACS="AWACS",
@@ -227,6 +228,7 @@ AUFTRAG.Type={
STRIKE="Strike", STRIKE="Strike",
TANKER="Tanker", TANKER="Tanker",
TROOPTRANSPORT="Troop Transport", TROOPTRANSPORT="Troop Transport",
ARTY="Fire At Point",
} }
--- Mission status. --- Mission status.
@@ -1033,6 +1035,18 @@ function AUFTRAG:NewTROOPTRANSPORT(TransportGroupSet, DropoffCoordinate, PickupC
return mission return mission
end end
--- Create an ARTY mission.
-- @param #AUFTRAG self
-- @param Core.Point#COORDINATE Coordinate Center of the firing solution.
-- @param #number Nshots Number of shots to be fired. Default 3.
-- @param #number Radius Radius of the shells in meters. Default 100 meters.
-- @return #AUFTRAG self
function AUFTRAG:NewARTY(Coordinate, Nshots, Radius)
local mission=AUFTRAG:New(AUFTRAG.Type.ARTY)
end
--- Create a mission to attack a group. Mission type is automatically chosen from the group category. --- Create a mission to attack a group. Mission type is automatically chosen from the group category.
-- @param #AUFTRAG self -- @param #AUFTRAG self
@@ -2954,6 +2968,16 @@ function AUFTRAG:GetDCSMissionTask(TaskControllable)
table.insert(DCStasks, DCStask) table.insert(DCStasks, DCStask)
elseif self.type==AUFTRAG.Type.RESCUEHELO then
------------------
-- ARTY Mission --
------------------
local DCStask=CONTROLLABLE.TaskFireAtPoint(nil, self:GetTargetVec2(),self.engageRadius, self.engageShots, self.engageWeaponType)
table.insert(DCStasks, DCStask)
else else
self:E(self.lid..string.format("ERROR: Unknown mission task!")) self:E(self.lid..string.format("ERROR: Unknown mission task!"))
return nil return nil
+4 -116
View File
@@ -673,18 +673,6 @@ function FLIGHTGROUP:IsFuelCritical()
return self.fuelcritical return self.fuelcritical
end end
--- Check if flight is alive.
-- @param #FLIGHTGROUP self
-- @return #boolean *true* if group is exists and is activated, *false* if group is exist but is NOT activated. *nil* otherwise, e.g. the GROUP object is *nil* or the group is not spawned yet.
function FLIGHTGROUP:IsAlive()
if self.group then
return self.group:IsAlive()
end
return nil
end
--- Check if flight can do air-to-ground tasks. --- Check if flight can do air-to-ground tasks.
-- @param #FLIGHTGROUP self -- @param #FLIGHTGROUP self
-- @param #boolean ExcludeGuns If true, exclude gun -- @param #boolean ExcludeGuns If true, exclude gun
@@ -851,7 +839,7 @@ function FLIGHTGROUP:onafterStart(From, Event, To)
-- Start the status monitoring. -- Start the status monitoring.
self:__CheckZone(-1) self:__CheckZone(-1)
self:__FlightStatus(-2) self:__Status(-2)
self:__QueueUpdate(-3) self:__QueueUpdate(-3)
end end
@@ -896,12 +884,12 @@ function FLIGHTGROUP:onafterStop(From, Event, To)
end end
--- On after "FlightStatus" event. --- On after "Status" event.
-- @param #FLIGHTGROUP self -- @param #FLIGHTGROUP self
-- @param #string From From state. -- @param #string From From state.
-- @param #string Event Event. -- @param #string Event Event.
-- @param #string To To state. -- @param #string To To state.
function FLIGHTGROUP:onafterFlightStatus(From, Event, To) function FLIGHTGROUP:onafterStatus(From, Event, To)
-- FSM state. -- FSM state.
local fsmstate=self:GetState() local fsmstate=self:GetState()
@@ -1149,23 +1137,7 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To)
-- Next check in ~30 seconds. -- Next check in ~30 seconds.
if not self:IsStopped() then if not self:IsStopped() then
self:__FlightStatus(-30) self:__Status(-30)
end
end
--- On after "CheckZone" event.
-- @param #FLIGHTGROUP self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function FLIGHTGROUP:onafterCheckZone(From, Event, To)
if self:IsAlive()==true then
self:_CheckInZones()
end
if not self:IsStopped() then
self:__CheckZone(-1)
end end
end end
@@ -1231,73 +1203,6 @@ function FLIGHTGROUP:onafterQueueUpdate(From, Event, To)
end end
end end
--- Get next task in queue. Task needs to be in state SCHEDULED and time must have passed.
-- @param #FLIGHTGROUP self
-- @return #FLIGHTGROUP.Task The next task in line or `nil`.
function FLIGHTGROUP:_GetNextTask()
if self.taskpaused then
--return self.taskpaused
end
if #self.taskqueue==0 then
return nil
end
-- Sort queue wrt prio and start time.
self:_SortTaskQueue()
-- Current time.
local time=timer.getAbsTime()
-- Look for first task that is SCHEDULED.
for _,_task in pairs(self.taskqueue) do
local task=_task --#FLIGHTGROUP.Task
if task.type==FLIGHTGROUP.TaskType.SCHEDULED and task.status==FLIGHTGROUP.TaskStatus.SCHEDULED and time>=task.time then
return task
end
end
return nil
end
--- Get next mission.
-- @param #FLIGHTGROUP self
-- @return Ops.Auftrag#AUFTRAG Next mission or *nil*.
function FLIGHTGROUP:_GetNextMission()
-- Number of missions.
local Nmissions=#self.missionqueue
-- Treat special cases.
if Nmissions==0 then
return nil
end
-- Sort results table wrt times they have already been engaged.
local function _sort(a, b)
local taskA=a --Ops.Auftrag#AUFTRAG
local taskB=b --Ops.Auftrag#AUFTRAG
return (taskA.prio<taskB.prio) or (taskA.prio==taskB.prio and taskA.Tstart<taskB.Tstart)
end
table.sort(self.missionqueue, _sort)
-- Current time.
local time=timer.getAbsTime()
-- Look for first mission that is SCHEDULED.
for _,_mission in pairs(self.missionqueue) do
local mission=_mission --Ops.Auftrag#AUFTRAG
if mission:GetFlightStatus(self)==AUFTRAG.Status.SCHEDULED and (mission:IsReadyToGo() or self.airwing) then
return mission
end
end
return nil
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Events -- Events
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -4827,23 +4732,6 @@ function FLIGHTGROUP:_GetPlayerUnitAndName(_unitName)
return nil,nil return nil,nil
end end
--- Returns the coalition side.
-- @param #FLIGHTGROUP self
-- @return #number Coalition side number.
function FLIGHTGROUP:GetCoalition()
return self.group:GetCoalition()
end
--- Returns the absolute (average) life points of the group.
-- @param #FLIGHTGROUP self
-- @return #number Life points. If group contains more than one element, the average is given.
-- @return #number Initial life points.
function FLIGHTGROUP:GetLifePoints()
if self.group then
return self.group:GetLife(), self.group:GetLife0()
end
end
--- Returns the parking spot of the element. --- Returns the parking spot of the element.
-- @param #FLIGHTGROUP self -- @param #FLIGHTGROUP self
-- @param #FLIGHTGROUP.Element element Element of the flight group. -- @param #FLIGHTGROUP.Element element Element of the flight group.
+10 -9
View File
@@ -2,7 +2,10 @@
-- --
-- **Main Features:** -- **Main Features:**
-- --
-- * Nice stuff. -- * Dynamically add and remove waypoints
-- * Let the group steam into the wind.
-- * Command a full stop.
-- * Let a submarine dive and surface.
-- --
-- === -- ===
-- --
@@ -23,7 +26,7 @@
-- --
-- # The NAVYGROUP Concept -- # The NAVYGROUP Concept
-- --
-- -- This class enhances naval groups.
-- --
-- @field #NAVYGROUP -- @field #NAVYGROUP
NAVYGROUP = { NAVYGROUP = {
@@ -61,7 +64,7 @@ function NAVYGROUP:New(GroupName)
local self=BASE:Inherit(self, OPSGROUP:New(GroupName)) -- #NAVYGROUP local self=BASE:Inherit(self, OPSGROUP:New(GroupName)) -- #NAVYGROUP
-- Set some string id for output to DCS.log file. -- Set some string id for output to DCS.log file.
self.lid=string.format("NAVYGROUP %s |", self.groupname) self.lid=string.format("NAVYGROUP %s | ", self.groupname)
-- Add FSM transitions. -- Add FSM transitions.
-- From State --> Event --> To State -- From State --> Event --> To State
@@ -202,6 +205,8 @@ function NAVYGROUP:onafterUpdateRoute(From, Event, To, n)
for i=n, #self.waypoints do for i=n, #self.waypoints do
local wp=self.waypoints[i] local wp=self.waypoints[i]
self:E({wp=wp})
-- Set speed. -- Set speed.
wp.speed=UTILS.KmphToMps(self.speedCruise) wp.speed=UTILS.KmphToMps(self.speedCruise)
@@ -402,15 +407,11 @@ function NAVYGROUP:_InitGroup()
self.actype=unit:GetTypeName() self.actype=unit:GetTypeName()
-- Init waypoints.
if not self.waypoints then
self:InitWaypoints()
end
-- Debug info. -- Debug info.
local text=string.format("Initialized Navy Group %s:\n", self.groupname) local text=string.format("Initialized Navy Group %s:\n", self.groupname)
text=text..string.format("AC type = %s\n", self.actype) text=text..string.format("AC type = %s\n", self.actype)
text=text..string.format("Speed max = %.1f Knots\n", UTILS.KmphToKnots(self.speedmax)) text=text..string.format("Speed max = %.1f Knots\n", UTILS.KmphToKnots(self.speedmax))
text=text..string.format("Speed cruise = %.1f Knots\n", UTILS.KmphToKnots(self.speedCruise))
text=text..string.format("Elements = %d\n", #self.elements) text=text..string.format("Elements = %d\n", #self.elements)
text=text..string.format("Waypoints = %d\n", #self.waypoints) text=text..string.format("Waypoints = %d\n", #self.waypoints)
text=text..string.format("Radio = %.1f MHz %s %s\n", self.radioFreq, UTILS.GetModulationName(self.radioModu), tostring(self.radioOn)) text=text..string.format("Radio = %.1f MHz %s %s\n", self.radioFreq, UTILS.GetModulationName(self.radioModu), tostring(self.radioOn))
@@ -441,7 +442,7 @@ function NAVYGROUP:InitWaypoints(waypoints)
self.waypoints=waypoints or UTILS.DeepCopy(self.waypoints0) self.waypoints=waypoints or UTILS.DeepCopy(self.waypoints0)
-- Debug info. -- Debug info.
self:T(self.lid..string.format("Initializing %d waypoints", #self.waypoints)) self:I(self.lid..string.format("Initializing %d waypoints", #self.waypoints))
-- Update route. -- Update route.
if #self.waypoints>0 then if #self.waypoints>0 then
+298 -257
View File
@@ -1,4 +1,4 @@
--- **Ops** - Generic group functions. --- **Ops** - Generic group enhancement functions.
-- --
-- --
-- === -- ===
@@ -67,7 +67,7 @@ OPSGROUP = {
template = nil, template = nil,
waypoints = nil, waypoints = nil,
waypoints0 = nil, waypoints0 = nil,
currentwp = -100, currentwp = 1,
elements = {}, elements = {},
taskqueue = {}, taskqueue = {},
taskcounter = nil, taskcounter = nil,
@@ -84,12 +84,12 @@ OPSGROUP = {
} }
--- Flight group task status. --- Flight group task status.
-- @type FLIGHTGROUP.TaskStatus -- @type OPSGROUP.TaskStatus
-- @field #string SCHEDULED Task is scheduled. -- @field #string SCHEDULED Task is scheduled.
-- @field #string EXECUTING Task is being executed. -- @field #string EXECUTING Task is being executed.
-- @field #string PAUSED Task is paused. -- @field #string PAUSED Task is paused.
-- @field #string DONE Task is done. -- @field #string DONE Task is done.
FLIGHTGROUP.TaskStatus={ OPSGROUP.TaskStatus={
SCHEDULED="scheduled", SCHEDULED="scheduled",
EXECUTING="executing", EXECUTING="executing",
PAUSED="paused", PAUSED="paused",
@@ -97,16 +97,16 @@ FLIGHTGROUP.TaskStatus={
} }
--- Flight group task status. --- Flight group task status.
-- @type FLIGHTGROUP.TaskType -- @type OPSGROUP.TaskType
-- @field #string SCHEDULED Task is scheduled and will be executed at a given time. -- @field #string SCHEDULED Task is scheduled and will be executed at a given time.
-- @field #string WAYPOINT Task is executed at a specific waypoint. -- @field #string WAYPOINT Task is executed at a specific waypoint.
FLIGHTGROUP.TaskType={ OPSGROUP.TaskType={
SCHEDULED="scheduled", SCHEDULED="scheduled",
WAYPOINT="waypoint", WAYPOINT="waypoint",
} }
--- Flight group task structure. --- Flight group task structure.
-- @type FLIGHTGROUP.Task -- @type OPSGROUP.Task
-- @field #string type Type of task: either SCHEDULED or WAYPOINT. -- @field #string type Type of task: either SCHEDULED or WAYPOINT.
-- @field #number id Task ID. Running number to get the task. -- @field #number id Task ID. Running number to get the task.
-- @field #number prio Priority. -- @field #number prio Priority.
@@ -120,7 +120,7 @@ FLIGHTGROUP.TaskType={
-- @field Core.UserFlag#USERFLAG stopflag If flag is set to 1 (=true), the task is stopped. -- @field Core.UserFlag#USERFLAG stopflag If flag is set to 1 (=true), the task is stopped.
--- Enroute task. --- Enroute task.
-- @type FLIGHTGROUP.EnrouteTask -- @type OPSGROUP.EnrouteTask
-- @field DCS#Task DCStask DCS task structure table. -- @field DCS#Task DCStask DCS task structure table.
-- @field #number WaypointIndex Waypoint number at which the enroute task is added. -- @field #number WaypointIndex Waypoint number at which the enroute task is added.
@@ -141,18 +141,21 @@ OPSGROUP.version="0.0.1"
--- Create a new OPSGROUP class object. --- Create a new OPSGROUP class object.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @param #string GroupName Name of the group. -- @param Wrapper.Group#GROUP Group The group object. Can also be given by its group name as #string.
-- @return #OPSGROUP self -- @return #OPSGROUP self
function OPSGROUP:New(GroupName) function OPSGROUP:New(Group)
-- Inherit everything from FSM class. -- Inherit everything from FSM class.
local self=BASE:Inherit(self, FSM:New()) -- #OPSGROUP local self=BASE:Inherit(self, FSM:New()) -- #OPSGROUP
-- Name of the group. -- Get group and group name.
self.groupname=GroupName if type(Group)=="string" then
self.groupname=Group
-- Set group object. self.group=GROUP:FindByName(self.groupname)
self.group=GROUP:FindByName(self.groupname) else
self.group=Group
self.groupname=Group:GetName()
end
-- Set some string id for output to DCS.log file. -- Set some string id for output to DCS.log file.
self.lid=string.format("OPSGROUP %s |", self.groupname) self.lid=string.format("OPSGROUP %s |", self.groupname)
@@ -250,6 +253,8 @@ function OPSGROUP:New(GroupName)
BASE:TraceLevel(1) BASE:TraceLevel(1)
end end
self:InitWaypoints()
return self return self
end end
@@ -271,29 +276,39 @@ function OPSGROUP:GetCoordinate()
return self.group:GetCoordinate() return self.group:GetCoordinate()
end end
--- Returns the absolute (average) life points of the group.
-- @param #OPSGROUP self
-- @return #number Life points. If group contains more than one element, the average is given.
-- @return #number Initial life points.
function OPSGROUP:GetLifePoints()
if self.group then
return self.group:GetLife(), self.group:GetLife0()
end
end
--- Set detection on or off. --- Set detection on or off.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param #boolean Switch If true, detection is on. If false or nil, detection is off. Default is off. -- @param #boolean Switch If true, detection is on. If false or nil, detection is off. Default is off.
-- @return #FLIGHTGROUP self -- @return #OPSGROUP self
function FLIGHTGROUP:SetDetection(Switch) function OPSGROUP:SetDetection(Switch)
self.detectionOn=Switch self.detectionOn=Switch
return self return self
end end
--- Define a SET of zones that trigger and event if the group enters or leaves any of the zones. --- Define a SET of zones that trigger and event if the group enters or leaves any of the zones.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param Core.Set#SET_ZONE CheckZonesSet Set of zones. -- @param Core.Set#SET_ZONE CheckZonesSet Set of zones.
-- @return #FLIGHTGROUP self -- @return #OPSGROUP self
function FLIGHTGROUP:SetCheckZones(CheckZonesSet) function OPSGROUP:SetCheckZones(CheckZonesSet)
self.checkzones=CheckZonesSet self.checkzones=CheckZonesSet
return self return self
end end
--- Add a zone that triggers and event if the group enters or leaves any of the zones. --- Add a zone that triggers and event if the group enters or leaves any of the zones.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param Core.Zone#ZONE CheckZone Zone to check. -- @param Core.Zone#ZONE CheckZone Zone to check.
-- @return #FLIGHTGROUP self -- @return #OPSGROUP self
function FLIGHTGROUP:AddCheckZone(CheckZone) function OPSGROUP:AddCheckZone(CheckZone)
if not self.checkzones then if not self.checkzones then
self.checkzones=SET_ZONE:New() self.checkzones=SET_ZONE:New()
end end
@@ -302,30 +317,30 @@ function FLIGHTGROUP:AddCheckZone(CheckZone)
end end
--- Get set of detected units. --- Get set of detected units.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @return Core.Set#SET_UNIT Set of detected units. -- @return Core.Set#SET_UNIT Set of detected units.
function FLIGHTGROUP:GetDetectedUnits() function OPSGROUP:GetDetectedUnits()
return self.detectedunits return self.detectedunits
end end
--- Get MOOSE group object. --- Get MOOSE GROUP object.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @return Wrapper.Group#GROUP Moose group object. -- @return Wrapper.Group#GROUP Moose group object.
function FLIGHTGROUP:GetGroup() function OPSGROUP:GetGroup()
return self.group return self.group
end end
--- Get flight group name. --- Get the group name.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @return #string Group name. -- @return #string Group name.
function FLIGHTGROUP:GetName() function OPSGROUP:GetName()
return self.groupname return self.groupname
end end
--- Get current coordinate of the group. --- Get current coordinate of the group.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @return Core.Point#COORDINATE The coordinate (of the first unit) of the group. -- @return Core.Point#COORDINATE The coordinate (of the first unit) of the group.
function FLIGHTGROUP:GetCoordinate() function OPSGROUP:GetCoordinate()
if self:IsAlive()~=nil then if self:IsAlive()~=nil then
return self.group:GetCoordinate() return self.group:GetCoordinate()
else else
@@ -335,44 +350,44 @@ function FLIGHTGROUP:GetCoordinate()
end end
--- Get waypoint. --- Get waypoint.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param #number indx Waypoint index. -- @param #number indx Waypoint index.
-- @return #table Waypoint table. -- @return #table Waypoint table.
function FLIGHTGROUP:GetWaypoint(indx) function OPSGROUP:GetWaypoint(indx)
return self.waypoints[indx] return self.waypoints[indx]
end end
--- Get final waypoint. --- Get final waypoint.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @return #table Waypoint table. -- @return #table Waypoint table.
function FLIGHTGROUP:GetWaypointFinal() function OPSGROUP:GetWaypointFinal()
return self.waypoints[#self.waypoints] return self.waypoints[#self.waypoints]
end end
--- Get next waypoint. --- Get next waypoint.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @return #table Waypoint table. -- @return #table Waypoint table.
function FLIGHTGROUP:GetWaypointNext() function OPSGROUP:GetWaypointNext()
local n=math.min(self.currentwp+1, #self.waypoints) local n=math.min(self.currentwp+1, #self.waypoints)
return self.waypoints[n] return self.waypoints[n]
end end
--- Get current waypoint. --- Get current waypoint.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @return #table Waypoint table. -- @return #table Waypoint table.
function FLIGHTGROUP:GetWaypointCurrent() function OPSGROUP:GetWaypointCurrent()
return self.waypoints[self.currentwp] return self.waypoints[self.currentwp]
end end
--- Activate a *late activated* group. --- Activate a *late activated* group.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param #number delay (Optional) Delay in seconds before the group is activated. Default is immediately. -- @param #number delay (Optional) Delay in seconds before the group is activated. Default is immediately.
-- @return #FLIGHTGROUP self -- @return #OPSGROUP self
function FLIGHTGROUP:Activate(delay) function OPSGROUP:Activate(delay)
if delay and delay>0 then if delay and delay>0 then
self:T2(self.lid..string.format("Activating late activated group in %d seconds", delay)) self:T2(self.lid..string.format("Activating late activated group in %d seconds", delay))
self:ScheduleOnce(delay, FLIGHTGROUP.Activate, self) self:ScheduleOnce(delay, OPSGROUP.Activate, self)
else else
if self:IsAlive()==false then if self:IsAlive()==false then
@@ -393,19 +408,19 @@ function FLIGHTGROUP:Activate(delay)
end end
--- Self destruction of group. An explosion is created at the position of each element. --- Self destruction of group. An explosion is created at the position of each element.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param #number Delay Delay in seconds. Default now. -- @param #number Delay Delay in seconds. Default now.
-- @param #number ExplosionPower (Optional) Explosion power in kg TNT. Default 500 kg. -- @param #number ExplosionPower (Optional) Explosion power in kg TNT. Default 500 kg.
-- @return #number Relative fuel in percent. -- @return #number Relative fuel in percent.
function FLIGHTGROUP:SelfDestruction(Delay, ExplosionPower) function OPSGROUP:SelfDestruction(Delay, ExplosionPower)
if Delay and Delay>0 then if Delay and Delay>0 then
self:ScheduleOnce(Delay, FLIGHTGROUP.SelfDestruction, self, 0, ExplosionPower) self:ScheduleOnce(Delay, OPSGROUP.SelfDestruction, self, 0, ExplosionPower)
else else
-- Loop over all elements. -- Loop over all elements.
for i,_element in pairs(self.elements) do for i,_element in pairs(self.elements) do
local element=_element --#FLIGHTGROUP.Element local element=_element --#OPSGROUP.Element
local unit=element.unit local unit=element.unit
@@ -417,36 +432,16 @@ function FLIGHTGROUP:SelfDestruction(Delay, ExplosionPower)
end end
--- Route group along waypoints. --- Check if flight is alive.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param #table waypoints Table of waypoints. -- @return #boolean *true* if group is exists and is activated, *false* if group is exist but is NOT activated. *nil* otherwise, e.g. the GROUP object is *nil* or the group is not spawned yet.
-- @return #FLIGHTGROUP self function OPSGROUP:IsAlive()
function FLIGHTGROUP:Route(waypoints)
if self:IsAlive() then if self.group then
return self.group:IsAlive()
-- DCS task combo.
local Tasks={}
-- Route (Mission) task.
local TaskRoute=self.group:TaskRoute(waypoints)
table.insert(Tasks, TaskRoute)
-- TaskCombo of enroute and mission tasks.
local TaskCombo=self.group:TaskCombo(Tasks)
-- Set tasks.
if #Tasks>1 then
self:SetTask(TaskCombo)
else
self:SetTask(TaskRoute)
end
else
self:E(self.lid.."ERROR: Group is not alive!")
end end
return self return nil
end end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -454,10 +449,10 @@ end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Remove a waypoint. --- Remove a waypoint.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param #number wpindex Waypoint number. -- @param #number wpindex Waypoint number.
-- @return #FLIGHTGROUP self -- @return #OPSGROUP self
function FLIGHTGROUP:RemoveWaypoint(wpindex) function OPSGROUP:RemoveWaypoint(wpindex)
if self.waypoints then if self.waypoints then
@@ -474,8 +469,8 @@ function FLIGHTGROUP:RemoveWaypoint(wpindex)
-- Shift all waypoint tasks after the removed waypoint. -- Shift all waypoint tasks after the removed waypoint.
for _,_task in pairs(self.taskqueue) do for _,_task in pairs(self.taskqueue) do
local task=_task --#FLIGHTGROUP.Task local task=_task --#OPSGROUP.Task
if task.type==FLIGHTGROUP.TaskType.WAYPOINT and task.waypoint and task.waypoint>wpindex then if task.type==OPSGROUP.TaskType.WAYPOINT and task.waypoint and task.waypoint>wpindex then
task.waypoint=task.waypoint-1 task.waypoint=task.waypoint-1
end end
end end
@@ -525,10 +520,10 @@ end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Set DCS task. Enroute tasks are injected automatically. --- Set DCS task. Enroute tasks are injected automatically.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param #table DCSTask DCS task structure. -- @param #table DCSTask DCS task structure.
-- @return #FLIGHTGROUP self -- @return #OPSGROUP self
function FLIGHTGROUP:SetTask(DCSTask) function OPSGROUP:SetTask(DCSTask)
if self:IsAlive() then if self:IsAlive() then
@@ -572,10 +567,10 @@ function FLIGHTGROUP:SetTask(DCSTask)
end end
--- Push DCS task. --- Push DCS task.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param #table DCSTask DCS task structure. -- @param #table DCSTask DCS task structure.
-- @return #FLIGHTGROUP self -- @return #OPSGROUP self
function FLIGHTGROUP:PushTask(DCSTask) function OPSGROUP:PushTask(DCSTask)
if self:IsAlive() then if self:IsAlive() then
@@ -596,10 +591,10 @@ function FLIGHTGROUP:PushTask(DCSTask)
end end
--- Clear DCS tasks. --- Clear DCS tasks.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param #table DCSTask DCS task structure. -- @param #table DCSTask DCS task structure.
-- @return #FLIGHTGROUP self -- @return #OPSGROUP self
function FLIGHTGROUP:ClearTasks() function OPSGROUP:ClearTasks()
if self:IsAlive() then if self:IsAlive() then
self.group:ClearTasks() self.group:ClearTasks()
self:I(self.lid..string.format("CLEARING Tasks")) self:I(self.lid..string.format("CLEARING Tasks"))
@@ -670,29 +665,29 @@ function OPSGROUP:NewTaskScheduled(task, clock, description, prio, duration)
end end
--- Add a *waypoint* task. --- Add a *waypoint* task.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param #table task DCS task table structure. -- @param #table task DCS task table structure.
-- @param #number waypointindex Number of waypoint. Counting starts at one! Default is the as *next* waypoint. -- @param #number waypointindex Number of waypoint. Counting starts at one! Default is the as *next* waypoint.
-- @param #string description Brief text describing the task, e.g. "Attack SAM". -- @param #string description Brief text describing the task, e.g. "Attack SAM".
-- @param #number prio Priority of the task. Number between 1 and 100. Default is 50. -- @param #number prio Priority of the task. Number between 1 and 100. Default is 50.
-- @param #number duration Duration before task is cancelled in seconds counted after task started. Default never. -- @param #number duration Duration before task is cancelled in seconds counted after task started. Default never.
-- @return #FLIGHTGROUP.Task The task structure. -- @return #OPSGROUP.Task The task structure.
function FLIGHTGROUP:AddTaskWaypoint(task, waypointindex, description, prio, duration) function OPSGROUP:AddTaskWaypoint(task, waypointindex, description, prio, duration)
-- Increase counter. -- Increase counter.
self.taskcounter=self.taskcounter+1 self.taskcounter=self.taskcounter+1
-- Task data structure. -- Task data structure.
local newtask={} --#FLIGHTGROUP.Task local newtask={} --#OPSGROUP.Task
newtask.description=description newtask.description=description
newtask.status=FLIGHTGROUP.TaskStatus.SCHEDULED newtask.status=OPSGROUP.TaskStatus.SCHEDULED
newtask.dcstask=task newtask.dcstask=task
newtask.prio=prio or 50 newtask.prio=prio or 50
newtask.id=self.taskcounter newtask.id=self.taskcounter
newtask.duration=duration newtask.duration=duration
newtask.time=0 newtask.time=0
newtask.waypoint=waypointindex or (self.currentwp and self.currentwp+1 or 2) newtask.waypoint=waypointindex or (self.currentwp and self.currentwp+1 or 2)
newtask.type=FLIGHTGROUP.TaskType.WAYPOINT newtask.type=OPSGROUP.TaskType.WAYPOINT
newtask.stopflag=USERFLAG:New(string.format("%s StopTaskFlag %d", self.groupname, newtask.id)) newtask.stopflag=USERFLAG:New(string.format("%s StopTaskFlag %d", self.groupname, newtask.id))
newtask.stopflag:Set(0) newtask.stopflag:Set(0)
@@ -711,9 +706,9 @@ function FLIGHTGROUP:AddTaskWaypoint(task, waypointindex, description, prio, dur
end end
--- Add an *enroute* task. --- Add an *enroute* task.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param #table task DCS task table structure. -- @param #table task DCS task table structure.
function FLIGHTGROUP:AddTaskEnroute(task) function OPSGROUP:AddTaskEnroute(task)
if not self.taskenroute then if not self.taskenroute then
self.taskenroute={} self.taskenroute={}
@@ -735,10 +730,10 @@ function FLIGHTGROUP:AddTaskEnroute(task)
end end
--- Get the unfinished waypoint tasks --- Get the unfinished waypoint tasks
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param #number n Waypoint index. Counting starts at one. -- @param #number n Waypoint index. Counting starts at one.
-- @return #table Table of tasks. Table could also be empty {}. -- @return #table Table of tasks. Table could also be empty {}.
function FLIGHTGROUP:GetTasksWaypoint(n) function OPSGROUP:GetTasksWaypoint(n)
-- Tasks table. -- Tasks table.
local tasks={} local tasks={}
@@ -748,8 +743,8 @@ function FLIGHTGROUP:GetTasksWaypoint(n)
-- Look for first task that SCHEDULED. -- Look for first task that SCHEDULED.
for _,_task in pairs(self.taskqueue) do for _,_task in pairs(self.taskqueue) do
local task=_task --#FLIGHTGROUP.Task local task=_task --#OPSGROUP.Task
if task.type==FLIGHTGROUP.TaskType.WAYPOINT and task.status==FLIGHTGROUP.TaskStatus.SCHEDULED and task.waypoint==n then if task.type==OPSGROUP.TaskType.WAYPOINT and task.status==OPSGROUP.TaskStatus.SCHEDULED and task.waypoint==n then
table.insert(tasks, task) table.insert(tasks, task)
end end
end end
@@ -758,13 +753,13 @@ function FLIGHTGROUP:GetTasksWaypoint(n)
end end
--- Sort task queue. --- Sort task queue.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
function FLIGHTGROUP:_SortTaskQueue() function OPSGROUP:_SortTaskQueue()
-- Sort results table wrt prio and then start time. -- Sort results table wrt prio and then start time.
local function _sort(a, b) local function _sort(a, b)
local taskA=a --#FLIGHTGROUP.Task local taskA=a --#OPSGROUP.Task
local taskB=b --#FLIGHTGROUP.Task local taskB=b --#OPSGROUP.Task
return (taskA.prio<taskB.prio) or (taskA.prio==taskB.prio and taskA.time<taskB.time) return (taskA.prio<taskB.prio) or (taskA.prio==taskB.prio and taskA.time<taskB.time)
end end
@@ -775,11 +770,11 @@ end
--- Count the number of tasks that still pending in the queue. --- Count the number of tasks that still pending in the queue.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @return #number Total number of tasks remaining. -- @return #number Total number of tasks remaining.
-- @return #number Number of SCHEDULED tasks remaining. -- @return #number Number of SCHEDULED tasks remaining.
-- @return #number Number of WAYPOINT tasks remaining. -- @return #number Number of WAYPOINT tasks remaining.
function FLIGHTGROUP:CountRemainingTasks() function OPSGROUP:CountRemainingTasks()
local Ntot=0 local Ntot=0
local Nwp=0 local Nwp=0
@@ -787,18 +782,18 @@ function FLIGHTGROUP:CountRemainingTasks()
-- Loop over tasks queue. -- Loop over tasks queue.
for _,_task in pairs(self.taskqueue) do for _,_task in pairs(self.taskqueue) do
local task=_task --#FLIGHTGROUP.Task local task=_task --#OPSGROUP.Task
-- Task is still scheduled. -- Task is still scheduled.
if task.status==FLIGHTGROUP.TaskStatus.SCHEDULED then if task.status==OPSGROUP.TaskStatus.SCHEDULED then
-- Total number of tasks. -- Total number of tasks.
Ntot=Ntot+1 Ntot=Ntot+1
if task.type==FLIGHTGROUP.TaskType.WAYPOINT then if task.type==OPSGROUP.TaskType.WAYPOINT then
--TODO: maybe check that waypoint was not already passed? --TODO: maybe check that waypoint was not already passed?
Nwp=Nwp+1 Nwp=Nwp+1
elseif task.type==FLIGHTGROUP.TaskType.SCHEDULED then elseif task.type==OPSGROUP.TaskType.SCHEDULED then
Nsched=Nsched+1 Nsched=Nsched+1
end end
@@ -810,13 +805,13 @@ function FLIGHTGROUP:CountRemainingTasks()
end end
--- Remove task from task queue. --- Remove task from task queue.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param #FLIGHTGROUP.Task Task The task to be removed from the queue. -- @param #OPSGROUP.Task Task The task to be removed from the queue.
-- @return #boolean True if task could be removed. -- @return #boolean True if task could be removed.
function FLIGHTGROUP:RemoveTask(Task) function OPSGROUP:RemoveTask(Task)
for i=#self.taskqueue,1,-1 do for i=#self.taskqueue,1,-1 do
local task=self.taskqueue[i] --#FLIGHTGROUP.Task local task=self.taskqueue[i] --#OPSGROUP.Task
if task.id==Task.id then if task.id==Task.id then
@@ -824,7 +819,7 @@ function FLIGHTGROUP:RemoveTask(Task)
table.remove(self.taskqueue, i) table.remove(self.taskqueue, i)
-- Update route if this is a waypoint task. -- Update route if this is a waypoint task.
if task.type==FLIGHTGROUP.TaskType.WAYPOINT and task.status==FLIGHTGROUP.TaskStatus.SCHEDULED then if task.type==OPSGROUP.TaskType.WAYPOINT and task.status==OPSGROUP.TaskStatus.SCHEDULED then
self:_CheckFlightDone(1) self:_CheckFlightDone(1)
--self:__UpdateRoute(-1) --self:__UpdateRoute(-1)
end end
@@ -836,22 +831,52 @@ function FLIGHTGROUP:RemoveTask(Task)
return false return false
end end
--- Get next task in queue. Task needs to be in state SCHEDULED and time must have passed.
-- @param #OPSGROUP self
-- @return #OPSGROUP.Task The next task in line or `nil`.
function OPSGROUP:_GetNextTask()
if self.taskpaused then
--return self.taskpaused
end
if #self.taskqueue==0 then
return nil
end
-- Sort queue wrt prio and start time.
self:_SortTaskQueue()
-- Current time.
local time=timer.getAbsTime()
-- Look for first task that is SCHEDULED.
for _,_task in pairs(self.taskqueue) do
local task=_task --#OPSGROUP.Task
if task.type==OPSGROUP.TaskType.SCHEDULED and task.status==OPSGROUP.TaskStatus.SCHEDULED and time>=task.time then
return task
end
end
return nil
end
--- Get the currently executed task if there is any. --- Get the currently executed task if there is any.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @return #FLIGHTGROUP.Task Current task or nil. -- @return #OPSGROUP.Task Current task or nil.
function FLIGHTGROUP:GetTaskCurrent() function OPSGROUP:GetTaskCurrent()
return self:GetTaskByID(self.taskcurrent, FLIGHTGROUP.TaskStatus.EXECUTING) return self:GetTaskByID(self.taskcurrent, OPSGROUP.TaskStatus.EXECUTING)
end end
--- Get task by its id. --- Get task by its id.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param #number id Task id. -- @param #number id Task id.
-- @param #string status (Optional) Only return tasks with this status, e.g. FLIGHTGROUP.TaskStatus.SCHEDULED. -- @param #string status (Optional) Only return tasks with this status, e.g. OPSGROUP.TaskStatus.SCHEDULED.
-- @return #FLIGHTGROUP.Task The task or nil. -- @return #OPSGROUP.Task The task or nil.
function FLIGHTGROUP:GetTaskByID(id, status) function OPSGROUP:GetTaskByID(id, status)
for _,_task in pairs(self.taskqueue) do for _,_task in pairs(self.taskqueue) do
local task=_task --#FLIGHTGROUP.Task local task=_task --#OPSGROUP.Task
if task.id==id then if task.id==id then
if status==nil or status==task.status then if status==nil or status==task.status then
@@ -864,66 +889,15 @@ function FLIGHTGROUP:GetTaskByID(id, status)
return nil return nil
end end
--- Get mission by its id (auftragsnummer).
-- @param #FLIGHTGROUP self
-- @param #number id Mission id (auftragsnummer).
-- @return Ops.Auftrag#AUFTRAG The mission.
function FLIGHTGROUP:GetMissionByID(id)
if not id then
return nil
end
for _,_mission in pairs(self.missionqueue) do
local mission=_mission --Ops.Auftrag#AUFTRAG
if mission.auftragsnummer==id then
return mission
end
end
return nil
end
--- Get mission by its task id.
-- @param #FLIGHTGROUP self
-- @param #number taskid The id of the (waypoint) task of the mission.
-- @return Ops.Auftrag#AUFTRAG The mission.
function FLIGHTGROUP:GetMissionByTaskID(taskid)
if taskid then
for _,_mission in pairs(self.missionqueue) do
local mission=_mission --Ops.Auftrag#AUFTRAG
local task=mission:GetFlightWaypointTask(self)
if task and task.id and task.id==taskid then
return mission
end
end
end
return nil
end
--- Get current mission.
-- @param #FLIGHTGROUP self
-- @return Ops.Auftrag#AUFTRAG The current mission or *nil*.
function FLIGHTGROUP:GetMissionCurrent()
return self:GetMissionByID(self.currentmission)
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Mission Functions -- Mission Functions
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Add mission to queue. --- Add mission to queue.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param Ops.Auftrag#AUFTRAG Mission Mission for this group. -- @param Ops.Auftrag#AUFTRAG Mission Mission for this group.
-- @return #FLIGHTGROUP self -- @return #OPSGROUP self
function FLIGHTGROUP:AddMission(Mission) function OPSGROUP:AddMission(Mission)
-- Add flight group to mission. -- Add flight group to mission.
Mission:AddFlightGroup(self) Mission:AddFlightGroup(self)
@@ -946,10 +920,10 @@ function FLIGHTGROUP:AddMission(Mission)
end end
--- Remove mission from queue. --- Remove mission from queue.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param Ops.Auftrag#AUFTRAG Mission Mission to be removed. -- @param Ops.Auftrag#AUFTRAG Mission Mission to be removed.
-- @return #FLIGHTGROUP self -- @return #OPSGROUP self
function FLIGHTGROUP:RemoveMission(Mission) function OPSGROUP:RemoveMission(Mission)
for i,_mission in pairs(self.missionqueue) do for i,_mission in pairs(self.missionqueue) do
local mission=_mission --Ops.Auftrag#AUFTRAG local mission=_mission --Ops.Auftrag#AUFTRAG
@@ -975,9 +949,9 @@ function FLIGHTGROUP:RemoveMission(Mission)
end end
--- Count remaining missons. --- Count remaining missons.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @return #number Number of missions to be done. -- @return #number Number of missions to be done.
function FLIGHTGROUP:CountRemainingMissison() function OPSGROUP:CountRemainingMissison()
local N=0 local N=0
@@ -1000,6 +974,93 @@ function FLIGHTGROUP:CountRemainingMissison()
return N return N
end end
--- Get next mission.
-- @param #OPSGROUP self
-- @return Ops.Auftrag#AUFTRAG Next mission or *nil*.
function OPSGROUP:_GetNextMission()
-- Number of missions.
local Nmissions=#self.missionqueue
-- Treat special cases.
if Nmissions==0 then
return nil
end
-- Sort results table wrt times they have already been engaged.
local function _sort(a, b)
local taskA=a --Ops.Auftrag#AUFTRAG
local taskB=b --Ops.Auftrag#AUFTRAG
return (taskA.prio<taskB.prio) or (taskA.prio==taskB.prio and taskA.Tstart<taskB.Tstart)
end
table.sort(self.missionqueue, _sort)
-- Current time.
local time=timer.getAbsTime()
-- Look for first mission that is SCHEDULED.
for _,_mission in pairs(self.missionqueue) do
local mission=_mission --Ops.Auftrag#AUFTRAG
if mission:GetFlightStatus(self)==AUFTRAG.Status.SCHEDULED and (mission:IsReadyToGo() or self.airwing) then
return mission
end
end
return nil
end
--- Get mission by its id (auftragsnummer).
-- @param #OPSGROUP self
-- @param #number id Mission id (auftragsnummer).
-- @return Ops.Auftrag#AUFTRAG The mission.
function OPSGROUP:GetMissionByID(id)
if not id then
return nil
end
for _,_mission in pairs(self.missionqueue) do
local mission=_mission --Ops.Auftrag#AUFTRAG
if mission.auftragsnummer==id then
return mission
end
end
return nil
end
--- Get mission by its task id.
-- @param #OPSGROUP self
-- @param #number taskid The id of the (waypoint) task of the mission.
-- @return Ops.Auftrag#AUFTRAG The mission.
function OPSGROUP:GetMissionByTaskID(taskid)
if taskid then
for _,_mission in pairs(self.missionqueue) do
local mission=_mission --Ops.Auftrag#AUFTRAG
local task=mission:GetFlightWaypointTask(self)
if task and task.id and task.id==taskid then
return mission
end
end
end
return nil
end
--- Get current mission.
-- @param #OPSGROUP self
-- @return Ops.Auftrag#AUFTRAG The current mission or *nil*.
function OPSGROUP:GetMissionCurrent()
return self:GetMissionByID(self.currentmission)
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- FSM Events -- FSM Events
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -1016,90 +1077,98 @@ function OPSGROUP:onafterPassingWaypoint(From, Event, To, n, N)
end end
--- On after "DetectedUnit" event. Add newly detected unit to detected units set. --- On after "DetectedUnit" event. Add newly detected unit to detected units set.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param #string From From state. -- @param #string From From state.
-- @param #string Event Event. -- @param #string Event Event.
-- @param #string To To state. -- @param #string To To state.
-- @param Wrapper.Unit#UNIT Unit The detected unit. -- @param Wrapper.Unit#UNIT Unit The detected unit.
function FLIGHTGROUP:onafterDetectedUnit(From, Event, To, Unit) function OPSGROUP:onafterDetectedUnit(From, Event, To, Unit)
self:T2(self.lid..string.format("Detected unit %s", Unit:GetName())) self:T2(self.lid..string.format("Detected unit %s", Unit:GetName()))
self.detectedunits:AddUnit(Unit) self.detectedunits:AddUnit(Unit)
end end
--- On after "DetectedUnitNew" event. --- On after "DetectedUnitNew" event.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param #string From From state. -- @param #string From From state.
-- @param #string Event Event. -- @param #string Event Event.
-- @param #string To To state. -- @param #string To To state.
-- @param Wrapper.Unit#UNIT Unit The detected unit. -- @param Wrapper.Unit#UNIT Unit The detected unit.
function FLIGHTGROUP:onafterDetectedUnitNew(From, Event, To, Unit) function OPSGROUP:onafterDetectedUnitNew(From, Event, To, Unit)
self:T(self.lid..string.format("Detected New unit %s", Unit:GetName())) self:T(self.lid..string.format("Detected New unit %s", Unit:GetName()))
end end
--- On after "EnterZone" event. Sets self.inzones[zonename]=true. --- On after "EnterZone" event. Sets self.inzones[zonename]=true.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param #string From From state. -- @param #string From From state.
-- @param #string Event Event. -- @param #string Event Event.
-- @param #string To To state. -- @param #string To To state.
-- @param Core.Zone#ZONE Zone The zone that the group entered. -- @param Core.Zone#ZONE Zone The zone that the group entered.
function FLIGHTGROUP:onafterEnterZone(From, Event, To, Zone) function OPSGROUP:onafterEnterZone(From, Event, To, Zone)
local zonename=Zone and Zone:GetName() or "unknown" local zonename=Zone and Zone:GetName() or "unknown"
self:T2(self.lid..string.format("Entered Zone %s", zonename)) self:T2(self.lid..string.format("Entered Zone %s", zonename))
self.inzones:Add(Zone:GetName(), Zone) self.inzones:Add(Zone:GetName(), Zone)
end end
--- On after "LeaveZone" event. Sets self.inzones[zonename]=false. --- On after "LeaveZone" event. Sets self.inzones[zonename]=false.
-- @param #FLIGHTGROUP self -- @param #OPSGROUP self
-- @param #string From From state. -- @param #string From From state.
-- @param #string Event Event. -- @param #string Event Event.
-- @param #string To To state. -- @param #string To To state.
-- @param Core.Zone#ZONE Zone The zone that the group entered. -- @param Core.Zone#ZONE Zone The zone that the group entered.
function FLIGHTGROUP:onafterLeaveZone(From, Event, To, Zone) function OPSGROUP:onafterLeaveZone(From, Event, To, Zone)
local zonename=Zone and Zone:GetName() or "unknown" local zonename=Zone and Zone:GetName() or "unknown"
self:T2(self.lid..string.format("Left Zone %s", zonename)) self:T2(self.lid..string.format("Left Zone %s", zonename))
self.inzones:Remove(zonename, true) self.inzones:Remove(zonename, true)
end end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --- On after "CheckZone" event.
-- Routing
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Set DCS task. Enroute tasks are injected automatically.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @param #table DCSTask DCS task structure. -- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function OPSGROUP:onafterCheckZone(From, Event, To)
if self:IsAlive()==true then
self:_CheckInZones()
end
if not self:IsStopped() then
self:__CheckZone(-1)
end
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Waypoints & Routing
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Initialize Mission Editor waypoints.
-- @param #OPSGROUP self
-- @param #table waypoints Table of waypoints. Default is from group template.
-- @return #OPSGROUP self -- @return #OPSGROUP self
function OPSGROUP:SetTask(DCSTask) function OPSGROUP:InitWaypoints(waypoints)
if self:IsAlive() then -- Template waypoints.
self.waypoints0=self.group:GetTemplateRoutePoints()
-- Set task. -- Waypoints of group as defined in the ME.
self.group:SetTask(DCSTask) self.waypoints=waypoints or UTILS.DeepCopy(self.waypoints0)
-- Debug info. -- Debug info.
local text=string.format("SETTING Task %s", tostring(DCSTask.id)) self:I(self.lid..string.format("Initializing %d waypoints", #self.waypoints))
if tostring(DCSTask.id)=="ComboTask" then
for i,task in pairs(DCSTask.params.tasks) do -- Update route.
text=text..string.format("\n[%d] %s", i, tostring(task.id)) if #self.waypoints>0 then
end
-- Check if only 1 wp?
if #self.waypoints==1 then
self.passedfinalwp=true
end end
self:I(self.lid..text)
end end
return self return self
end end
--- Check if flight is alive.
-- @param #OPSGROUP self
-- @return #boolean *true* if group is exists and is activated, *false* if group is exist but is NOT activated. *nil* otherwise, e.g. the GROUP object is *nil* or the group is not spawned yet.
function OPSGROUP:IsAlive()
if self.group then
return self.group:IsAlive()
end
return nil
end
--- Route group along waypoints. Enroute tasks are also applied. --- Route group along waypoints. Enroute tasks are also applied.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @param #table waypoints Table of waypoints. -- @param #table waypoints Table of waypoints.
@@ -1132,35 +1201,7 @@ function OPSGROUP:Route(waypoints)
return self return self
end end
--- Initialize Mission Editor waypoints.
-- @param #OPSGROUP self
-- @param #table waypoints Table of waypoints. Default is from group template.
-- @return #OPSGROUP self
function OPSGROUP:InitWaypoints(waypoints)
-- Template waypoints.
self.waypoints0=self.group:GetTemplateRoutePoints()
-- Waypoints of group as defined in the ME.
self.waypoints=waypoints or UTILS.DeepCopy(self.waypoints0)
-- Debug info.
self:T(self.lid..string.format("Initializing %d waypoints", #self.waypoints))
-- Update route.
if #self.waypoints>0 then
-- Check if only 1 wp?
if #self.waypoints==1 then
self.passedfinalwp=true
end
-- Update route (when airborne).
self:__UpdateRoute(-1)
end
return self
end
--- Initialize Mission Editor waypoints. --- Initialize Mission Editor waypoints.
-- @param #OPSGROUP self -- @param #OPSGROUP self
@@ -1217,9 +1258,9 @@ end
--- Function called when a task is executed. --- Function called when a task is executed.
--@param Wrapper.Group#GROUP group Group which should execute the task. --@param Wrapper.Group#GROUP group Group which should execute the task.
--@param #FLIGHTGROUP flightgroup Flight group. --@param #OPSGROUP flightgroup Flight group.
--@param #FLIGHTGROUP.Task task Task. --@param #OPSGROUP.Task task Task.
function FLIGHTGROUP._TaskExecute(group, flightgroup, task) function OPSGROUP._TaskExecute(group, flightgroup, task)
-- Debug message. -- Debug message.
local text=string.format("_TaskExecute %s", task.description) local text=string.format("_TaskExecute %s", task.description)
@@ -1233,9 +1274,9 @@ end
--- Function called when a task is done. --- Function called when a task is done.
--@param Wrapper.Group#GROUP group Group for which the task is done. --@param Wrapper.Group#GROUP group Group for which the task is done.
--@param #FLIGHTGROUP flightgroup Flight group. --@param #OPSGROUP flightgroup Flight group.
--@param #FLIGHTGROUP.Task task Task. --@param #OPSGROUP.Task task Task.
function FLIGHTGROUP._TaskDone(group, flightgroup, task) function OPSGROUP._TaskDone(group, flightgroup, task)
-- Debug message. -- Debug message.
local text=string.format("_TaskDone %s", task.description) local text=string.format("_TaskDone %s", task.description)