From f929951dbe45da0511ab378d1ec4e9cac08b4503 Mon Sep 17 00:00:00 2001 From: ttrebuchon Date: Sun, 13 Aug 2023 15:12:51 -0400 Subject: [PATCH 1/6] Fix WAREHOUSE.AssetItem size calculation --- Moose Development/Moose/Functional/Warehouse.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Moose Development/Moose/Functional/Warehouse.lua b/Moose Development/Moose/Functional/Warehouse.lua index f420a770e..dc92562b1 100644 --- a/Moose Development/Moose/Functional/Warehouse.lua +++ b/Moose Development/Moose/Functional/Warehouse.lua @@ -4101,9 +4101,9 @@ function WAREHOUSE:_RegisterAsset(group, ngroups, forceattribute, forcecargobay, -- Get the size of an object. local function _GetObjectSize(DCSdesc) if DCSdesc.box then - local x=DCSdesc.box.max.x+math.abs(DCSdesc.box.min.x) --length - local y=DCSdesc.box.max.y+math.abs(DCSdesc.box.min.y) --height - local z=DCSdesc.box.max.z+math.abs(DCSdesc.box.min.z) --width + local x=DCSdesc.box.max.x-DCSdesc.box.min.x --length + local y=DCSdesc.box.max.y-DCSdesc.box.min.y --height + local z=DCSdesc.box.max.z-DCSdesc.box.min.z --width return math.max(x,z), x , y, z end return 0,0,0,0 From d08219f9d9e3f56fd735462210a988ee716a45fa Mon Sep 17 00:00:00 2001 From: ttrebuchon Date: Sun, 13 Aug 2023 15:16:46 -0400 Subject: [PATCH 2/6] Add missing "Mission.escortMissionType" argument to call to AssignAssetsForEscort --- Moose Development/Moose/Ops/Commander.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Moose Development/Moose/Ops/Commander.lua b/Moose Development/Moose/Ops/Commander.lua index 0af40ed2d..132b474f0 100644 --- a/Moose Development/Moose/Ops/Commander.lua +++ b/Moose Development/Moose/Ops/Commander.lua @@ -1747,7 +1747,7 @@ function COMMANDER:RecruitAssetsForEscort(Mission, Assets) local Cohorts=self:_GetCohorts(Mission.escortLegions, Mission.escortCohorts, Mission.operation) -- Call LEGION function but provide COMMANDER as self. - local assigned=LEGION.AssignAssetsForEscort(self, Cohorts, Assets, Mission.NescortMin, Mission.NescortMax, Mission.escortTargetTypes, Mission.escortEngageRange) + local assigned=LEGION.AssignAssetsForEscort(self, Cohorts, Assets, Mission.NescortMin, Mission.NescortMax, Mission.escortMissionType, Mission.escortTargetTypes, Mission.escortEngageRange) return assigned end From 2e9320df0309a07f61d4483bfe79c5c4870cc11c Mon Sep 17 00:00:00 2001 From: ttrebuchon Date: Sun, 13 Aug 2023 15:18:09 -0400 Subject: [PATCH 3/6] Add check for whether targetcoord is nil in UpdateMarker() call --- Moose Development/Moose/Ops/Auftrag.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Moose Development/Moose/Ops/Auftrag.lua b/Moose Development/Moose/Ops/Auftrag.lua index 7d4deac86..1bf4f8710 100644 --- a/Moose Development/Moose/Ops/Auftrag.lua +++ b/Moose Development/Moose/Ops/Auftrag.lua @@ -5776,10 +5776,12 @@ function AUFTRAG:UpdateMarker() -- Get target coordinates. Can be nil! local targetcoord=self:GetTargetCoordinate() - if self.markerCoaliton and self.markerCoaliton>=0 then - self.marker=MARKER:New(targetcoord, text):ReadOnly():ToCoalition(self.markerCoaliton) - else - self.marker=MARKER:New(targetcoord, text):ReadOnly():ToAll() + if targetcoord then + if self.markerCoaliton and self.markerCoaliton>=0 then + self.marker=MARKER:New(targetcoord, text):ReadOnly():ToCoalition(self.markerCoaliton) + else + self.marker=MARKER:New(targetcoord, text):ReadOnly():ToAll() + end end else From 3adf6d635a3e2ba9c9ad35ec2427d1137867f21f Mon Sep 17 00:00:00 2001 From: ttrebuchon Date: Sun, 13 Aug 2023 15:22:05 -0400 Subject: [PATCH 4/6] Handle OPSGROUP:MarkWaypoints() when waypoint altitude is nil --- Moose Development/Moose/Ops/OpsGroup.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index 594f916ce..6afe0d51e 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -3013,7 +3013,7 @@ function OPSGROUP:MarkWaypoints(Duration) local waypoint=_waypoint --#OPSGROUP.Waypoint local text=string.format("Waypoint ID=%d of %s", waypoint.uid, self.groupname) - text=text..string.format("\nSpeed=%.1f kts, Alt=%d ft (%s)", UTILS.MpsToKnots(waypoint.speed), UTILS.MetersToFeet(waypoint.alt), "BARO") + text=text..string.format("\nSpeed=%.1f kts, Alt=%d ft (%s)", UTILS.MpsToKnots(waypoint.speed), UTILS.MetersToFeet(waypoint.alt or 0), "BARO") if waypoint.marker then if waypoint.marker.text~=text then From 32e1d4f8fad6a5bcee0a424746ffc3a928c804ba Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 16 Aug 2023 23:58:32 +0200 Subject: [PATCH 5/6] DCS Warehouse --- Moose Development/Moose/DCS.lua | 95 +++++++- Moose Development/Moose/Modules.lua | 1 + Moose Development/Moose/Wrapper/Storage.lua | 247 ++++++++++++++++++++ Moose Setup/Moose.files | 1 + 4 files changed, 343 insertions(+), 1 deletion(-) create mode 100644 Moose Development/Moose/Wrapper/Storage.lua diff --git a/Moose Development/Moose/DCS.lua b/Moose Development/Moose/DCS.lua index ee1c9e9d7..46a7ded63 100644 --- a/Moose Development/Moose/DCS.lua +++ b/Moose Development/Moose/DCS.lua @@ -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) diff --git a/Moose Development/Moose/Modules.lua b/Moose Development/Moose/Modules.lua index 9d4ae533c..22b16d9ef 100644 --- a/Moose Development/Moose/Modules.lua +++ b/Moose Development/Moose/Modules.lua @@ -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' ) diff --git a/Moose Development/Moose/Wrapper/Storage.lua b/Moose Development/Moose/Wrapper/Storage.lua new file mode 100644 index 000000000..cda71906c --- /dev/null +++ b/Moose Development/Moose/Wrapper/Storage.lua @@ -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 +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/Moose Setup/Moose.files b/Moose Setup/Moose.files index ecb27c170..46213ce2e 100644 --- a/Moose Setup/Moose.files +++ b/Moose Setup/Moose.files @@ -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 From 4471ec9b9644d805b0bd161a8bdb94df3b79bf20 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 17 Aug 2023 18:46:09 +0200 Subject: [PATCH 6/6] DCS Warehouse --- Moose Development/Moose/Core/Database.lua | 38 ++++- Moose Development/Moose/DCS.lua | 12 +- Moose Development/Moose/Wrapper/Airbase.lua | 85 +++++++++++ Moose Development/Moose/Wrapper/Storage.lua | 150 +++++++++++++++++--- 4 files changed, 263 insertions(+), 22 deletions(-) diff --git a/Moose Development/Moose/Core/Database.lua b/Moose Development/Moose/Core/Database.lua index 4ad7f9e50..1398d7088 100644 --- a/Moose Development/Moose/Core/Database.lua +++ b/Moose Development/Moose/Core/Database.lua @@ -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. diff --git a/Moose Development/Moose/DCS.lua b/Moose Development/Moose/DCS.lua index 46a7ded63..8a76a867d 100644 --- a/Moose Development/Moose/DCS.lua +++ b/Moose Development/Moose/DCS.lua @@ -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 diff --git a/Moose Development/Moose/Wrapper/Airbase.lua b/Moose Development/Moose/Wrapper/Airbase.lua index dd52825fa..5dcf2757b 100644 --- a/Moose Development/Moose/Wrapper/Airbase.lua +++ b/Moose Development/Moose/Wrapper/Airbase.lua @@ -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 diff --git a/Moose Development/Moose/Wrapper/Storage.lua b/Moose Development/Moose/Wrapper/Storage.lua index cda71906c..191e916ca 100644 --- a/Moose Development/Moose/Wrapper/Storage.lua +++ b/Moose Development/Moose/Wrapper/Storage.lua @@ -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)