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
32e1d4f8fa
commit
4471ec9b96
@ -32,10 +32,12 @@
|
||||
-- @image Core_Database.JPG
|
||||
|
||||
|
||||
--- @type DATABASE
|
||||
--- DATABASE class.
|
||||
-- @type DATABASE
|
||||
-- @field #string ClassName Name of the class.
|
||||
-- @field #table Templates Templates: Units, Groups, Statics, ClientsByName, ClientsByID.
|
||||
-- @field #table CLIENTS Clients.
|
||||
-- @field #table STORAGES DCS warehouse storages.
|
||||
-- @extends Core.Base#BASE
|
||||
|
||||
--- Contains collections of wrapper objects defined within MOOSE that reflect objects within the simulator.
|
||||
@ -50,6 +52,7 @@
|
||||
-- * PLAYERSJOINED
|
||||
-- * PLAYERS
|
||||
-- * CARGOS
|
||||
-- * STORAGES (DCS warehouses)
|
||||
--
|
||||
-- On top, for internal MOOSE administration purposes, the DATABASE administers the Unit and Group TEMPLATES as defined within the Mission Editor.
|
||||
--
|
||||
@ -90,6 +93,7 @@ DATABASE = {
|
||||
FLIGHTCONTROLS = {},
|
||||
OPSZONES = {},
|
||||
PATHLINES = {},
|
||||
STORAGES = {},
|
||||
}
|
||||
|
||||
local _DATABASECoalition =
|
||||
@ -246,6 +250,38 @@ function DATABASE:FindAirbase( AirbaseName )
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Adds a STORAGE (DCS warehouse wrapper) based on the Airbase Name to the DATABASE.
|
||||
-- @param #DATABASE self
|
||||
-- @param #string AirbaseName The name of the airbase.
|
||||
-- @return Wrapper.Storage#STORAGE Storage object.
|
||||
function DATABASE:AddStorage( AirbaseName )
|
||||
|
||||
if not self.STORAGES[AirbaseName] then
|
||||
self.STORAGES[AirbaseName] = STORAGE:New( AirbaseName )
|
||||
end
|
||||
|
||||
return self.STORAGES[AirbaseName]
|
||||
end
|
||||
|
||||
|
||||
--- Deletes a STORAGE from the DATABASE based on the name of the associated airbase.
|
||||
-- @param #DATABASE self
|
||||
-- @param #string AirbaseName The name of the airbase.
|
||||
function DATABASE:DeleteStorage( AirbaseName )
|
||||
self.STORAGES[AirbaseName] = nil
|
||||
end
|
||||
|
||||
|
||||
--- Finds an STORAGE based on the name of the associated airbase.
|
||||
-- @param #DATABASE self
|
||||
-- @param #string AirbaseName Name of the airbase.
|
||||
-- @return Wrapper.Storage#STORAGE The found STORAGE.
|
||||
function DATABASE:FindStorage( AirbaseName )
|
||||
local storage = self.STORAGES[AirbaseName]
|
||||
return storage
|
||||
end
|
||||
|
||||
do -- Zones and Pathlines
|
||||
|
||||
--- Finds a @{Core.Zone} based on the zone name.
|
||||
|
||||
@ -799,7 +799,8 @@ do -- Airbase
|
||||
-- @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.
|
||||
--- 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
|
||||
@ -809,11 +810,18 @@ do -- Airbase
|
||||
-- @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.
|
||||
--- 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.
|
||||
|
||||
--- Returns the wsType of every object that exists in DCS. A wsType is a table consisting of 4 entries indexed numerically.
|
||||
-- It can be used to broadly categorize object types. The table can be broken down as: {mainCategory, subCat1, subCat2, index}
|
||||
-- @function [parent=#Airbase] getResourceMap
|
||||
-- @param self
|
||||
-- @return #table wsType of every object that exists in DCS.
|
||||
|
||||
Airbase = {} --#Airbase
|
||||
|
||||
end -- Airbase
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
-- @field #table runways Runways of airdromes.
|
||||
-- @field #AIRBASE.Runway runwayLanding Runway used for landing.
|
||||
-- @field #AIRBASE.Runway runwayTakeoff Runway used for takeoff.
|
||||
-- @field Wrapper.Storage#STORAGE storage The DCS warehouse storage.
|
||||
-- @extends Wrapper.Positionable#POSITIONABLE
|
||||
|
||||
--- Wrapper class to handle the DCS Airbase objects:
|
||||
@ -832,6 +833,9 @@ function AIRBASE:Register(AirbaseName)
|
||||
|
||||
-- Init coordinate.
|
||||
self:GetCoordinate()
|
||||
|
||||
-- Storage.
|
||||
self.storage=_DATABASE:AddStorage(AirbaseName)
|
||||
|
||||
if vec2 then
|
||||
if self.isShip then
|
||||
@ -919,6 +923,87 @@ function AIRBASE:GetZone()
|
||||
return self.AirbaseZone
|
||||
end
|
||||
|
||||
--- Get the DCS warehouse.
|
||||
-- @param #AIRBASE self
|
||||
-- @return DCS#Warehouse The DCS warehouse object.
|
||||
function AIRBASE:GetWarehouse()
|
||||
local warehouse=nil --DCS#Warehouse
|
||||
local airbase=self:GetDCSObject()
|
||||
if airbase then
|
||||
warehouse=airbase:getWarehouse()
|
||||
end
|
||||
return warehouse
|
||||
end
|
||||
|
||||
--- Get the warehouse storage of this airbase. The returned `STORAGE` object is the wrapper of the DCS warehouse.
|
||||
-- This allows you to add and remove items such as aircraft, liquids, weapons and other equipment.
|
||||
-- @param #AIRBASE self
|
||||
-- @return Wrapper.Storage#STORAGE The storage.
|
||||
function AIRBASE:GetStorage()
|
||||
return self.storage
|
||||
end
|
||||
|
||||
--- Enables or disables automatic capturing of the airbase.
|
||||
-- @param #AIRBASE self
|
||||
-- @param #boolean Switch If `true`, enable auto capturing. If `false`, disable it.
|
||||
-- @return #AIRBASE self
|
||||
function AIRBASE:SetAutoCapture(Switch)
|
||||
|
||||
local airbase=self:GetDCSObject()
|
||||
|
||||
if airbase then
|
||||
airbase:autoCapture(Switch)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Enables automatic capturing of the airbase.
|
||||
-- @param #AIRBASE self
|
||||
-- @return #AIRBASE self
|
||||
function AIRBASE:SetAutoCaptureON()
|
||||
self:SetAutoCapture(true)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Disables automatic capturing of the airbase.
|
||||
-- @param #AIRBASE self
|
||||
-- @return #AIRBASE self
|
||||
function AIRBASE:SetAutoCaptureOFF()
|
||||
self:SetAutoCapture(false)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Returns whether auto capturing of the airbase is on or off.
|
||||
-- @param #AIRBASE self
|
||||
-- @return #boolean Returns `true` if auto capturing is on, `false` if off and `nil` if the airbase object cannot be retrieved.
|
||||
function AIRBASE:IsAutoCapture()
|
||||
|
||||
local airbase=self:GetDCSObject()
|
||||
|
||||
local auto=nil
|
||||
if airbase then
|
||||
auto=airbase:autoCaptureIsOn()
|
||||
end
|
||||
|
||||
return auto
|
||||
end
|
||||
|
||||
--- Sets the coalition of the airbase.
|
||||
-- @param #AIRBASE self
|
||||
-- @param #number Coal Coalition that the airbase should have (0=Neutral, 1=Red, 2=Blue).
|
||||
-- @return #AIRBASE self
|
||||
function AIRBASE:SetCoalition(Coal)
|
||||
|
||||
local airbase=self:GetDCSObject()
|
||||
|
||||
if airbase then
|
||||
airbase:setCoalition(Coal)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Get all airbases of the current map. This includes ships and FARPS.
|
||||
-- @param DCS#Coalition coalition (Optional) Return only airbases belonging to the specified coalition. By default, all airbases of the map are returned.
|
||||
-- @param #number category (Optional) Return only airbases of a certain category, e.g. Airbase.Category.FARP
|
||||
|
||||
@ -34,17 +34,95 @@
|
||||
--
|
||||
-- # 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.
|
||||
-- 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.
|
||||
-- This class allows you to add and remove items to a DCS warehouse, such as aircraft, liquids, weapons and other equipment.
|
||||
--
|
||||
-- # Constructor
|
||||
--
|
||||
-- A DCS warehouse is associated with an airbase. Therefore, to get the storage, you need to pass the airbase name as parameter:
|
||||
-- A DCS warehouse is associated with an airbase. Therefore, a `STORAGE` instance is automatically created, once an airbase is registered and added to the MOOSE database.
|
||||
--
|
||||
-- You can get the `STORAGE` object from the
|
||||
--
|
||||
-- -- Create a STORAGE instance of the Batumi warehouse
|
||||
-- local storage=STORAGE:New("Batumi")
|
||||
-- local storage=STORAGE:FindByName("Batumi")
|
||||
--
|
||||
-- An other way to get the `STORAGE` object is to retrieve it from the AIRBASE function `AIRBASE:GetStorage()`
|
||||
--
|
||||
-- -- Get storage instance of Batumi airbase
|
||||
-- local Batumi=AIRBASE:FindByName("Batumi")
|
||||
-- local storage=Batumi:GetStorage()
|
||||
--
|
||||
-- # Aircraft, Weapons and Equipment
|
||||
--
|
||||
-- ## Adding Items
|
||||
--
|
||||
-- To add aircraft, weapons and/or othe equipment, you can use the @{#STORAGE.AddItem}() function
|
||||
--
|
||||
-- storage:AddItem("A-10C", 3)
|
||||
-- storage:AddItem("weapons.missiles.AIM_120C", 10)
|
||||
--
|
||||
-- This will add three A-10Cs and ten AIM-120C missiles to the warehouse inventory.
|
||||
--
|
||||
-- ## Setting Items
|
||||
--
|
||||
-- You can also explicitly set, how many items are in the inventory with the @{#STORAGE.SetItem}() function.
|
||||
--
|
||||
-- ## Removing Items
|
||||
--
|
||||
-- Items can be removed from the inventory with the @{#STORAGE.RemoveItem}() function.
|
||||
--
|
||||
-- ## Getting Amount
|
||||
--
|
||||
-- The number of items currently in the inventory can be obtained with the @{#STORAGE.GetItemAmount}() function
|
||||
--
|
||||
-- local N=storage:GetItemAmount("A-10C")
|
||||
-- env.info(string.format("We currently have %d A-10Cs available", N))
|
||||
--
|
||||
-- # Liquids
|
||||
--
|
||||
-- Liquids can be added and removed by slightly different functions as described below. Currently there are four types of liquids
|
||||
--
|
||||
-- * Jet fuel `STORAGE.Liquid.JETFUEL`
|
||||
-- * Aircraft gasoline `STORAGE.Liquid.GASOLINE`
|
||||
-- * MW 50 `STORAGE.Liquid.MW50`
|
||||
-- * Diesel `STORAGE.Liquid.DIESEL`
|
||||
--
|
||||
-- ## Adding Liquids
|
||||
--
|
||||
-- To add a certain type of liquid, you can use the @{#STORAGE.AddItem}(Type, Amount) function
|
||||
--
|
||||
-- storage:AddLiquid(STORAGE.Liquid.JETFUEL, 10000)
|
||||
-- storage:AddLiquid(STORAGE.Liquid.DIESEL, 20000)
|
||||
--
|
||||
-- This will add 10,000 kg of jet fuel and 20,000 kg of diesel to the inventory.
|
||||
--
|
||||
-- ## Setting Liquids
|
||||
--
|
||||
-- You can also explicitly set the amount of liquid with the @{#STORAGE.SetLiquid}(Type, Amount) function.
|
||||
--
|
||||
-- ## Removing Liquids
|
||||
--
|
||||
-- Liquids can be removed with @{#STORAGE.RemoveLiquid}(Type, Amount) function.
|
||||
--
|
||||
-- ## Getting Amount
|
||||
--
|
||||
-- The current amount of a certain liquid can be obtained with the @{#STORAGE.GetLiquidAmount}(Type) function
|
||||
--
|
||||
-- local N=storage:GetLiquidAmount(STORAGE.Liquid.DIESEL)
|
||||
-- env.info(string.format("We currently have %d kg of Diesel available", N))
|
||||
--
|
||||
--
|
||||
-- # Inventory
|
||||
--
|
||||
-- The current inventory of the warehouse can be obtained with the @{#STORAGE.GetInventory}() function. This returns three tables with the aircraft, liquids and weapons:
|
||||
--
|
||||
-- local aircraft, liquids, weapons=storage:GetInventory()
|
||||
--
|
||||
-- UTILS.PrintTableToLog(aircraft)
|
||||
-- UTILS.PrintTableToLog(liquids)
|
||||
-- UTILS.PrintTableToLog(weapons)
|
||||
--
|
||||
-- @field #STORAGE
|
||||
STORAGE = {
|
||||
@ -54,10 +132,10 @@ STORAGE = {
|
||||
|
||||
--- Liquid types.
|
||||
-- @type STORAGE.Liquid
|
||||
-- @field #number JETFUEL Jet fuel.
|
||||
-- @field #number GASOLINE Aviation gasoline.
|
||||
-- @field #number MW50 MW50.
|
||||
-- @field #number DIESEL Diesel.
|
||||
-- @field #number JETFUEL Jet fuel (0).
|
||||
-- @field #number GASOLINE Aviation gasoline (1).
|
||||
-- @field #number MW50 MW50 (2).
|
||||
-- @field #number DIESEL Diesel (3).
|
||||
STORAGE.Liquid = {
|
||||
JETFUEL = 0,
|
||||
GASOLINE = 1,
|
||||
@ -86,17 +164,28 @@ STORAGE.version="0.0.1"
|
||||
-- @return #STORAGE self
|
||||
function STORAGE:New(AirbaseName)
|
||||
|
||||
-- Inherit everything from FSM class.
|
||||
-- Inherit everything from BASE class.
|
||||
local self=BASE:Inherit(self, BASE:New()) -- #STORAGE
|
||||
|
||||
self.airbase=Airbase.getByName(AirbaseName)
|
||||
|
||||
self.warehouse=self.airbase:getWarehouse()
|
||||
|
||||
self.lid = string.format("STORAGE %s", AirbaseName)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Find a STORAGE in the **_DATABASE** using the name associated airbase.
|
||||
-- @param #STORAGE self
|
||||
-- @param #string AirbaseName The Airbase Name.
|
||||
-- @return #STORAGE self
|
||||
function STORAGE:FindByName( AirbaseName )
|
||||
local storage = _DATABASE:FindStorage( AirbaseName )
|
||||
return storage
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- User API Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
@ -118,7 +207,7 @@ end
|
||||
-- @return #STORAGE self
|
||||
function STORAGE:AddItem(Name, Amount)
|
||||
|
||||
self:T(self.lid..string.format("Adding %d items of %s", Amount, Name))
|
||||
self:T(self.lid..string.format("Adding %d items of %s", Amount, UTILS.OneLineSerialize(Name)))
|
||||
|
||||
self.warehouse:addItem(Name, Amount)
|
||||
|
||||
@ -133,7 +222,7 @@ end
|
||||
-- @return #STORAGE self
|
||||
function STORAGE:SetItem(Name, Amount)
|
||||
|
||||
self:T(self.lid..string.format("Setting item %s to N=%d", Name, Amount))
|
||||
self:T(self.lid..string.format("Setting item %s to N=%d", UTILS.OneLineSerialize(Name), Amount))
|
||||
|
||||
self.warehouse:setItem(Name, Amount)
|
||||
|
||||
@ -177,9 +266,9 @@ end
|
||||
-- @return #STORAGE self
|
||||
function STORAGE:AddLiquid(Type, Amount)
|
||||
|
||||
self:T(self.lid..string.format("Adding %d liquids of %s", Amount, Type))
|
||||
self:T(self.lid..string.format("Adding %d liquids of %s", Amount, self:GetLiquidName(Type)))
|
||||
|
||||
self.warehouse:addLiquid(Name, Amount)
|
||||
self.warehouse:addLiquid(Type, Amount)
|
||||
|
||||
return self
|
||||
end
|
||||
@ -192,21 +281,21 @@ end
|
||||
-- @return #STORAGE self
|
||||
function STORAGE:SetLiquid(Type, Amount)
|
||||
|
||||
self:T(self.lid..string.format("Setting liquid %s to N=%d", Type, Amount))
|
||||
self:T(self.lid..string.format("Setting liquid %s to N=%d", self:GetLiquidName(Type), Amount))
|
||||
|
||||
self.warehouse:setLiquid(Type, Amount)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Removes the amount of the passed liquid from the warehouse.
|
||||
--- Removes the amount of the given liquid type from the warehouse.
|
||||
-- @param #STORAGE self
|
||||
-- @param #number Type Type of liquid.
|
||||
-- @param #number Amount Amount of liquid to remove.
|
||||
-- @param #number Amount Amount of liquid in kg to be removed.
|
||||
-- @return #STORAGE self
|
||||
function STORAGE:RemoveLiquid(Type, Amount)
|
||||
|
||||
self:T(self.lid..string.format("Removing N=%d of liquid %s", Amount, Type))
|
||||
self:T(self.lid..string.format("Removing N=%d of liquid %s", Amount, self:GetLiquidName(Type)))
|
||||
|
||||
self.warehouse:removeLiquid(Type, Amount)
|
||||
|
||||
@ -216,7 +305,7 @@ 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.
|
||||
-- @return #number Amount of liquid in kg.
|
||||
function STORAGE:GetLiquidAmount(Type)
|
||||
|
||||
local N=self.warehouse:getLiquidAmount(Type)
|
||||
@ -224,13 +313,36 @@ function STORAGE:GetLiquidAmount(Type)
|
||||
return N
|
||||
end
|
||||
|
||||
--- Returns the name of the liquid from its numeric type.
|
||||
-- @param #STORAGE self
|
||||
-- @param #number Type Type of liquid.
|
||||
-- @return #string Name of the liquid.
|
||||
function STORAGE:GetLiquidName(Type)
|
||||
|
||||
local name="Unknown"
|
||||
|
||||
if Type==STORAGE.Liquid.JETFUEL then
|
||||
name = "Jet fuel"
|
||||
elseif Type==STORAGE.Liquid.GASOLINE then
|
||||
name = "Aircraft gasoline"
|
||||
elseif Type==STORAGE.Liquid.MW50 then
|
||||
name = "MW 50"
|
||||
elseif Type==STORAGE.Liquid.DIESEL then
|
||||
name = "Diesel"
|
||||
else
|
||||
self:E(self.lid..string.format("ERROR: Unknown liquid type %s", tostring(Type)))
|
||||
end
|
||||
|
||||
return name
|
||||
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.
|
||||
-- @return #table Table of weapons and other equipment. Table is emtpy `{}` if number of liquids is set to be unlimited.
|
||||
function STORAGE:GetInventory(Item)
|
||||
|
||||
local inventory=self.warehouse:getInventory(Item)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user