OPSTRANSPORT

- Added storage demos
This commit is contained in:
Frank
2023-08-27 20:02:53 +02:00
parent 2f450bcf0e
commit c8a808ca12
8 changed files with 346 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
---
-- STORAGE: Liquids
--
-- The airbase at Batumi ran out of fuel.
--
-- A truck from the nearby FARP Berlin is ordered to transport
-- 1000 kg jet fuel and 1000 kg diesel to Batumi.
--
-- The truck can load ~1140 kg of cargo at once.
-- So it has to go two times to deliver all liquids.
---
-- Get FARP airbase.
local berlinFARP=AIRBASE:FindByName("FARP Berlin")
-- Get the warehouse storage of FARP Berlin
local berlinStorage=berlinFARP:GetStorage()
-- Pickup zone near FARP Berlin.
local zonePickup=ZONE:FindByName("Storage Berlin"):DrawZone()
-- Get airbase of Batumi.
local batumiAirbase=AIRBASE:FindByName("Batumi")
-- Get the warehouse storage of Batumi airbase.
local batumiStorage=batumiAirbase:GetStorage()
-- Deploy zone at Batumi.
local zoneDeploy=ZONE:FindByName("Storage Batumi"):DrawZone()
-- Create a transport from pickup at Berlin to Batumi. The first parameter has to be nil, as this applies only to troop tansports.
local transport=OPSTRANSPORT:New(nil, zonePickup, zoneDeploy)
-- Define the cargo transport from Berlin to Batumi. We need to pass the STORAGE from which the cargo is taken and the STORAGE to which it should be delivered.
--Add storage amount to deliver from Berlin to Batumi. We want 1000 kg of jet fuel and 1000 kg Diesel.
transport:AddCargoStorage(berlinStorage, batumiStorage, STORAGE.Liquid.JETFUEL, 1000)
transport:AddCargoStorage(berlinStorage, batumiStorage, STORAGE.Liquid.DIESEL, 1000)
-- Create armygroup object.
local truck=ARMYGROUP:New("Truck M939 Alpha")
-- Assign transport to truck.
truck:AddOpsTransport(transport)
--- Function to report the current amount of fuel at Berlin and Batumi
local function reportStorage()
local text=string.format("Current storage amount:\n")
local text=string.format("Berlin has %d kg of jet fuel and %d kg of Diesel\n", berlinStorage:GetLiquidAmount(STORAGE.Liquid.JETFUEL), berlinStorage:GetLiquidAmount(STORAGE.Liquid.DIESEL))
text=text..string.format("Batumi has %d kg of jet fuel and %d kg of Diesel", batumiStorage:GetLiquidAmount(STORAGE.Liquid.JETFUEL), batumiStorage:GetLiquidAmount(STORAGE.Liquid.DIESEL))
MESSAGE:New(text, 300):ToAll():ToLog()
end
-- Report initial storage.
reportStorage()
--- Function called after truck has loaded a batch of cargo.
function truck:OnAfterLoadingDone(From, Event, To)
-- Report storage after truck has loaded all its current cargo.
reportStorage()
end
--- Function called after truck has unloaded a batch of cargo.
function truck:OnAfterUnloadingDone(From,Event,To)
-- Report storage after truck has delivered all its current cargo.
reportStorage()
end
--- Function called when transport was delivered or everyone (remaining) is dead.
function transport:OnAfterDelivered(From, Event, To)
-- Report that everything was delivered
local text=string.format("Transport UID=%d was delivered. Ncargo=%d Ndelivered=%d", transport:GetUID(), transport:GetNcargoTotal(), transport:GetNcargoDelivered())
MESSAGE:New(text, 300):ToAll():ToLog()
-- Report storage after everything was delivered.
reportStorage()
end

View File

