mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-08-19 22:17:13 +00:00
Ops
This commit is contained in:
@@ -1763,7 +1763,7 @@ _WAREHOUSEDB = {
|
|||||||
|
|
||||||
--- Warehouse class version.
|
--- Warehouse class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
WAREHOUSE.version="0.9.9"
|
WAREHOUSE.version="1.0.0"
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- TODO: Warehouse todo list.
|
-- TODO: Warehouse todo list.
|
||||||
@@ -1835,7 +1835,7 @@ function WAREHOUSE:New(warehouse, alias)
|
|||||||
local warehousename=warehouse
|
local warehousename=warehouse
|
||||||
warehouse=UNIT:FindByName(warehousename)
|
warehouse=UNIT:FindByName(warehousename)
|
||||||
if warehouse==nil then
|
if warehouse==nil then
|
||||||
env.info(string.format("No warehouse unit with name %s found trying static.", tostring(warehousename)))
|
--env.info(string.format("No warehouse unit with name %s found trying static.", tostring(warehousename)))
|
||||||
warehouse=STATIC:FindByName(warehousename, true)
|
warehouse=STATIC:FindByName(warehousename, true)
|
||||||
self.isunit=false
|
self.isunit=false
|
||||||
else
|
else
|
||||||
@@ -1870,12 +1870,9 @@ function WAREHOUSE:New(warehouse, alias)
|
|||||||
-- Set unique ID for this warehouse.
|
-- Set unique ID for this warehouse.
|
||||||
self.uid=_WAREHOUSEDB.WarehouseID
|
self.uid=_WAREHOUSEDB.WarehouseID
|
||||||
|
|
||||||
-- As Kalbuth found out, this would fail when using SPAWNSTATIC https://forums.eagle.ru/showthread.php?p=3703488#post3703488
|
-- Closest of the same coalition but within 5 km range.
|
||||||
--self.uid=tonumber(warehouse:GetID())
|
|
||||||
|
|
||||||
-- Closest of the same coalition but within a certain range.
|
|
||||||
local _airbase=self:GetCoordinate():GetClosestAirbase(nil, self:GetCoalition())
|
local _airbase=self:GetCoordinate():GetClosestAirbase(nil, self:GetCoalition())
|
||||||
if _airbase and _airbase:GetCoordinate():Get2DDistance(self:GetCoordinate()) < 3000 then
|
if _airbase and _airbase:GetCoordinate():Get2DDistance(self:GetCoordinate()) <= 5000 then
|
||||||
self:SetAirbase(_airbase)
|
self:SetAirbase(_airbase)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -3354,7 +3351,7 @@ end
|
|||||||
function WAREHOUSE:onafterStatus(From, Event, To)
|
function WAREHOUSE:onafterStatus(From, Event, To)
|
||||||
|
|
||||||
-- Info.
|
-- Info.
|
||||||
self:I(self.lid..string.format("FSM state %s. Assets=%d (global %d). Requests waiting=%d, pending=%d", self:GetState(), #self.stock, #_WAREHOUSEDB.Assets, #self.queue, #self.pending))
|
self:I(self.lid..string.format("State=%s, Assets=%d, Requests: waiting=%d, pending=%d", self:GetState(), #self.stock, #self.queue, #self.pending))
|
||||||
|
|
||||||
-- Check if any pending jobs are done and can be deleted from the queue.
|
-- Check if any pending jobs are done and can be deleted from the queue.
|
||||||
self:_JobDone()
|
self:_JobDone()
|
||||||
@@ -3729,8 +3726,7 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu
|
|||||||
|
|
||||||
-- If no assignment was given we take the assignment of the request if there is any.
|
-- If no assignment was given we take the assignment of the request if there is any.
|
||||||
if assignment==nil and request.assignment~=nil then
|
if assignment==nil and request.assignment~=nil then
|
||||||
-- WARNING: not doing this any more
|
assignment=request.assignment
|
||||||
--assignment=request.assignment
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -3760,7 +3756,7 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Set skill.
|
-- Set skill.
|
||||||
asset.skill=skill
|
asset.skill=skill or asset.skill
|
||||||
|
|
||||||
-- Asset is not spawned.
|
-- Asset is not spawned.
|
||||||
asset.spawned=false
|
asset.spawned=false
|
||||||
@@ -3985,7 +3981,7 @@ end
|
|||||||
-- @param #WAREHOUSE.Assetitem asset The asset that has just been added.
|
-- @param #WAREHOUSE.Assetitem asset The asset that has just been added.
|
||||||
-- @param #string assignment The (optional) assignment for the asset.
|
-- @param #string assignment The (optional) assignment for the asset.
|
||||||
function WAREHOUSE:onafterNewAsset(From, Event, To, asset, assignment)
|
function WAREHOUSE:onafterNewAsset(From, Event, To, asset, assignment)
|
||||||
self:T(self.lid..string.format("New asset %s id=%d with assignment %s.", tostring(asset.templatename), asset.uid, tostring(assignment)))
|
self:I(self.lid..string.format("New asset %s id=%d with assignment %s.", tostring(asset.templatename), asset.uid, tostring(assignment)))
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -5608,7 +5604,7 @@ function WAREHOUSE:_SpawnAssetAircraft(alias, asset, request, parking, uncontrol
|
|||||||
end
|
end
|
||||||
|
|
||||||
if asset.payload then
|
if asset.payload then
|
||||||
unit.payload.pylons=asset.payload.pylons
|
unit.payload=asset.payload.pylons
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ AIRWING = {
|
|||||||
|
|
||||||
--- AIRWING class version.
|
--- AIRWING class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
AIRWING.version="0.1.2"
|
AIRWING.version="0.1.3"
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- ToDo list
|
-- ToDo list
|
||||||
@@ -83,7 +83,7 @@ AIRWING.version="0.1.2"
|
|||||||
-- DONE: Build mission queue.
|
-- DONE: Build mission queue.
|
||||||
-- DONE: Find way to start missions.
|
-- DONE: Find way to start missions.
|
||||||
-- TODO: Check if missions are accomplished.
|
-- TODO: Check if missions are accomplished.
|
||||||
-- TODO: Payloads as resources.
|
-- DONE: Payloads as resources.
|
||||||
-- TODO: Spawn in air or hot.
|
-- TODO: Spawn in air or hot.
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -332,10 +332,7 @@ function AIRWING:AddMission(Mission, Nassets, WaypointCoordinate)
|
|||||||
Mission.waypointindex=nil
|
Mission.waypointindex=nil
|
||||||
|
|
||||||
-- Set status to scheduled.
|
-- Set status to scheduled.
|
||||||
Mission.status=AUFTRAG.Status.QUEUED
|
Mission:Queue()
|
||||||
|
|
||||||
-- Todo call FSM event.
|
|
||||||
--Mission:Queue()
|
|
||||||
|
|
||||||
-- Add mission to queue.
|
-- Add mission to queue.
|
||||||
table.insert(self.missionqueue, Mission)
|
table.insert(self.missionqueue, Mission)
|
||||||
@@ -370,8 +367,6 @@ function AIRWING:onafterStart(From, Event, To)
|
|||||||
self:_AddSquadonMenu(squadron)
|
self:_AddSquadonMenu(squadron)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Init status updates.
|
|
||||||
--self:__AirwingStatus(-1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Update status.
|
--- Update status.
|
||||||
@@ -408,20 +403,17 @@ function AIRWING:onafterStatus(From, Event, To)
|
|||||||
local asset=_asset --#AIRWING.SquadronAsset
|
local asset=_asset --#AIRWING.SquadronAsset
|
||||||
local assignment=asset.assignment or "none"
|
local assignment=asset.assignment or "none"
|
||||||
local name=asset.templatename
|
local name=asset.templatename
|
||||||
local task=asset.mission and asset.mission.name or "none"
|
|
||||||
local spawned=tostring(asset.spawned)
|
local spawned=tostring(asset.spawned)
|
||||||
local groupname=asset.spawngroupname
|
local groupname=asset.spawngroupname
|
||||||
local group=nil --Wrapper.Group#GROUP
|
|
||||||
local typename=asset.unittype
|
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
|
||||||
end
|
end
|
||||||
@@ -439,7 +431,6 @@ function AIRWING:onafterStatus(From, Event, To)
|
|||||||
self:MissionRequest(mission)
|
self:MissionRequest(mission)
|
||||||
end
|
end
|
||||||
|
|
||||||
--self:__AirwingStatus(-30)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get next mission.
|
--- 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)
|
self:GetParent(self).onafterNewAsset(self, From, Event, To, asset, assignment)
|
||||||
|
|
||||||
-- Get squadron.
|
-- 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!
|
-- 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)
|
function AIRWING:onafterMissionRequest(From, Event, To, Mission)
|
||||||
|
|
||||||
-- Set mission status to ASSIGNED.
|
-- 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).
|
-- 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
|
-- 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!
|
--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.
|
-- Check if the payload of this asset is compatible with the mission.
|
||||||
if self:CheckMissionType(MissionType, asset.payload.missiontypes) then
|
if self:CheckMissionType(MissionType, asset.payload.missiontypes) then
|
||||||
@@ -891,6 +882,20 @@ function AIRWING:IsAssetOnMission(asset, MissionTypes)
|
|||||||
return false
|
return false
|
||||||
end
|
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.
|
--- Check if assets for a given mission type are available.
|
||||||
-- @param #AIRWING self
|
-- @param #AIRWING self
|
||||||
-- @param #string MissionType Type of mission.
|
-- @param #string MissionType Type of mission.
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ AUFTRAG.Status={
|
|||||||
|
|
||||||
--- AUFTRAG class version.
|
--- AUFTRAG class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
AUFTRAG.version="0.0.2"
|
AUFTRAG.version="0.0.3"
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- TODO list
|
-- TODO list
|
||||||
@@ -439,6 +439,65 @@ end
|
|||||||
-- FSM Functions
|
-- 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
|
-- Misc Functions
|
||||||
@@ -468,13 +527,16 @@ end
|
|||||||
-- @param Core.Point#COORDINATE The target coordinate or nil.
|
-- @param Core.Point#COORDINATE The target coordinate or nil.
|
||||||
function AUFTRAG:GetTargetCoordinate()
|
function AUFTRAG:GetTargetCoordinate()
|
||||||
|
|
||||||
if self.engageTargetGroupset then
|
if self.engageTargetGroupset then
|
||||||
|
|
||||||
local group=self.engageTargetGroupset:GetFirst() --Wrapper.Group#GROUP
|
local group=self.engageTargetGroupset:GetFirst() --Wrapper.Group#GROUP
|
||||||
return group:GetCoordinate()
|
return group:GetCoordinate()
|
||||||
elseif self.engageTargetUnitset then
|
elseif self.engageTargetUnitset then
|
||||||
local unit=self.engageTargetUnitset:GetFirst() --Wrapper.Unit#UNIT
|
local unit=self.engageTargetUnitset:GetFirst() --Wrapper.Unit#UNIT
|
||||||
return unit:GetCoordinate()
|
return unit:GetCoordinate()
|
||||||
|
elseif self.engageCoord then
|
||||||
|
return self.engageCoord
|
||||||
|
elseif self.orbitCoord then
|
||||||
|
return self.orbitCoord
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -661,6 +723,7 @@ function AUFTRAG:GetDCSMissionTask()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Return the task.
|
||||||
if #DCStasks==1 then
|
if #DCStasks==1 then
|
||||||
return DCStasks[1]
|
return DCStasks[1]
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ FLIGHTGROUP.TaskType={
|
|||||||
|
|
||||||
--- FLIGHTGROUP class version.
|
--- FLIGHTGROUP class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
FLIGHTGROUP.version="0.3.2"
|
FLIGHTGROUP.version="0.3.3"
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- TODO list
|
-- TODO list
|
||||||
@@ -407,7 +407,7 @@ function FLIGHTGROUP:New(groupname, autostart)
|
|||||||
|
|
||||||
self:AddTransition("*", "PassingWaypoint", "*") -- Group passed a waypoint.
|
self:AddTransition("*", "PassingWaypoint", "*") -- Group passed a waypoint.
|
||||||
self:AddTransition("*", "GotoWaypoint", "*") -- Group switches to a specific 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("*", "FuelLow", "*") -- Fuel state of group is low. Default ~25%.
|
||||||
self:AddTransition("*", "FuelCritical", "*") -- Fuel state of group is critical. Default ~10%.
|
self:AddTransition("*", "FuelCritical", "*") -- Fuel state of group is critical. Default ~10%.
|
||||||
@@ -667,10 +667,8 @@ function FLIGHTGROUP:AddMission(Mission, WaypointCoordinate, WaypointIndex)
|
|||||||
Mission.waypointindex=WaypointIndex
|
Mission.waypointindex=WaypointIndex
|
||||||
|
|
||||||
-- Set status to scheduled.
|
-- Set status to scheduled.
|
||||||
Mission.status=AUFTRAG.Status.SCHEDULED
|
Mission:Schedule()
|
||||||
|
--Mission.status=AUFTRAG.Status.SCHEDULED
|
||||||
-- Route flight to mission zone.
|
|
||||||
--self:RouteToMission(Mission)
|
|
||||||
|
|
||||||
-- Add mission to queue.
|
-- Add mission to queue.
|
||||||
table.insert(self.missionqueue, Mission)
|
table.insert(self.missionqueue, Mission)
|
||||||
@@ -1319,9 +1317,9 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To)
|
|||||||
end
|
end
|
||||||
-- Output text for element.
|
-- Output text for element.
|
||||||
if task.type==FLIGHTGROUP.TaskType.SCHEDULED then
|
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
|
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
|
||||||
end
|
end
|
||||||
if #self.taskqueue>0 then
|
if #self.taskqueue>0 then
|
||||||
@@ -1337,11 +1335,11 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To)
|
|||||||
local mymission=Mission and Mission.name or "none"
|
local mymission=Mission and Mission.name or "none"
|
||||||
|
|
||||||
-- Current status.
|
-- 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
|
for i,_mission in pairs(self.missionqueue) do
|
||||||
local mission=_mission --Ops.Auftrag#AUFTRAG
|
local mission=_mission --Ops.Auftrag#AUFTRAG
|
||||||
local Cstart= UTILS.SecondsToClock(mission.Tstart, true)
|
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",
|
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())
|
i, tostring(mission.name), mission.type, tostring(mission.status), Cstart, Cstop, tostring(mission.waypointindex), mission.prio, mission:CountMissionTargets())
|
||||||
end
|
end
|
||||||
@@ -2310,11 +2308,11 @@ end
|
|||||||
-- @param #number n Waypoint number passed.
|
-- @param #number n Waypoint number passed.
|
||||||
-- @param #number N Final waypoint number.
|
-- @param #number N Final waypoint number.
|
||||||
function FLIGHTGROUP:onafterPassingWaypoint(From, Event, To, n, N)
|
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)
|
self:I(self.lid..text)
|
||||||
MESSAGE:New(text, 30, "DEBUG"):ToAllIf(self.Debug)
|
MESSAGE:New(text, 30, "DEBUG"):ToAllIf(self.Debug)
|
||||||
|
|
||||||
--[[
|
if true then
|
||||||
|
|
||||||
-- Get all waypoint tasks.
|
-- Get all waypoint tasks.
|
||||||
local tasks=self:GetTasksWaypoint(n)
|
local tasks=self:GetTasksWaypoint(n)
|
||||||
@@ -2359,19 +2357,21 @@ function FLIGHTGROUP:onafterPassingWaypoint(From, Event, To, n, N)
|
|||||||
self:SetTask(self.group:TaskCombo(taskswp))
|
self:SetTask(self.group:TaskCombo(taskswp))
|
||||||
end
|
end
|
||||||
|
|
||||||
]]
|
end
|
||||||
|
|
||||||
-- Final AIR waypoint reached?
|
-- 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
|
if self.destbase then
|
||||||
self:__RTB(-1, self.destbase)
|
self:__RTB(-1, self.destbase)
|
||||||
elseif self.destzone then
|
elseif self.destzone then
|
||||||
self:__RTZ(-1, self.destzone)
|
self:__RTZ(-1, self.destzone)
|
||||||
else
|
else
|
||||||
|
self:__Wait(-1)
|
||||||
self:E(self.lid.."ERROR: Reached final waypoint but no destination set! Don't know what to do?!")
|
self:E(self.lid.."ERROR: Reached final waypoint but no destination set! Don't know what to do?!")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -2406,28 +2406,6 @@ function FLIGHTGROUP:onafterGotoWaypoint(From, Event, To, n)
|
|||||||
|
|
||||||
end
|
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.
|
--- On before "RTB" event.
|
||||||
-- @param #FLIGHTGROUP self
|
-- @param #FLIGHTGROUP self
|
||||||
-- @param #string From From state.
|
-- @param #string From From state.
|
||||||
@@ -2442,13 +2420,13 @@ function FLIGHTGROUP:onbeforeRTB(From, Event, To, airbase, SpeedTo, SpeedHold)
|
|||||||
local Tsuspend=nil
|
local Tsuspend=nil
|
||||||
|
|
||||||
if airbase==nil then
|
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
|
allowed=false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check that coaliton is okay. We allow same (blue=blue, red=red) or landing on neutral bases.
|
-- 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
|
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
|
allowed=false
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -2456,19 +2434,19 @@ function FLIGHTGROUP:onbeforeRTB(From, Event, To, airbase, SpeedTo, SpeedHold)
|
|||||||
local Ntot,Nsched, Nwp=self:CountRemainingTasks()
|
local Ntot,Nsched, Nwp=self:CountRemainingTasks()
|
||||||
|
|
||||||
if self.taskcurrent>0 then
|
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
|
Tsuspend=-10
|
||||||
allowed=false
|
allowed=false
|
||||||
end
|
end
|
||||||
|
|
||||||
if Nsched>0 then
|
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
|
Tsuspend=-10
|
||||||
allowed=false
|
allowed=false
|
||||||
end
|
end
|
||||||
|
|
||||||
if Nwp>0 then
|
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
|
Tsuspend=-10
|
||||||
allowed=false
|
allowed=false
|
||||||
end
|
end
|
||||||
@@ -2586,6 +2564,76 @@ function FLIGHTGROUP:onafterRTB(From, Event, To, airbase, SpeedTo, SpeedHold, Sp
|
|||||||
|
|
||||||
end
|
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.
|
--- On after "Holding" event. Flight arrived at the holding point.
|
||||||
-- @param #FLIGHTGROUP self
|
-- @param #FLIGHTGROUP self
|
||||||
-- @param #string From From state.
|
-- @param #string From From state.
|
||||||
@@ -2819,8 +2867,9 @@ function FLIGHTGROUP:CountRemainingTasks()
|
|||||||
Ntot=Ntot+1
|
Ntot=Ntot+1
|
||||||
|
|
||||||
if task.type==FLIGHTGROUP.TaskType.WAYPOINT then
|
if task.type==FLIGHTGROUP.TaskType.WAYPOINT then
|
||||||
|
--TODO: maybe check that waypoint was not already passed?
|
||||||
Nwp=Nwp+1
|
Nwp=Nwp+1
|
||||||
elseif task.type==FLIGHTGROUP.TaskType.WAYPOINT then
|
elseif task.type==FLIGHTGROUP.TaskType.SCHEDULED then
|
||||||
Nsched=Nsched+1
|
Nsched=Nsched+1
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -2831,6 +2880,23 @@ function FLIGHTGROUP:CountRemainingTasks()
|
|||||||
return Ntot, Nsched, Nwp
|
return Ntot, Nsched, Nwp
|
||||||
end
|
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.
|
--- On after TaskExecute event.
|
||||||
-- @param #FLIGHTGROUP self
|
-- @param #FLIGHTGROUP self
|
||||||
@@ -2889,15 +2955,15 @@ function FLIGHTGROUP:onafterTaskExecute(From, Event, To, Task)
|
|||||||
|
|
||||||
-- Set task for group.
|
-- Set task for group.
|
||||||
self:SetTask(TaskFinal, 1)
|
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
|
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
|
end
|
||||||
|
|
||||||
@@ -3058,7 +3124,8 @@ function FLIGHTGROUP:onafterMissionStart(From, Event, To, Mission)
|
|||||||
self.currentmission=Mission.auftragsnummer
|
self.currentmission=Mission.auftragsnummer
|
||||||
|
|
||||||
-- Set mission status.
|
-- Set mission status.
|
||||||
Mission.status=AUFTRAG.Status.STARTED
|
Mission:Start()
|
||||||
|
--Mission.status=AUFTRAG.Status.STARTED
|
||||||
|
|
||||||
-- Route flight to mission zone.
|
-- Route flight to mission zone.
|
||||||
self:RouteToMission(Mission, 5)
|
self:RouteToMission(Mission, 5)
|
||||||
@@ -3077,7 +3144,8 @@ function FLIGHTGROUP:onafterMissionExecute(From, Event, To, Mission)
|
|||||||
self:I(self.lid..text)
|
self:I(self.lid..text)
|
||||||
MESSAGE:New(text, 120, "DEBUG"):ToAllIf(true)
|
MESSAGE:New(text, 120, "DEBUG"):ToAllIf(true)
|
||||||
|
|
||||||
Mission.status=AUFTRAG.Status.EXECUTING
|
Mission:Execute()
|
||||||
|
--Mission.status=AUFTRAG.Status.EXECUTING
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -3110,7 +3178,8 @@ function FLIGHTGROUP:onafterMissionDone(From, Event, To, Mission)
|
|||||||
|
|
||||||
-- TODO: evaluate mission success or failure! complicated!
|
-- TODO: evaluate mission success or failure! complicated!
|
||||||
|
|
||||||
Mission.status=AUFTRAG.Status.DONE
|
--Mission.status=AUFTRAG.Status.DONE
|
||||||
|
Mission:Done()
|
||||||
|
|
||||||
local airwing=self:GetAirWing()
|
local airwing=self:GetAirWing()
|
||||||
if airwing then
|
if airwing then
|
||||||
@@ -3659,20 +3728,29 @@ end
|
|||||||
-- @return Ops.Auftrag#AUFTRAG The mission.
|
-- @return Ops.Auftrag#AUFTRAG The mission.
|
||||||
function FLIGHTGROUP:GetMissionByTaskID(taskid)
|
function FLIGHTGROUP:GetMissionByTaskID(taskid)
|
||||||
|
|
||||||
for _,_mission in pairs(self.missionqueue) do
|
if taskid then
|
||||||
local mission=_mission --Ops.Auftrag#AUFTRAG
|
for _,_mission in pairs(self.missionqueue) do
|
||||||
|
local mission=_mission --Ops.Auftrag#AUFTRAG
|
||||||
local task=mission.waypointtask
|
|
||||||
|
local task=mission.waypointtask
|
||||||
if task and task.id and task.id==taskid then
|
|
||||||
return mission
|
if task and task.id and task.id==taskid then
|
||||||
|
return mission
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
end
|
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.
|
--- Get next waypoint of the flight group.
|
||||||
-- @param #FLIGHTGROUP self
|
-- @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.
|
-- 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.
|
-- I have moved it to the onafterpassingwaypoint function instead.
|
||||||
|
|
||||||
if true then
|
if false then
|
||||||
|
|
||||||
-- Get taks
|
-- Get taks
|
||||||
local tasks=self:GetTasksWaypoint(i)
|
local tasks=self:GetTasksWaypoint(i)
|
||||||
|
|
||||||
for _,task in pairs(tasks) do
|
|
||||||
local Task=task --#FLIGHTGROUP.Task
|
|
||||||
|
|
||||||
-- Task execute.
|
for _,task in pairs(tasks) do
|
||||||
table.insert(taskswp, self.group:TaskFunction("FLIGHTGROUP._TaskExecute", self, Task))
|
local Task=task --#FLIGHTGROUP.Task
|
||||||
|
|
||||||
-- Stop condition if userflag is set to 1.
|
-- Task execute.
|
||||||
local TaskCondition=self.group:TaskCondition(nil, Task.stopflag:GetName(), 1, nil, Task.duration)
|
table.insert(taskswp, self.group:TaskFunction("FLIGHTGROUP._TaskExecute", self, Task))
|
||||||
|
|
||||||
-- Controlled task.
|
-- Stop condition if userflag is set to 1.
|
||||||
table.insert(taskswp, self.group:TaskControlled(Task.dcstask, TaskCondition))
|
local TaskCondition=self.group:TaskCondition(nil, Task.stopflag:GetName(), 1, nil, Task.duration)
|
||||||
|
|
||||||
-- Task done.
|
-- Controlled task.
|
||||||
table.insert(taskswp, self.group:TaskFunction("FLIGHTGROUP._TaskDone", self, Task))
|
table.insert(taskswp, self.group:TaskControlled(Task.dcstask, TaskCondition))
|
||||||
|
|
||||||
end
|
-- Task done.
|
||||||
|
table.insert(taskswp, self.group:TaskFunction("FLIGHTGROUP._TaskDone", self, Task))
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user