mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
WAREHOUSE
This commit is contained in:
parent
e0564876f4
commit
d4449f7913
@ -17,6 +17,10 @@
|
|||||||
--- WAREHOUSE class.
|
--- WAREHOUSE class.
|
||||||
-- @type WAREHOUSE
|
-- @type WAREHOUSE
|
||||||
-- @field #string ClassName Name of the class.
|
-- @field #string ClassName Name of the class.
|
||||||
|
-- @field DCS#Coalition coalition Coalition the warehouse belongs to.
|
||||||
|
-- @field Core.Point#COORDINATE coordinate Coordinate of the warehouse.
|
||||||
|
-- @field Wrapper.Airbase#AIRBASE airbase Airbase the warehouse belongs to.
|
||||||
|
-- @field #table stock Table holding all assets in stock. Table entries are of type @{#WAREHOUSE.Stock}.
|
||||||
-- @extends Core.Fsm#FSM
|
-- @extends Core.Fsm#FSM
|
||||||
|
|
||||||
--- Manages ground assets of an airbase and offers the possibility to transport them to another airbase or warehouse.
|
--- Manages ground assets of an airbase and offers the possibility to transport them to another airbase or warehouse.
|
||||||
@ -47,10 +51,11 @@
|
|||||||
--
|
--
|
||||||
-- @field #WAREHOUSE
|
-- @field #WAREHOUSE
|
||||||
WAREHOUSE = {
|
WAREHOUSE = {
|
||||||
ClassName = "WAREHOUSE",
|
ClassName = "WAREHOUSE",
|
||||||
coalition = nil,
|
coalition = nil,
|
||||||
homebase = nil,
|
homebase = nil,
|
||||||
stock = {},
|
coordinate = nil,
|
||||||
|
stock = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
--- Type Warehouse stock table. table.insert(self.stock, {templatename=templategroupname, category=DCScategory, type=DCStype, transport=transport, fighther=fighter, tanker=tanker, awacs=awacs, artillery=artillery})
|
--- Type Warehouse stock table. table.insert(self.stock, {templatename=templategroupname, category=DCScategory, type=DCStype, transport=transport, fighther=fighter, tanker=tanker, awacs=awacs, artillery=artillery})
|
||||||
@ -59,11 +64,20 @@ WAREHOUSE = {
|
|||||||
-- @field DCS#Category category Category of the group. Airplane, helicopter, ...
|
-- @field DCS#Category category Category of the group. Airplane, helicopter, ...
|
||||||
-- @field #string type Type of the group
|
-- @field #string type Type of the group
|
||||||
-- @field #boolean fighter If true, group is a fighter airplane.
|
-- @field #boolean fighter If true, group is a fighter airplane.
|
||||||
|
-- @field #boolean attackhelo If true, group is an attack helicopter.
|
||||||
-- @field #boolean transport If truie, group can transport other units either by air or ground.
|
-- @field #boolean transport If truie, group can transport other units either by air or ground.
|
||||||
-- @field #boolean tanker If true, group is a tanker and can refuel other air units.
|
-- @field #boolean tanker If true, group is a tanker and can refuel other air units.
|
||||||
-- @field #boolean awacs If true, group has AWACS capabilities.
|
-- @field #boolean awacs If true, group has AWACS capabilities.
|
||||||
-- @field #boolean artillery If true, group is an artillery unit.
|
-- @field #boolean artillery If true, group is an artillery unit.
|
||||||
|
|
||||||
|
--- Asset descriptor.
|
||||||
|
-- @field Warehouse.AssetDescriptor Assetdescriptor
|
||||||
|
WAREHOUSE.Descriptor = {
|
||||||
|
TEMPLATENAME="templatename",
|
||||||
|
CATEGORY="category",
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
--- Warehouse classes.
|
--- Warehouse classes.
|
||||||
-- @field Warehouse.Class Class
|
-- @field Warehouse.Class Class
|
||||||
WAREHOUSE.Class = {
|
WAREHOUSE.Class = {
|
||||||
@ -72,16 +86,18 @@ WAREHOUSE.Class = {
|
|||||||
TANKER=3,
|
TANKER=3,
|
||||||
AWACS=4,
|
AWACS=4,
|
||||||
ARTY=5,
|
ARTY=5,
|
||||||
|
ATTACKHELO=6,
|
||||||
}
|
}
|
||||||
|
|
||||||
--- Warehouse categories
|
--- Warehouse categories
|
||||||
-- @field Category
|
-- @field Category
|
||||||
WAREHOUSE.Category = {
|
WAREHOUSE.Category = {
|
||||||
AIRPLANE = 0,
|
AIRPLANE = "plane",
|
||||||
HELICOPTER = 1,
|
HELICOPTER = "helo",
|
||||||
GROUND = 2,
|
GROUND = "apc",
|
||||||
SHIP = 3,
|
SHIP = "ship",
|
||||||
TRAIN = 4,
|
TRAIN = "train",
|
||||||
|
SELF = "self",
|
||||||
}
|
}
|
||||||
|
|
||||||
--- Warehouse class version.
|
--- Warehouse class version.
|
||||||
@ -207,12 +223,63 @@ function WAREHOUSE:onafterStatus(From, Event, To)
|
|||||||
|
|
||||||
env.info(string.format("FF warehouse at %s: number of stock = %d", self.homebase:GetName(), #self.stock))
|
env.info(string.format("FF warehouse at %s: number of stock = %d", self.homebase:GetName(), #self.stock))
|
||||||
|
|
||||||
self:__Status(-30)
|
self:__Status(30)
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
--- On before "Request" event. Checks if the request can be fullfilled.
|
||||||
|
-- @param #WAREHOUSE self
|
||||||
|
-- @param #string From From state.
|
||||||
|
-- @param #string Event Event.
|
||||||
|
-- @param #string To To state.
|
||||||
|
-- @param Wrapper.Airbase#AIRBASE Airbase Airbase requesting supply.
|
||||||
|
-- @param #string AssetDescriptor Asset that is requested. Can be "templatename", ...
|
||||||
|
-- @param depends AssetDescriptorvalue Value of the asset descriptor. Type depends on descriptor, i.e. could be a string,
|
||||||
|
-- @param #number nAssed Number of groups of that asset requested.
|
||||||
|
-- @param #string TransportType Type of transport: "Plane", "Helicopter", "APC"
|
||||||
|
-- @return boolean If true, request is granted.
|
||||||
|
--
|
||||||
|
-- @usage mywarehouse:Request(AIRBASE:)...
|
||||||
|
function WAREHOUSE:onbeforeRequest(From, Event, To, Airbase, AssetDescriptor, AssetDescriptorValue, nAsset, TransportType)
|
||||||
|
|
||||||
--- Warehouse
|
-- Distance from warehouse to
|
||||||
|
local distance=self.coordinate:Get2DDistance(Airbase:GetCoordinate())
|
||||||
|
|
||||||
|
--
|
||||||
|
local _stockrequest=self._FilterStock(self.stock, AssetDescriptor, AssetDescriptorValue)
|
||||||
|
|
||||||
|
-- Asset is not in stock ==> request denied.
|
||||||
|
if #_stockrequest==0 then
|
||||||
|
self:E(self.wid..string.format("Request denied! Asset is currently not in stock."))
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local _TT=TransportType:lower()
|
||||||
|
if _TT==nil then
|
||||||
|
if AssetDescriptor=="" then
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if TransportType:lower() == "plane" then
|
||||||
|
|
||||||
|
elseif TransportType:lower() == "helicopter" then
|
||||||
|
|
||||||
|
elseif TransportType:lower() == "apc" then
|
||||||
|
|
||||||
|
elseif TransportType:lower() == "train" then
|
||||||
|
|
||||||
|
elseif TransportType:lower() == "ship" then
|
||||||
|
|
||||||
|
elseif TransportType:lower() == "self" then
|
||||||
|
|
||||||
|
else
|
||||||
|
self:E(self.wid..string.format("ERROR: unknown transport type requested! type = %s", tostring(TransportType)))
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- On after "Request" event.
|
||||||
-- @param #WAREHOUSE self
|
-- @param #WAREHOUSE self
|
||||||
-- @param #string From From state.
|
-- @param #string From From state.
|
||||||
-- @param #string Event Event.
|
-- @param #string Event Event.
|
||||||
@ -229,10 +296,12 @@ function WAREHOUSE:onafterRequest(From, Event, To, Airbase, Asset, nAsset, Trans
|
|||||||
if TransportType=="Air" then
|
if TransportType=="Air" then
|
||||||
|
|
||||||
-- Get a random template from the stock list.
|
-- Get a random template from the stock list.
|
||||||
local _chosenone=math.random(#self.stock)
|
local _chosenone=math.random(#self.stock) --#WAREHOUSE.Stock
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Select template group name.
|
-- Select template group name.
|
||||||
--TODO: FILTER HERE'!
|
--TODO: FILTER HERE!
|
||||||
local template=self.stock[_chosenone].templatename
|
local template=self.stock[_chosenone].templatename
|
||||||
|
|
||||||
if template then
|
if template then
|
||||||
@ -270,17 +339,19 @@ function WAREHOUSE:onafterRequest(From, Event, To, Airbase, Asset, nAsset, Trans
|
|||||||
-- Set warehouse state so that we can retreive it later.
|
-- Set warehouse state so that we can retreive it later.
|
||||||
Plane:SetState(Plane, "WAREHOUSE", self)
|
Plane:SetState(Plane, "WAREHOUSE", self)
|
||||||
|
|
||||||
-- Once the cargo was loaded start off to deploy airbase.
|
--- Once the cargo was loaded start off to deploy airbase.
|
||||||
function CargoPlane:OnAfterLoaded(Airplane, From, Event, To)
|
function CargoPlane:OnAfterLoaded(Airplane, From, Event, To)
|
||||||
CargoPlane:__Deploy(10, Airbase, 500)
|
CargoPlane:__Deploy(10, Airbase, 500)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Function
|
--- Function called when cargo has arrived and was unloaded.
|
||||||
-- @param Wrapper.Group#GROUP Airplane
|
|
||||||
function CargoPlane:OnAfterUnloaded(Airplane, From, Event, To)
|
function CargoPlane:OnAfterUnloaded(Airplane, From, Event, To)
|
||||||
|
|
||||||
local group=CargoPlane.Cargo:GetObject()
|
local group=CargoPlane.Cargo:GetObject()
|
||||||
local Airplane=Airplane --Wrapper.Group#GROUP
|
local Airplane=Airplane --Wrapper.Group#GROUP
|
||||||
local warehouse Airplane:GetState(Airplane, "WAREHOUSE") --#WAREHOUSE
|
local warehouse=Airplane:GetState(Airplane, "WAREHOUSE") --#WAREHOUSE
|
||||||
|
|
||||||
|
-- Trigger Delivered event.
|
||||||
warehouse:__Delivered(1, group)
|
warehouse:__Delivered(1, group)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -370,11 +441,20 @@ end
|
|||||||
|
|
||||||
--- Filter stock assets by table entry.
|
--- Filter stock assets by table entry.
|
||||||
-- @param #WAREHOUSE self
|
-- @param #WAREHOUSE self
|
||||||
-- @param #WAREHOUSE.Stock entry
|
-- @param #WAREHOUSE.Stock stock
|
||||||
function WAREHOUSE:_FilterStock(entry)
|
-- @param #string item Descriptor
|
||||||
--entry.artillery
|
-- @param depends value
|
||||||
|
function WAREHOUSE:_FilterStock(stock, item, value)
|
||||||
|
|
||||||
return
|
local filtered={}
|
||||||
|
|
||||||
|
for _,_stock in pairs(stock) do
|
||||||
|
if _stock[item]==value then
|
||||||
|
table.insert(filtered, _stock)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return filtered
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user