@@ -0,0 +1,92 @@
---
-- STORAGE: Weapons
--
-- The airbase at Batumi ran out of weapons.
--
-- A group of two trucks from the nearby FARP Berlin is ordered to transport 14 AIM-120C missiles
-- and 9 MK-82 bombs. The FARP initially has 100 AIM-120Cs and 200 MK-82s in store.
--
-- Each truck can load ~1140 kg of cargo at once. So both have 2280 kg cargo capacity combined.
-- As explained below, the group will need three runs to transport all the cargo.
--
-- NOTE that the weight of the weapons cannot be retrieved from the DCS API.
-- Therefore it has to be specified manually as input parameter:
--
-- * For the AIM-120C, we set a weight of 162 kg. So in total 2268 kg need to be transported.
-- Each carrier element/unit can load seven missiles (1140/162=7.037). So all 14 missiles can
-- be loaded into both carriers and can be transported in one go.
--
-- * For the MK-82, we use a weight of 230 kg. So in total 2070 kg need to be transported.
-- Note that even though 2070 is less then 2280, which suggests that the cargo can be transported
-- by both carriers in one go, each carrier can only load four bombs (4*230=920 but 5*230=1150).
-- Hence, in one run, the group can only transport 8 bombs and one additonal run is needed to transport
-- the last one.
---
-- Get FARP airbase.
local berlinFARP=AIRBASE:FindByName("FARP Berlin")
-- Get the warehouse storage of FARP Berlin
local berlinStorage=berlinFARP:GetStorage()
-- Pickup zone near FARP Berlin.
local zonePickup=ZONE:FindByName("Storage Berlin"):DrawZone()
-- Get airbase of Batumi.
local batumiAirbase=AIRBASE:FindByName("Batumi")
-- Get the warehouse storage of Batumi airbase.
local batumiStorage=batumiAirbase:GetStorage()
-- Deploy zone at Batumi.
local zoneDeploy=ZONE:FindByName("Storage Batumi"):DrawZone()
-- Create a transport from pickup at Berlin to Batumi. The first parameter has to be nil, as this applies only to troop tansports.
local transport=OPSTRANSPORT:New(nil, zonePickup, zoneDeploy)
-- Add storage amount to deliver from Berlin to Batumi.
-- Note that for weapons/equipment, we need to specify the weight of each item as parameter.
transport:AddCargoStorage(berlinStorage, batumiStorage, ENUMS.Storage.weapons.missiles.AIM_120C, 14, 162)
transport:AddCargoStorage(berlinStorage, batumiStorage, ENUMS.Storage.weapons.bombs.Mk_82, 9, 230)
-- Create armygroup object.
local truck=ARMYGROUP:New("Truck M939 Bravo")
-- Assign transport to truck.
truck:AddOpsTransport(transport)
--- Function to report the current amount of fuel at Berlin and Batumi
local function reportStorage()
local text=string.format("Current storage amount:\n")
local text=string.format("Berlin has %d AIM-120Cs and %d MK-82s\n", berlinStorage:GetItemAmount(ENUMS.Storage.weapons.missiles.AIM_120C), berlinStorage:GetItemAmount(ENUMS.Storage.weapons.bombs.Mk_82))
text=text..string.format("Batumi has %d AIM-120Cs and %d MK-82s", batumiStorage:GetItemAmount(ENUMS.Storage.weapons.missiles.AIM_120C), batumiStorage:GetItemAmount(ENUMS.Storage.weapons.bombs.Mk_82))
MESSAGE:New(text, 300):ToAll():ToLog()
end
-- Report initial storage.
reportStorage()
--- Function called after truck has loaded a batch of cargo.
function truck:OnAfterLoadingDone(From, Event, To)
reportStorage()
end
--- Function called after truck has unloaded a batch of cargo.
function truck:OnAfterUnloadingDone(From, Event, To)
reportStorage()
end
--- Function called when transport was delivered or everyone (remaining) is dead.
function transport:OnAfterDelivered(From, Event, To)
-- Report that everything was delivered
local text=string.format("Transport UID=%d was delivered. Ncargo=%d Ndelivered=%d", transport:GetUID(), transport:GetNcargoTotal(), transport:GetNcargoDelivered())
MESSAGE:New(text, 300):ToAll():ToLog()
-- Report storage after everything was delivered.
reportStorage()
end

View File

@@ -0,0 +1,97 @@
---
-- STORAGE: Cargo Lost
--
-- The airbase at Batumi ran out of Diesel.
--
-- Two groups of trucks are ordered to transport 6 tons Diesel from nearby FRAP Berlin to Batumi.
-- Truck group Alpha consists of one truck while group Bravo consists of two trucks.
--
-- Each truck can load ~1140 kg of cargo at once.
--
-- After truck Alpha has loaded its fuel, it comes to an explosion. The loaded cargo is lost
-- and only group Bravo can deliver the fuel.
--
-- The amount of Diesel taken from Berlin will be 6 tons but Batumi will only receive 4860 kg beacuse 1140 kg are lost.
---
-- Get FARP airbase.
local berlinFARP=AIRBASE:FindByName("FARP Berlin")
-- Get the warehouse storage of FARP Berlin
local berlinStorage=berlinFARP:GetStorage()
-- Pickup zone near FARP Berlin.
local zonePickup=ZONE:FindByName("Storage Berlin"):DrawZone()
-- Get airbase of Batumi.
local batumiAirbase=AIRBASE:FindByName("Batumi")
-- Get the warehouse storage of Batumi airbase.
local batumiStorage=batumiAirbase:GetStorage()
-- Deploy zone at Batumi.
local zoneDeploy=ZONE:FindByName("Storage Batumi"):DrawZone()
-- Create a transport from pickup at Berlin to Batumi. The first parameter has to be nil, as this applies only to troop tansports.
local transport=OPSTRANSPORT:New(nil, zonePickup, zoneDeploy)
-- Add storage amount to deliver from Berlin to Batumi.
transport:AddCargoStorage(berlinStorage, batumiStorage, STORAGE.Liquid.DIESEL, 6000)
-- Create armygroup object.
local truckAlpha=ARMYGROUP:New("Truck M939 Alpha")
-- Create armygroup object.
local truckBravo=ARMYGROUP:New("Truck M939 Bravo")
-- Assign transport to truck groups.
truckAlpha:AddOpsTransport(transport)
truckBravo:AddOpsTransport(transport)
--- Function to report the current amount of fuel at Berlin and Batumi
local function reportStorage()
local text=string.format("Current storage amount:\n")
local text=string.format("Berlin has %d kg Diesel\n", berlinStorage:GetAmount(STORAGE.Liquid.DIESEL))
text=text..string.format("Batumi has %d kg Diesel", batumiStorage:GetAmount(STORAGE.Liquid.DIESEL))
MESSAGE:New(text, 300):ToAll():ToLog()
end
-- Report initial storage.
reportStorage()
--- Function called after truck has loaded a batch of cargo.
function truckAlpha:OnAfterLoadingDone(From, Event, To)
reportStorage()
truckAlpha:SelfDestruction(3*60, 50)
end
--- Function called after truck has unloaded a batch of cargo.
function truckAlpha:OnAfterUnloadingDone(From, Event, To)
reportStorage()
end
--- Function called after truck has loaded a batch of cargo.
function truckBravo:OnAfterLoadingDone(From, Event, To)
reportStorage()
end
--- Function called after truck has unloaded a batch of cargo.
function truckBravo:OnAfterUnloadingDone(From, Event, To)
reportStorage()
end
--- Function called when transport was delivered or everyone (remaining) is dead.
function transport:OnAfterDelivered(From, Event, To)
-- Report that everything was delivered
local text=string.format("Transport UID=%d was delivered. Ncargo=%d Ndelivered=%d", transport:GetUID(), transport:GetNcargoTotal(), transport:GetNcargoDelivered())
MESSAGE:New(text, 300):ToAll():ToLog()
-- Report storage after everything was delivered.
reportStorage()
end

