This commit is contained in:
Frank
2020-02-08 23:42:52 +01:00
parent 29995e1584
commit ecd76dec7d
3 changed files with 91 additions and 25 deletions
+81 -14
View File
@@ -614,8 +614,8 @@ end
--- Add an *enroute* task to attack targets in a certain **cicular** zone. --- Add an *enroute* task to attack targets in a certain **cicular** zone.
-- @param #FLIGHTGROUP self -- @param #FLIGHTGROUP self
-- @param Core.Zone#ZONE_RADIUS ZoneRadius The circular zone, where to engage targets. -- @param Core.Zone#ZONE_RADIUS ZoneRadius The circular zone, where to engage targets.
-- @param #table TargetTypes (Optional) The target types, passed as a table, i.e. mind the cirly brackets {}. -- @param #table TargetTypes (Optional) The target types, passed as a table, i.e. mind the cirly brackets {}. Default {"Air"}.
-- @param #number Priority (Optional) Priority. -- @param #number Priority (Optional) Priority. Default 0.
function FLIGHTGROUP:AddTaskEnrouteEngageTargetsInZone(ZoneRadius, TargetTypes, Priority) function FLIGHTGROUP:AddTaskEnrouteEngageTargetsInZone(ZoneRadius, TargetTypes, Priority)
local Task=self.group:EnRouteTaskEngageTargetsInZone(ZoneRadius:GetVec2(), ZoneRadius:GetRadius(), TargetTypes, Priority) local Task=self.group:EnRouteTaskEngageTargetsInZone(ZoneRadius:GetVec2(), ZoneRadius:GetRadius(), TargetTypes, Priority)
self:AddTaskEnroute(Task) self:AddTaskEnroute(Task)
@@ -970,6 +970,55 @@ function FLIGHTGROUP:StartUncontrolled(delay)
return self return self
end end
--- Set DCS task.
-- @param #FLIGHTGROUP self
-- @param #table DCSTask DCS task structure.
-- @return #FLIGHTGROUP self
function FLIGHTGROUP:SetTask(DCSTask)
if self:IsAlive() then
self.group:SetTask(DCSTask, 1)
local text=string.format("SETTING Task %s", tostring(DCSTask.id))
if tostring(DCSTask.id)=="ComboTask" then
for i,task in pairs(DCSTask.params.tasks) do
text=text..string.format("\n[%d] %s", i, tostring(task.id))
end
end
self:I(self.lid..text)
end
return self
end
--- Push DCS task.
-- @param #FLIGHTGROUP self
-- @param #table DCSTask DCS task structure.
-- @return #FLIGHTGROUP self
function FLIGHTGROUP:PushTask(DCSTask)
if self:IsAlive() then
self.group:PushTask(DCSTask, 1)
local text=string.format("PUSHING Task %s", tostring(DCSTask.id))
if tostring(DCSTask.id)=="ComboTask" then
for i,task in pairs(DCSTask.params.tasks) do
text=text..string.format("\n[%d] %s", i, tostring(task.id))
end
end
self:I(self.lid..text)
end
return self
end
--- Push DCS task.
-- @param #FLIGHTGROUP self
-- @param #table DCSTask DCS task structure.
-- @return #FLIGHTGROUP self
function FLIGHTGROUP:ClearTasks()
if self:IsAlive() then
self.group:ClearTasks()
self:I(self.lid..string.format("CLEARING Tasks"))
end
return self
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Start & Status -- Start & Status
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -1877,7 +1926,7 @@ function FLIGHTGROUP:onafterFlightAirborne(From, Event, To, airbase)
end end
if task then if task then
self.group:PushTask(task, 0.1) self:PushTask(task, 0.1)
end end
-- Update queue. -- Update queue.
@@ -1944,6 +1993,7 @@ function FLIGHTGROUP:onafterFlightDead(From, Event, To)
-- Delete waypoints so they are re-initialized at the next spawn. -- Delete waypoints so they are re-initialized at the next spawn.
self.waypoints=nil self.waypoints=nil
self.groupinitialized=false
-- Remove flight from all FC queues. -- Remove flight from all FC queues.
if self.flightcontrol then if self.flightcontrol then
@@ -1952,7 +2002,7 @@ function FLIGHTGROUP:onafterFlightDead(From, Event, To)
end end
-- Stop -- Stop
self:__Stop(0.5) self:Stop()
end end
@@ -2079,11 +2129,22 @@ function FLIGHTGROUP:onafterUpdateRoute(From, Event, To, n)
local db=self.destbase and self.destbase:GetName() or "unknown" local db=self.destbase and self.destbase:GetName() or "unknown"
self:I(self.lid..string.format("Updating route for WP>=%d/%d (%d) homebase=%s destination=%s", n, #wp, #self.waypoints, hb, db)) self:I(self.lid..string.format("Updating route for WP>=%d/%d (%d) homebase=%s destination=%s", n, #wp, #self.waypoints, hb, db))
if #wp>0 then if #wp>0 then
-- Route group to all defined waypoints remaining. -- Route group to all defined waypoints remaining.
self.group:Route(wp, 1) self.group:Route(wp, 1)
if self.taskenroute then
for _,task in pairs(self.taskenroute) do
self:I(self.lid..string.format("Pushing enroute task %s", tostring(task.id)))
self:PushTask(task, 1.1)
--table.insert(taskswp, task)
end
end
else else
--- ---
@@ -2157,7 +2218,17 @@ function FLIGHTGROUP:onafterPassingWaypoint(From, Event, To, n, N)
self:I(self.lid..text) self:I(self.lid..text)
-- Tasks at this waypoints.
local taskswp={} local taskswp={}
-- Enroute tasks
if self.taskenroute and false then
for _,taskE in pairs(self.taskenroute) do
self:I(self.lid..string.format("Adding enroute task %s", tostring(taskE.id)))
table.insert(taskswp, taskE)
end
end
for _,task in pairs(tasks) do for _,task in pairs(tasks) do
local Task=task --#FLIGHTGROUP.Task local Task=task --#FLIGHTGROUP.Task
@@ -2168,9 +2239,9 @@ function FLIGHTGROUP:onafterPassingWaypoint(From, Event, To, n, N)
local TaskCondition=self.group:TaskCondition(nil, Task.stopflag:GetName(), 1, nil, Task.duration) local TaskCondition=self.group:TaskCondition(nil, Task.stopflag:GetName(), 1, nil, Task.duration)
-- Controlled task. -- Controlled task.
table.insert(taskswp, self.group:TaskControlled(Task.dcstask, TaskCondition)) --table.insert(taskswp, self.group:TaskControlled(Task.dcstask, TaskCondition))
--table.insert(taskswp, Task.dcstask) table.insert(taskswp, Task.dcstask)
-- Task done. -- Task done.
table.insert(taskswp, self.group:TaskFunction("FLIGHTGROUP._TaskDone", self, Task)) table.insert(taskswp, self.group:TaskFunction("FLIGHTGROUP._TaskDone", self, Task))
@@ -2184,7 +2255,7 @@ function FLIGHTGROUP:onafterPassingWaypoint(From, Event, To, n, N)
else else
-- Waypoint task combo. -- Waypoint task combo.
if #taskswp>0 then if #taskswp>0 then
self.group:SetTask(self.group:TaskCombo(taskswp)) self:SetTask(self.group:TaskCombo(taskswp))
end end
end end
@@ -2273,7 +2344,7 @@ function FLIGHTGROUP:onafterOrbit(From, Event, To, Coord, Altitude, Speed)
local TaskOrbit=self.group:TaskOrbit(Coord, Altitude, UTILS.KmphToMps(Speed)) local TaskOrbit=self.group:TaskOrbit(Coord, Altitude, UTILS.KmphToMps(Speed))
self.group:SetTask(TaskOrbit) self:SetTask(TaskOrbit)
end end
--- On before "Hold" event. --- On before "Hold" event.
@@ -2554,7 +2625,7 @@ function FLIGHTGROUP:onafterTaskExecute(From, Event, To, Task)
self:I({task=TaskControlled}) self:I({task=TaskControlled})
-- Set task for group. -- Set task for group.
self.group:SetTask(TaskControlled, 1) self:SetTask(TaskControlled, 1)
end end
@@ -2968,7 +3039,7 @@ function FLIGHTGROUP:RouteOrbit(CoordOrbit, Speed, Altitude, CoordRaceTrack)
local TaskCombo=self.group:TaskControlled(TaskRoute, TaskOrbit) local TaskCombo=self.group:TaskControlled(TaskRoute, TaskOrbit)
self.group:SetTask(TaskCombo, 1) self:SetTask(TaskCombo, 1)
-- Route the group or this will not work. -- Route the group or this will not work.
--self.group:Route(wp, 1) --self.group:Route(wp, 1)
@@ -3357,10 +3428,6 @@ function FLIGHTGROUP:_UpdateWaypointTasks()
-- Tasks of this waypoint -- Tasks of this waypoint
local taskswp={} local taskswp={}
if self.taskenroute then
table.insert(taskswp, self.taskenroute[1])
end
-- At each waypoint report passing. -- At each waypoint report passing.
local TaskPassingWaypoint=self.group:TaskFunction("FLIGHTGROUP._PassingWaypoint", self, i) local TaskPassingWaypoint=self.group:TaskFunction("FLIGHTGROUP._PassingWaypoint", self, i)
table.insert(taskswp, TaskPassingWaypoint) table.insert(taskswp, TaskPassingWaypoint)
+5 -6
View File
@@ -107,21 +107,23 @@ TANKERGROUP.version="0.0.1"
-- @return #TANKERGROUP self -- @return #TANKERGROUP self
function TANKERGROUP:New(groupname) function TANKERGROUP:New(groupname)
-- Create flight group.
local fg=FLIGHTGROUP:New(groupname, false) local fg=FLIGHTGROUP:New(groupname, false)
-- Inherit everything from TANKERGROUP class. -- Inherit everything from TANKERGROUP class.
local self=BASE:Inherit(self, fg) -- #TANKERGROUP local self=BASE:Inherit(self, fg) -- #TANKERGROUP
-- Init mission counter.
self.missioncounter=0 self.missioncounter=0
self.lid=string.format("TANKERGROUP %s | ", groupname) -- Log id.
self.lid=string.format("FLIGHTGROUP %s (TANKER) | ", groupname)
if false then if false then
BASE:TraceOn() BASE:TraceOn()
BASE:TraceLevel(3) BASE:TraceLevel(3)
BASE:TraceClass(self.ClassName) BASE:TraceClass(self.ClassName)
BASE:TraceClass("FLIGHTGROUP") BASE:TraceClass("FLIGHTGROUP")
--BASE:TraceAll(true)
end end
-- Add FSM transitions. -- Add FSM transitions.
@@ -131,13 +133,10 @@ function TANKERGROUP:New(groupname)
self:AddTransition("*", "MissionStart", "*") -- Tanker is on station and ready to refuel. self:AddTransition("*", "MissionStart", "*") -- Tanker is on station and ready to refuel.
-- Scheduler to update the status.
--self.Statusupdater=SCHEDULER:New(self, TANKERGROUP.TankerState, {self}, 1, 5)
-- Call status update. -- Call status update.
-- TODO: WARNING, if the call is delayed, it is NOT executed!
self:__TankerState(-5) self:__TankerState(-5)
-- Start FSM.
self:Start() self:Start()
return self return self
@@ -1524,8 +1524,8 @@ end
-- @param #CONTROLLABLE self -- @param #CONTROLLABLE self
-- @param DCS#Vec2 Vec2 2D-coordinates of the zone. -- @param DCS#Vec2 Vec2 2D-coordinates of the zone.
-- @param DCS#Distance Radius Radius of the zone. -- @param DCS#Distance Radius Radius of the zone.
-- @param DCS#AttributeNameArray TargetTypes Array of target categories allowed to engage. -- @param DCS#AttributeNameArray (Optional) TargetTypes Array of target categories allowed to engage. Default {"Air"}.
-- @param #number Priority All en-route tasks have the priority parameter. This is a number (less value - higher priority) that determines actions related to what task will be performed first. -- @param #number Priority (Optional) All en-route tasks have the priority parameter. This is a number (less value - higher priority) that determines actions related to what task will be performed first. Default 0.
-- @return DCS#Task The DCS task structure. -- @return DCS#Task The DCS task structure.
function CONTROLLABLE:EnRouteTaskEngageTargetsInZone( Vec2, Radius, TargetTypes, Priority ) function CONTROLLABLE:EnRouteTaskEngageTargetsInZone( Vec2, Radius, TargetTypes, Priority )
self:F2( { self.ControllableName, Vec2, Radius, TargetTypes, Priority } ) self:F2( { self.ControllableName, Vec2, Radius, TargetTypes, Priority } )
@@ -1545,8 +1545,8 @@ function CONTROLLABLE:EnRouteTaskEngageTargetsInZone( Vec2, Radius, TargetTypes,
params = { params = {
point = Vec2, point = Vec2,
zoneRadius = Radius, zoneRadius = Radius,
targetTypes = TargetTypes, targetTypes = TargetTypes or {"Air"},
priority = Priority priority = Priority or 0
} }
} }