mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
DCS Warehouse
This commit is contained in:
parent
747e5d801a
commit
32e1d4f8fa
@ -793,11 +793,104 @@ do -- Airbase
|
||||
-- @function [parent=#Airbase] getDesc
|
||||
-- @param self
|
||||
-- @return #Airbase.Desc
|
||||
|
||||
|
||||
--- Returns the warehouse object associated with the airbase object. Can then be used to call the warehouse class functions to modify the contents of the warehouse.
|
||||
-- @function [parent=#Airbase] getWarehouse
|
||||
-- @param self
|
||||
-- @return #Warehouse The DCS warehouse object of this airbase.
|
||||
|
||||
--- Enables or disables the airbase and FARP auto capture game mechanic where ownership of a base can change based on the presence of ground forces or the default setting assigned in the editor.
|
||||
-- @function [parent=#Airbase] autoCapture
|
||||
-- @param self
|
||||
-- @param #boolean setting `true` : enables autoCapture behavior, `false` : disables autoCapture behavior
|
||||
|
||||
--- Returns the current autoCapture setting for the passed base.
|
||||
-- @function [parent=#Airbase] autoCaptureIsOn
|
||||
-- @param self
|
||||
-- @return #boolean `true` if autoCapture behavior is enabled and `false` otherwise.
|
||||
|
||||
--- Changes the passed airbase object's coalition to the set value. Must be used with Airbase.autoCapture to disable auto capturing of the base, otherwise the base can revert back to a different coalition depending on the situation and built in game capture rules.
|
||||
-- @function [parent=#Airbase] setCoalition
|
||||
-- @param self
|
||||
-- @param #number coa The new owner coalition: 0=neutra, 1=red, 2=blue.
|
||||
|
||||
Airbase = {} --#Airbase
|
||||
|
||||
end -- Airbase
|
||||
|
||||
|
||||
do -- Warehouse
|
||||
|
||||
--- [DCS Class Warehouse](https://wiki.hoggitworld.com/view/DCS_Class_Warehouse)
|
||||
-- The warehouse class gives control over warehouses that exist in airbase objects. These warehouses can limit the aircraft, munitions, and fuel available to coalition aircraft.
|
||||
-- @type Warehouse
|
||||
|
||||
--- Adds the passed amount of a given item to the warehouse.
|
||||
-- itemName is the typeName associated with the item: "weapons.missiles.AIM_54C_Mk47"
|
||||
-- A wsType table can also be used, however the last digit with wsTypes has been known to change. {4, 4, 7, 322}
|
||||
-- @function [parent=#Warehouse] addItem
|
||||
-- @param self
|
||||
-- @param #string itemName Name of the item.
|
||||
-- @param #number count Number of items to add.
|
||||
|
||||
--- Returns the number of the passed type of item currently in a warehouse object.
|
||||
-- @function [parent=#Warehouse] getItemCount
|
||||
-- @param self
|
||||
-- @param #string itemName Name of the item.
|
||||
|
||||
--- Sets the passed amount of a given item to the warehouse.
|
||||
-- @function [parent=#Warehouse] setItem
|
||||
-- @param self
|
||||
-- @param #string itemName Name of the item.
|
||||
-- @param #number count Number of items to add.
|
||||
|
||||
--- Removes the amount of the passed item from the warehouse.
|
||||
-- @function [parent=#Warehouse] removeItem
|
||||
-- @param self
|
||||
-- @param #string itemName Name of the item.
|
||||
-- @param #number count Number of items to be removed.
|
||||
|
||||
--- Adds the passed amount of a liquid fuel into the warehouse inventory.
|
||||
-- @function [parent=#Warehouse] addLiquid
|
||||
-- @param self
|
||||
-- @param #number liquidType Type of liquid to add: 0=jetfuel, 1=aviation gasoline, 2=MW50, 3=Diesel.
|
||||
-- @param #number count Amount of liquid to add.
|
||||
|
||||
--- Returns the amount of the passed liquid type within a given warehouse.
|
||||
-- @function [parent=#Warehouse] getLiquidAmount
|
||||
-- @param self
|
||||
-- @param #number liquidType Type of liquid to add: 0=jetfuel, 1=aviation gasoline, 2=MW50, 3=Diesel.
|
||||
-- @return #number Amount of liquid.
|
||||
|
||||
--- Sets the passed amount of a liquid fuel into the warehouse inventory.
|
||||
-- @function [parent=#Warehouse] setLiquidAmount
|
||||
-- @param self
|
||||
-- @param #number liquidType Type of liquid to add: 0=jetfuel, 1=aviation gasoline, 2=MW50, 3=Diesel.
|
||||
-- @param #number count Amount of liquid.
|
||||
|
||||
--- Removes the set amount of liquid from the inventory in a warehouse.
|
||||
-- @function [parent=#Warehouse] setLiquidAmount
|
||||
-- @param self
|
||||
-- @param #number liquidType Type of liquid to add: 0=jetfuel, 1=aviation gasoline, 2=MW50, 3=Diesel.
|
||||
-- @param #number count Amount of liquid.
|
||||
|
||||
--- Returns the airbase object associated with the warehouse object.
|
||||
-- @function [parent=#Warehouse] getOwner
|
||||
-- @param self
|
||||
-- @return #Airbase The airbase object owning this warehouse.
|
||||
|
||||
--- Returns a full itemized list of everything currently in a warehouse. If a category is set to unlimited then the table will be returned empty.
|
||||
-- Aircraft and weapons are indexed by strings. Liquids are indexed by number.
|
||||
-- @function [parent=#Warehouse] getInventory
|
||||
-- @param self
|
||||
-- @param #string itemName Name of the item.
|
||||
-- @return #table Itemized list of everything currently in a warehouse
|
||||
|
||||
|
||||
Warehouse = {} --#Warehouse
|
||||
|
||||
end
|
||||
|
||||
do -- Spot
|
||||
|
||||
--- [DCS Class Spot](https://wiki.hoggitworld.com/view/DCS_Class_Spot)
|
||||
|
||||
@ -48,6 +48,7 @@ __Moose.Include( 'Scripts/Moose/Wrapper/Scenery.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Wrapper/Marker.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Wrapper/Weapon.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Wrapper/Net.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Wrapper/Storage.lua' )
|
||||
|
||||
__Moose.Include( 'Scripts/Moose/Cargo/Cargo.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Cargo/CargoUnit.lua' )
|
||||
|
||||
247
Moose Development/Moose/Wrapper/Storage.lua
Normal file
247
Moose Development/Moose/Wrapper/Storage.lua
Normal file
@ -0,0 +1,247 @@
|
||||
--- **Wrapper** - Warehouse storage of DCS airbases.
|
||||
--
|
||||
-- ## Main Features:
|
||||
--
|
||||
-- * Convenient access to DCS API functions
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ## Example Missions:
|
||||
--
|
||||
-- Demo missions can be found on [github](https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/develop/Wrapper%20-%20Storage).
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **funkyfranky**
|
||||
--
|
||||
-- ===
|
||||
-- @module Wrapper.Storage
|
||||
-- @image Wrapper_Storage.png
|
||||
|
||||
|
||||
--- STORAGE class.
|
||||
-- @type STORAGE
|
||||
-- @field #string ClassName Name of the class.
|
||||
-- @field #number verbose Verbosity level.
|
||||
-- @field #string lid Class id string for output to DCS log file.
|
||||
-- @field DCS#Warehouse warehouse The DCS warehouse object.
|
||||
-- @field DCS#Airbase airbase The DCS airbase object.
|
||||
-- @extends Core.Base#BASE
|
||||
|
||||
--- *The capitalist cannot store labour-power in warehouses after he has bought it, as he may do with the raw material.* -- Karl Marx
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- # The STORAGE Concept
|
||||
--
|
||||
-- The STORAGE class offers an easy-to-use wrapper interface to all DCS API functions of DCS warehouses. We named the class STORAGE, because the name WAREHOUSE is already taken by another MOOSE class.
|
||||
--
|
||||
-- This class allows you to add and remove items to a DCS warehouse, such as aircraft, weapons and liquids.
|
||||
--
|
||||
-- # Constructor
|
||||
--
|
||||
-- A DCS warehouse is associated with an airbase. Therefore, to get the storage, you need to pass the airbase name as parameter:
|
||||
--
|
||||
-- -- Create a STORAGE instance of the Batumi warehouse
|
||||
-- local storage=STORAGE:New("Batumi")
|
||||
--
|
||||
--
|
||||
-- @field #STORAGE
|
||||
STORAGE = {
|
||||
ClassName = "STORAGE",
|
||||
verbose = 0,
|
||||
}
|
||||
|
||||
--- Liquid types.
|
||||
-- @type STORAGE.Liquid
|
||||
-- @field #number JETFUEL Jet fuel.
|
||||
-- @field #number GASOLINE Aviation gasoline.
|
||||
-- @field #number MW50 MW50.
|
||||
-- @field #number DIESEL Diesel.
|
||||
STORAGE.Liquid = {
|
||||
JETFUEL = 0,
|
||||
GASOLINE = 1,
|
||||
MW50 = 2,
|
||||
DIESEL = 3,
|
||||
}
|
||||
|
||||
--- STORAGE class version.
|
||||
-- @field #string version
|
||||
STORAGE.version="0.0.1"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- TODO list
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- TODO: A lot...
|
||||
-- TODO: Persistence
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Constructor
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Create a new STORAGE object from the DCS weapon object.
|
||||
-- @param #STORAGE self
|
||||
-- @param #string AirbaseName Name of the airbase.
|
||||
-- @return #STORAGE self
|
||||
function STORAGE:New(AirbaseName)
|
||||
|
||||
-- Inherit everything from FSM class.
|
||||
local self=BASE:Inherit(self, BASE:New()) -- #STORAGE
|
||||
|
||||
self.airbase=Airbase.getByName(AirbaseName)
|
||||
|
||||
self.warehouse=self.airbase:getWarehouse()
|
||||
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- User API Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Set verbosity level.
|
||||
-- @param #STORAGE self
|
||||
-- @param #number VerbosityLevel Level of output (higher=more). Default 0.
|
||||
-- @return #STORAGE self
|
||||
function STORAGE:SetVerbosity(VerbosityLevel)
|
||||
self.verbose=VerbosityLevel or 0
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Adds the passed amount of a given item to the warehouse.
|
||||
-- @param #STORAGE self
|
||||
-- @param #string Name Name of the item to add.
|
||||
-- @param #number Amount Amount of items to add.
|
||||
-- @return #STORAGE self
|
||||
function STORAGE:AddItem(Name, Amount)
|
||||
|
||||
self:T(self.lid..string.format("Adding %d items of %s", Amount, Name))
|
||||
|
||||
self.warehouse:addItem(Name, Amount)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Sets the specified amount of a given item to the warehouse.
|
||||
-- @param #STORAGE self
|
||||
-- @param #string Name Name of the item.
|
||||
-- @param #number Amount Amount of items.
|
||||
-- @return #STORAGE self
|
||||
function STORAGE:SetItem(Name, Amount)
|
||||
|
||||
self:T(self.lid..string.format("Setting item %s to N=%d", Name, Amount))
|
||||
|
||||
self.warehouse:setItem(Name, Amount)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Gets the amount of a given item currently present the warehouse.
|
||||
-- @param #STORAGE self
|
||||
-- @param #string Name Name of the item.
|
||||
-- @return #number Amount of items.
|
||||
function STORAGE:GetItemAmount(Name)
|
||||
|
||||
local N=self.warehouse:getItemCount(Name)
|
||||
|
||||
return N
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Removes the amount of the passed item from the warehouse.
|
||||
-- @param #STORAGE self
|
||||
-- @param #string Name Name of the item.
|
||||
-- @param #number Amount Amount of items.
|
||||
-- @return #STORAGE self
|
||||
function STORAGE:RemoveItem(Name, Amount)
|
||||
|
||||
self:T(self.lid..string.format("Removing N=%d of item %s", Amount, Name))
|
||||
|
||||
self.warehouse:removeItem(Name, Amount)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--- Adds the passed amount of a given liquid to the warehouse.
|
||||
-- @param #STORAGE self
|
||||
-- @param #number Type Type of liquid.
|
||||
-- @param #number Amount Amount of liquid to add.
|
||||
-- @return #STORAGE self
|
||||
function STORAGE:AddLiquid(Type, Amount)
|
||||
|
||||
self:T(self.lid..string.format("Adding %d liquids of %s", Amount, Type))
|
||||
|
||||
self.warehouse:addLiquid(Name, Amount)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Sets the specified amount of a given liquid to the warehouse.
|
||||
-- @param #STORAGE self
|
||||
-- @param #number Type Type of liquid.
|
||||
-- @param #number Amount Amount of liquid.
|
||||
-- @return #STORAGE self
|
||||
function STORAGE:SetLiquid(Type, Amount)
|
||||
|
||||
self:T(self.lid..string.format("Setting liquid %s to N=%d", Type, Amount))
|
||||
|
||||
self.warehouse:setLiquid(Type, Amount)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Removes the amount of the passed liquid from the warehouse.
|
||||
-- @param #STORAGE self
|
||||
-- @param #number Type Type of liquid.
|
||||
-- @param #number Amount Amount of liquid to remove.
|
||||
-- @return #STORAGE self
|
||||
function STORAGE:RemoveLiquid(Type, Amount)
|
||||
|
||||
self:T(self.lid..string.format("Removing N=%d of liquid %s", Amount, Type))
|
||||
|
||||
self.warehouse:removeLiquid(Type, Amount)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Gets the amount of a given liquid currently present the warehouse.
|
||||
-- @param #STORAGE self
|
||||
-- @param #number Type Type of liquid.
|
||||
-- @return #number Amount of liquid.
|
||||
function STORAGE:GetLiquidAmount(Type)
|
||||
|
||||
local N=self.warehouse:getLiquidAmount(Type)
|
||||
|
||||
return N
|
||||
end
|
||||
|
||||
|
||||
--- Returns a full itemized list of everything currently in a warehouse. If a category is set to unlimited then the table will be returned empty.
|
||||
-- @param #STORAGE self
|
||||
-- @param #string Item Name of item as #string or type of liquid as #number.
|
||||
-- @return #table Table of aircraft. Table is emtpy `{}` if number of aircraft is set to be unlimited.
|
||||
-- @return #table Table of liquids. Table is emtpy `{}` if number of liquids is set to be unlimited.
|
||||
-- @return #table Table of weapons. Table is emtpy `{}` if number of liquids is set to be unlimited.
|
||||
function STORAGE:GetInventory(Item)
|
||||
|
||||
local inventory=self.warehouse:getInventory(Item)
|
||||
|
||||
return inventory.aircraft, inventory.liquids, inventory.weapon
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Private Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
@ -49,6 +49,7 @@ Wrapper/Scenery.lua
|
||||
Wrapper/Marker.lua
|
||||
Wrapper/Weapon.lua
|
||||
Wrapper/Net.lua
|
||||
Wrapper/Storage.lua
|
||||
|
||||
Cargo/Cargo.lua
|
||||
Cargo/CargoUnit.lua
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user