View File

@@ -0,0 +1,77 @@
---
-- STORAGE: Helo transport liquids
--
-- The airbase at Batumi ran out of fuel.
--
-- A Chinook from FARP Berlin is ordered to transport 2 tons jet fuel
-- and 2 tons gasoline from Berlin to Batumi.
--
-- The helo can load 3751 kg of cargo in total.
-- So it has to go two times to deliver all liquids.
---
-- Get FARP airbase.
local berlinFARP=AIRBASE:FindByName("FARP Berlin")
-- Get the warehouse storage of FARP Berlin
local berlinStorage=berlinFARP:GetStorage()
-- Get airbase of Batumi.
local batumiAirbase=AIRBASE:FindByName("Batumi")
-- Get the warehouse storage of Batumi airbase.
local batumiStorage=batumiAirbase:GetStorage()
-- Pickup and deploy base. NOTE that we use ZONE_AIRBASE here, so the helo lands at the airbase.
local zonePickup=ZONE_AIRBASE:New("FARP Berlin", 2000)
local zoneDeploy=ZONE_AIRBASE:New(AIRBASE.Caucasus.Batumi, 2000)
-- Create a transport from pickup at Berlin to Batumi. The first parameter has to be nil, as this applies only to troop tansports.
local transport=OPSTRANSPORT:New(nil, zonePickup, zoneDeploy)
-- Define the cargo transport from Berlin to Batumi. We need to pass the STORAGE from which the cargo is taken and the STORAGE to which it should be delivered.
-- Add storage amount to deliver from Berlin to Batumi. We want 2000 kg of jet fuel and 2000 kg Diesel.
transport:AddCargoStorage(berlinStorage, batumiStorage, STORAGE.Liquid.JETFUEL, 2000)
transport:AddCargoStorage(berlinStorage, batumiStorage, STORAGE.Liquid.GASOLINE, 2000)
-- Create armygroup object.
local helo=FLIGHTGROUP:New("CH-47D Alpha")
-- Assign transport to truck.
helo:AddOpsTransport(transport)
--- Function to report the current amount of fuel at Berlin and Batumi
local function reportStorage()
local text=string.format("Current storage amount:\n")
local text=string.format("Berlin has %d kg of jet fuel and %d kg of gasoline\n", berlinStorage:GetAmount(STORAGE.Liquid.JETFUEL), berlinStorage:GetAmount(STORAGE.Liquid.GASOLINE))
text=text..string.format("Batumi has %d kg of jet fuel and %d kg of gasoline", batumiStorage:GetAmount(STORAGE.Liquid.JETFUEL), batumiStorage:GetAmount(STORAGE.Liquid.GASOLINE))
MESSAGE:New(text, 300):ToAll():ToLog()
end
-- Report initial storage.
reportStorage()
--- Function called after truck has loaded a batch of cargo.
function helo:OnAfterLoadingDone(From, Event, To)
-- Report storage after truck has loaded all its current cargo.
reportStorage()
end
--- Function called after truck has unloaded a batch of cargo.
function helo:OnAfterUnloadingDone(From,Event,To)
-- Report storage after truck has delivered all its current cargo.
reportStorage()
end
--- Function called when transport was delivered or everyone (remaining) is dead.
function transport:OnAfterDelivered(From, Event, To)
-- Report that everything was delivered
local text=string.format("Transport UID=%d was delivered. Ncargo=%d Ndelivered=%d", transport:GetUID(), transport:GetNcargoTotal(), transport:GetNcargoDelivered())
MESSAGE:New(text, 300):ToAll():ToLog()
-- Report storage after everything was delivered.
reportStorage()
end