mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-08-10 17:59:24 +00:00
Ops
This commit is contained in:
@@ -72,7 +72,7 @@ AIRWING = {
|
||||
|
||||
--- AIRWING class version.
|
||||
-- @field #string version
|
||||
AIRWING.version="0.1.2"
|
||||
AIRWING.version="0.1.3"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- ToDo list
|
||||
@@ -83,7 +83,7 @@ AIRWING.version="0.1.2"
|
||||
-- DONE: Build mission queue.
|
||||
-- DONE: Find way to start missions.
|
||||
-- TODO: Check if missions are accomplished.
|
||||
-- TODO: Payloads as resources.
|
||||
-- DONE: Payloads as resources.
|
||||
-- TODO: Spawn in air or hot.
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -332,10 +332,7 @@ function AIRWING:AddMission(Mission, Nassets, WaypointCoordinate)
|
||||
Mission.waypointindex=nil
|
||||
|
||||
-- Set status to scheduled.
|
||||
Mission.status=AUFTRAG.Status.QUEUED
|
||||
|
||||
-- Todo call FSM event.
|
||||
--Mission:Queue()
|
||||
Mission:Queue()
|
||||
|
||||
-- Add mission to queue.
|
||||
table.insert(self.missionqueue, Mission)
|
||||
@@ -370,8 +367,6 @@ function AIRWING:onafterStart(From, Event, To)
|
||||
self:_AddSquadonMenu(squadron)
|
||||
end
|
||||
|
||||
-- Init status updates.
|
||||
--self:__AirwingStatus(-1)
|
||||
end
|
||||
|
||||
--- Update status.
|
||||
@@ -408,20 +403,17 @@ function AIRWING:onafterStatus(From, Event, To)
|
||||
local asset=_asset --#AIRWING.SquadronAsset
|
||||
local assignment=asset.assignment or "none"
|
||||
local name=asset.templatename
|
||||
local task=asset.mission and asset.mission.name or "none"
|
||||
local spawned=tostring(asset.spawned)
|
||||
local groupname=asset.spawngroupname
|
||||
local group=nil --Wrapper.Group#GROUP
|
||||
local typename=asset.unittype
|
||||
local fuel=100
|
||||
if groupname then
|
||||
group=GROUP:FindByName(groupname)
|
||||
if group then
|
||||
fuel=group:GetFuelMin()
|
||||
end
|
||||
end
|
||||
|
||||
text=text..string.format("\n -[%d] %s*%d: spawned=%s, mission=%s, fuel=%d", j, typename, asset.nunits, spawned, task, fuel)
|
||||
local mission=self:GetAssetCurrentMission(asset)
|
||||
local missiontext=""
|
||||
if mission then
|
||||
missiontext=string.format(" [%s (%s): status=%s]", mission.type, mission.name, mission.status)
|
||||
end
|
||||
|
||||
text=text..string.format("\n -[%d] %s*%d: spawned=%s, mission=%s%s", j, typename, asset.nunits, spawned, tostring(self:IsAssetOnMission(asset)), missiontext)
|
||||
|
||||
end
|
||||
end
|
||||
@@ -439,7 +431,6 @@ function AIRWING:onafterStatus(From, Event, To)
|
||||
self:MissionRequest(mission)
|
||||
end
|
||||
|
||||
--self:__AirwingStatus(-30)
|
||||
end
|
||||
|
||||
--- Get next mission.
|
||||
@@ -578,9 +569,9 @@ function AIRWING:onafterNewAsset(From, Event, To, asset, assignment)
|
||||
self:GetParent(self).onafterNewAsset(self, From, Event, To, asset, assignment)
|
||||
|
||||
-- Get squadron.
|
||||
local squad=self:GetSquadron(assignment)
|
||||
local squad=self:GetSquadron(asset.assignment)
|
||||
|
||||
if squad then
|
||||
if squad and asset.assignment==assignment then
|
||||
|
||||
-- TODO: Check if asset is already part of the squadron. If an asset returns, it will be added again!
|
||||
|
||||
@@ -615,7 +606,7 @@ end
|
||||
function AIRWING:onafterMissionRequest(From, Event, To, Mission)
|
||||
|
||||
-- Set mission status to ASSIGNED.
|
||||
Mission.status=AUFTRAG.Status.ASSIGNED
|
||||
Mission:Assign()
|
||||
|
||||
-- Some assets might already be spawned and even on a different mission (orbit).
|
||||
-- Need to dived to set into spawned and instock assets and handle the other
|
||||
@@ -812,7 +803,7 @@ function AIRWING:SquadronCanMission(Squadron, MissionType, Nassets)
|
||||
---
|
||||
|
||||
--TODO: This only checks if it has an ORBIT mission. It could have others as well!
|
||||
if self:IsAssetOnMission(asset, AUFTRAG.Type.ORBIT) then
|
||||
if self:IsAssetOnMission(asset, AUFTRAG.Type.ORBIT) and MissionType~=AUFTRAG.Type.ORBIT then
|
||||
|
||||
-- Check if the payload of this asset is compatible with the mission.
|
||||
if self:CheckMissionType(MissionType, asset.payload.missiontypes) then
|
||||
@@ -891,6 +882,20 @@ function AIRWING:IsAssetOnMission(asset, MissionTypes)
|
||||
return false
|
||||
end
|
||||
|
||||
--- Get the current mission of the asset.
|
||||
-- @param #AIRWING self
|
||||
-- @param #AIRWING.SquadronAsset asset The asset.
|
||||
-- @return Ops.Auftrag#AUFTRAG Current mission or *nil*.
|
||||
function AIRWING:GetAssetCurrentMission(asset)
|
||||
|
||||
if asset.flightgroup then
|
||||
return asset.flightgroup:GetMissionCurrent()
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
--- Check if assets for a given mission type are available.
|
||||
-- @param #AIRWING self
|
||||
-- @param #string MissionType Type of mission.
|
||||
|
||||
@@ -150,7 +150,7 @@ AUFTRAG.Status={
|
||||
|
||||
--- AUFTRAG class version.
|
||||
-- @field #string version
|
||||
AUFTRAG.version="0.0.2"
|
||||
AUFTRAG.version="0.0.3"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- TODO list
|
||||
@@ -439,6 +439,65 @@ end
|
||||
-- FSM Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- On after "Queue" event.
|
||||
-- @param #AUFTRAG self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
function AUFTRAG:onafterQueue(From, Event, To)
|
||||
self.status=AUFTRAG.Status.QUEUED
|
||||
self:I(self.lid..string.format("New mission status=%s", self.status))
|
||||
end
|
||||
|
||||
--- On after "Assign" event.
|
||||
-- @param #AUFTRAG self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
function AUFTRAG:onafterAssign(From, Event, To)
|
||||
self.status=AUFTRAG.Status.ASSIGNED
|
||||
self:I(self.lid..string.format("New mission status=%s", self.status))
|
||||
end
|
||||
|
||||
--- On after "Schedule" event.
|
||||
-- @param #AUFTRAG self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
function AUFTRAG:onafterSchedule(From, Event, To)
|
||||
self.status=AUFTRAG.Status.SCHEDULED
|
||||
self:I(self.lid..string.format("New mission status=%s", self.status))
|
||||
end
|
||||
|
||||
--- On after "Start" event.
|
||||
-- @param #AUFTRAG self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
function AUFTRAG:onafterStart(From, Event, To)
|
||||
self.status=AUFTRAG.Status.STARTED
|
||||
self:I(self.lid..string.format("New mission status=%s", self.status))
|
||||
end
|
||||
|
||||
--- On after "Execute" event.
|
||||
-- @param #AUFTRAG self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
function AUFTRAG:onafterExecute(From, Event, To)
|
||||
self.status=AUFTRAG.Status.EXECUTING
|
||||
self:I(self.lid..string.format("New mission status=%s", self.status))
|
||||
end
|
||||
|
||||
--- On after "Done" event.
|
||||
-- @param #AUFTRAG self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
function AUFTRAG:onafterDone(From, Event, To)
|
||||
self.status=AUFTRAG.Status.DONE
|
||||
self:I(self.lid..string.format("New mission status=%s", self.status))
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Misc Functions
|
||||
@@ -468,13 +527,16 @@ end
|
||||
-- @param Core.Point#COORDINATE The target coordinate or nil.
|
||||
function AUFTRAG:GetTargetCoordinate()
|
||||
|
||||
if self.engageTargetGroupset then
|
||||
|
||||
if self.engageTargetGroupset then
|
||||
local group=self.engageTargetGroupset:GetFirst() --Wrapper.Group#GROUP
|
||||
return group:GetCoordinate()
|
||||
elseif self.engageTargetUnitset then
|
||||
local unit=self.engageTargetUnitset:GetFirst() --Wrapper.Unit#UNIT
|
||||
return unit:GetCoordinate()
|
||||
elseif self.engageCoord then
|
||||
return self.engageCoord
|
||||
elseif self.orbitCoord then
|
||||
return self.orbitCoord
|
||||
end
|
||||
|
||||
return nil
|
||||
@@ -661,6 +723,7 @@ function AUFTRAG:GetDCSMissionTask()
|
||||
end
|
||||
|
||||
|
||||
-- Return the task.
|
||||
if #DCStasks==1 then
|
||||
return DCStasks[1]
|
||||
else
|
||||
|
||||
@@ -316,7 +316,7 @@ FLIGHTGROUP.TaskType={
|
||||
|
||||
--- FLIGHTGROUP class version.
|
||||
-- @field #string version
|
||||
FLIGHTGROUP.version="0.3.2"
|
||||
FLIGHTGROUP.version="0.3.3"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- TODO list
|
||||
@@ -407,7 +407,7 @@ function FLIGHTGROUP:New(groupname, autostart)
|
||||
|
||||
self:AddTransition("*", "PassingWaypoint", "*") -- Group passed a waypoint.
|
||||
self:AddTransition("*", "GotoWaypoint", "*") -- Group switches to a specific waypoint.
|
||||
self:AddTransition("*", "Orbit", "Orbiting") -- Group is orbiting.
|
||||
self:AddTransition("*", "Wait", "Waiting") -- Group is orbiting.
|
||||
|
||||
self:AddTransition("*", "FuelLow", "*") -- Fuel state of group is low. Default ~25%.
|
||||
self:AddTransition("*", "FuelCritical", "*") -- Fuel state of group is critical. Default ~10%.
|
||||
@@ -667,10 +667,8 @@ function FLIGHTGROUP:AddMission(Mission, WaypointCoordinate, WaypointIndex)
|
||||
Mission.waypointindex=WaypointIndex
|
||||
|
||||
-- Set status to scheduled.
|
||||
Mission.status=AUFTRAG.Status.SCHEDULED
|
||||
|
||||
-- Route flight to mission zone.
|
||||
--self:RouteToMission(Mission)
|
||||
Mission:Schedule()
|
||||
--Mission.status=AUFTRAG.Status.SCHEDULED
|
||||
|
||||
-- Add mission to queue.
|
||||
table.insert(self.missionqueue, Mission)
|
||||
@@ -1319,9 +1317,9 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To)
|
||||
end
|
||||
-- Output text for element.
|
||||
if task.type==FLIGHTGROUP.TaskType.SCHEDULED then
|
||||
text=text..string.format("\n[%d] %s: %s: status=%s, scheduled=%s (%d sec), started=%s, duration=%d", i, taskid, name, status, clock, eta, started, duration)
|
||||
text=text..string.format("\n[%d] %s (%s): status=%s, scheduled=%s (%d sec), started=%s, duration=%d", i, taskid, name, status, clock, eta, started, duration)
|
||||
elseif task.type==FLIGHTGROUP.TaskType.WAYPOINT then
|
||||
text=text..string.format("\n[%d] %s: %s: status=%s, waypoint=%d, started=%s, duration=%d, stopflag=%d", i, taskid, name, status, task.waypoint, started, duration, task.stopflag:Get())
|
||||
text=text..string.format("\n[%d] %s (%s): status=%s, waypoint=%d, started=%s, duration=%d, stopflag=%d", i, taskid, name, status, task.waypoint, started, duration, task.stopflag:Get())
|
||||
end
|
||||
end
|
||||
if #self.taskqueue>0 then
|
||||
@@ -1337,11 +1335,11 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To)
|
||||
local mymission=Mission and Mission.name or "none"
|
||||
|
||||
-- Current status.
|
||||
local text=string.format("Missions=%d Current: %s", #self.missionqueue, mymission)
|
||||
local text=string.format("Missions %d, Current: %s", self:CountRemainingMissison(), mymission)
|
||||
for i,_mission in pairs(self.missionqueue) do
|
||||
local mission=_mission --Ops.Auftrag#AUFTRAG
|
||||
local Cstart= UTILS.SecondsToClock(mission.Tstart, true)
|
||||
local Cstop = mission.Tstop and UTILS.SecondsToClock(mission.Tstop, true) or "N/A"
|
||||
local Cstop = mission.Tstop and UTILS.SecondsToClock(mission.Tstop, true) or "INF"
|
||||
text=text..string.format("\n[%d] %s (%s) status=%s, Time=%s-%s, waypoint=%s, prio=%d targets=%d",
|
||||
i, tostring(mission.name), mission.type, tostring(mission.status), Cstart, Cstop, tostring(mission.waypointindex), mission.prio, mission:CountMissionTargets())
|
||||
end
|
||||
@@ -2310,11 +2308,11 @@ end
|
||||
-- @param #number n Waypoint number passed.
|
||||
-- @param #number N Final waypoint number.
|
||||
function FLIGHTGROUP:onafterPassingWaypoint(From, Event, To, n, N)
|
||||
local text=string.format("Flight %s passed waypoint %d/%d", self.groupname, n, N)
|
||||
local text=string.format("Flight passed waypoint %d/%d", n, N)
|
||||
self:I(self.lid..text)
|
||||
MESSAGE:New(text, 30, "DEBUG"):ToAllIf(self.Debug)
|
||||
|
||||
--[[
|
||||
if true then
|
||||
|
||||
-- Get all waypoint tasks.
|
||||
local tasks=self:GetTasksWaypoint(n)
|
||||
@@ -2359,19 +2357,21 @@ function FLIGHTGROUP:onafterPassingWaypoint(From, Event, To, n, N)
|
||||
self:SetTask(self.group:TaskCombo(taskswp))
|
||||
end
|
||||
|
||||
]]
|
||||
end
|
||||
|
||||
-- Final AIR waypoint reached?
|
||||
if n==N and false then
|
||||
if n==N then
|
||||
|
||||
--TODO: Find better way to RTB!
|
||||
--TODO: Find better way to RTB!
|
||||
self:I(self.lid.."FF group passed final waypoint!")
|
||||
|
||||
-- Send flight to destination.
|
||||
-- Send flight to destination. NOTE that if there are still remaining tasks, the RTB call is delayed by 10 sec until all tasks are done.
|
||||
if self.destbase then
|
||||
self:__RTB(-1, self.destbase)
|
||||
elseif self.destzone then
|
||||
self:__RTZ(-1, self.destzone)
|
||||
else
|
||||
self:__Wait(-1)
|
||||
self:E(self.lid.."ERROR: Reached final waypoint but no destination set! Don't know what to do?!")
|
||||
end
|
||||
|
||||
@@ -2406,28 +2406,6 @@ function FLIGHTGROUP:onafterGotoWaypoint(From, Event, To, n)
|
||||
|
||||
end
|
||||
|
||||
--- On after "Orbit" 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:onafterOrbit(From, Event, To, Coord, Altitude, Speed)
|
||||
|
||||
-- Debug message.
|
||||
local text=string.format("Flight group set to orbit at altitude %d m and speed %.1f km/h", Altitude, Speed)
|
||||
MESSAGE:New(text, 30, "DEBUG"):ToAllIf(self.Debug)
|
||||
self:I(self.lid..text)
|
||||
|
||||
--TODO: set ROE passive. introduce roe event/state/variable.
|
||||
|
||||
local TaskOrbit=self.group:TaskOrbit(Coord, Altitude, UTILS.KmphToMps(Speed))
|
||||
|
||||
self:SetTask(TaskOrbit)
|
||||
end
|
||||
|
||||
--- On before "RTB" event.
|
||||
-- @param #FLIGHTGROUP self
|
||||
-- @param #string From From state.
|
||||
@@ -2442,13 +2420,13 @@ function FLIGHTGROUP:onbeforeRTB(From, Event, To, airbase, SpeedTo, SpeedHold)
|
||||
local Tsuspend=nil
|
||||
|
||||
if airbase==nil then
|
||||
self:E(self.lid.."ERROR: Airbase is nil in Hold() call!")
|
||||
self:E(self.lid.."ERROR: Airbase is nil in RTB() call!")
|
||||
allowed=false
|
||||
end
|
||||
|
||||
-- Check that coaliton is okay. We allow same (blue=blue, red=red) or landing on neutral bases.
|
||||
if airbase and airbase:GetCoalition()~=self.group:GetCoalition() and airbase:GetCoalition()>0 then
|
||||
self:E(self.lid.."ERROR: Wrong airbase coalition in Hold() call! We allow only same as group or neutral airbases.")
|
||||
self:E(self.lid.."ERROR: Wrong airbase coalition in RTB() call! We allow only same as group or neutral airbases.")
|
||||
allowed=false
|
||||
end
|
||||
|
||||
@@ -2456,19 +2434,19 @@ function FLIGHTGROUP:onbeforeRTB(From, Event, To, airbase, SpeedTo, SpeedHold)
|
||||
local Ntot,Nsched, Nwp=self:CountRemainingTasks()
|
||||
|
||||
if self.taskcurrent>0 then
|
||||
self:I(self.lid..string.format("WARNING: Got current task ==> Hold event is suspended for 10 sec."))
|
||||
self:I(self.lid..string.format("WARNING: Got current task ==> RTB event is suspended for 10 sec."))
|
||||
Tsuspend=-10
|
||||
allowed=false
|
||||
end
|
||||
|
||||
if Nsched>0 then
|
||||
self:I(self.lid..string.format("WARNING: Still got %d SCHEDULED tasks in the queue ==> Hold event is suspended for 10 sec.", Nsched))
|
||||
self:I(self.lid..string.format("WARNING: Still got %d SCHEDULED tasks in the queue ==> RTB event is suspended for 10 sec.", Nsched))
|
||||
Tsuspend=-10
|
||||
allowed=false
|
||||
end
|
||||
|
||||
if Nwp>0 then
|
||||
self:I(self.lid..string.format("WARNING: Still got %d WAYPOINT tasks in the queue ==> Hold event is suspended for 10 sec.", Nsched))
|
||||
self:I(self.lid..string.format("WARNING: Still got %d WAYPOINT tasks in the queue ==> RTB event is suspended for 10 sec.", Nwp))
|
||||
Tsuspend=-10
|
||||
allowed=false
|
||||
end
|
||||
@@ -2586,6 +2564,76 @@ function FLIGHTGROUP:onafterRTB(From, Event, To, airbase, SpeedTo, SpeedHold, Sp
|
||||
|
||||
end
|
||||
|
||||
--- On before "Wait" 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. Default current position.
|
||||
-- @param #number Altitude Altitude in feet. Default 10000 ft.
|
||||
-- @param #number Speed Speed in knots. Default 250 kts.
|
||||
function FLIGHTGROUP:onafterWait(From, Event, To, Coord, Altitude, Speed)
|
||||
|
||||
local allowed=true
|
||||
local Tsuspend=nil
|
||||
|
||||
-- Check if there are remaining tasks.
|
||||
local Ntot,Nsched, Nwp=self:CountRemainingTasks()
|
||||
|
||||
if self.taskcurrent>0 then
|
||||
self:I(self.lid..string.format("WARNING: Got current task ==> WAIT event is suspended for 10 sec."))
|
||||
Tsuspend=-10
|
||||
allowed=false
|
||||
end
|
||||
|
||||
if Nsched>0 then
|
||||
self:I(self.lid..string.format("WARNING: Still got %d SCHEDULED tasks in the queue ==> WAIT event is suspended for 10 sec.", Nsched))
|
||||
Tsuspend=-10
|
||||
allowed=false
|
||||
end
|
||||
|
||||
if Nwp>0 then
|
||||
self:I(self.lid..string.format("WARNING: Still got %d WAYPOINT tasks in the queue ==> WAIT event is suspended for 10 sec.", Nwp))
|
||||
Tsuspend=-10
|
||||
allowed=false
|
||||
end
|
||||
|
||||
if Tsuspend and not allowed then
|
||||
self:__WAIT(Tsuspend, Coord, Altitude, Speed)
|
||||
end
|
||||
|
||||
return allowed
|
||||
end
|
||||
|
||||
|
||||
--- On after "Wait" 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. Default current position.
|
||||
-- @param #number Altitude Altitude in feet. Default 10000 ft.
|
||||
-- @param #number Speed Speed in knots. Default 250 kts.
|
||||
function FLIGHTGROUP:onafterWait(From, Event, To, Coord, Altitude, Speed)
|
||||
|
||||
Coord=Coord or self.group:GetCoordinate()
|
||||
Altitude=Altitude or 10000
|
||||
Speed=Speed or 250
|
||||
|
||||
-- Debug message.
|
||||
local text=string.format("Flight group set to wait/orbit at altitude %d m and speed %.1f km/h", Altitude, Speed)
|
||||
MESSAGE:New(text, 30, "DEBUG"):ToAllIf(self.Debug)
|
||||
self:I(self.lid..text)
|
||||
|
||||
--TODO: set ROE passive. introduce roe event/state/variable.
|
||||
|
||||
-- Orbit task.
|
||||
local TaskOrbit=self.group:TaskOrbit(Coord, UTILS.FeetToMeters(Altitude), UTILS.KnotsToMps(Speed))
|
||||
|
||||
-- Set task.
|
||||
self:SetTask(TaskOrbit)
|
||||
end
|
||||
|
||||
--- On after "Holding" event. Flight arrived at the holding point.
|
||||
-- @param #FLIGHTGROUP self
|
||||
-- @param #string From From state.
|
||||
@@ -2819,8 +2867,9 @@ function FLIGHTGROUP:CountRemainingTasks()
|
||||
Ntot=Ntot+1
|
||||
|
||||
if task.type==FLIGHTGROUP.TaskType.WAYPOINT then
|
||||
--TODO: maybe check that waypoint was not already passed?
|
||||
Nwp=Nwp+1
|
||||
elseif task.type==FLIGHTGROUP.TaskType.WAYPOINT then
|
||||
elseif task.type==FLIGHTGROUP.TaskType.SCHEDULED then
|
||||
Nsched=Nsched+1
|
||||
end
|
||||
|
||||
@@ -2831,6 +2880,23 @@ function FLIGHTGROUP:CountRemainingTasks()
|
||||
return Ntot, Nsched, Nwp
|
||||
end
|
||||
|
||||
--- Count remaining missons.
|
||||
-- @param #FLIGHTGROUP self
|
||||
-- @return #number Number of missions to be done.
|
||||
function FLIGHTGROUP:CountRemainingMissison()
|
||||
|
||||
local N=0
|
||||
|
||||
-- Loop over mission queue.
|
||||
for _,_mission in pairs(self.missionqueue) do
|
||||
local mission=_mission --Ops.Auftrag#AUFTRAG
|
||||
if mission.status~=AUFTRAG.Status.DONE then
|
||||
N=N+1
|
||||
end
|
||||
end
|
||||
|
||||
return N
|
||||
end
|
||||
|
||||
--- On after TaskExecute event.
|
||||
-- @param #FLIGHTGROUP self
|
||||
@@ -2889,15 +2955,15 @@ function FLIGHTGROUP:onafterTaskExecute(From, Event, To, Task)
|
||||
|
||||
-- Set task for group.
|
||||
self:SetTask(TaskFinal, 1)
|
||||
|
||||
-- Get mission of this task (if any).
|
||||
local Mission=self:GetMissionByTaskID(self.taskcurrent)
|
||||
if Mission then
|
||||
-- Set AUFTRAG status.
|
||||
self:MissionExecute(Mission)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- Get mission of this task (if any).
|
||||
local Mission=self:GetMissionByTaskID(self.taskcurrent)
|
||||
if Mission then
|
||||
-- Set AUFTRAG status.
|
||||
self:MissionExecute(Mission)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -3058,7 +3124,8 @@ function FLIGHTGROUP:onafterMissionStart(From, Event, To, Mission)
|
||||
self.currentmission=Mission.auftragsnummer
|
||||
|
||||
-- Set mission status.
|
||||
Mission.status=AUFTRAG.Status.STARTED
|
||||
Mission:Start()
|
||||
--Mission.status=AUFTRAG.Status.STARTED
|
||||
|
||||
-- Route flight to mission zone.
|
||||
self:RouteToMission(Mission, 5)
|
||||
@@ -3077,7 +3144,8 @@ function FLIGHTGROUP:onafterMissionExecute(From, Event, To, Mission)
|
||||
self:I(self.lid..text)
|
||||
MESSAGE:New(text, 120, "DEBUG"):ToAllIf(true)
|
||||
|
||||
Mission.status=AUFTRAG.Status.EXECUTING
|
||||
Mission:Execute()
|
||||
--Mission.status=AUFTRAG.Status.EXECUTING
|
||||
|
||||
end
|
||||
|
||||
@@ -3110,7 +3178,8 @@ function FLIGHTGROUP:onafterMissionDone(From, Event, To, Mission)
|
||||
|
||||
-- TODO: evaluate mission success or failure! complicated!
|
||||
|
||||
Mission.status=AUFTRAG.Status.DONE
|
||||
--Mission.status=AUFTRAG.Status.DONE
|
||||
Mission:Done()
|
||||
|
||||
local airwing=self:GetAirWing()
|
||||
if airwing then
|
||||
@@ -3659,20 +3728,29 @@ end
|
||||
-- @return Ops.Auftrag#AUFTRAG The mission.
|
||||
function FLIGHTGROUP:GetMissionByTaskID(taskid)
|
||||
|
||||
for _,_mission in pairs(self.missionqueue) do
|
||||
local mission=_mission --Ops.Auftrag#AUFTRAG
|
||||
|
||||
local task=mission.waypointtask
|
||||
|
||||
if task and task.id and task.id==taskid then
|
||||
return mission
|
||||
if taskid then
|
||||
for _,_mission in pairs(self.missionqueue) do
|
||||
local mission=_mission --Ops.Auftrag#AUFTRAG
|
||||
|
||||
local task=mission.waypointtask
|
||||
|
||||
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
|
||||
|
||||
|
||||
--- Get next waypoint of the flight group.
|
||||
-- @param #FLIGHTGROUP self
|
||||
@@ -3731,27 +3809,27 @@ function FLIGHTGROUP:_UpdateWaypointTasks()
|
||||
-- For some reason THIS DOES NOT WORK if executed at the last waypoint if it is an AIR WAYPOINT.
|
||||
-- I have moved it to the onafterpassingwaypoint function instead.
|
||||
|
||||
if true then
|
||||
if false then
|
||||
|
||||
-- Get taks
|
||||
local tasks=self:GetTasksWaypoint(i)
|
||||
|
||||
for _,task in pairs(tasks) do
|
||||
local Task=task --#FLIGHTGROUP.Task
|
||||
-- Get taks
|
||||
local tasks=self:GetTasksWaypoint(i)
|
||||
|
||||
-- Task execute.
|
||||
table.insert(taskswp, self.group:TaskFunction("FLIGHTGROUP._TaskExecute", self, Task))
|
||||
|
||||
-- Stop condition if userflag is set to 1.
|
||||
local TaskCondition=self.group:TaskCondition(nil, Task.stopflag:GetName(), 1, nil, Task.duration)
|
||||
|
||||
-- Controlled task.
|
||||
table.insert(taskswp, self.group:TaskControlled(Task.dcstask, TaskCondition))
|
||||
|
||||
-- Task done.
|
||||
table.insert(taskswp, self.group:TaskFunction("FLIGHTGROUP._TaskDone", self, Task))
|
||||
|
||||
end
|
||||
for _,task in pairs(tasks) do
|
||||
local Task=task --#FLIGHTGROUP.Task
|
||||
|
||||
-- Task execute.
|
||||
table.insert(taskswp, self.group:TaskFunction("FLIGHTGROUP._TaskExecute", self, Task))
|
||||
|
||||
-- Stop condition if userflag is set to 1.
|
||||
local TaskCondition=self.group:TaskCondition(nil, Task.stopflag:GetName(), 1, nil, Task.duration)
|
||||
|
||||
-- Controlled task.
|
||||
table.insert(taskswp, self.group:TaskControlled(Task.dcstask, TaskCondition))
|
||||
|
||||
-- Task done.
|
||||
table.insert(taskswp, self.group:TaskFunction("FLIGHTGROUP._TaskDone", self, Task))
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user