mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-08-21 11:53:30 +00:00
Ops
This commit is contained in:
@@ -3793,9 +3793,9 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu
|
|||||||
|
|
||||||
-- Destroy group if it is alive.
|
-- Destroy group if it is alive.
|
||||||
if group:IsAlive()==true then
|
if group:IsAlive()==true then
|
||||||
self:_DebugMessage(string.format("Destroying group %s.", group:GetName()), 5)
|
self:_DebugMessage(string.format("Removing group %s.", group:GetName()), 5)
|
||||||
-- Setting parameter to false, i.e. creating NO dead or remove unit event, seems to not confuse the dispatcher logic.
|
-- Setting parameter to false, i.e. creating NO dead or remove unit event, seems to not confuse the dispatcher logic.
|
||||||
group:Destroy(false)
|
group:Destroy()
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
@@ -5021,7 +5021,7 @@ end
|
|||||||
-- @param #WAREHOUSE.Pendingitem request The request of the dead asset.
|
-- @param #WAREHOUSE.Pendingitem request The request of the dead asset.
|
||||||
function WAREHOUSE:onafterAssetSpawned(From, Event, To, group, asset, request)
|
function WAREHOUSE:onafterAssetSpawned(From, Event, To, group, asset, request)
|
||||||
local text=string.format("Asset %s from request id=%d was spawned!", asset.templatename, request.uid)
|
local text=string.format("Asset %s from request id=%d was spawned!", asset.templatename, request.uid)
|
||||||
self:T(self.wid..text)
|
self:I(self.wid..text)
|
||||||
self:_DebugMessage(text)
|
self:_DebugMessage(text)
|
||||||
|
|
||||||
-- Sete asset state to spawned.
|
-- Sete asset state to spawned.
|
||||||
@@ -6093,29 +6093,34 @@ function WAREHOUSE:_OnEventArrived(EventData)
|
|||||||
if self.uid==wid then
|
if self.uid==wid then
|
||||||
|
|
||||||
local request=self:_GetRequestOfGroup(group, self.pending)
|
local request=self:_GetRequestOfGroup(group, self.pending)
|
||||||
local istransport=self:_GroupIsTransport(group, request)
|
|
||||||
|
|
||||||
-- Get closest airbase.
|
-- Better check that the request still exists, because for a group with more units, the
|
||||||
-- Note, this crashed at somepoint when the Tarawa was in the mission. Don't know why. Deleting the Tarawa and adding it again solved the problem.
|
if request then
|
||||||
local closest=group:GetCoordinate():GetClosestAirbase()
|
|
||||||
|
local istransport=self:_GroupIsTransport(group, request)
|
||||||
-- Check if engine shutdown happend at right airbase because the event is also triggered in other situations.
|
|
||||||
local rightairbase=closest:GetName()==request.warehouse:GetAirbase():GetName()
|
-- Get closest airbase.
|
||||||
|
-- Note, this crashed at somepoint when the Tarawa was in the mission. Don't know why. Deleting the Tarawa and adding it again solved the problem.
|
||||||
-- Check that group is cargo and not transport.
|
local closest=group:GetCoordinate():GetClosestAirbase()
|
||||||
if istransport==false and rightairbase then
|
|
||||||
|
-- Check if engine shutdown happend at right airbase because the event is also triggered in other situations.
|
||||||
-- Debug info.
|
local rightairbase=closest:GetName()==request.warehouse:GetAirbase():GetName()
|
||||||
local text=string.format("Air asset group %s from warehouse %s arrived at its destination.", group:GetName(), self.alias)
|
|
||||||
self:_InfoMessage(text)
|
-- Check that group is cargo and not transport.
|
||||||
|
if istransport==false and rightairbase then
|
||||||
-- Trigger arrived event for this group. Note that each unit of a group will trigger this event. So the onafterArrived function needs to take care of that.
|
|
||||||
-- Actually, we only take the first unit of the group that arrives. If it does, we assume the whole group arrived, which might not be the case, since
|
-- Debug info.
|
||||||
-- some units might still be taxiing or whatever. Therefore, we add 10 seconds for each additional unit of the group until the first arrived event is triggered.
|
local text=string.format("Air asset group %s from warehouse %s arrived at its destination.", group:GetName(), self.alias)
|
||||||
local nunits=#group:GetUnits()
|
self:_InfoMessage(text)
|
||||||
local dt=10*(nunits-1)+1 -- one unit = 1 sec, two units = 11 sec, three units = 21 sec before we call the group arrived.
|
|
||||||
self:__Arrived(dt, group)
|
-- Trigger arrived event for this group. Note that each unit of a group will trigger this event. So the onafterArrived function needs to take care of that.
|
||||||
|
-- Actually, we only take the first unit of the group that arrives. If it does, we assume the whole group arrived, which might not be the case, since
|
||||||
|
-- some units might still be taxiing or whatever. Therefore, we add 10 seconds for each additional unit of the group until the first arrived event is triggered.
|
||||||
|
local nunits=#group:GetUnits()
|
||||||
|
local dt=10*(nunits-1)+1 -- one unit = 1 sec, two units = 11 sec, three units = 21 sec before we call the group arrived.
|
||||||
|
self:__Arrived(dt, group)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ function FLIGHTCONTROL:New(airbasename)
|
|||||||
self:AddTransition("*", "Status", "*") -- Update status.
|
self:AddTransition("*", "Status", "*") -- Update status.
|
||||||
|
|
||||||
-- Debug trace.
|
-- Debug trace.
|
||||||
if true then
|
if false then
|
||||||
self.Debug=true
|
self.Debug=true
|
||||||
BASE:TraceOnOff(true)
|
BASE:TraceOnOff(true)
|
||||||
BASE:TraceClass(self.ClassName)
|
BASE:TraceClass(self.ClassName)
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
-- @field #string type Aircraft type of flight group.
|
-- @field #string type Aircraft type of flight group.
|
||||||
-- @field #table elements Table of elements, i.e. units of the group.
|
-- @field #table elements Table of elements, i.e. units of the group.
|
||||||
-- @field #table waypoints Table of waypoints.
|
-- @field #table waypoints Table of waypoints.
|
||||||
|
-- @field #table waypoints0 Table of initial waypoints.
|
||||||
-- @field #table coordinates Table of waypoint coordinates.
|
-- @field #table coordinates Table of waypoint coordinates.
|
||||||
-- @field #table taskqueue Queue of tasks.
|
-- @field #table taskqueue Queue of tasks.
|
||||||
-- @field #number taskcounter Running number of task ids.
|
-- @field #number taskcounter Running number of task ids.
|
||||||
@@ -70,6 +71,7 @@ FLIGHTGROUP = {
|
|||||||
grouptemplate = nil,
|
grouptemplate = nil,
|
||||||
type = nil,
|
type = nil,
|
||||||
waypoints = nil,
|
waypoints = nil,
|
||||||
|
waypoints0 = nil,
|
||||||
coordinates = {},
|
coordinates = {},
|
||||||
elements = {},
|
elements = {},
|
||||||
taskqueue = {},
|
taskqueue = {},
|
||||||
@@ -333,7 +335,7 @@ function FLIGHTGROUP:New(groupname)
|
|||||||
|
|
||||||
|
|
||||||
-- Debug trace.
|
-- Debug trace.
|
||||||
if true then
|
if false then
|
||||||
self.Debug=true
|
self.Debug=true
|
||||||
BASE:TraceOnOff(true)
|
BASE:TraceOnOff(true)
|
||||||
BASE:TraceClass(self.ClassName)
|
BASE:TraceClass(self.ClassName)
|
||||||
@@ -434,6 +436,10 @@ function FLIGHTGROUP:AddTaskWaypoint(description, task, waypointindex, prio, dur
|
|||||||
|
|
||||||
-- Add to table.
|
-- Add to table.
|
||||||
table.insert(self.taskqueue, newtask)
|
table.insert(self.taskqueue, newtask)
|
||||||
|
|
||||||
|
if self.group and self.group:IsAlive() then
|
||||||
|
self:_UpdateRoute(self.currentwp)
|
||||||
|
end
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@@ -643,19 +649,25 @@ function FLIGHTGROUP:onafterStart(From, Event, To)
|
|||||||
|
|
||||||
-- Check if the group is already alive and if so, add its elements.
|
-- Check if the group is already alive and if so, add its elements.
|
||||||
local group=GROUP:FindByName(self.groupname)
|
local group=GROUP:FindByName(self.groupname)
|
||||||
|
|
||||||
if group and group:IsAlive() then
|
if group and group:IsAlive() then
|
||||||
|
|
||||||
|
-- Set group object.
|
||||||
|
env.info("FF setting self.group object")
|
||||||
self.group=group
|
self.group=group
|
||||||
|
|
||||||
local units=group:GetUnits()
|
local units=group:GetUnits()
|
||||||
|
|
||||||
for _,_unit in pairs(units) do
|
for _,_unit in pairs(units) do
|
||||||
local unit=_unit --Wrapper.Unit#UNIT
|
local unit=_unit --Wrapper.Unit#UNIT
|
||||||
local element=self:AddElementByName(unit:GetName())
|
local element=self:AddElementByName(unit:GetName())
|
||||||
|
|
||||||
-- Trigger Spawned event. Delay a bit to start.
|
-- Trigger Spawned event.
|
||||||
self:__ElementSpawned(0.1, element)
|
self:ElementSpawned(element)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Handle events:
|
-- Handle events:
|
||||||
self:HandleEvent(EVENTS.Birth, self.OnEventBirth)
|
self:HandleEvent(EVENTS.Birth, self.OnEventBirth)
|
||||||
self:HandleEvent(EVENTS.EngineStartup, self.OnEventEngineStartup)
|
self:HandleEvent(EVENTS.EngineStartup, self.OnEventEngineStartup)
|
||||||
@@ -665,6 +677,7 @@ function FLIGHTGROUP:onafterStart(From, Event, To)
|
|||||||
self:HandleEvent(EVENTS.PilotDead, self.OnEventPilotDead)
|
self:HandleEvent(EVENTS.PilotDead, self.OnEventPilotDead)
|
||||||
self:HandleEvent(EVENTS.Ejection, self.OnEventEjection)
|
self:HandleEvent(EVENTS.Ejection, self.OnEventEjection)
|
||||||
self:HandleEvent(EVENTS.Crash, self.OnEventCrash)
|
self:HandleEvent(EVENTS.Crash, self.OnEventCrash)
|
||||||
|
self:HandleEvent(EVENTS.RemoveUnit, self.OnEventRemoveUnit)
|
||||||
|
|
||||||
-- Start the status monitoring.
|
-- Start the status monitoring.
|
||||||
self:__FlightStatus(-1)
|
self:__FlightStatus(-1)
|
||||||
@@ -686,7 +699,8 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To)
|
|||||||
|
|
||||||
-- Short info.
|
-- Short info.
|
||||||
local text=string.format("Flight status %s [%d/%d]. Task=%d/%d. Waypoint=%d/%d. Detected=%d. FC=%s. Destination=%s",
|
local text=string.format("Flight status %s [%d/%d]. Task=%d/%d. Waypoint=%d/%d. Detected=%d. FC=%s. Destination=%s",
|
||||||
fsmstate, #self.elements, #self.elements, self.taskcurrent, #self.taskqueue, self.currentwp or 0, #self.waypoints or 0, self.detectedunits:Count(), self.flightcontrol and self.flightcontrol.airbasename or "none", self.destination and self.destination:GetName() or "unknown")
|
fsmstate, #self.elements, #self.elements, self.taskcurrent, #self.taskqueue, self.currentwp or 0, self.waypoints and #self.waypoints or 0,
|
||||||
|
self.detectedunits:Count(), self.flightcontrol and self.flightcontrol.airbasename or "none", self.destination and self.destination:GetName() or "unknown")
|
||||||
self:I(self.sid..text)
|
self:I(self.sid..text)
|
||||||
|
|
||||||
-- Element status.
|
-- Element status.
|
||||||
@@ -831,16 +845,19 @@ function FLIGHTGROUP:OnEventBirth(EventData)
|
|||||||
if EventData.Place then
|
if EventData.Place then
|
||||||
self.homebase=self.homebase or EventData.Place
|
self.homebase=self.homebase or EventData.Place
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Get element.
|
||||||
|
local element=self:GetElementByName(unitname)
|
||||||
|
|
||||||
-- Create element spawned event if not already present.
|
-- Create element spawned event if not already present.
|
||||||
if not self:_IsElement(unitname) then
|
if not self:_IsElement(unitname) then
|
||||||
local element=self:AddElementByName(unitname)
|
element=self:AddElementByName(unitname)
|
||||||
|
|
||||||
self:T3(self.sid..string.format("EVENT: Element %s born ==> spawned", element.name))
|
|
||||||
|
|
||||||
self:ElementSpawned(element)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self:T3(self.sid..string.format("EVENT: Element %s born ==> spawned", element.name))
|
||||||
|
|
||||||
|
self:ElementSpawned(element)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -993,6 +1010,29 @@ function FLIGHTGROUP:OnEventCrash(EventData)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Flightgroup event function handling the crash of a unit.
|
||||||
|
-- @param #FLIGHTGROUP self
|
||||||
|
-- @param Core.Event#EVENTDATA EventData Event data.
|
||||||
|
function FLIGHTGROUP:OnEventRemoveUnit(EventData)
|
||||||
|
|
||||||
|
-- Check that this is the right group.
|
||||||
|
if EventData and EventData.IniGroup and EventData.IniUnit and EventData.IniGroupName and EventData.IniGroupName==self.groupname then
|
||||||
|
local unit=EventData.IniUnit
|
||||||
|
local group=EventData.IniGroup
|
||||||
|
local unitname=EventData.IniUnitName
|
||||||
|
|
||||||
|
-- Get element.
|
||||||
|
local element=self:GetElementByName(unitname)
|
||||||
|
|
||||||
|
if element then
|
||||||
|
self:T3(self.sid..string.format("EVENT: Element %s removed ==> dead", element.name))
|
||||||
|
self:ElementDead(element)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- FSM functions
|
-- FSM functions
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -1282,6 +1322,28 @@ function FLIGHTGROUP:onafterFlightLanded(From, Event, To, airbase)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- On after "FlightArrived" event.
|
||||||
|
-- @param #FLIGHTGROUP self
|
||||||
|
-- @param #string From From state.
|
||||||
|
-- @param #string Event Event.
|
||||||
|
-- @param #string To To state.
|
||||||
|
function FLIGHTGROUP:onafterFlightArrived(From, Event, To)
|
||||||
|
self:T(self.sid..string.format("Flight arrived %s", self.groupname))
|
||||||
|
end
|
||||||
|
|
||||||
|
--- On after "FlightDead" event.
|
||||||
|
-- @param #FLIGHTGROUP self
|
||||||
|
-- @param #string From From state.
|
||||||
|
-- @param #string Event Event.
|
||||||
|
-- @param #string To To state.
|
||||||
|
function FLIGHTGROUP:onafterFlightDead(From, Event, To)
|
||||||
|
self:T(self.sid..string.format("Flight dead %s", self.groupname))
|
||||||
|
|
||||||
|
-- Delete waypoints so they are re-initialized at the next spawn.
|
||||||
|
self.waypoints=nil
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- On after "PassingWaypoint" event.
|
--- On after "PassingWaypoint" event.
|
||||||
-- @param #FLIGHTGROUP self
|
-- @param #FLIGHTGROUP self
|
||||||
-- @param #string From From state.
|
-- @param #string From From state.
|
||||||
@@ -1291,7 +1353,7 @@ end
|
|||||||
-- @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 %s passed waypoint %d/%d", self.groupname, n, N)
|
||||||
self:T(self.sid..text)
|
self:I(self.sid..text)
|
||||||
MESSAGE:New(text, 30, "DEBUG"):ToAllIf(self.Debug)
|
MESSAGE:New(text, 30, "DEBUG"):ToAllIf(self.Debug)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1789,7 +1851,7 @@ function FLIGHTGROUP._PassingWaypoint(group, flightgroup, i)
|
|||||||
|
|
||||||
-- Debug message.
|
-- Debug message.
|
||||||
--MESSAGE:New(text,10):ToAllIf(flightgroup.Debug)
|
--MESSAGE:New(text,10):ToAllIf(flightgroup.Debug)
|
||||||
flightgroup:T2(flightgroup.sid..text)
|
flightgroup:T3(flightgroup.sid..text)
|
||||||
|
|
||||||
-- Set current waypoint.
|
-- Set current waypoint.
|
||||||
flightgroup.currentwp=i
|
flightgroup.currentwp=i
|
||||||
@@ -2128,6 +2190,9 @@ function FLIGHTGROUP:_UpdateRoute(n)
|
|||||||
|
|
||||||
-- TODO: what happens if currentwp=#waypoints
|
-- TODO: what happens if currentwp=#waypoints
|
||||||
n=n or self.currentwp+1
|
n=n or self.currentwp+1
|
||||||
|
|
||||||
|
-- Update waypoint tasks, i.e. inject WP tasks into waypoint table.
|
||||||
|
self:_UpdateWaypointTasks()
|
||||||
|
|
||||||
local wp={}
|
local wp={}
|
||||||
|
|
||||||
@@ -2142,8 +2207,9 @@ function FLIGHTGROUP:_UpdateRoute(n)
|
|||||||
-- Get destination airbase from waypoints.
|
-- Get destination airbase from waypoints.
|
||||||
self.destination=self:GetDestinationFromWaypoints() or self.destination
|
self.destination=self:GetDestinationFromWaypoints() or self.destination
|
||||||
|
|
||||||
if self.destination and #wp>0 then
|
if self.destination and #wp>0 and _DATABASE:GetFlightControl(self.destination:GetName())then
|
||||||
|
|
||||||
|
-- Task to hold.
|
||||||
local TaskOverhead=self.group:TaskFunction("FLIGHTGROUP._DestinationOverhead", self, self.destination)
|
local TaskOverhead=self.group:TaskFunction("FLIGHTGROUP._DestinationOverhead", self, self.destination)
|
||||||
|
|
||||||
local coordoverhead=self.destination:GetZone():GetRandomCoordinate():SetAltitude(UTILS.FeetToMeters(6000))
|
local coordoverhead=self.destination:GetZone():GetRandomCoordinate():SetAltitude(UTILS.FeetToMeters(6000))
|
||||||
@@ -2153,6 +2219,8 @@ function FLIGHTGROUP:_UpdateRoute(n)
|
|||||||
table.insert(wp, #wp, wpoverhead)
|
table.insert(wp, #wp, wpoverhead)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self:I(self.sid..string.format("Updating route: #WP=%d homebase=%s destination=%s", #wp, self.homebase and self.homebase:GetName() or "unknown", self.destination and self.destination:GetName() or "unknown"))
|
self:I(self.sid..string.format("Updating route: #WP=%d homebase=%s destination=%s", #wp, self.homebase and self.homebase:GetName() or "unknown", self.destination and self.destination:GetName() or "unknown"))
|
||||||
|
|
||||||
if #wp>0 then
|
if #wp>0 then
|
||||||
@@ -2235,11 +2303,10 @@ end
|
|||||||
-- @return #FLIGHTGROUP self
|
-- @return #FLIGHTGROUP self
|
||||||
function FLIGHTGROUP:InitWaypoints(waypoints)
|
function FLIGHTGROUP:InitWaypoints(waypoints)
|
||||||
|
|
||||||
|
self.waypoints0=self.group:GetTemplateRoutePoints()
|
||||||
|
|
||||||
-- Waypoints of group as defined in the ME.
|
-- Waypoints of group as defined in the ME.
|
||||||
self.waypoints=waypoints or self.group:GetTemplateRoutePoints()
|
self.waypoints=waypoints or self.group:GetTemplateRoutePoints()
|
||||||
|
|
||||||
-- Update waypoint tasks.
|
|
||||||
self:_UpdateWaypointTasks()
|
|
||||||
|
|
||||||
-- Init array.
|
-- Init array.
|
||||||
self.coordinates={}
|
self.coordinates={}
|
||||||
|
|||||||
Reference in New Issue
Block a user