Merge pull request #1019 from FlightControl-Master/FF/Develop

Warehouse v0.5.9
This commit is contained in:
Frank 2018-10-07 00:21:52 +02:00 committed by GitHub
commit 87d82aa674
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -137,7 +137,7 @@
-- --
-- # Adding Assets -- # Adding Assets
-- --
-- Assets can be added to the warehouse stock by using the @{#WAREHOUSE.AddAsset}(*group*, *ngroups*, *forceattribute*, *forcecargobay*, *forceweight*, *loadradius*) function. -- Assets can be added to the warehouse stock by using the @{#WAREHOUSE.AddAsset}(*group*, *ngroups*, *forceattribute*, *forcecargobay*, *forceweight*, *loadradius*, *skill*, *liveries*, *assignment*) function.
-- The parameter *group* has to be a MOOSE @{Wrapper.Group#GROUP}. This is also the only mandatory parameters. All other parameters are optional and can be used for fine tuning if -- The parameter *group* has to be a MOOSE @{Wrapper.Group#GROUP}. This is also the only mandatory parameters. All other parameters are optional and can be used for fine tuning if
-- nessary. The parameter *ngroups* specifies how many clones of this group are added to the stock. -- nessary. The parameter *ngroups* specifies how many clones of this group are added to the stock.
-- --
@ -150,8 +150,8 @@
-- Also note that the coalition of the template group (red, blue or neutral) does not matter. The coalition of the assets is determined by the coalition of the warehouse owner. -- Also note that the coalition of the template group (red, blue or neutral) does not matter. The coalition of the assets is determined by the coalition of the warehouse owner.
-- In other words, it is no problem to add red groups to blue warehouses and vice versa. The assets will automatically have the coalition of the warehouse. -- In other words, it is no problem to add red groups to blue warehouses and vice versa. The assets will automatically have the coalition of the warehouse.
-- --
-- You can add assets with a delay by using the @{#WAREHOUSE.__AddAsset}(*delay*, *group*, *ngroups*, *foceattribute*, *forcecargobay*, *forceweight*, *loadradius*), where *delay* -- You can add assets with a delay by using the @{#WAREHOUSE.__AddAsset}(*delay*, *group*, *ngroups*, *forceattribute*, *forcecargobay*, *forceweight*, *loadradius*, *skill*, *liveries*, *assignment*),
-- is the delay in seconds before the asset is added. -- where *delay* is the delay in seconds before the asset is added.
-- --
-- In game, the warehouse will get a mark which is regularly updated and showing the currently available assets in stock. -- In game, the warehouse will get a mark which is regularly updated and showing the currently available assets in stock.
-- --
@ -204,6 +204,54 @@
-- warehouseBatumi:AddAsset("Leopard 2", nil, nil, nil, nil, 250) -- warehouseBatumi:AddAsset("Leopard 2", nil, nil, nil, nil, 250)
-- --
-- Adding the asset like this will cause the units to be loaded into the carrier already at a distance of 250 meters. -- Adding the asset like this will cause the units to be loaded into the carrier already at a distance of 250 meters.
--
-- ### Setting the AI Skill
--
-- By default, the asset has the skill of its template group. The optional parameter *skill* allows to set a different skill when the asset is added. See the
-- [hoggit page](https://wiki.hoggitworld.com/view/DCS_enum_AI) possible values of this enumerator.
-- For example you can use
--
-- warehouseBatumi:AddAsset("Leopard 2", nil, nil, nil, nil, nil, AI.Skill.EXCELLENT)
--
-- do set the skill of the asset to excellent.
--
-- ### Setting Liveries
--
-- By default ,the asset uses the livery of its template group. The optional parameter *liveries* allows to define one or multiple liveries.
-- If multiple liveries are given in form of a table of livery names, each asset gets a random one.
--
-- For example
--
-- warehouseBatumi:AddAsset("Mi-8", nil, nil, nil, nil, nil, nil, "China UN")
--
-- would spawn the asset with a chinese UN livery.
--
-- Or
--
-- warehouseBatumi:AddAsset("Mi-8", nil, nil, nil, nil, nil, nil, {"China UN", "German"})
--
-- would spawn the asset with either a chinese UN or German livery. Mind the curly brackets **{}** when you want to specify multiple liveries.
--
-- Four each unit type, the livery names can be found in the DCS root folder under Bazar\Liveries. You have to use the name of the livery subdirectory. The names of the liveries
-- as displayed in the mission editor might be different and won't work in general.
--
-- ### Setting an Assignment
--
-- Assets can be added with a specific assignment given as a text, e.g.
--
-- warehouseBatumi:AddAsset("Mi-8", nil, nil, nil, nil, nil, nil, nil, "Go to Warehouse Kobuleti")
--
-- This is helpful to establish supply chains once an asset has arrived at its (first) destination and is meant to be forwarded to another warehouse.
--
-- ## Retrieving the Asset
--
-- Once a an asset is added to a warehouse, the @{#WAREHOUSE.NewAsset} event is triggered. You can hook into this event with the @{#WAREHOUSE.OnAfterNewAsset}(*asset*, *assignment*) function.
--
-- The first parameter *asset* is a table of type @{#WAREHOUSE.Assetitem} and contains a lot of information about the asset. The seconed parameter *assignment* is optional and is the specific
-- assignment the asset got when it was added.
--
-- Note that the assignment is can also be the assignment that was specified when adding a request (see next section). Once an asset that was requested from another warehouse and an assignment
-- was specified in the @{#WAREHOUSE.AddRequest} function, the assignment can be checked when the asset has arrived and is added to the receiving warehouse.
-- --
-- === -- ===
-- --
@ -1275,7 +1323,7 @@
-- -- Kobuleti requests all available trucks from London. -- -- Kobuleti requests all available trucks from London.
-- warehouse.London:AddRequest(warehouse.Kobuleti, WAREHOUSE.Descriptor.ATTRIBUTE, WAREHOUSE.Attribute.GROUND_TRUCK, WAREHOUSE.Quantity.HALF) -- warehouse.London:AddRequest(warehouse.Kobuleti, WAREHOUSE.Descriptor.ATTRIBUTE, WAREHOUSE.Attribute.GROUND_TRUCK, WAREHOUSE.Quantity.HALF)
-- --
--## Example 16 Resupply of Dead Assets -- ## Example 16: Resupply of Dead Assets
-- --
-- Warehouse at FARP Berlin is located at the front line and sends infantry groups to the battle zone. -- Warehouse at FARP Berlin is located at the front line and sends infantry groups to the battle zone.
-- Whenever a group dies, a new group is send from the warehouse to the battle zone. -- Whenever a group dies, a new group is send from the warehouse to the battle zone.
@ -1340,6 +1388,65 @@
-- warehouse.Berlin:AddRequest(warehouse.Berlin, WAREHOUSE.Descriptor.ATTRIBUTE, asset.attribute, 1, nil, nil, nil, assignment) -- warehouse.Berlin:AddRequest(warehouse.Berlin, WAREHOUSE.Descriptor.ATTRIBUTE, asset.attribute, 1, nil, nil, nil, assignment)
-- end -- end
-- --
-- ## Example 17: Supply Chains
--
-- Our remote warehouse "Pampa" south of Batumi needs assets but does not have any air infrastructure (FARP or airdrome).
-- Leopard 2 tanks are transported from Kobuleti to Batumi using two C-17As. From there they go be themselfs to Pampa.
-- Eight infantry groups and two mortar groups are also being transferred from Kobuleti to Batumi by helicopter.
-- The infantry has a higher priority and will be transported first using all available Mi-8 helicopters.
-- Once infantry has arrived at Batumi, it walk by itself to warehouse Pampa.
-- The mortars can only be transported once the Mi-8 helos are available again, i.e. when the infantry has been delivered.
-- Once the mortars arrive at Batumi, they will be transported by APCs to Pampa.
--
-- -- Start warehouses.
-- warehouse.Kobuleti:Start()
-- warehouse.Batumi:Start()
-- warehouse.Pampa:Start()
--
-- -- Add assets to Kobuleti warehouse, which is our main hub.
-- warehouse.Kobuleti:AddAsset("C-130", 2)
-- warehouse.Kobuleti:AddAsset("C-17A", 2, nil, 77000)
-- warehouse.Kobuleti:AddAsset("Mi-8", 2, WAREHOUSE.Attribute.AIR_TRANSPORTHELO, nil, nil, nil, AI.Skill.EXCELLENT, {"Germany", "United Kingdom"})
-- warehouse.Kobuleti:AddAsset("Leopard 2", 10, nil, nil, 62000, 500)
-- warehouse.Kobuleti:AddAsset("Mortar Alpha", 10, nil, nil, 210)
-- warehouse.Kobuleti:AddAsset("Infantry Platoon Alpha", 20)
--
-- -- Transports at Batumi.
-- warehouse.Batumi:AddAsset("SPz Marder", 2)
-- warehouse.Batumi:AddAsset("TPz Fuchs", 2)
--
-- -- Tanks transported by plane from Batumi to Kobuleti
-- warehouse.Kobuleti:AddRequest(warehouse.Batumi, WAREHOUSE.Descriptor.ATTRIBUTE, WAREHOUSE.Attribute.GROUND_TANK, 2, WAREHOUSE.TransportType.AIRPLANE, 2, 10, "Assets for Pampa")
-- -- Artillery transported by helicopter from Kobuleti to Batumi.
-- warehouse.Kobuleti:AddRequest(warehouse.Batumi, WAREHOUSE.Descriptor.ATTRIBUTE, WAREHOUSE.Attribute.GROUND_ARTILLERY, 2, WAREHOUSE.TransportType.HELICOPTER, 2, 30, "Assets for Pampa via APC")
-- -- Infantry transported by helicopter
-- warehouse.Kobuleti:AddRequest(warehouse.Batumi, WAREHOUSE.Descriptor.ATTRIBUTE, WAREHOUSE.Attribute.GROUND_INFANTRY, 8, WAREHOUSE.TransportType.HELICOPTER, 2, 20, "Assets for Pampa")
--
-- --- Function handling assets delivered from Kobuleti warehouse.
-- function warehouse.Kobuleti:OnAfterDelivered(From, Event, To, request)
-- local request=request --Functional.Warehouse#WAREHOUSE.Pendingitem
--
-- -- Get assignment.
-- local assignment=warehouse.Kobuleti:GetAssignment(request)
--
-- -- Check if these assets were meant for Warehouse Pampa.
-- if assignment=="Assets for Pampa via APC" then
-- -- Forward everything that arrived at Batumi to Pampa via APC.
-- warehouse.Batumi:AddRequest(warehouse.Pampa, WAREHOUSE.Descriptor.ATTRIBUTE, request.cargoattribute, request.ndelivered, WAREHOUSE.TransportType.APC, WAREHOUSE.Quantity.ALL)
-- end
-- end
--
-- -- Forward all mobile ground assets to Pampa once they arrived.
-- function warehouse.Batumi:OnAfterNewAsset(From, Event, To, asset, assignment)
-- local asset=asset --Functional.Warehouse#WAREHOUSE.Assetitem
-- -- if assignment=="Assets for Pampa" then
-- if asset.category==Group.Category.GROUND and asset.speedmax>0 then
-- warehouse.Batumi:AddRequest(warehouse.Pampa, WAREHOUSE.Descriptor.GROUPNAME, asset.templatename)
-- end
-- end
-- end
--
--
-- @field #WAREHOUSE -- @field #WAREHOUSE
WAREHOUSE = { WAREHOUSE = {
ClassName = "WAREHOUSE", ClassName = "WAREHOUSE",
@ -1388,6 +1495,8 @@ WAREHOUSE = {
-- @field #number cargobaytot Total weight in kg that fits in the cargo bay of all asset group units. -- @field #number cargobaytot Total weight in kg that fits in the cargo bay of all asset group units.
-- @field #number cargobaymax Largest cargo bay of all units in the group. -- @field #number cargobaymax Largest cargo bay of all units in the group.
-- @field #number loadradius Distance when cargo is loaded into the carrier. -- @field #number loadradius Distance when cargo is loaded into the carrier.
-- @field DCS#AI.Skill skill Skill of AI unit.
-- @field #string livery Livery of the asset.
--- Item of the warehouse queue table. --- Item of the warehouse queue table.
-- @type WAREHOUSE.Queueitem -- @type WAREHOUSE.Queueitem
@ -1536,7 +1645,7 @@ WAREHOUSE.db = {
--- Warehouse class version. --- Warehouse class version.
-- @field #string version -- @field #string version
WAREHOUSE.version="0.5.8" WAREHOUSE.version="0.5.9"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO: Warehouse todo list. -- TODO: Warehouse todo list.
@ -1738,6 +1847,9 @@ function WAREHOUSE:New(warehouse, alias)
-- @param #number forcecargobay (Optional) Explicitly force cargobay weight limit in kg for cargo carriers. This is for each *unit* of the group. -- @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. -- @param #number forceweight (Optional) Explicitly force weight in kg of each unit in the group.
-- @param #number loadradius (Optional) The distance in meters when the cargo is loaded into the carrier. Default is the bounding box size of the carrier. -- @param #number loadradius (Optional) The distance in meters when the cargo is loaded into the carrier. Default is the bounding box size of the carrier.
-- @param DCS#AI.Skill skill Skill of the asset.
-- @param #table liveries Table of livery names. When the asset is spawned one livery is chosen randomly.
-- @param #string assignment A free to choose string specifying an assignment for the asset. This can be used with the @{#WAREHOUSE.OnAfterNewAsset} function.
--- 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
@ -1749,18 +1861,23 @@ function WAREHOUSE:New(warehouse, alias)
-- @param #number forcecargobay (Optional) Explicitly force cargobay weight limit in kg for cargo carriers. This is for each *unit* of the group. -- @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. -- @param #number forceweight (Optional) Explicitly force weight in kg of each unit in the group.
-- @param #number loadradius (Optional) The distance in meters when the cargo is loaded into the carrier. Default is the bounding box size of the carrier. -- @param #number loadradius (Optional) The distance in meters when the cargo is loaded into the carrier. Default is the bounding box size of the carrier.
-- @param DCS#AI.Skill skill Skill of the asset.
-- @param #table liveries Table of livery names. When the asset is spawned one livery is chosen randomly.
-- @param #string assignment A free to choose string specifying an assignment for the asset. This can be used with the @{#WAREHOUSE.OnAfterNewAsset} function.
--- Triggers the FSM event "NewAsset" when a new asset has been added to the warehouse stock.
-- @function [parent=#WAREHOUSE] NewAsset
-- @param #WAREHOUSE self
-- @param #number delay Delay in seconds.
-- @param #WAREHOUSE.Assetitem asset The new asset.
--- Triggers the FSM delayed event "NewAsset" when a new asset has been added to the warehouse stock. --- Triggers the FSM delayed event "NewAsset" when a new asset has been added to the warehouse stock.
-- @function [parent=#WAREHOUSE] NewAsset -- @function [parent=#WAREHOUSE] NewAsset
-- @param #WAREHOUSE self -- @param #WAREHOUSE self
-- @param #WAREHOUSE.Assetitem asset The new asset. -- @param #WAREHOUSE.Assetitem asset The new asset.
-- @param #string assignment (Optional) Assignment text for the asset.
--- Triggers the FSM delayed event "NewAsset" when a new asset has been added to the warehouse stock.
-- @function [parent=#WAREHOUSE] __NewAsset
-- @param #WAREHOUSE self
-- @param #number delay Delay in seconds.
-- @param #WAREHOUSE.Assetitem asset The new asset.
-- @param #string assignment (Optional) Assignment text for the asset.
--- On after "NewAsset" event user function. A new asset has been added to the warehouse stock. --- On after "NewAsset" event user function. A new asset has been added to the warehouse stock.
-- @function [parent=#WAREHOUSE] OnAfterNewAsset -- @function [parent=#WAREHOUSE] OnAfterNewAsset
@ -1768,7 +1885,8 @@ function WAREHOUSE:New(warehouse, alias)
-- @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 #WAREHOUSE.Assetitem asset The asset that has just been added -- @param #WAREHOUSE.Assetitem asset The asset that has just been added.
-- @param #string assignment (Optional) Assignment text for the asset.
--- 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.
@ -2861,8 +2979,8 @@ function WAREHOUSE:_JobDone()
--------------- ---------------
-- Info on job. -- Info on job.
local text=string.format("Warehouse %s: Job on request id=%d done!\n", self.alias, request.uid) local text=string.format("Warehouse %s: Job on request id=%d for warehouse %s done!\n", self.alias, request.uid, request.warehouse.alias)
text=text..string.format("- %d of %d assets delivered to %s. Casualties %d.", ncargodelivered, ncargotot, request.warehouse.alias, ncargodead) text=text..string.format("- %d of %d assets delivered. Casualties %d.", ncargodelivered, ncargotot, ncargodead)
if request.ntransport>0 then if request.ntransport>0 then
text=text..string.format("\n- %d of %d transports returned home. Casualties %d.", ntransporthome, ntransporttot, ntransportdead) text=text..string.format("\n- %d of %d transports returned home. Casualties %d.", ntransporthome, ntransporttot, ntransportdead)
end end
@ -2943,9 +3061,8 @@ function WAREHOUSE:_JobDone()
-- Still cargo but no transports -- -- Still cargo but no transports --
----------------------------------- -----------------------------------
-- Info message. local ncargoalive=0
self:_InfoMessage(string.format("Warehouse %s: All transports of request id=%s dead! Putting remaining %s cargo assets back into warehouse!", self.alias, request.uid, ncargo))
-- All transports are dead but there is still cargo left ==> Put cargo back into stock. -- All transports are dead but there is still cargo left ==> Put cargo back into stock.
for _,_group in pairs(request.cargogroupset:GetSetObjects()) do for _,_group in pairs(request.cargogroupset:GetSetObjects()) do
--local group=group --Wrapper.Group#GROUP --local group=group --Wrapper.Group#GROUP
@ -2965,12 +3082,16 @@ function WAREHOUSE:_JobDone()
end end
-- Add asset group back to stock. -- Add asset group back to stock.
self:AddAsset(group) self:AddAsset(group)
ncargoalive=ncargoalive+1
end end
end end
end end
-- Info message.
self:_InfoMessage(string.format("Warehouse %s: All transports of request id=%s dead! Putting remaining %s cargo assets back into warehouse!", self.alias, request.uid, ncargoalive))
end end
end end
end -- loop over requests end -- loop over requests
@ -3071,7 +3192,10 @@ end
-- @param #number forcecargobay (Optional) Explicitly force cargobay weight limit in kg for cargo carriers. This is for each *unit* of the group. -- @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. -- @param #number forceweight (Optional) Explicitly force weight in kg of each unit in the group.
-- @param #number loadradius (Optional) Radius in meters when the cargo is loaded into the carrier. -- @param #number loadradius (Optional) Radius in meters when the cargo is loaded into the carrier.
function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribute, forcecargobay, forceweight, loadradius) -- @param DCS#AI.Skill skill Skill of the asset.
-- @param #table liveries Table of livery names. When the asset is spawned one livery is chosen randomly.
-- @param #string assignment A free to choose string specifying an assignment for the asset. This can be used with the @{#WAREHOUSE.OnAfterNewAsset} function.
function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribute, forcecargobay, forceweight, loadradius, skill, liveries, assignment)
self:T({group=group, ngroups=ngroups, forceattribute=forceattribute, forcecargobay=forcecargobay, forceweight=forceweight}) self:T({group=group, ngroups=ngroups, forceattribute=forceattribute, forcecargobay=forcecargobay, forceweight=forceweight})
-- Set default. -- Set default.
@ -3082,6 +3206,9 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu
group=GROUP:FindByName(group) group=GROUP:FindByName(group)
end end
if liveries and type(liveries)=="string" then
liveries={liveries}
end
if group then if group then
@ -3114,17 +3241,30 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu
end end
end end
-- If no assignment was given we take the assignment of the request if there is any.
if assignment==nil and request.assignment~=nil then
assignment=request.assignment
end
end end
-- Get the asset from the global DB. -- Get the asset from the global DB.
local asset=self:FindAssetInDB(group) local asset=self:FindAssetInDB(group)
-- Set livery.
if liveries then
asset.livery=liveries[math.random(#liveries)]
end
-- Set skill.
asset.skill=skill
-- Note the group is only added once, i.e. the ngroups parameter is ignored here. -- Note the group is only added once, i.e. the ngroups parameter is ignored here.
-- This is because usually these request comes from an asset that has been transfered from another warehouse and hence should only be added once. -- This is because usually these request comes from an asset that has been transfered from another warehouse and hence should only be added once.
if asset~=nil then if asset~=nil then
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)
table.insert(self.stock, asset) table.insert(self.stock, asset)
self:NewAsset(asset) self:NewAsset(asset, assignment or "")
else else
self:_ErrorMessage(string.format("ERROR: Known asset could not be found in global warehouse db!"), 0) self:_ErrorMessage(string.format("ERROR: Known asset could not be found in global warehouse db!"), 0)
end end
@ -3138,12 +3278,12 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu
self:_DebugMessage(string.format("Warehouse %s: Adding %d NEW assets of group %s to stock.", self.alias, n, tostring(group:GetName())), 5) self:_DebugMessage(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, forcecargobay, forceweight, loadradius) local assets=self:_RegisterAsset(group, n, forceattribute, forcecargobay, forceweight, loadradius, liveries, skill)
-- 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
table.insert(self.stock, asset) table.insert(self.stock, asset)
self:NewAsset(asset) self:NewAsset(asset, assignment or "")
end end
end end
@ -3160,7 +3300,7 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu
end end
-- Update status. -- Update status.
self:__Status(-1) --self:__Status(-1)
end end
--- Register new asset in globase warehouse data base. --- Register new asset in globase warehouse data base.
@ -3171,8 +3311,10 @@ end
-- @param #number forcecargobay Cargo bay weight limit in kg. -- @param #number forcecargobay Cargo bay weight limit in kg.
-- @param #number forceweight Weight of units in kg. -- @param #number forceweight Weight of units in kg.
-- @param #number loadradius Radius in meters when cargo is loaded into the carrier. -- @param #number loadradius Radius in meters when cargo is loaded into the carrier.
-- @param #table liveries Table of liveries.
-- @param DCS#AI.Skill skill Skill of AI.
-- @return #table A table containing all registered assets. -- @return #table A table containing all registered assets.
function WAREHOUSE:_RegisterAsset(group, ngroups, forceattribute, forcecargobay, forceweight, loadradius) function WAREHOUSE:_RegisterAsset(group, ngroups, forceattribute, forcecargobay, forceweight, loadradius, liveries, skill)
self:F({groupname=group:GetName(), ngroups=ngroups, forceattribute=forceattribute, forcecargobay=forcecargobay, forceweight=forceweight}) self:F({groupname=group:GetName(), ngroups=ngroups, forceattribute=forceattribute, forcecargobay=forcecargobay, forceweight=forceweight})
-- Set default. -- Set default.
@ -3268,6 +3410,10 @@ function WAREHOUSE:_RegisterAsset(group, ngroups, forceattribute, forcecargobay,
asset.cargobaytot=cargobaytot asset.cargobaytot=cargobaytot
asset.cargobaymax=cargobaymax asset.cargobaymax=cargobaymax
asset.loadradius=loadradius asset.loadradius=loadradius
if liveries then
asset.livery=liveries[math.random(#liveries)]
end
asset.skill=skill
if i==1 then if i==1 then
self:_AssetItemInfo(asset) self:_AssetItemInfo(asset)
@ -3300,7 +3446,9 @@ function WAREHOUSE:_AssetItemInfo(asset)
text=text..string.format("Weight total = %5.2f kg\n", asset.weight) text=text..string.format("Weight total = %5.2f kg\n", asset.weight)
text=text..string.format("Cargo bay tot = %5.2f kg\n", asset.cargobaytot) text=text..string.format("Cargo bay tot = %5.2f kg\n", asset.cargobaytot)
text=text..string.format("Cargo bay max = %5.2f kg\n", asset.cargobaymax) text=text..string.format("Cargo bay max = %5.2f kg\n", asset.cargobaymax)
text=text..string.format("Load radius = %s m", tostring(asset.loadradius)) text=text..string.format("Load radius = %s m\n", tostring(asset.loadradius))
text=text..string.format("Skill = %s\n", tostring(asset.skill))
text=text..string.format("Livery = %s", tostring(asset.livery))
self:T(self.wid..text) self:T(self.wid..text)
self:T({DCSdesc=asset.DCSdesc}) self:T({DCSdesc=asset.DCSdesc})
self:T3({Template=asset.template}) self:T3({Template=asset.template})
@ -3311,8 +3459,10 @@ 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 #WAREHOUSE.Assetitem asset The asset that has just been added -- @param #WAREHOUSE.Assetitem asset The asset that has just been added.
function WAREHOUSE:onafterNewAsset(From, Event, To, asset) -- @parma #string assignment The (optional) assignment for the asset.
function WAREHOUSE:onafterNewAsset(From, Event, To, asset, assignment)
self:T(self.wid..string.format("New asset %s id=%d with assignment %s.", asset.templatename, asset.uid, assignment))
end end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ -3461,7 +3611,7 @@ function WAREHOUSE:onafterAddRequest(From, Event, To, warehouse, AssetDescriptor
self:_DebugMessage(text, 5) self:_DebugMessage(text, 5)
-- Update status -- Update status
self:__Status(-1) --self:__Status(-1)
end end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ -3923,7 +4073,7 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
local warehouse=Carrier:GetState(Carrier, "WAREHOUSE") --#WAREHOUSE local warehouse=Carrier:GetState(Carrier, "WAREHOUSE") --#WAREHOUSE
-- Debug message. -- Debug message.
local text=string.format("Carrier group %s loaded cargo %s into unit %s in pickup zone %s", Carrier:GetName(), Cargo:GetObject():GetName(), CarrierUnit:GetName(), PickupZone:GetName()) local text=string.format("Carrier group %s loaded cargo %s into unit %s in pickup zone %s", Carrier:GetName(), Cargo:GetName(), CarrierUnit:GetName(), PickupZone:GetName())
warehouse:T(warehouse.wid..text) warehouse:T(warehouse.wid..text)
-- Get cargo group object. -- Get cargo group object.
@ -3933,7 +4083,7 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
local request=warehouse:_GetRequestOfGroup(group, warehouse.pending) local request=warehouse:_GetRequestOfGroup(group, warehouse.pending)
-- Add cargo group to this carrier. -- Add cargo group to this carrier.
table.insert(request.carriercargo[CarrierUnit:GetName()], group) table.insert(request.carriercargo[CarrierUnit:GetName()], warehouse:_GetNameWithOut(Cargo:GetName()))
end end
@ -4100,7 +4250,9 @@ function WAREHOUSE:onafterDelivered(From, Event, To, request)
self:_InfoMessage(text, 5) self:_InfoMessage(text, 5)
-- Make some noise :) -- Make some noise :)
self:_Fireworks(request.warehouse:GetCoordinate()) if self.Debug then
self:_Fireworks(request.warehouse:GetCoordinate())
end
-- Set delivered status for this request uid. -- Set delivered status for this request uid.
self.delivered[request.uid]=true self.delivered[request.uid]=true
@ -4502,7 +4654,14 @@ function WAREHOUSE:_SpawnAssetGroundNaval(alias, asset, request, spawnzone, aiof
template.units[i].x = TX template.units[i].x = TX
template.units[i].y = TY template.units[i].y = TY
if asset.livery then
unit.livery_id = asset.livery
end
if asset.skill then
unit.skill= asset.skill
end
end end
template.route.points[1].x = coord.x template.route.points[1].x = coord.x
@ -4622,6 +4781,14 @@ function WAREHOUSE:_SpawnAssetAircraft(alias, asset, request, parking, uncontrol
unit.parking = terminal unit.parking = terminal
end end
if asset.livery then
unit.livery_id = asset.livery
end
if asset.skill then
unit.skill= asset.skill
end
end end
-- And template position. -- And template position.
@ -5165,7 +5332,7 @@ function WAREHOUSE:_UnitDead(deadunit, request)
-- Not sure what this does actually and if it would be better to set it to true. -- Not sure what this does actually and if it would be better to set it to true.
local NoTriggerEvent=false local NoTriggerEvent=true
if request.transporttype==WAREHOUSE.TransportType.SELFPROPELLED then if request.transporttype==WAREHOUSE.TransportType.SELFPROPELLED then
@ -5193,13 +5360,12 @@ function WAREHOUSE:_UnitDead(deadunit, request)
if istransport==true then if istransport==true then
-- Get the carrier unit table holding the cargo groups inside this carrier. -- Get the carrier unit table holding the cargo groups inside this carrier.
local cargogroups=request.carriercargo[unitname] local cargogroupnames=request.carriercargo[unitname]
if cargogroups then if cargogroupnames then
-- Loop over all groups inside the destroyed carrier ==> all dead. -- Loop over all groups inside the destroyed carrier ==> all dead.
for _,cargogroup in pairs(cargogroups) do for _,cargoname in pairs(cargogroupnames) do
local cargoname=self:_GetNameWithOut(cargogroup)
request.cargogroupset:Remove(cargoname, NoTriggerEvent) request.cargogroupset:Remove(cargoname, NoTriggerEvent)
self:T(self.wid..string.format("Removed transported cargo %s inside dead carrier %s: ncargo=%d", cargoname, unitname, request.cargogroupset:Count())) self:T(self.wid..string.format("Removed transported cargo %s inside dead carrier %s: ncargo=%d", cargoname, unitname, request.cargogroupset:Count()))
end end
@ -5877,7 +6043,7 @@ function WAREHOUSE:_CheckRequestNow(request)
if _assetcategory==Group.Category.GROUND then if _assetcategory==Group.Category.GROUND then
-- Distance between warehouse and spawn zone. -- Distance between warehouse and spawn zone.
local dist=self.warehouse:GetCoordinate():Get2DDistance(request.warehouse.spawnzone:GetCoordinate()) local dist=self.warehouse:GetCoordinate():Get2DDistance(self.spawnzone:GetCoordinate())
-- Check min dist to spawn zone. -- Check min dist to spawn zone.
if dist>5000 then if dist>5000 then
@ -6468,7 +6634,12 @@ end
-- @return #string Name of the object without trailing #... -- @return #string Name of the object without trailing #...
function WAREHOUSE:_GetNameWithOut(group) function WAREHOUSE:_GetNameWithOut(group)
if group then if group then
local name=group:GetName() local name
if type(group)=="string" then
name=group
else
name=group:GetName()
end
local namewithout=UTILS.Split(name, "#")[1] local namewithout=UTILS.Split(name, "#")[1]
if namewithout then if namewithout then
return namewithout return namewithout
@ -6476,7 +6647,11 @@ function WAREHOUSE:_GetNameWithOut(group)
return name return name
end end
end end
return group:GetName() if type(group)=="string" then
return group
else
return group:GetName()
end
end end