mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-08-11 03:43:38 +00:00
up
This commit is contained in:
@@ -1254,7 +1254,10 @@ do -- COORDINATE
|
||||
if airbase then
|
||||
local category=airbase:GetCategory()
|
||||
if Category and Category==category or Category==nil then
|
||||
|
||||
-- Distance to airbase.
|
||||
local dist=self:Get2DDistance(airbase:GetCoordinate())
|
||||
|
||||
if closest==nil then
|
||||
distmin=dist
|
||||
closest=airbase
|
||||
@@ -1264,6 +1267,7 @@ do -- COORDINATE
|
||||
closest=airbase
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2193,8 +2193,8 @@ function RANGE:_DisplayBombTargets(_unitname)
|
||||
if coord then
|
||||
|
||||
local ca2g=coord:ToStringA2G(_unit, _settings)
|
||||
local lldms=coord:ToStringLLDMS()
|
||||
_text=_text..string.format("\n- %s: %s %s", bombtarget.name or "unknown", ca2g, lldms)
|
||||
local lldms=coord:ToStringLLDMS(_settings)
|
||||
_text=_text..string.format("\n- %s:\n%s\n%s", bombtarget.name or "unknown", ca2g, lldms)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1752,7 +1752,7 @@ _WAREHOUSEDB = {
|
||||
|
||||
--- Warehouse class version.
|
||||
-- @field #string version
|
||||
WAREHOUSE.version="0.9.6wip"
|
||||
WAREHOUSE.version="0.9.7"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- TODO: Warehouse todo list.
|
||||
@@ -3315,7 +3315,9 @@ end
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
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.
|
||||
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)
|
||||
|
||||
-- Asset now belongs to this warehouse. Set warehouse ID.
|
||||
asset.wid=self.wid
|
||||
asset.wid=self.uid
|
||||
|
||||
-- No request associated with this asset.
|
||||
asset.rid=nil
|
||||
@@ -3717,7 +3719,7 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu
|
||||
|
||||
-- Asset is not spawned.
|
||||
asset.spawned=false
|
||||
asset.spawngroupname=nil
|
||||
asset.iscargo=nil
|
||||
|
||||
-- Add asset to stock.
|
||||
table.insert(self.stock, asset)
|
||||
@@ -3743,7 +3745,7 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu
|
||||
for _,asset in pairs(assets) do
|
||||
|
||||
-- Asset belongs to this warehouse. Set warehouse ID.
|
||||
asset.wid=self.wid
|
||||
asset.wid=self.uid
|
||||
|
||||
-- No request associated with this asset.
|
||||
asset.rid=nil
|
||||
@@ -4044,7 +4046,7 @@ end
|
||||
-- @param #WAREHOUSE.TransportType TransportType Type of transport.
|
||||
-- @param #number nTransport Number of transport units requested.
|
||||
-- @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)
|
||||
|
||||
-- Defaults.
|
||||
@@ -4206,7 +4208,6 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
|
||||
|
||||
-- Asset is transport.
|
||||
_assetitem.spawned=false
|
||||
--_assetitem.spawngroupname=nil
|
||||
_assetitem.iscargo=false
|
||||
|
||||
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:_DebugMessage(text)
|
||||
|
||||
-- Check if all assets groups are spawned and trigger events.
|
||||
|
||||
-- Sete asset state to spawned.
|
||||
asset.spawned=true
|
||||
|
||||
-- Check if all assets groups are spawned and trigger events.
|
||||
local allspawned=true
|
||||
for _,_asset in pairs(request.assets) do
|
||||
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
|
||||
allspawned=false
|
||||
end
|
||||
end
|
||||
|
||||
-- Trigger event.
|
||||
if allspawned then
|
||||
self:RequestSpawned(request, request.cargogroupset, request.transportgroupset)
|
||||
end
|
||||
@@ -5311,7 +5313,6 @@ function WAREHOUSE:_SpawnAssetRequest(Request)
|
||||
|
||||
-- Set asset status to not spawned until we capture its birth event.
|
||||
asset.spawned=false
|
||||
--asset.spawngroupname=nil
|
||||
asset.iscargo=true
|
||||
asset.rid=Request.uid
|
||||
|
||||
@@ -5462,7 +5463,12 @@ function WAREHOUSE:_SpawnAssetAircraft(alias, asset, request, parking, uncontrol
|
||||
if request.transporttype==WAREHOUSE.TransportType.SELFPROPELLED then
|
||||
|
||||
-- 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
|
||||
|
||||
@@ -5587,8 +5593,6 @@ function WAREHOUSE:_SpawnAssetPrepareTemplate(asset, alias)
|
||||
|
||||
-- Set unique name.
|
||||
template.name=alias
|
||||
|
||||
env.info(string.format("FF template name %s", alias))
|
||||
|
||||
-- Set current(!) coalition and country.
|
||||
template.CoalitionID=self:GetCoalition()
|
||||
@@ -6043,10 +6047,14 @@ function WAREHOUSE:_OnEventArrived(EventData)
|
||||
if self.uid==wid then
|
||||
|
||||
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.
|
||||
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.
|
||||
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
|
||||
|
||||
-- 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.
|
||||
local nasset=request.ntransport
|
||||
@@ -6952,7 +6960,7 @@ end
|
||||
function WAREHOUSE:_GetTransportsForAssets(request)
|
||||
|
||||
-- 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.
|
||||
local cargoassets=UTILS.DeepCopy(request.cargoassets)
|
||||
|
||||
@@ -31,6 +31,12 @@
|
||||
-- @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 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
|
||||
|
||||
--- Be surprised!
|
||||
@@ -46,25 +52,30 @@
|
||||
-- @field #FLIGHTGROUP
|
||||
FLIGHTGROUP = {
|
||||
ClassName = "FLIGHTGROUP",
|
||||
Debug = nil,
|
||||
sid = nil,
|
||||
groupname = nil,
|
||||
flightgroup = nil,
|
||||
grouptemplate = nil,
|
||||
type = nil,
|
||||
waypoints = {},
|
||||
coordinates = {},
|
||||
element = {},
|
||||
taskqueue = {},
|
||||
taskcounter = nil,
|
||||
taskcurrent = nil,
|
||||
detectedunits = {},
|
||||
homebase = nil,
|
||||
destination = nil,
|
||||
speedmax = nil,
|
||||
range = nil,
|
||||
altmax = nil,
|
||||
fuelthresh = nil,
|
||||
Debug = nil,
|
||||
sid = nil,
|
||||
groupname = nil,
|
||||
flightgroup = nil,
|
||||
grouptemplate = nil,
|
||||
type = nil,
|
||||
waypoints = {},
|
||||
coordinates = {},
|
||||
element = {},
|
||||
taskqueue = {},
|
||||
taskcounter = nil,
|
||||
taskcurrent = nil,
|
||||
detectedunits = {},
|
||||
homebase = nil,
|
||||
destination = nil,
|
||||
speedmax = nil,
|
||||
range = nil,
|
||||
altmax = nil,
|
||||
fuellow = false,
|
||||
fuellowthresh = nil,
|
||||
fuellowrtb = nil,
|
||||
fuelcritical = nil,
|
||||
fuelcriticalthresh = nil,
|
||||
fuelcriticalrtb = false,
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +167,7 @@ FLIGHTGROUP.TaskType={
|
||||
|
||||
--- FLIGHTGROUP class version.
|
||||
-- @field #string version
|
||||
FLIGHTGROUP.version="0.0.7"
|
||||
FLIGHTGROUP.version="0.0.8"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- TODO list
|
||||
@@ -201,6 +212,7 @@ function FLIGHTGROUP:New(groupname)
|
||||
|
||||
-- Defaults
|
||||
self:SetFuelLowThreshold()
|
||||
self:SetFuelCriticalThreshold()
|
||||
|
||||
|
||||
-- Add FSM transitions.
|
||||
@@ -291,7 +303,6 @@ function FLIGHTGROUP:New(groupname)
|
||||
BASE:TraceClass(self.ClassName)
|
||||
BASE:TraceLevel(1)
|
||||
end
|
||||
self.Debug=true
|
||||
|
||||
-- Check if the group is already alive and if so, add its elements.
|
||||
-- TODO: move this to start?
|
||||
@@ -399,18 +410,30 @@ function FLIGHTGROUP:AddTaskWaypoint(description, task, waypointindex, prio, dur
|
||||
return self
|
||||
end
|
||||
|
||||
--- Fuel threshold for RTB.
|
||||
--- Set low fuel threshold. Triggers event "FuelLow" and calls event function "OnAfterFuelLow".
|
||||
-- @param #FLIGHTGROUP self
|
||||
-- @param #number threshold Fuel threshold in percent. Default 15 %.
|
||||
-- @param #boolean rtb If true, RTB on low fuel event.
|
||||
-- @param #number threshold Fuel threshold in percent. Default 25 %.
|
||||
-- @param #boolean rtb If true, RTB on fuel low event.
|
||||
-- @return #FLIGHTGROUP self
|
||||
function FLIGHTGROUP:SetFuelLowThreshold(threshold, rtb)
|
||||
self.fuellowthresh=threshold or 15
|
||||
self.fuellow=false
|
||||
self.fuellowthresh=threshold or 25
|
||||
self.fuellowrtb=rtb
|
||||
return self
|
||||
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.
|
||||
-- @param #FLIGHTGROUP self
|
||||
-- @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 life=unit:GetLifeRelative() or 0
|
||||
|
||||
if fuel<fuelmin then
|
||||
fuelmin=fuel
|
||||
if fuel*100<fuelmin then
|
||||
fuelmin=fuel*100
|
||||
end
|
||||
|
||||
-- Check if element is not dead and we missed an event.
|
||||
@@ -595,9 +618,15 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To)
|
||||
end
|
||||
self:I(self.sid..text)
|
||||
|
||||
-- Low fuel?
|
||||
if fuelmin<self.fuellowthresh and not self.fuellow then
|
||||
self:FuelLow()
|
||||
end
|
||||
|
||||
-- Critical fuel?
|
||||
if fuelmin<self.fuelcriticalthresh and not self.fuelcritical then
|
||||
self:FuelCritical()
|
||||
end
|
||||
|
||||
-- Task queue.
|
||||
text=string.format("Tasks #%d", #self.taskqueue)
|
||||
@@ -954,7 +983,7 @@ end
|
||||
function FLIGHTGROUP:onafterFuelLow(From, Event, To)
|
||||
|
||||
-- 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)
|
||||
self:I(self.sid..text)
|
||||
|
||||
@@ -965,7 +994,30 @@ function FLIGHTGROUP:onafterFuelLow(From, Event, To)
|
||||
local airbase=self.destination or self.homebase
|
||||
|
||||
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
|
||||
|
||||
@@ -992,16 +1044,19 @@ end
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param Wrapper.Airbase#AIRBASE airbase The base to return to.
|
||||
function FLIGHTGROUP:onafterOrbit(From, Event, To, Coord)
|
||||
-- @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 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)
|
||||
self:I(self.sid..text)
|
||||
|
||||
local TaskOrbit=self.flightgroup:TaskOrbit(Coord, Altitude, UTILS.KmphToMps(Speed))
|
||||
|
||||
-- Route helo back home. It is respawned! But this is the only way to ensure that it actually lands at the airbase.
|
||||
self:RouteRTB(airbase)
|
||||
self.flightgroup:SetTask(TaskOrbit)
|
||||
end
|
||||
|
||||
--- On after TaskExecute event.
|
||||
@@ -1487,7 +1542,7 @@ function FLIGHTGROUP:_UpdateRoute(n)
|
||||
self:RTB(airbase)
|
||||
else
|
||||
-- Let flight orbit.
|
||||
self:Orbit()
|
||||
--self:Orbit(self.flightgroup:GetCoordinate(), UTILS.FeetToMeters(20000), self.flightgroup:GetSpeedMax()*0.4)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1041,4 +1041,83 @@ do -- Detection
|
||||
end
|
||||
|
||||
|
||||
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