mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Warehouse v0.4.9
Added option to force cargo bay limit and cargo asset weight.
This commit is contained in:
@@ -142,9 +142,11 @@ function AI_CARGO:New( Carrier, CargoSet )
|
|||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
|
|
||||||
for _, CarrierUnit in pairs( Carrier:GetUnits() ) do
|
-- FF "Workaround" for not being able to set the cargo bay limit manually for the carrier group.
|
||||||
CarrierUnit:SetCargoBayWeightLimit()
|
-- FF Moreover, the carrier group is an input parameter and should not be overwritten here.
|
||||||
end
|
--for _, CarrierUnit in pairs( Carrier:GetUnits() ) do
|
||||||
|
--CarrierUnit:SetCargoBayWeightLimit()
|
||||||
|
--end
|
||||||
|
|
||||||
self.Transporting = false
|
self.Transporting = false
|
||||||
self.Relocating = false
|
self.Relocating = false
|
||||||
|
|||||||
@@ -986,7 +986,7 @@ WAREHOUSE.db = {
|
|||||||
|
|
||||||
--- Warehouse class version.
|
--- Warehouse class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
WAREHOUSE.version="0.4.8"
|
WAREHOUSE.version="0.4.9"
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- TODO: Warehouse todo list.
|
-- TODO: Warehouse todo list.
|
||||||
@@ -1090,6 +1090,10 @@ function WAREHOUSE:New(warehouse, alias)
|
|||||||
-- Add warehouse to database.
|
-- Add warehouse to database.
|
||||||
WAREHOUSE.db.Warehouses[self.uid]=self
|
WAREHOUSE.db.Warehouses[self.uid]=self
|
||||||
|
|
||||||
|
-----------------------
|
||||||
|
--- FSM Transitions ---
|
||||||
|
-----------------------
|
||||||
|
|
||||||
-- Start State.
|
-- Start State.
|
||||||
self:SetStartState("NotReadyYet")
|
self:SetStartState("NotReadyYet")
|
||||||
|
|
||||||
@@ -1176,6 +1180,8 @@ function WAREHOUSE:New(warehouse, alias)
|
|||||||
-- @param Wrapper.Group#GROUP group Group to be added as new asset.
|
-- @param Wrapper.Group#GROUP group Group to be added as new asset.
|
||||||
-- @param #number ngroups Number of groups to add to the warehouse stock. Default is 1.
|
-- @param #number ngroups Number of groups to add to the warehouse stock. Default is 1.
|
||||||
-- @param #WAREHOUSE.Attribute forceattribute (Optional) Explicitly force a generalized attribute for the asset. This has to be an @{#WAREHOUSE.Attribute}.
|
-- @param #WAREHOUSE.Attribute forceattribute (Optional) Explicitly force a generalized attribute for the asset. This has to be an @{#WAREHOUSE.Attribute}.
|
||||||
|
-- @param #number forcecargobay (Optional) Explicitly force cargobay weight limit in kg for cargo carriers. This is for each *unit* of the group.
|
||||||
|
-- @param #number forceweight (Optional) Explicitly force weight in kg of each unit in the group.
|
||||||
|
|
||||||
--- Trigger the FSM event "AddAsset" with a delay. Add a group to the warehouse stock.
|
--- Trigger the FSM event "AddAsset" with a delay. Add a group to the warehouse stock.
|
||||||
-- @function [parent=#WAREHOUSE] __AddAsset
|
-- @function [parent=#WAREHOUSE] __AddAsset
|
||||||
@@ -1184,6 +1190,8 @@ function WAREHOUSE:New(warehouse, alias)
|
|||||||
-- @param Wrapper.Group#GROUP group Group to be added as new asset.
|
-- @param Wrapper.Group#GROUP group Group to be added as new asset.
|
||||||
-- @param #number ngroups Number of groups to add to the warehouse stock. Default is 1.
|
-- @param #number ngroups Number of groups to add to the warehouse stock. Default is 1.
|
||||||
-- @param #WAREHOUSE.Attribute forceattribute (Optional) Explicitly force a generalized attribute for the asset. This has to be an @{#WAREHOUSE.Attribute}.
|
-- @param #WAREHOUSE.Attribute forceattribute (Optional) Explicitly force a generalized attribute for the asset. This has to be an @{#WAREHOUSE.Attribute}.
|
||||||
|
-- @param #number forcecargobay (Optional) Explicitly force cargobay weight limit in kg for cargo carriers. This is for each *unit* of the group.
|
||||||
|
-- @param #number forceweight (Optional) Explicitly force weight in kg of each unit in the group.
|
||||||
|
|
||||||
|
|
||||||
--- Triggers the FSM event "AddRequest". Add a request to the warehouse queue, which is processed when possible.
|
--- Triggers the FSM event "AddRequest". Add a request to the warehouse queue, which is processed when possible.
|
||||||
@@ -2178,7 +2186,7 @@ function WAREHOUSE:onafterStatus(From, Event, To)
|
|||||||
|
|
||||||
-- Display complete list of stock itmes.
|
-- Display complete list of stock itmes.
|
||||||
if self.Debug then
|
if self.Debug then
|
||||||
--self:_DisplayStockItems(self.stock)
|
self:_DisplayStockItems(self.stock)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Call status again in ~30 sec (user choice).
|
-- Call status again in ~30 sec (user choice).
|
||||||
@@ -2374,7 +2382,9 @@ end
|
|||||||
-- @param Wrapper.Group#GROUP group Group or template group to be added to the warehouse stock.
|
-- @param Wrapper.Group#GROUP group Group or template group to be added to the warehouse stock.
|
||||||
-- @param #number ngroups Number of groups to add to the warehouse stock. Default is 1.
|
-- @param #number ngroups Number of groups to add to the warehouse stock. Default is 1.
|
||||||
-- @param #WAREHOUSE.Attribute forceattribute (Optional) Explicitly force a generalized attribute for the asset. This has to be an @{#WAREHOUSE.Attribute}.
|
-- @param #WAREHOUSE.Attribute forceattribute (Optional) Explicitly force a generalized attribute for the asset. This has to be an @{#WAREHOUSE.Attribute}.
|
||||||
function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribute)
|
-- @param #number forcecargobay (Optional) Explicitly force cargobay weight limit in kg for cargo carriers. This is for each *unit* of the group.
|
||||||
|
-- @param #number forceweight (Optional) Explicitly force weight in kg of each unit in the group.
|
||||||
|
function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribute, forcecargobay, forceweight)
|
||||||
|
|
||||||
-- Set default.
|
-- Set default.
|
||||||
local n=ngroups or 1
|
local n=ngroups or 1
|
||||||
@@ -2439,7 +2449,7 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu
|
|||||||
self:_DebugMessage(self.wid..string.format("Warehouse %s: Adding %d NEW assets of group %s to stock.", self.alias, n, tostring(group:GetName())), 5)
|
self:_DebugMessage(self.wid..string.format("Warehouse %s: Adding %d NEW assets of group %s to stock.", self.alias, n, tostring(group:GetName())), 5)
|
||||||
|
|
||||||
-- This is a group that is not in the db yet. Add it n times.
|
-- This is a group that is not in the db yet. Add it n times.
|
||||||
local assets=self:_RegisterAsset(group, n, forceattribute)
|
local assets=self:_RegisterAsset(group, n, forceattribute, forcecargobay, forceweight)
|
||||||
|
|
||||||
-- Add created assets to stock of this warehouse.
|
-- Add created assets to stock of this warehouse.
|
||||||
for _,asset in pairs(assets) do
|
for _,asset in pairs(assets) do
|
||||||
@@ -2468,8 +2478,10 @@ end
|
|||||||
-- @param Wrapper.Group#GROUP group The group that will be added to the warehouse stock.
|
-- @param Wrapper.Group#GROUP group The group that will be added to the warehouse stock.
|
||||||
-- @param #number ngroups Number of groups to be added.
|
-- @param #number ngroups Number of groups to be added.
|
||||||
-- @param #string forceattribute Forced generalized attribute.
|
-- @param #string forceattribute Forced generalized attribute.
|
||||||
|
-- @param #number forcecargobay Cargo bay weight limit in kg.
|
||||||
|
-- @param #number forceweight Weight of units in kg.
|
||||||
-- @return #table A table containing all registered assets.
|
-- @return #table A table containing all registered assets.
|
||||||
function WAREHOUSE:_RegisterAsset(group, ngroups, forceattribute)
|
function WAREHOUSE:_RegisterAsset(group, ngroups, forceattribute, forcecargobay, forceweight)
|
||||||
self:F({groupname=group:GetName(), ngroups=ngroups, forceattribute=forceattribute})
|
self:F({groupname=group:GetName(), ngroups=ngroups, forceattribute=forceattribute})
|
||||||
|
|
||||||
-- Set default.
|
-- Set default.
|
||||||
@@ -2506,15 +2518,30 @@ function WAREHOUSE:_RegisterAsset(group, ngroups, forceattribute)
|
|||||||
local Desc=unit:GetDesc()
|
local Desc=unit:GetDesc()
|
||||||
|
|
||||||
-- Weight. We sum up all units in the group.
|
-- Weight. We sum up all units in the group.
|
||||||
local unitweight=Desc.massEmpty
|
local unitweight=forceweight or Desc.massEmpty
|
||||||
if unitweight then
|
if unitweight then
|
||||||
weight=weight+unitweight
|
weight=weight+unitweight
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local cargomax=0
|
||||||
|
local massfuel=Desc.fuelMassMax or 0
|
||||||
|
local massempty=Desc.massEmpty or 0
|
||||||
|
local massmax=Desc.massMax or 0
|
||||||
|
|
||||||
|
-- Calcuate cargo bay limit value.
|
||||||
|
cargomax=massmax-massfuel-massempty
|
||||||
|
self:T3(self.wid..string.format("Unit name=%s: mass empty=%.1f kg, fuel=%.1f kg, max=%.1f kg ==> cargo=%.1f kg", unit:GetName(), unitweight, massfuel, massmax, cargomax))
|
||||||
|
|
||||||
-- Cargo bay size.
|
-- Cargo bay size.
|
||||||
local bay=unit:GetCargoBayFreeWeight()
|
local bay=forcecargobay or unit:GetCargoBayFreeWeight()
|
||||||
|
|
||||||
|
-- Add bay size to table.
|
||||||
table.insert(cargobay, bay)
|
table.insert(cargobay, bay)
|
||||||
|
|
||||||
|
-- Sum up total bay size.
|
||||||
cargobaytot=cargobaytot+bay
|
cargobaytot=cargobaytot+bay
|
||||||
|
|
||||||
|
-- Get max bay size.
|
||||||
if bay>cargobaymax then
|
if bay>cargobaymax then
|
||||||
cargobaymax=bay
|
cargobaymax=bay
|
||||||
end
|
end
|
||||||
@@ -2912,9 +2939,26 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
|
|||||||
-- Empty cargo group set.
|
-- Empty cargo group set.
|
||||||
CargoGroups = SET_CARGO:New()
|
CargoGroups = SET_CARGO:New()
|
||||||
|
|
||||||
|
local function getasset(group)
|
||||||
|
local _,aid,_=self:_GetIDsFromGroup(group)
|
||||||
|
self:FindAssetInDB(group)
|
||||||
|
end
|
||||||
|
|
||||||
-- Add cargo groups to set.
|
-- Add cargo groups to set.
|
||||||
for _i,_group in pairs(_spawngroups:GetSetObjects()) do
|
for _i,_group in pairs(_spawngroups:GetSetObjects()) do
|
||||||
CargoGroups:AddCargo(CARGO_GROUP:New(_group, _cargotype,_group:GetName(),_loadradius,_nearradius))
|
|
||||||
|
-- New cargo group object.
|
||||||
|
local cargogroup=CARGO_GROUP:New(_group, _cargotype,_group:GetName(),_loadradius,_nearradius)
|
||||||
|
|
||||||
|
-- Find asset belonging to this group.
|
||||||
|
local asset=self:FindAssetInDB(_group)
|
||||||
|
if asset then
|
||||||
|
-- Set weight for this group.
|
||||||
|
cargogroup:SetWeight(asset.weight)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Add group to group set.
|
||||||
|
CargoGroups:AddCargo(cargogroup)
|
||||||
end
|
end
|
||||||
|
|
||||||
------------------------------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -3017,20 +3061,31 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
|
|||||||
|
|
||||||
-- Add cargo group set.
|
-- Add cargo group set.
|
||||||
Pending.transportcargoset=CargoGroups
|
Pending.transportcargoset=CargoGroups
|
||||||
|
|
||||||
-- Create empty tables which will be filled with the cargo groups of each carrier unit. Needed in case a carrier unit dies.
|
|
||||||
Pending.carriercargo={}
|
|
||||||
for _,carriergroup in pairs(TransportSet:GetSetObjects()) do
|
|
||||||
for _,carrierunit in pairs(carriergroup:GetUnits()) do
|
|
||||||
Pending.carriercargo[carrierunit:GetName()]={}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Add request to pending queue.
|
-- Add request to pending queue.
|
||||||
table.insert(self.pending, Pending)
|
table.insert(self.pending, Pending)
|
||||||
|
|
||||||
-- Delete request from queue.
|
-- Delete request from queue.
|
||||||
self:_DeleteQueueItem(Request, self.queue)
|
self:_DeleteQueueItem(Request, self.queue)
|
||||||
|
|
||||||
|
-- Adjust carrier units. This has to come AFTER the dispatchers have been defined because they set the cargobay free weight!
|
||||||
|
Pending.carriercargo={}
|
||||||
|
for _,carriergroup in pairs(TransportSet:GetSetObjects()) do
|
||||||
|
local asset=self:FindAssetInDB(carriergroup)
|
||||||
|
for _i,_carrierunit in pairs(carriergroup:GetUnits()) do
|
||||||
|
local carrierunit=_carrierunit --Wrapper.Unit#UNIT
|
||||||
|
|
||||||
|
-- Create empty tables which will be filled with the cargo groups of each carrier unit. Needed in case a carrier unit dies.
|
||||||
|
Pending.carriercargo[carrierunit:GetName()]={}
|
||||||
|
|
||||||
|
-- Adjust cargo bay of carrier unit.
|
||||||
|
local cargobay=asset.cargobay[_i]
|
||||||
|
carrierunit:SetCargoBayWeightLimit(cargobay)
|
||||||
|
|
||||||
|
-- Debug info.
|
||||||
|
self:T2(self.wid..string.format("Cargo bay weight limit ofcarrier unit %s: %.1f kg.", carrierunit:GetName(), carrierunit:GetCargoBayFreeWeight()))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
------------------------
|
------------------------
|
||||||
-- Create Dispatchers --
|
-- Create Dispatchers --
|
||||||
@@ -3656,7 +3711,7 @@ function WAREHOUSE:_SpawnAssetRequest(Request)
|
|||||||
-- Add group to group set and asset list.
|
-- Add group to group set and asset list.
|
||||||
if _group then
|
if _group then
|
||||||
_groupset:AddGroup(_group)
|
_groupset:AddGroup(_group)
|
||||||
table.insert(_assets, _assetitem)
|
table.insert(_assets, _assetitem)
|
||||||
else
|
else
|
||||||
self:E(self.wid.."ERROR: Cargo asset could not be spawned!")
|
self:E(self.wid.."ERROR: Cargo asset could not be spawned!")
|
||||||
end
|
end
|
||||||
@@ -4989,7 +5044,8 @@ function WAREHOUSE:_CheckRequestNow(request)
|
|||||||
if not _enough then
|
if not _enough then
|
||||||
local text=string.format("Warehouse %s: Request denied! Not enough (cargo) assets currently available.", self.alias)
|
local text=string.format("Warehouse %s: Request denied! Not enough (cargo) assets currently available.", self.alias)
|
||||||
self:_InfoMessage(text, 5)
|
self:_InfoMessage(text, 5)
|
||||||
|
text=string.format("Enough=%s, #_assets=%d, _nassets=%d, request.nasset=%s", tostring(_enough), #_assets,_nassets, tostring(request.nasset))
|
||||||
|
env.info(text)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -5178,7 +5234,7 @@ function WAREHOUSE:_GetTransportsForAssets(request)
|
|||||||
--self:E(self.wid..string.format("%s unit %d loads cargo uid=%d: bayempty=%02d, bayloaded = %02d - weight=%02d", transport.templatename, k, asset.uid, transport.cargobay[k], cargobay, asset.weight))
|
--self:E(self.wid..string.format("%s unit %d loads cargo uid=%d: bayempty=%02d, bayloaded = %02d - weight=%02d", transport.templatename, k, asset.uid, transport.cargobay[k], cargobay, asset.weight))
|
||||||
|
|
||||||
-- Cargo fits into carrier
|
-- Cargo fits into carrier
|
||||||
if delta>0 then
|
if delta>=0 then
|
||||||
-- Reduce remaining cargobay.
|
-- Reduce remaining cargobay.
|
||||||
cargobay=cargobay-asset.weight
|
cargobay=cargobay-asset.weight
|
||||||
self:T3(self.wid..string.format("%s unit %d loads cargo uid=%d: bayempty=%02d, bayloaded = %02d - weight=%02d", transport.templatename, k, asset.uid, transport.cargobay[k], cargobay, asset.weight))
|
self:T3(self.wid..string.format("%s unit %d loads cargo uid=%d: bayempty=%02d, bayloaded = %02d - weight=%02d", transport.templatename, k, asset.uid, transport.cargobay[k], cargobay, asset.weight))
|
||||||
@@ -5189,7 +5245,7 @@ function WAREHOUSE:_GetTransportsForAssets(request)
|
|||||||
-- This transport group is used.
|
-- This transport group is used.
|
||||||
used=true
|
used=true
|
||||||
else
|
else
|
||||||
self:T2(self.wid..string.format("Carrier unit %s too small for cargo asset %s ==> cannot be not used! Cargo bay - asset weight = %d kg", transport.templatename, asset.templatename, delta))
|
self:T2(self.wid..string.format("Carrier unit %s too small for cargo asset %s ==> cannot be used! Cargo bay - asset weight = %d kg", transport.templatename, asset.templatename, delta))
|
||||||
end
|
end
|
||||||
|
|
||||||
end -- loop over assets
|
end -- loop over assets
|
||||||
@@ -6118,14 +6174,26 @@ end
|
|||||||
-- @param #table stock Table holding all assets in stock of the warehouse. Each entry is of type @{#WAREHOUSE.Assetitem}.
|
-- @param #table stock Table holding all assets in stock of the warehouse. Each entry is of type @{#WAREHOUSE.Assetitem}.
|
||||||
function WAREHOUSE:_DisplayStockItems(stock)
|
function WAREHOUSE:_DisplayStockItems(stock)
|
||||||
|
|
||||||
local text=self.wid..string.format("Warehouse %s stock assets:\n", self.airbase:GetName())
|
local text=self.wid..string.format("Warehouse %s stock assets:", self.airbase:GetName())
|
||||||
for _,_stock in pairs(stock) do
|
for _i,_stock in pairs(stock) do
|
||||||
local mystock=_stock --#WAREHOUSE.Assetitem
|
local mystock=_stock --#WAREHOUSE.Assetitem
|
||||||
text=text..string.format("template = %s, category = %d, unittype = %s, attribute = %s\n", mystock.templatename, mystock.category, mystock.unittype, mystock.attribute)
|
local name=mystock.templatename
|
||||||
|
local category=mystock.category
|
||||||
|
local cargobaymax=mystock.cargobaymax
|
||||||
|
local cargobaytot=mystock.cargobaytot
|
||||||
|
local nunits=mystock.nunits
|
||||||
|
local range=mystock.range
|
||||||
|
local size=mystock.size
|
||||||
|
local speed=mystock.speedmax
|
||||||
|
local uid=mystock.uid
|
||||||
|
local unittype=mystock.unittype
|
||||||
|
local weight=mystock.weight
|
||||||
|
local attribute=mystock.attribute
|
||||||
|
text=text..string.format("\n%02d) uid=%d, name=%s, unittype=%s, category=%d, attribute=%s, nunits=%d, speed=%.1f km/h, range=%.1f km, size=%.1f m, weight=%.1f kg, cargobax max=%.1f kg tot=%.1f kg",
|
||||||
|
_i, uid, name, unittype, category, attribute, nunits, speed, range/1000, size, weight, cargobaymax, cargobaytot)
|
||||||
end
|
end
|
||||||
|
|
||||||
env.info(text)
|
self:T3(text)
|
||||||
MESSAGE:New(text, 10):ToAll()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Fireworks!
|
--- Fireworks!
|
||||||
|
|||||||
@@ -1019,7 +1019,7 @@ do -- Cargo
|
|||||||
-- self.__.CargoBayVolumeLimit = VolumeLimit
|
-- self.__.CargoBayVolumeLimit = VolumeLimit
|
||||||
-- end
|
-- end
|
||||||
|
|
||||||
--- Get Cargo Bay Weight Limit in kg.
|
--- Set Cargo Bay Weight Limit in kg.
|
||||||
-- @param #POSITIONABLE self
|
-- @param #POSITIONABLE self
|
||||||
-- @param #number WeightLimit
|
-- @param #number WeightLimit
|
||||||
function POSITIONABLE:SetCargoBayWeightLimit( WeightLimit )
|
function POSITIONABLE:SetCargoBayWeightLimit( WeightLimit )
|
||||||
|
|||||||
Reference in New Issue
Block a user