mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-08-19 22:17:13 +00:00
WH
- WAREHOUSE - FlIGHTGROUP
This commit is contained in:
@@ -1598,6 +1598,7 @@ WAREHOUSE = {
|
|||||||
-- @field #string assignment Assignment of the asset. This could, e.g., be used in the @{#WAREHOUSE.OnAfterNewAsset) function.
|
-- @field #string assignment Assignment of the asset. This could, e.g., be used in the @{#WAREHOUSE.OnAfterNewAsset) function.
|
||||||
-- @field #boolean spawned If true, asset was spawned into the cruel world. If false, it is still in stock.
|
-- @field #boolean spawned If true, asset was spawned into the cruel world. If false, it is still in stock.
|
||||||
-- @field #string spawngroupname Name of the spawned group.
|
-- @field #string spawngroupname Name of the spawned group.
|
||||||
|
-- @field #boolean iscargo If true, asset is cargo. If false asset is transport. Nil if in stock.
|
||||||
|
|
||||||
--- Item of the warehouse queue table.
|
--- Item of the warehouse queue table.
|
||||||
-- @type WAREHOUSE.Queueitem
|
-- @type WAREHOUSE.Queueitem
|
||||||
@@ -4171,6 +4172,11 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
|
|||||||
-- Create an alias name with the UIDs for the sending warehouse, asset and request.
|
-- Create an alias name with the UIDs for the sending warehouse, asset and request.
|
||||||
local _alias=self:_alias(_assetitem.unittype, self.uid, _assetitem.uid, Request.uid)
|
local _alias=self:_alias(_assetitem.unittype, self.uid, _assetitem.uid, Request.uid)
|
||||||
|
|
||||||
|
-- Asset is transport.
|
||||||
|
_assetitem.spawned=false
|
||||||
|
_assetitem.spawngroupname=nil
|
||||||
|
_assetitem.iscargo=false
|
||||||
|
|
||||||
local spawngroup=nil --Wrapper.Group#GROUP
|
local spawngroup=nil --Wrapper.Group#GROUP
|
||||||
|
|
||||||
-- Spawn assets depending on type.
|
-- Spawn assets depending on type.
|
||||||
@@ -4240,7 +4246,7 @@ function WAREHOUSE:onafterRequestSpawned(From, Event, To, Request, CargoGroupSet
|
|||||||
local _cargocategory=Request.cargocategory --DCS#Group.Category
|
local _cargocategory=Request.cargocategory --DCS#Group.Category
|
||||||
|
|
||||||
-- Add groups to pending item.
|
-- Add groups to pending item.
|
||||||
Request.cargogroupset=CargoGroupSet
|
--Request.cargogroupset=CargoGroupSet
|
||||||
|
|
||||||
------------------------------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- Self request: assets are spawned at warehouse but not transported anywhere.
|
-- Self request: assets are spawned at warehouse but not transported anywhere.
|
||||||
@@ -4959,20 +4965,19 @@ function WAREHOUSE:onafterAssetSpawned(From, Event, To, group, asset, request)
|
|||||||
|
|
||||||
local allspawned=true
|
local allspawned=true
|
||||||
for _,_asset in pairs(request.assets) do
|
for _,_asset in pairs(request.assets) do
|
||||||
local asset=_asset --#WAREHOUSE.Assetitem
|
local assetitem=_asset --#WAREHOUSE.Assetitem
|
||||||
|
|
||||||
if not asset.spawned then
|
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
|
allspawned=false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if allspawned then
|
if allspawned then
|
||||||
if request.toself then
|
self:RequestSpawned(request, request.cargogroupset, request.transportgroupset)
|
||||||
self:SelfRequest(request.cargogroupset, request)
|
|
||||||
else
|
|
||||||
self:RequestSpawned(request, request.cargogroupset, request.transportgroupset)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- On after "AssetDead" event triggered when an asset group died.
|
--- On after "AssetDead" event triggered when an asset group died.
|
||||||
@@ -5275,6 +5280,7 @@ 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.spawngroupname=nil
|
||||||
|
asset.iscargo=true
|
||||||
|
|
||||||
-- Alias of the group.
|
-- Alias of the group.
|
||||||
local _alias=self:_Alias(asset, Request)
|
local _alias=self:_Alias(asset, Request)
|
||||||
@@ -5826,8 +5832,7 @@ end
|
|||||||
--- Get a warehouse request from its unique id.
|
--- Get a warehouse request from its unique id.
|
||||||
-- @param #WAREHOUSE self
|
-- @param #WAREHOUSE self
|
||||||
-- @param #number id Asset ID.
|
-- @param #number id Asset ID.
|
||||||
-- @return #WAREHOUSE.Pendingitem The warehouse requested - either queued or pending.
|
-- @return #WAREHOUSE.Pendingitem The warehouse requested - either queued or pending. #boolean If *true*, request is queued, if *false*, request is pending, if *nil*, request could not be found.
|
||||||
-- @return #boolean If *true*, request is queued, if *false*, request is pending, if *nil*, request could not be found.
|
|
||||||
function WAREHOUSE:GetRequestByID(id)
|
function WAREHOUSE:GetRequestByID(id)
|
||||||
|
|
||||||
if id then
|
if id then
|
||||||
@@ -5870,18 +5875,32 @@ function WAREHOUSE:_OnEventBirth(EventData)
|
|||||||
local asset=self:GetAssetByID(aid)
|
local asset=self:GetAssetByID(aid)
|
||||||
local request=self:GetRequestByID(rid)
|
local request=self:GetRequestByID(rid)
|
||||||
|
|
||||||
-- Remove asset from stock.
|
-- Birth is triggered for each unit. We need to make sure not to call this too often!
|
||||||
self:_DeleteStockItem(asset)
|
if not asset.spawned then
|
||||||
|
|
||||||
-- Set spawned switch.
|
-- Remove asset from stock.
|
||||||
asset.spawned=true
|
self:_DeleteStockItem(asset)
|
||||||
asset.spawngroupname=group:GetName()
|
|
||||||
|
|
||||||
-- Set warehouse state.
|
-- Set spawned switch.
|
||||||
group:SetState(group, "WAREHOUSE", self)
|
asset.spawned=true
|
||||||
|
asset.spawngroupname=group:GetName()
|
||||||
|
|
||||||
-- Asset spawned FSM function.
|
-- Add group.
|
||||||
self:__AssetSpawned(0.1, group, asset, request)
|
if asset.iscargo==true then
|
||||||
|
request.cargogroupset=request.cargogroupset or SET_GROUP:New()
|
||||||
|
request.cargogroupset:AddGroup(group)
|
||||||
|
else
|
||||||
|
request.transportgroupset=request.transportgroupset or SET_GROUP:New()
|
||||||
|
request.transportgroupset:AddGroup(group)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Set warehouse state.
|
||||||
|
group:SetState(group, "WAREHOUSE", self)
|
||||||
|
|
||||||
|
-- Asset spawned FSM function.
|
||||||
|
self:__AssetSpawned(1, group, asset, request)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
--self:T3({wid=wid, uid=self.uid, match=(wid==self.uid), tw=type(wid), tu=type(self.uid)})
|
--self:T3({wid=wid, uid=self.uid, match=(wid==self.uid), tw=type(wid), tu=type(self.uid)})
|
||||||
|
|||||||
@@ -45,9 +45,9 @@ FLIGHTGROUP = {
|
|||||||
|
|
||||||
--- Flight group element.
|
--- Flight group element.
|
||||||
-- @type FLIGHTGROUP.Element
|
-- @type FLIGHTGROUP.Element
|
||||||
-- @param #string name Name of the element.
|
-- @field #string name Name of the element.
|
||||||
-- @param Wrapper.Unit#UNIT unit Element unit object.
|
-- @field Wrapper.Unit#UNIT unit Element unit object.
|
||||||
-- @param #string status Status, i.e. born, parking, taxiing.
|
-- @field #string status Status, i.e. born, parking, taxiing.
|
||||||
|
|
||||||
--- Flight group tasks.
|
--- Flight group tasks.
|
||||||
-- @type FLIGHTGROUP.Task
|
-- @type FLIGHTGROUP.Task
|
||||||
@@ -164,4 +164,112 @@ function FLIGHTGROUP:New(AIGroup)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
-- Start & Status
|
||||||
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
--- On after Start event. Starts the warehouse. Addes event handlers and schedules status updates of reqests and queue.
|
||||||
|
-- @param #FLIGHTGROUP self
|
||||||
|
-- @param Wrapper.Group#GROUP Group Flight group.
|
||||||
|
-- @param #string From From state.
|
||||||
|
-- @param #string Event Event.
|
||||||
|
-- @param #string To To state.
|
||||||
|
function FLIGHTGROUP:onafterStart(Group, From, Event, To)
|
||||||
|
|
||||||
|
-- Short info.
|
||||||
|
local text=string.format("Starting flight group %s\n", self.groupname)
|
||||||
|
self:I(self.sid..text)
|
||||||
|
|
||||||
|
|
||||||
|
-- Handle events:
|
||||||
|
self:HandleEvent(EVENTS.Birth, self.OnEventBirth)
|
||||||
|
self:HandleEvent(EVENTS.EngineStartup, self.OnEventEngineStartup)
|
||||||
|
self:HandleEvent(EVENTS.Takeoff, self.OnEventTakeOff)
|
||||||
|
self:HandleEvent(EVENTS.Land, self.OnEventLanding)
|
||||||
|
self:HandleEvent(EVENTS.EngineShutdown, self.OnEventEngineShutdown)
|
||||||
|
self:HandleEvent(EVENTS.PilotDead, self.OnEventPilotDead)
|
||||||
|
self:HandleEvent(EVENTS.Ejection, self.OnEventEjection)
|
||||||
|
self:HandleEvent(EVENTS.Crash, self.OnEventCrash)
|
||||||
|
|
||||||
|
-- Start the status monitoring.
|
||||||
|
self:__Status(-1)
|
||||||
|
end
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
-- Events
|
||||||
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
--- Flightgroup event function, handling the birth of a unit.
|
||||||
|
-- @param #FLIGHTGROUP self
|
||||||
|
-- @param Core.Event#EVENTDATA EventData Event data.
|
||||||
|
function FLIGHTGROUP:OnEventBirth(EventData)
|
||||||
|
|
||||||
|
if EventData and EventData.IniGroup and EventData.IniUnit then
|
||||||
|
local unit=EventData.IniUnit
|
||||||
|
local group=EventData.IniGroup
|
||||||
|
local unitname=EventData.IniUnitName
|
||||||
|
|
||||||
|
local element=self:GetElementByName(unitname)
|
||||||
|
|
||||||
|
if element then
|
||||||
|
element.status="born"
|
||||||
|
|
||||||
|
if unit:InAir() then
|
||||||
|
element.status="airborn"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
-- FSM functions
|
||||||
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
-- Misc functions
|
||||||
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
--- Check if a unit is and element of the flightgroup.
|
||||||
|
-- @param #FLIGHTGROUP self
|
||||||
|
-- @param #string unitname Name of unit.
|
||||||
|
-- @return #FLIGHTGROUP.Element The element.
|
||||||
|
function FLIGHTGROUP:GetElementByName(unitname)
|
||||||
|
|
||||||
|
for _,_element in pairs(self.element) do
|
||||||
|
local element=_element --#FLIGHTGROUP.Element
|
||||||
|
|
||||||
|
if element.name==unitname then
|
||||||
|
return element
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Check if a unit is and element of the flightgroup.
|
||||||
|
-- @param #FLIGHTGROUP self
|
||||||
|
-- @param #string unitname Name of unit.
|
||||||
|
function FLIGHTGROUP:_IsElement(unitname)
|
||||||
|
|
||||||
|
for _,_element in pairs(self.element) do
|
||||||
|
local element=_element --#FLIGHTGROUP.Element
|
||||||
|
|
||||||
|
if element.name==unitname then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user