mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-08-20 17:07:54 +00:00
up
This commit is contained in:
@@ -1254,7 +1254,10 @@ do -- COORDINATE
|
|||||||
if airbase then
|
if airbase then
|
||||||
local category=airbase:GetCategory()
|
local category=airbase:GetCategory()
|
||||||
if Category and Category==category or Category==nil then
|
if Category and Category==category or Category==nil then
|
||||||
|
|
||||||
|
-- Distance to airbase.
|
||||||
local dist=self:Get2DDistance(airbase:GetCoordinate())
|
local dist=self:Get2DDistance(airbase:GetCoordinate())
|
||||||
|
|
||||||
if closest==nil then
|
if closest==nil then
|
||||||
distmin=dist
|
distmin=dist
|
||||||
closest=airbase
|
closest=airbase
|
||||||
@@ -1264,6 +1267,7 @@ do -- COORDINATE
|
|||||||
closest=airbase
|
closest=airbase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2193,8 +2193,8 @@ function RANGE:_DisplayBombTargets(_unitname)
|
|||||||
if coord then
|
if coord then
|
||||||
|
|
||||||
local ca2g=coord:ToStringA2G(_unit, _settings)
|
local ca2g=coord:ToStringA2G(_unit, _settings)
|
||||||
local lldms=coord:ToStringLLDMS()
|
local lldms=coord:ToStringLLDMS(_settings)
|
||||||
_text=_text..string.format("\n- %s: %s %s", bombtarget.name or "unknown", ca2g, lldms)
|
_text=_text..string.format("\n- %s:\n%s\n%s", bombtarget.name or "unknown", ca2g, lldms)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1752,7 +1752,7 @@ _WAREHOUSEDB = {
|
|||||||
|
|
||||||
--- Warehouse class version.
|
--- Warehouse class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
WAREHOUSE.version="0.9.6wip"
|
WAREHOUSE.version="0.9.7"
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- TODO: Warehouse todo list.
|
-- TODO: Warehouse todo list.
|
||||||
@@ -3315,7 +3315,9 @@ end
|
|||||||
-- @param #string Event Event.
|
-- @param #string Event Event.
|
||||||
-- @param #string To To state.
|
-- @param #string To To state.
|
||||||
function WAREHOUSE:onafterStatus(From, Event, To)
|
function WAREHOUSE:onafterStatus(From, Event, To)
|
||||||
self:I(self.wid..string.format("Checking status of warehouse %s. Current FSM state %s. Global warehouse assets = %d.", self.alias, self:GetState(), #_WAREHOUSEDB.Assets))
|
|
||||||
|
-- Info.
|
||||||
|
self:I(self.wid..string.format("FSM state %s. Assets=%d (global %d). Requests waiting=%d, pending=%d", self:GetState(), #self.stock, #_WAREHOUSEDB.Assets, #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()
|
||||||
@@ -3702,7 +3704,7 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu
|
|||||||
self:_DebugMessage(string.format("Warehouse %s: Adding KNOWN asset uid=%d with attribute=%s to stock.", self.alias, asset.uid, asset.attribute), 5)
|
self:_DebugMessage(string.format("Warehouse %s: Adding KNOWN asset uid=%d with attribute=%s to stock.", self.alias, asset.uid, asset.attribute), 5)
|
||||||
|
|
||||||
-- Asset now belongs to this warehouse. Set warehouse ID.
|
-- Asset now belongs to this warehouse. Set warehouse ID.
|
||||||
asset.wid=self.wid
|
asset.wid=self.uid
|
||||||
|
|
||||||
-- No request associated with this asset.
|
-- No request associated with this asset.
|
||||||
asset.rid=nil
|
asset.rid=nil
|
||||||
@@ -3717,7 +3719,7 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu
|
|||||||
|
|
||||||
-- Asset is not spawned.
|
-- Asset is not spawned.
|
||||||
asset.spawned=false
|
asset.spawned=false
|
||||||
asset.spawngroupname=nil
|
asset.iscargo=nil
|
||||||
|
|
||||||
-- Add asset to stock.
|
-- Add asset to stock.
|
||||||
table.insert(self.stock, asset)
|
table.insert(self.stock, asset)
|
||||||
@@ -3743,7 +3745,7 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu
|
|||||||
for _,asset in pairs(assets) do
|
for _,asset in pairs(assets) do
|
||||||
|
|
||||||
-- Asset belongs to this warehouse. Set warehouse ID.
|
-- Asset belongs to this warehouse. Set warehouse ID.
|
||||||
asset.wid=self.wid
|
asset.wid=self.uid
|
||||||
|
|
||||||
-- No request associated with this asset.
|
-- No request associated with this asset.
|
||||||
asset.rid=nil
|
asset.rid=nil
|
||||||
@@ -4044,7 +4046,7 @@ end
|
|||||||
-- @param #WAREHOUSE.TransportType TransportType Type of transport.
|
-- @param #WAREHOUSE.TransportType TransportType Type of transport.
|
||||||
-- @param #number nTransport Number of transport units requested.
|
-- @param #number nTransport Number of transport units requested.
|
||||||
-- @param #number Prio Priority of the request. Number ranging from 1=high to 100=low.
|
-- @param #number Prio Priority of the request. Number ranging from 1=high to 100=low.
|
||||||
-- @param #string Assignment A keyword or text that later be used to identify this request and postprocess the assets.
|
-- @param #string Assignment A keyword or text that can later be used to identify this request and postprocess the assets.
|
||||||
function WAREHOUSE:onafterAddRequest(From, Event, To, warehouse, AssetDescriptor, AssetDescriptorValue, nAsset, TransportType, nTransport, Prio, Assignment)
|
function WAREHOUSE:onafterAddRequest(From, Event, To, warehouse, AssetDescriptor, AssetDescriptorValue, nAsset, TransportType, nTransport, Prio, Assignment)
|
||||||
|
|
||||||
-- Defaults.
|
-- Defaults.
|
||||||
@@ -4206,7 +4208,6 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
|
|||||||
|
|
||||||
-- Asset is transport.
|
-- Asset is transport.
|
||||||
_assetitem.spawned=false
|
_assetitem.spawned=false
|
||||||
--_assetitem.spawngroupname=nil
|
|
||||||
_assetitem.iscargo=false
|
_assetitem.iscargo=false
|
||||||
|
|
||||||
local spawngroup=nil --Wrapper.Group#GROUP
|
local spawngroup=nil --Wrapper.Group#GROUP
|
||||||
@@ -4991,21 +4992,22 @@ function WAREHOUSE:onafterAssetSpawned(From, Event, To, group, asset, request)
|
|||||||
self:T(self.wid..text)
|
self:T(self.wid..text)
|
||||||
self:_DebugMessage(text)
|
self:_DebugMessage(text)
|
||||||
|
|
||||||
-- Check if all assets groups are spawned and trigger events.
|
-- Sete asset state to spawned.
|
||||||
|
|
||||||
asset.spawned=true
|
asset.spawned=true
|
||||||
|
|
||||||
|
-- Check if all assets groups are spawned and trigger events.
|
||||||
local allspawned=true
|
local allspawned=true
|
||||||
for _,_asset in pairs(request.assets) do
|
for _,_asset in pairs(request.assets) do
|
||||||
local assetitem=_asset --#WAREHOUSE.Assetitem
|
local assetitem=_asset --#WAREHOUSE.Assetitem
|
||||||
|
|
||||||
self:I(string.format("FF Asset %s spawned %s as %s", assetitem.templatename, tostring(assetitem.spawned), tostring(assetitem.spawngroupname)))
|
--self:I(string.format("FF Asset %s spawned %s as %s", assetitem.templatename, tostring(assetitem.spawned), tostring(assetitem.spawngroupname)))
|
||||||
|
|
||||||
if not assetitem.spawned then
|
if not assetitem.spawned then
|
||||||
allspawned=false
|
allspawned=false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Trigger event.
|
||||||
if allspawned then
|
if allspawned then
|
||||||
self:RequestSpawned(request, request.cargogroupset, request.transportgroupset)
|
self:RequestSpawned(request, request.cargogroupset, request.transportgroupset)
|
||||||
end
|
end
|
||||||
@@ -5311,7 +5313,6 @@ function WAREHOUSE:_SpawnAssetRequest(Request)
|
|||||||
|
|
||||||
-- Set asset status to not spawned until we capture its birth event.
|
-- Set asset status to not spawned until we capture its birth event.
|
||||||
asset.spawned=false
|
asset.spawned=false
|
||||||
--asset.spawngroupname=nil
|
|
||||||
asset.iscargo=true
|
asset.iscargo=true
|
||||||
asset.rid=Request.uid
|
asset.rid=Request.uid
|
||||||
|
|
||||||
@@ -5462,7 +5463,12 @@ function WAREHOUSE:_SpawnAssetAircraft(alias, asset, request, parking, uncontrol
|
|||||||
if request.transporttype==WAREHOUSE.TransportType.SELFPROPELLED then
|
if request.transporttype==WAREHOUSE.TransportType.SELFPROPELLED then
|
||||||
|
|
||||||
-- Get flight path if the group goes to another warehouse by itself.
|
-- Get flight path if the group goes to another warehouse by itself.
|
||||||
template.route.points=self:_GetFlightplan(asset, self.airbase, request.warehouse.airbase)
|
if request.toself then
|
||||||
|
local wp=self.airbase:GetCoordinate():WaypointAir("RADIO", COORDINATE.WaypointType.TakeOffParking, COORDINATE.WaypointAction.FromParkingArea, 0, false, self.airbase, {}, "Parking")
|
||||||
|
template.route.points={wp}
|
||||||
|
else
|
||||||
|
template.route.points=self:_GetFlightplan(asset, self.airbase, request.warehouse.airbase)
|
||||||
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
@@ -5588,8 +5594,6 @@ function WAREHOUSE:_SpawnAssetPrepareTemplate(asset, alias)
|
|||||||
-- Set unique name.
|
-- Set unique name.
|
||||||
template.name=alias
|
template.name=alias
|
||||||
|
|
||||||
env.info(string.format("FF template name %s", alias))
|
|
||||||
|
|
||||||
-- Set current(!) coalition and country.
|
-- Set current(!) coalition and country.
|
||||||
template.CoalitionID=self:GetCoalition()
|
template.CoalitionID=self:GetCoalition()
|
||||||
template.CountryID=self:GetCountry()
|
template.CountryID=self:GetCountry()
|
||||||
@@ -6043,10 +6047,14 @@ 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)
|
local istransport=self:_GroupIsTransport(group, request)
|
||||||
|
|
||||||
|
-- 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.
|
||||||
|
local closest=group:GetCoordinate():GetClosestAirbase()
|
||||||
|
|
||||||
-- Check if engine shutdown happend at right airbase because the event is also triggered in other situations.
|
-- Check if engine shutdown happend at right airbase because the event is also triggered in other situations.
|
||||||
local rightairbase=group:GetCoordinate():GetClosestAirbase():GetName()==request.warehouse:GetAirbase():GetName()
|
local rightairbase=closest:GetName()==request.warehouse:GetAirbase():GetName()
|
||||||
|
|
||||||
-- Check that group is cargo and not transport.
|
-- Check that group is cargo and not transport.
|
||||||
if istransport==false and rightairbase then
|
if istransport==false and rightairbase then
|
||||||
@@ -6729,7 +6737,7 @@ function WAREHOUSE:_CheckRequestValid(request)
|
|||||||
if request.transporttype==WAREHOUSE.TransportType.AIRPLANE or request.transporttype==WAREHOUSE.TransportType.HELICOPTER then
|
if request.transporttype==WAREHOUSE.TransportType.AIRPLANE or request.transporttype==WAREHOUSE.TransportType.HELICOPTER then
|
||||||
|
|
||||||
-- Check if number of requested assets is in stock.
|
-- Check if number of requested assets is in stock.
|
||||||
local _assets,_nassets,_enough=self:_FilterStock(self.stock, WAREHOUSE.Descriptor.ATTRIBUTE, request.transporttype, request.ntransport)
|
local _assets,_nassets,_enough=self:_FilterStock(self.stock, WAREHOUSE.Descriptor.ATTRIBUTE, request.transporttype, request.ntransport, true)
|
||||||
|
|
||||||
-- Convert relative to absolute number if necessary.
|
-- Convert relative to absolute number if necessary.
|
||||||
local nasset=request.ntransport
|
local nasset=request.ntransport
|
||||||
@@ -6952,7 +6960,7 @@ end
|
|||||||
function WAREHOUSE:_GetTransportsForAssets(request)
|
function WAREHOUSE:_GetTransportsForAssets(request)
|
||||||
|
|
||||||
-- Get all transports of the requested type in stock.
|
-- Get all transports of the requested type in stock.
|
||||||
local transports=self:_FilterStock(self.stock, WAREHOUSE.Descriptor.ATTRIBUTE, request.transporttype)
|
local transports=self:_FilterStock(self.stock, WAREHOUSE.Descriptor.ATTRIBUTE, request.transporttype, true)
|
||||||
|
|
||||||
-- Copy asset.
|
-- Copy asset.
|
||||||
local cargoassets=UTILS.DeepCopy(request.cargoassets)
|
local cargoassets=UTILS.DeepCopy(request.cargoassets)
|
||||||
|
|||||||
@@ -31,6 +31,12 @@
|
|||||||
-- @field Core.Set#SET_UNIT detectedunits Set of detected units.
|
-- @field Core.Set#SET_UNIT detectedunits Set of detected units.
|
||||||
-- @field Wrapper.Airbase#AIRBASE homebase The home base of the flight group.
|
-- @field Wrapper.Airbase#AIRBASE homebase The home base of the flight group.
|
||||||
-- @field Wrapper.Airbase#AIRBASE destination The destination base of the flight group.
|
-- @field Wrapper.Airbase#AIRBASE destination The destination base of the flight group.
|
||||||
|
-- @field #boolean fuellow Fuel low switch.
|
||||||
|
-- @field #number fuellowthresh Low fuel threshold in percent.
|
||||||
|
-- @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.
|
||||||
-- @extends Core.Fsm#FSM
|
-- @extends Core.Fsm#FSM
|
||||||
|
|
||||||
--- Be surprised!
|
--- Be surprised!
|
||||||
@@ -46,25 +52,30 @@
|
|||||||
-- @field #FLIGHTGROUP
|
-- @field #FLIGHTGROUP
|
||||||
FLIGHTGROUP = {
|
FLIGHTGROUP = {
|
||||||
ClassName = "FLIGHTGROUP",
|
ClassName = "FLIGHTGROUP",
|
||||||
Debug = nil,
|
Debug = nil,
|
||||||
sid = nil,
|
sid = nil,
|
||||||
groupname = nil,
|
groupname = nil,
|
||||||
flightgroup = nil,
|
flightgroup = nil,
|
||||||
grouptemplate = nil,
|
grouptemplate = nil,
|
||||||
type = nil,
|
type = nil,
|
||||||
waypoints = {},
|
waypoints = {},
|
||||||
coordinates = {},
|
coordinates = {},
|
||||||
element = {},
|
element = {},
|
||||||
taskqueue = {},
|
taskqueue = {},
|
||||||
taskcounter = nil,
|
taskcounter = nil,
|
||||||
taskcurrent = nil,
|
taskcurrent = nil,
|
||||||
detectedunits = {},
|
detectedunits = {},
|
||||||
homebase = nil,
|
homebase = nil,
|
||||||
destination = nil,
|
destination = nil,
|
||||||
speedmax = nil,
|
speedmax = nil,
|
||||||
range = nil,
|
range = nil,
|
||||||
altmax = nil,
|
altmax = nil,
|
||||||
fuelthresh = nil,
|
fuellow = false,
|
||||||
|
fuellowthresh = nil,
|
||||||
|
fuellowrtb = nil,
|
||||||
|
fuelcritical = nil,
|
||||||
|
fuelcriticalthresh = nil,
|
||||||
|
fuelcriticalrtb = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -156,7 +167,7 @@ FLIGHTGROUP.TaskType={
|
|||||||
|
|
||||||
--- FLIGHTGROUP class version.
|
--- FLIGHTGROUP class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
FLIGHTGROUP.version="0.0.7"
|
FLIGHTGROUP.version="0.0.8"
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- TODO list
|
-- TODO list
|
||||||
@@ -201,6 +212,7 @@ function FLIGHTGROUP:New(groupname)
|
|||||||
|
|
||||||
-- Defaults
|
-- Defaults
|
||||||
self:SetFuelLowThreshold()
|
self:SetFuelLowThreshold()
|
||||||
|
self:SetFuelCriticalThreshold()
|
||||||
|
|
||||||
|
|
||||||
-- Add FSM transitions.
|
-- Add FSM transitions.
|
||||||
@@ -291,7 +303,6 @@ function FLIGHTGROUP:New(groupname)
|
|||||||
BASE:TraceClass(self.ClassName)
|
BASE:TraceClass(self.ClassName)
|
||||||
BASE:TraceLevel(1)
|
BASE:TraceLevel(1)
|
||||||
end
|
end
|
||||||
self.Debug=true
|
|
||||||
|
|
||||||
-- 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.
|
||||||
-- TODO: move this to start?
|
-- TODO: move this to start?
|
||||||
@@ -399,18 +410,30 @@ function FLIGHTGROUP:AddTaskWaypoint(description, task, waypointindex, prio, dur
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Fuel threshold for RTB.
|
--- Set low fuel threshold. Triggers event "FuelLow" and calls event function "OnAfterFuelLow".
|
||||||
-- @param #FLIGHTGROUP self
|
-- @param #FLIGHTGROUP self
|
||||||
-- @param #number threshold Fuel threshold in percent. Default 15 %.
|
-- @param #number threshold Fuel threshold in percent. Default 25 %.
|
||||||
-- @param #boolean rtb If true, RTB on low fuel event.
|
-- @param #boolean rtb If true, RTB on fuel low event.
|
||||||
-- @return #FLIGHTGROUP self
|
-- @return #FLIGHTGROUP self
|
||||||
function FLIGHTGROUP:SetFuelLowThreshold(threshold, rtb)
|
function FLIGHTGROUP:SetFuelLowThreshold(threshold, rtb)
|
||||||
self.fuellowthresh=threshold or 15
|
|
||||||
self.fuellow=false
|
self.fuellow=false
|
||||||
|
self.fuellowthresh=threshold or 25
|
||||||
self.fuellowrtb=rtb
|
self.fuellowrtb=rtb
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Set fuel critical threshold. Triggers event "FuelCritical" and event function "OnAfterFuelCritical".
|
||||||
|
-- @param #FLIGHTGROUP self
|
||||||
|
-- @param #number threshold Fuel threshold in percent. Default 10 %.
|
||||||
|
-- @param #boolean rtb If true, RTB on fuel critical event.
|
||||||
|
-- @return #FLIGHTGROUP self
|
||||||
|
function FLIGHTGROUP:SetFuelCriticalThreshold(threshold, rtb)
|
||||||
|
self.fuelcritical=false
|
||||||
|
self.fuelcriticalthresh=threshold or 10
|
||||||
|
self.fuelcriticalrtb=rtb
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
--- Get set of decteded units.
|
--- Get set of decteded units.
|
||||||
-- @param #FLIGHTGROUP self
|
-- @param #FLIGHTGROUP self
|
||||||
-- @return Core.Set#SET_UNIT Set of detected units.
|
-- @return Core.Set#SET_UNIT Set of detected units.
|
||||||
@@ -569,8 +592,8 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To)
|
|||||||
local fuel=unit:GetFuel() or 0
|
local fuel=unit:GetFuel() or 0
|
||||||
local life=unit:GetLifeRelative() or 0
|
local life=unit:GetLifeRelative() or 0
|
||||||
|
|
||||||
if fuel<fuelmin then
|
if fuel*100<fuelmin then
|
||||||
fuelmin=fuel
|
fuelmin=fuel*100
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check if element is not dead and we missed an event.
|
-- Check if element is not dead and we missed an event.
|
||||||
@@ -595,10 +618,16 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To)
|
|||||||
end
|
end
|
||||||
self:I(self.sid..text)
|
self:I(self.sid..text)
|
||||||
|
|
||||||
|
-- Low fuel?
|
||||||
if fuelmin<self.fuellowthresh and not self.fuellow then
|
if fuelmin<self.fuellowthresh and not self.fuellow then
|
||||||
self:FuelLow()
|
self:FuelLow()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Critical fuel?
|
||||||
|
if fuelmin<self.fuelcriticalthresh and not self.fuelcritical then
|
||||||
|
self:FuelCritical()
|
||||||
|
end
|
||||||
|
|
||||||
-- Task queue.
|
-- Task queue.
|
||||||
text=string.format("Tasks #%d", #self.taskqueue)
|
text=string.format("Tasks #%d", #self.taskqueue)
|
||||||
for i,_task in pairs(self.taskqueue) do
|
for i,_task in pairs(self.taskqueue) do
|
||||||
@@ -954,7 +983,7 @@ end
|
|||||||
function FLIGHTGROUP:onafterFuelLow(From, Event, To)
|
function FLIGHTGROUP:onafterFuelLow(From, Event, To)
|
||||||
|
|
||||||
-- Debug message.
|
-- Debug message.
|
||||||
local text=string.format("Low fuel for flight group", self.groupname)
|
local text=string.format("Low fuel for flight group %s", self.groupname)
|
||||||
MESSAGE:New(text, 10, "DEBUG"):ToAllIf(self.Debug)
|
MESSAGE:New(text, 10, "DEBUG"):ToAllIf(self.Debug)
|
||||||
self:I(self.sid..text)
|
self:I(self.sid..text)
|
||||||
|
|
||||||
@@ -965,7 +994,30 @@ function FLIGHTGROUP:onafterFuelLow(From, Event, To)
|
|||||||
local airbase=self.destination or self.homebase
|
local airbase=self.destination or self.homebase
|
||||||
|
|
||||||
if airbase and self.fuellowrtb then
|
if airbase and self.fuellowrtb then
|
||||||
self:RouteRTB(airbase)
|
self:RTB(airbase)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- On after "FuelCritical" event.
|
||||||
|
-- @param #FLIGHTGROUP self
|
||||||
|
-- @param #string From From state.
|
||||||
|
-- @param #string Event Event.
|
||||||
|
-- @param #string To To state.
|
||||||
|
function FLIGHTGROUP:onafterFuelCritical(From, Event, To)
|
||||||
|
|
||||||
|
-- Debug message.
|
||||||
|
local text=string.format("Critical fuel for flight group %s", self.groupname)
|
||||||
|
MESSAGE:New(text, 10, "DEBUG"):ToAllIf(self.Debug)
|
||||||
|
self:I(self.sid..text)
|
||||||
|
|
||||||
|
-- Set switch to true.
|
||||||
|
self.fuelcritical=true
|
||||||
|
|
||||||
|
-- Route helo back home. It is respawned! But this is the only way to ensure that it actually lands at the airbase.
|
||||||
|
local airbase=self.destination or self.homebase
|
||||||
|
|
||||||
|
if airbase and self.fuelcriticalrtb then
|
||||||
|
self:RTB(airbase)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -992,16 +1044,19 @@ end
|
|||||||
-- @param #string From From state.
|
-- @param #string From From state.
|
||||||
-- @param #string Event Event.
|
-- @param #string Event Event.
|
||||||
-- @param #string To To state.
|
-- @param #string To To state.
|
||||||
-- @param Wrapper.Airbase#AIRBASE airbase The base to return to.
|
-- @param Core.Point#COORDINATE Coord Coordinate where to orbit.
|
||||||
function FLIGHTGROUP:onafterOrbit(From, Event, To, Coord)
|
-- @param #number Altitude Altitude in meters.
|
||||||
|
-- @param #number Speed Speed in km/h.
|
||||||
|
function FLIGHTGROUP:onafterOrbit(From, Event, To, Coord, Altitude, Speed)
|
||||||
|
|
||||||
-- Debug message.
|
-- Debug message.
|
||||||
local text=string.format("Flight group returning to airbase %s.", airbase:GetName())
|
local text=string.format("Flight group set to orbit at altitude %d m and speed %.1f km/h", Altitude, Speed)
|
||||||
MESSAGE:New(text, 10, "DEBUG"):ToAllIf(self.Debug)
|
MESSAGE:New(text, 10, "DEBUG"):ToAllIf(self.Debug)
|
||||||
self:I(self.sid..text)
|
self:I(self.sid..text)
|
||||||
|
|
||||||
-- Route helo back home. It is respawned! But this is the only way to ensure that it actually lands at the airbase.
|
local TaskOrbit=self.flightgroup:TaskOrbit(Coord, Altitude, UTILS.KmphToMps(Speed))
|
||||||
self:RouteRTB(airbase)
|
|
||||||
|
self.flightgroup:SetTask(TaskOrbit)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- On after TaskExecute event.
|
--- On after TaskExecute event.
|
||||||
@@ -1487,7 +1542,7 @@ function FLIGHTGROUP:_UpdateRoute(n)
|
|||||||
self:RTB(airbase)
|
self:RTB(airbase)
|
||||||
else
|
else
|
||||||
-- Let flight orbit.
|
-- Let flight orbit.
|
||||||
self:Orbit()
|
--self:Orbit(self.flightgroup:GetCoordinate(), UTILS.FeetToMeters(20000), self.flightgroup:GetSpeedMax()*0.4)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1042,3 +1042,82 @@ do -- Detection
|
|||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Get the unit table from a unit's template.
|
||||||
|
-- @param #UNIT self
|
||||||
|
-- @return #table Table of the unit template (deep copy) or #nil.
|
||||||
|
function UNIT:GetTemplate()
|
||||||
|
|
||||||
|
local group=self:GetGroup()
|
||||||
|
|
||||||
|
local name=self:GetName()
|
||||||
|
|
||||||
|
if group then
|
||||||
|
local template=group:GetTemplate()
|
||||||
|
|
||||||
|
if template then
|
||||||
|
|
||||||
|
for _,unit in pairs(template.units) do
|
||||||
|
|
||||||
|
self:I(string.format("FF template unit %s = %s", unit.name, name))
|
||||||
|
|
||||||
|
if unit.name==name then
|
||||||
|
return UTILS.DeepCopy(unit)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Get the payload table from a unit's template.
|
||||||
|
-- The payload table has elements:
|
||||||
|
--
|
||||||
|
-- * pylons
|
||||||
|
-- * fuel
|
||||||
|
-- * chaff
|
||||||
|
-- * gun
|
||||||
|
--
|
||||||
|
-- @param #UNIT self
|
||||||
|
-- @return #table Payload table (deep copy) or #nil.
|
||||||
|
function UNIT:GetTemplatePayload()
|
||||||
|
|
||||||
|
local unit=self:GetTemplate()
|
||||||
|
|
||||||
|
if unit then
|
||||||
|
return unit.payload
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Get the pylons table from a unit's template. This can be a complex table depending on the weapons the unit is carrying.
|
||||||
|
-- @param #UNIT self
|
||||||
|
-- @return #table Table of pylons (deepcopy) or #nil.
|
||||||
|
function UNIT:GetTemplatePylons()
|
||||||
|
|
||||||
|
local payload=self:GetTemplatePayload()
|
||||||
|
|
||||||
|
if payload then
|
||||||
|
return payload.pylons
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Get the fuel of the unit from its template.
|
||||||
|
-- @param #UNIT self
|
||||||
|
-- @return #number Fuel of unit in kg.
|
||||||
|
function UNIT:GetTemplateFuel()
|
||||||
|
|
||||||
|
local payload=self:GetTemplatePayload()
|
||||||
|
|
||||||
|
if payload then
|
||||||
|
return payload.fuel
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user