mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-08-13 17:31:41 +00:00
Ops
This commit is contained in:
@@ -131,8 +131,7 @@ function AIRWING:New(warehousename, airwingname)
|
||||
-- Add FSM transitions.
|
||||
-- From State --> Event --> To State
|
||||
self:AddTransition("*", "MissionRequest", "*") -- Add a (mission) request to the warehouse.
|
||||
self:AddTransition("*", "MissionDone", "*") -- Mission is over.
|
||||
self:AddTransition("*", "MissionCancel", "*") -- Mission is over.
|
||||
self:AddTransition("*", "MissionCancel", "*") -- Cancel mission.
|
||||
|
||||
------------------------
|
||||
--- Pseudo Functions ---
|
||||
@@ -223,6 +222,11 @@ function AIRWING:NewPayload(Unit, MissionTypes, Npayloads, Unlimited)
|
||||
if Unit:IsInstanceOf("GROUP") then
|
||||
Unit=Unit:GetUnit(1)
|
||||
end
|
||||
|
||||
-- Ensure Missiontypes is a table.
|
||||
if MissionTypes and type(MissionTypes)~="table" then
|
||||
MissionTypes={MissionTypes}
|
||||
end
|
||||
|
||||
if Unit then
|
||||
|
||||
@@ -512,6 +516,13 @@ function AIRWING:onafterStatus(From, Event, To)
|
||||
|
||||
text=text..string.format("\n -[%d] %s*%d: spawned=%s, mission=%s%s", j, typename, asset.nunits, spawned, tostring(self:IsAssetOnMission(asset)), missiontext)
|
||||
|
||||
local payload=asset.payload
|
||||
if payload then
|
||||
text=text.." payload "..table.concat(payload.missiontypes, ", ")
|
||||
else
|
||||
text=text.." NO payload!"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
self:I(self.lid..text)
|
||||
@@ -798,6 +809,10 @@ function AIRWING:onafterNewAsset(From, Event, To, asset, assignment)
|
||||
-- Call parent warehouse function first.
|
||||
self:GetParent(self).onafterNewAsset(self, From, Event, To, asset, assignment)
|
||||
|
||||
-- Debug text.
|
||||
local text=string.format("New asset %s with assignment %s and request assignment %s", asset.spawngroupname, tostring(asset.assignment), tostring(assignment))
|
||||
self:I(self.lid..text)
|
||||
|
||||
-- Get squadron.
|
||||
local squad=self:GetSquadron(asset.assignment)
|
||||
|
||||
@@ -815,14 +830,21 @@ function AIRWING:onafterNewAsset(From, Event, To, asset, assignment)
|
||||
|
||||
else
|
||||
|
||||
self:I(self.lid..string.format("Asset %s from squadron %s returned! asset.assignment=\"%s\", assignment=\"%s\"", asset.spawngroupname, squad.name, tostring(asset.assignment), tostring(assignment)))
|
||||
self:ReturnPayloadFromAsset(asset)
|
||||
|
||||
-- Mission might already be removed from the queue!
|
||||
--[[
|
||||
local mission=self:GetMissionByID(assignment)
|
||||
|
||||
if mission then
|
||||
local text=string.format("Asset %s returned from %s mission %s", asset.spawngroupname, mission.type, mission.name)
|
||||
self:I(self.lid..text)
|
||||
self:ReturnPayloadFromAsset(asset)
|
||||
else
|
||||
self:E(self.lid.."ERROR: new asset not beloning to any s")
|
||||
self:E(self.lid..string.format("ERROR: asset %s from squadron %s returned but could not find its mission! asset.assignment=\"%s\", assignment=\"%s\"", asset.spawngroupname, squad.name, tostring(asset.assignment), tostring(assignment)))
|
||||
end
|
||||
]]
|
||||
|
||||
end
|
||||
|
||||
@@ -1189,7 +1211,10 @@ function AIRWING:CanMission(MissionType, Nassets)
|
||||
-- Now clear all reserved payloads.
|
||||
for _,_asset in pairs(Assets) do
|
||||
local asset=_asset --#AIRWING.SquadronAsset
|
||||
self:ReturnPayloadFromAsset(asset)
|
||||
-- Only unspawned payloads are returned.
|
||||
if not asset.spawned then
|
||||
self:ReturnPayloadFromAsset(asset)
|
||||
end
|
||||
end
|
||||
|
||||
return Can, Assets
|
||||
|
||||
@@ -703,6 +703,12 @@ end
|
||||
-- @param #string status New status.
|
||||
function AUFTRAG:SetFlightStatus(flightgroup, status)
|
||||
self.flightdata[flightgroup.groupname].status=status
|
||||
|
||||
-- Check if ALL flights are done with their mission.
|
||||
if self:IsNotOver() and self:CheckFlightsDone() then
|
||||
self:Done()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Get flightgroup mission status.
|
||||
@@ -907,7 +913,7 @@ end
|
||||
--- Add asset to mission.
|
||||
-- @param #AUFTRAG self
|
||||
-- @param Ops.AirWing#AIRWING.SquadronAsset Asset The asset to be added to the mission.
|
||||
-- @return #AIRWING self
|
||||
-- @return #AUFTRAG self
|
||||
function AUFTRAG:AddAsset(Asset)
|
||||
|
||||
self.assets=self.assets or {}
|
||||
@@ -920,7 +926,7 @@ end
|
||||
--- Delete asset from mission.
|
||||
-- @param #AUFTRAG self
|
||||
-- @param Ops.AirWing#AIRWING.SquadronAsset Asset The asset to be removed.
|
||||
-- @return #AIRWING self
|
||||
-- @return #AUFTRAG self
|
||||
function AUFTRAG:DelAsset(Asset)
|
||||
|
||||
for i,_asset in pairs(self.assets or {}) do
|
||||
@@ -928,10 +934,12 @@ function AUFTRAG:DelAsset(Asset)
|
||||
|
||||
if asset.uid==Asset.uid then
|
||||
table.remove(self.assets, i)
|
||||
return self
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
@@ -1006,6 +1014,19 @@ function AUFTRAG:GetTargetCoordinate()
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Get coordinate of target. First unit/group of the set is used.
|
||||
-- @param #AUFTRAG self
|
||||
-- @return #string
|
||||
function AUFTRAG:GetMissionTypesText(MissionTypes)
|
||||
|
||||
local text=""
|
||||
for _,missiontype in pairs(MissionTypes) do
|
||||
text=text..string.format("%s, ", missiontype)
|
||||
end
|
||||
|
||||
return text
|
||||
end
|
||||
|
||||
--- Get DCS task table for the given mission.
|
||||
-- @param #AUFTRAG self
|
||||
-- @return DCS#Task The DCS task table. If multiple tasks are necessary, this is returned as a combo task.
|
||||
|
||||
@@ -49,7 +49,8 @@
|
||||
-- @field #boolean fuellowrtb RTB on low fuel switch.
|
||||
-- @field #boolean fuelcritical Fuel critical switch.
|
||||
-- @field #number fuelcriticalthresh Critical fuel threshold in percent.
|
||||
-- @field #boolean fuelcriticalrtb RTB on critical fuel switch.
|
||||
-- @field #boolean fuelcriticalrtb RTB on critical fuel switch.
|
||||
-- @field #boolean passedfinalwp Group has passed the final waypoint.
|
||||
-- @field Ops.Airwing#AIRWING airwing The airwing the flight group belongs to.
|
||||
-- @field Ops.FlightControl#FLIGHTCONTROL flightcontrol The flightcontrol handling this group.
|
||||
-- @field Core.UserFlag#USERFLAG flaghold Flag for holding.
|
||||
@@ -1265,7 +1266,7 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To)
|
||||
local nTaskTot, nTaskSched, nTaskWP=self:CountRemainingTasks()
|
||||
|
||||
-- Short info.
|
||||
local text=string.format("Flight status %s [%d/%d]. Tasks=%d (%d,%d) Current=%d. Waypoint=%d/%d. Detected=%d. Destination=%s, FC=%s",
|
||||
local text=string.format("Status %s [%d/%d]: Tasks=%d (%d,%d) Current=%d. Waypoint=%d/%d. Detected=%d. Destination=%s, FC=%s",
|
||||
fsmstate, #self.elements, #self.elements, nTaskTot, nTaskSched, nTaskWP, self.taskcurrent, self.currentwp or 0, self.waypoints and #self.waypoints or 0,
|
||||
self.detectedunits:Count(), self.destbase and self.destbase:GetName() or "unknown", self.flightcontrol and self.flightcontrol.airbasename or "none")
|
||||
self:I(self.lid..text)
|
||||
@@ -2215,7 +2216,6 @@ function FLIGHTGROUP:onafterUpdateRoute(From, Event, To, n)
|
||||
MESSAGE:New(text, 10):ToAllIf(false)
|
||||
self:I(self.lid..text)
|
||||
|
||||
|
||||
-- Update waypoint tasks, i.e. inject WP tasks into waypoint table.
|
||||
self:_UpdateWaypointTasks()
|
||||
|
||||
@@ -2270,22 +2270,25 @@ function FLIGHTGROUP:onafterUpdateRoute(From, Event, To, n)
|
||||
-- No waypoints left
|
||||
---
|
||||
|
||||
self:E(self.lid.."WARNING: No waypoints left. Dunno what to do!")
|
||||
if self.passedfinalwp then
|
||||
|
||||
--[[
|
||||
self:I(self.lid.."UpdateRoute: Passed Final WP ==> RTB/RTZ/Wait!")
|
||||
|
||||
-- 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)
|
||||
-- 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:I(self.lid.."UpdateRoute: Passed Final WP ==> RTB!")
|
||||
self:__RTB(-1, self.destbase)
|
||||
elseif self.destzone then
|
||||
self:I(self.lid.."UpdateRoute: Passed Final WP ==> RTZ!")
|
||||
self:__RTZ(-1, self.destzone)
|
||||
else
|
||||
self:I(self.lid.."UpdateRoute: Passed Final WP ==> Wait!")
|
||||
self:__Wait(-1)
|
||||
end
|
||||
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.."WARNING: No waypoints left. Dunno what to do!")
|
||||
end
|
||||
|
||||
]]
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -2298,6 +2301,8 @@ end
|
||||
-- @param #table Template The template used to respawn the group.
|
||||
function FLIGHTGROUP:onafterRespawn(From, Event, To, Template)
|
||||
|
||||
self:I(self.lid.."Respawning group!")
|
||||
|
||||
local template=UTILS.DeepCopy(Template or self.template)
|
||||
|
||||
if self.group and self.group:InAir() then
|
||||
@@ -2320,14 +2325,12 @@ function FLIGHTGROUP:onafterPassingWaypoint(From, Event, To, 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)
|
||||
|
||||
-- Debug info.
|
||||
local text=string.format("WP %d/%d tasks:", n, N)
|
||||
if tasks then
|
||||
if #tasks>0 then
|
||||
for i,_task in pairs(tasks) do
|
||||
local task=_task --#FLIGHTGROUP.Task
|
||||
text=text..string.format("\n[%d] %s", i, task.description)
|
||||
@@ -2365,27 +2368,26 @@ function FLIGHTGROUP:onafterPassingWaypoint(From, Event, To, n, N)
|
||||
self:PushTask(self.group:TaskCombo(taskswp))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- Final AIR waypoint reached?
|
||||
if n==N then
|
||||
|
||||
--TODO: Find better way to RTB!
|
||||
self:I(self.lid.."FF group passed final waypoint!")
|
||||
|
||||
--[[
|
||||
|
||||
-- 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
|
||||
|
||||
]]
|
||||
self.passedfinalwp=true
|
||||
|
||||
if #taskswp==0 then
|
||||
|
||||
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
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -2480,6 +2482,8 @@ end
|
||||
-- @param #number SpeedHold Holding speed in knots. Default 250 kts.
|
||||
-- @param #number SpeedLand Landing speed in knots. Default 170 kts.
|
||||
function FLIGHTGROUP:onafterRTB(From, Event, To, airbase, SpeedTo, SpeedHold, SpeedLand)
|
||||
|
||||
self:I(self.lid..string.format("RTB: event=%s: %s --> %s", Event, From, To))
|
||||
|
||||
-- Defaults:
|
||||
SpeedTo=SpeedTo or 350
|
||||
@@ -2559,10 +2563,13 @@ function FLIGHTGROUP:onafterRTB(From, Event, To, airbase, SpeedTo, SpeedHold, Sp
|
||||
if fc or world.event.S_EVENT_KILL then
|
||||
|
||||
-- Just route the group. Respawn will happen when going from holding to final.
|
||||
env.info("FF route (not repawn)")
|
||||
self:Route(wp, 1)
|
||||
|
||||
else
|
||||
|
||||
env.info("FF respawn (not route)")
|
||||
|
||||
-- Get group template.
|
||||
local Template=self.group:GetTemplate()
|
||||
|
||||
@@ -3958,6 +3965,13 @@ function FLIGHTGROUP:InitWaypoints(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
|
||||
|
||||
@@ -3977,6 +3991,10 @@ function FLIGHTGROUP:AddWaypointAir(coordinate, wpnumber, speed, updateroute)
|
||||
--TODO: by default add after last AIR waypoint! Last WP could be landing...
|
||||
wpnumber=wpnumber or #self.waypoints+1
|
||||
|
||||
if wpnumber>self.currentwp then
|
||||
self.passedfinalwp=false
|
||||
end
|
||||
|
||||
-- Speed in knots.
|
||||
speed=speed or 350
|
||||
|
||||
@@ -4006,7 +4024,7 @@ function FLIGHTGROUP:AddWaypointAir(coordinate, wpnumber, speed, updateroute)
|
||||
if mission.waypointindex and mission.waypointindex>=wpnumber then
|
||||
mission.waypointindex=mission.waypointindex+1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Update route.
|
||||
if updateroute==nil or updateroute==true then
|
||||
|
||||
Reference in New Issue
Block a user