mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Merge branch 'master' into develop
This commit is contained in:
commit
b0d0fb9ae1
@ -1,36 +1,36 @@
|
|||||||
--- **Core** - Spawn statics.
|
--- **Core** - Spawn statics.
|
||||||
--
|
--
|
||||||
-- ===
|
-- ===
|
||||||
--
|
--
|
||||||
-- ## Features:
|
-- ## Features:
|
||||||
--
|
--
|
||||||
-- * Spawn new statics from a static already defined in the mission editor.
|
-- * Spawn new statics from a static already defined in the mission editor.
|
||||||
-- * Spawn new statics from a given template.
|
-- * Spawn new statics from a given template.
|
||||||
-- * Spawn new statics from a given type.
|
-- * Spawn new statics from a given type.
|
||||||
-- * Spawn with a custom heading and location.
|
-- * Spawn with a custom heading and location.
|
||||||
-- * Spawn within a zone.
|
-- * Spawn within a zone.
|
||||||
-- * Spawn statics linked to units, .e.g on aircraft carriers.
|
-- * Spawn statics linked to units, .e.g on aircraft carriers.
|
||||||
--
|
|
||||||
-- ===
|
|
||||||
--
|
|
||||||
-- # Demo Missions
|
|
||||||
--
|
|
||||||
-- ## [SPAWNSTATIC Demo Missions](https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/master/Core/SpawnStatic)
|
|
||||||
--
|
--
|
||||||
--
|
|
||||||
-- ===
|
-- ===
|
||||||
--
|
--
|
||||||
|
-- # Demo Missions
|
||||||
|
--
|
||||||
|
-- ## [SPAWNSTATIC Demo Missions](https://github.com/FlightControl-Master/MOOSE_Demos/tree/master/Core/SpawnStatic)
|
||||||
|
--
|
||||||
|
--
|
||||||
|
-- ===
|
||||||
|
--
|
||||||
-- # YouTube Channel
|
-- # YouTube Channel
|
||||||
--
|
--
|
||||||
-- ## No videos yet!
|
-- ## No videos yet!
|
||||||
--
|
--
|
||||||
-- ===
|
-- ===
|
||||||
--
|
--
|
||||||
-- ### Author: **FlightControl**
|
-- ### Author: **FlightControl**
|
||||||
-- ### Contributions: **funkyfranky**
|
-- ### Contributions: **funkyfranky**
|
||||||
--
|
--
|
||||||
-- ===
|
-- ===
|
||||||
--
|
--
|
||||||
-- @module Core.SpawnStatic
|
-- @module Core.SpawnStatic
|
||||||
-- @image Core_Spawnstatic.JPG
|
-- @image Core_Spawnstatic.JPG
|
||||||
|
|
||||||
@ -58,37 +58,37 @@
|
|||||||
|
|
||||||
|
|
||||||
--- Allows to spawn dynamically new @{Wrapper.Static}s into your mission.
|
--- Allows to spawn dynamically new @{Wrapper.Static}s into your mission.
|
||||||
--
|
--
|
||||||
-- Through creating a copy of an existing static object template as defined in the Mission Editor (ME), SPAWNSTATIC can retireve the properties of the defined static object template (like type, category etc),
|
-- Through creating a copy of an existing static object template as defined in the Mission Editor (ME), SPAWNSTATIC can retireve the properties of the defined static object template (like type, category etc),
|
||||||
-- and "copy" these properties to create a new static object and place it at the desired coordinate.
|
-- and "copy" these properties to create a new static object and place it at the desired coordinate.
|
||||||
--
|
--
|
||||||
-- New spawned @{Wrapper.Static}s get **the same name** as the name of the template Static, or gets the given name when a new name is provided at the Spawn method.
|
-- New spawned @{Wrapper.Static}s get **the same name** as the name of the template Static, or gets the given name when a new name is provided at the Spawn method.
|
||||||
-- By default, spawned @{Wrapper.Static}s will follow a naming convention at run-time:
|
-- By default, spawned @{Wrapper.Static}s will follow a naming convention at run-time:
|
||||||
--
|
--
|
||||||
-- * Spawned @{Wrapper.Static}s will have the name _StaticName_#_nnn_, where _StaticName_ is the name of the **Template Static**, and _nnn_ is a **counter from 0 to 99999**.
|
-- * Spawned @{Wrapper.Static}s will have the name _StaticName_#_nnn_, where _StaticName_ is the name of the **Template Static**, and _nnn_ is a **counter from 0 to 99999**.
|
||||||
--
|
--
|
||||||
-- # SPAWNSTATIC Constructors
|
-- # SPAWNSTATIC Constructors
|
||||||
--
|
--
|
||||||
-- Firstly, we need to create a SPAWNSTATIC object that will be used to spawn new statics into the mission. There are three ways to do this.
|
-- Firstly, we need to create a SPAWNSTATIC object that will be used to spawn new statics into the mission. There are three ways to do this.
|
||||||
--
|
--
|
||||||
-- ## Use another Static
|
-- ## Use another Static
|
||||||
--
|
--
|
||||||
-- A new SPAWNSTATIC object can be created using another static by the @{#SPAWNSTATIC.NewFromStatic}() function. All parameters such as position, heading, country will be initialized
|
-- A new SPAWNSTATIC object can be created using another static by the @{#SPAWNSTATIC.NewFromStatic}() function. All parameters such as position, heading, country will be initialized
|
||||||
-- from the static.
|
-- from the static.
|
||||||
--
|
--
|
||||||
-- ## From a Template
|
-- ## From a Template
|
||||||
--
|
--
|
||||||
-- A SPAWNSTATIC object can also be created from a template table using the @{#SPAWNSTATIC.NewFromTemplate}(SpawnTemplate, CountryID) function. All parameters are taken from the template.
|
-- A SPAWNSTATIC object can also be created from a template table using the @{#SPAWNSTATIC.NewFromTemplate}(SpawnTemplate, CountryID) function. All parameters are taken from the template.
|
||||||
--
|
--
|
||||||
-- ## From a Type
|
-- ## From a Type
|
||||||
--
|
--
|
||||||
-- A very basic method is to create a SPAWNSTATIC object by just giving the type of the static. All parameters must be initialized from the InitXYZ functions described below. Otherwise default values
|
-- A very basic method is to create a SPAWNSTATIC object by just giving the type of the static. All parameters must be initialized from the InitXYZ functions described below. Otherwise default values
|
||||||
-- are used. For example, if no spawn coordinate is given, the static will be created at the origin of the map.
|
-- are used. For example, if no spawn coordinate is given, the static will be created at the origin of the map.
|
||||||
--
|
--
|
||||||
-- # Setting Parameters
|
-- # Setting Parameters
|
||||||
--
|
--
|
||||||
-- Parameters such as the spawn position, heading, country etc. can be set via :Init*XYZ* functions. Note that these functions must be given before the actual spawn command!
|
-- Parameters such as the spawn position, heading, country etc. can be set via :Init*XYZ* functions. Note that these functions must be given before the actual spawn command!
|
||||||
--
|
--
|
||||||
-- * @{#SPAWNSTATIC.InitCoordinate}(Coordinate) Sets the coordinate where the static is spawned. Statics are always spawnd on the ground.
|
-- * @{#SPAWNSTATIC.InitCoordinate}(Coordinate) Sets the coordinate where the static is spawned. Statics are always spawnd on the ground.
|
||||||
-- * @{#SPAWNSTATIC.InitHeading}(Heading) sets the orientation of the static.
|
-- * @{#SPAWNSTATIC.InitHeading}(Heading) sets the orientation of the static.
|
||||||
-- * @{#SPAWNSTATIC.InitLivery}(LiveryName) sets the livery of the static. Not all statics support this.
|
-- * @{#SPAWNSTATIC.InitLivery}(LiveryName) sets the livery of the static. Not all statics support this.
|
||||||
@ -99,17 +99,17 @@
|
|||||||
-- * @{#SPAWNSTATIC.InitLinkToUnit}(Unit, OffsetX, OffsetY, OffsetAngle) links the static to a unit, e.g. to an aircraft carrier.
|
-- * @{#SPAWNSTATIC.InitLinkToUnit}(Unit, OffsetX, OffsetY, OffsetAngle) links the static to a unit, e.g. to an aircraft carrier.
|
||||||
--
|
--
|
||||||
-- # Spawning the Statics
|
-- # Spawning the Statics
|
||||||
--
|
--
|
||||||
-- Once the SPAWNSTATIC object is created and parameters are initialized, the spawn command can be given. There are different methods where some can be used to directly set parameters
|
-- Once the SPAWNSTATIC object is created and parameters are initialized, the spawn command can be given. There are different methods where some can be used to directly set parameters
|
||||||
-- such as position and heading.
|
-- such as position and heading.
|
||||||
--
|
--
|
||||||
-- * @{#SPAWNSTATIC.Spawn}(Heading, NewName) spawns the static with the set parameters. Optionally, heading and name can be given. The name **must be unique**!
|
-- * @{#SPAWNSTATIC.Spawn}(Heading, NewName) spawns the static with the set parameters. Optionally, heading and name can be given. The name **must be unique**!
|
||||||
-- * @{#SPAWNSTATIC.SpawnFromCoordinate}(Coordinate, Heading, NewName) spawn the static at the given coordinate. Optionally, heading and name can be given. The name **must be unique**!
|
-- * @{#SPAWNSTATIC.SpawnFromCoordinate}(Coordinate, Heading, NewName) spawn the static at the given coordinate. Optionally, heading and name can be given. The name **must be unique**!
|
||||||
-- * @{#SPAWNSTATIC.SpawnFromPointVec2}(PointVec2, Heading, NewName) spawns the static at a POINT_VEC2 coordinate. Optionally, heading and name can be given. The name **must be unique**!
|
-- * @{#SPAWNSTATIC.SpawnFromPointVec2}(PointVec2, Heading, NewName) spawns the static at a POINT_VEC2 coordinate. Optionally, heading and name can be given. The name **must be unique**!
|
||||||
-- * @{#SPAWNSTATIC.SpawnFromZone}(Zone, Heading, NewName) spawns the static at the center of a @{Core.Zone}. Optionally, heading and name can be given. The name **must be unique**!
|
-- * @{#SPAWNSTATIC.SpawnFromZone}(Zone, Heading, NewName) spawns the static at the center of a @{Core.Zone}. Optionally, heading and name can be given. The name **must be unique**!
|
||||||
--
|
--
|
||||||
-- @field #SPAWNSTATIC SPAWNSTATIC
|
-- @field #SPAWNSTATIC SPAWNSTATIC
|
||||||
--
|
--
|
||||||
SPAWNSTATIC = {
|
SPAWNSTATIC = {
|
||||||
ClassName = "SPAWNSTATIC",
|
ClassName = "SPAWNSTATIC",
|
||||||
SpawnIndex = 0,
|
SpawnIndex = 0,
|
||||||
@ -139,9 +139,9 @@ SPAWNSTATIC = {
|
|||||||
function SPAWNSTATIC:NewFromStatic(SpawnTemplateName, SpawnCountryID)
|
function SPAWNSTATIC:NewFromStatic(SpawnTemplateName, SpawnCountryID)
|
||||||
|
|
||||||
local self = BASE:Inherit( self, BASE:New() ) -- #SPAWNSTATIC
|
local self = BASE:Inherit( self, BASE:New() ) -- #SPAWNSTATIC
|
||||||
|
|
||||||
local TemplateStatic, CoalitionID, CategoryID, CountryID = _DATABASE:GetStaticGroupTemplate(SpawnTemplateName)
|
local TemplateStatic, CoalitionID, CategoryID, CountryID = _DATABASE:GetStaticGroupTemplate(SpawnTemplateName)
|
||||||
|
|
||||||
if TemplateStatic then
|
if TemplateStatic then
|
||||||
self.SpawnTemplatePrefix = SpawnTemplateName
|
self.SpawnTemplatePrefix = SpawnTemplateName
|
||||||
self.TemplateStaticUnit = UTILS.DeepCopy(TemplateStatic.units[1])
|
self.TemplateStaticUnit = UTILS.DeepCopy(TemplateStatic.units[1])
|
||||||
@ -166,11 +166,11 @@ end
|
|||||||
function SPAWNSTATIC:NewFromTemplate(SpawnTemplate, CountryID)
|
function SPAWNSTATIC:NewFromTemplate(SpawnTemplate, CountryID)
|
||||||
|
|
||||||
local self = BASE:Inherit( self, BASE:New() ) -- #SPAWNSTATIC
|
local self = BASE:Inherit( self, BASE:New() ) -- #SPAWNSTATIC
|
||||||
|
|
||||||
self.TemplateStaticUnit = UTILS.DeepCopy(SpawnTemplate)
|
self.TemplateStaticUnit = UTILS.DeepCopy(SpawnTemplate)
|
||||||
self.SpawnTemplatePrefix = SpawnTemplate.name
|
self.SpawnTemplatePrefix = SpawnTemplate.name
|
||||||
self.CountryID = CountryID or country.id.USA
|
self.CountryID = CountryID or country.id.USA
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ function SPAWNSTATIC:NewFromType(StaticType, StaticCategory, CountryID)
|
|||||||
self.InitStaticCategory=StaticCategory
|
self.InitStaticCategory=StaticCategory
|
||||||
self.CountryID=CountryID or country.id.USA
|
self.CountryID=CountryID or country.id.USA
|
||||||
self.SpawnTemplatePrefix=self.InitStaticType
|
self.SpawnTemplatePrefix=self.InitStaticType
|
||||||
|
|
||||||
self.InitStaticCoordinate=COORDINATE:New(0, 0, 0)
|
self.InitStaticCoordinate=COORDINATE:New(0, 0, 0)
|
||||||
self.InitStaticHeading=0
|
self.InitStaticHeading=0
|
||||||
|
|
||||||
@ -291,7 +291,7 @@ function SPAWNSTATIC:InitCountry(CountryID)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Initialize name prefix statics get. This will be appended by "#0001", "#0002" etc.
|
--- Initialize name prefix statics get. This will be appended by "#0001", "#0002" etc.
|
||||||
-- @param #SPAWNSTATIC self
|
-- @param #SPAWNSTATIC self
|
||||||
-- @param #string NamePrefix Name prefix of statics spawned. Will append #0001, etc to the name.
|
-- @param #string NamePrefix Name prefix of statics spawned. Will append #0001, etc to the name.
|
||||||
-- @return #SPAWNSTATIC self
|
-- @return #SPAWNSTATIC self
|
||||||
@ -327,13 +327,13 @@ function SPAWNSTATIC:Spawn(Heading, NewName)
|
|||||||
if Heading then
|
if Heading then
|
||||||
self.InitStaticHeading=Heading
|
self.InitStaticHeading=Heading
|
||||||
end
|
end
|
||||||
|
|
||||||
if NewName then
|
if NewName then
|
||||||
self.InitStaticName=NewName
|
self.InitStaticName=NewName
|
||||||
end
|
end
|
||||||
|
|
||||||
return self:_SpawnStatic(self.TemplateStaticUnit, self.CountryID)
|
return self:_SpawnStatic(self.TemplateStaticUnit, self.CountryID)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Creates a new @{Wrapper.Static} from a POINT_VEC2.
|
--- Creates a new @{Wrapper.Static} from a POINT_VEC2.
|
||||||
@ -347,7 +347,7 @@ function SPAWNSTATIC:SpawnFromPointVec2(PointVec2, Heading, NewName)
|
|||||||
local vec2={x=PointVec2:GetX(), y=PointVec2:GetY()}
|
local vec2={x=PointVec2:GetX(), y=PointVec2:GetY()}
|
||||||
|
|
||||||
local Coordinate=COORDINATE:NewFromVec2(vec2)
|
local Coordinate=COORDINATE:NewFromVec2(vec2)
|
||||||
|
|
||||||
return self:SpawnFromCoordinate(Coordinate, Heading, NewName)
|
return self:SpawnFromCoordinate(Coordinate, Heading, NewName)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -362,11 +362,11 @@ function SPAWNSTATIC:SpawnFromCoordinate(Coordinate, Heading, NewName)
|
|||||||
|
|
||||||
-- Set up coordinate.
|
-- Set up coordinate.
|
||||||
self.InitStaticCoordinate=Coordinate
|
self.InitStaticCoordinate=Coordinate
|
||||||
|
|
||||||
if Heading then
|
if Heading then
|
||||||
self.InitStaticHeading=Heading
|
self.InitStaticHeading=Heading
|
||||||
end
|
end
|
||||||
|
|
||||||
if NewName then
|
if NewName then
|
||||||
self.InitStaticName=NewName
|
self.InitStaticName=NewName
|
||||||
end
|
end
|
||||||
@ -385,7 +385,7 @@ function SPAWNSTATIC:SpawnFromZone(Zone, Heading, NewName)
|
|||||||
|
|
||||||
-- Spawn the new static at the center of the zone.
|
-- Spawn the new static at the center of the zone.
|
||||||
local Static = self:SpawnFromPointVec2( Zone:GetPointVec2(), Heading, NewName )
|
local Static = self:SpawnFromPointVec2( Zone:GetPointVec2(), Heading, NewName )
|
||||||
|
|
||||||
return Static
|
return Static
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -399,45 +399,45 @@ function SPAWNSTATIC:_SpawnStatic(Template, CountryID)
|
|||||||
Template=Template or {}
|
Template=Template or {}
|
||||||
|
|
||||||
local CountryID=CountryID or self.CountryID
|
local CountryID=CountryID or self.CountryID
|
||||||
|
|
||||||
if self.InitStaticType then
|
if self.InitStaticType then
|
||||||
Template.type=self.InitStaticType
|
Template.type=self.InitStaticType
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.InitStaticCategory then
|
if self.InitStaticCategory then
|
||||||
Template.category=self.InitStaticCategory
|
Template.category=self.InitStaticCategory
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.InitStaticCoordinate then
|
if self.InitStaticCoordinate then
|
||||||
Template.x = self.InitStaticCoordinate.x
|
Template.x = self.InitStaticCoordinate.x
|
||||||
Template.y = self.InitStaticCoordinate.z
|
Template.y = self.InitStaticCoordinate.z
|
||||||
Template.alt = self.InitStaticCoordinate.y
|
Template.alt = self.InitStaticCoordinate.y
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.InitStaticHeading then
|
if self.InitStaticHeading then
|
||||||
Template.heading = math.rad(self.InitStaticHeading)
|
Template.heading = math.rad(self.InitStaticHeading)
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.InitStaticShape then
|
if self.InitStaticShape then
|
||||||
Template.shape_name=self.InitStaticShape
|
Template.shape_name=self.InitStaticShape
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.InitStaticLivery then
|
if self.InitStaticLivery then
|
||||||
Template.livery_id=self.InitStaticLivery
|
Template.livery_id=self.InitStaticLivery
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.InitStaticDead~=nil then
|
if self.InitStaticDead~=nil then
|
||||||
Template.dead=self.InitStaticDead
|
Template.dead=self.InitStaticDead
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.InitStaticCargo~=nil then
|
if self.InitStaticCargo~=nil then
|
||||||
Template.canCargo=self.InitStaticCargo
|
Template.canCargo=self.InitStaticCargo
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.InitStaticCargoMass~=nil then
|
if self.InitStaticCargoMass~=nil then
|
||||||
Template.mass=self.InitStaticCargoMass
|
Template.mass=self.InitStaticCargoMass
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.InitLinkUnit then
|
if self.InitLinkUnit then
|
||||||
Template.linkUnit=self.InitLinkUnit:GetID()
|
Template.linkUnit=self.InitLinkUnit:GetID()
|
||||||
Template.linkOffset=true
|
Template.linkOffset=true
|
||||||
@ -446,45 +446,45 @@ function SPAWNSTATIC:_SpawnStatic(Template, CountryID)
|
|||||||
Template.offsets.x=self.InitOffsetX
|
Template.offsets.x=self.InitOffsetX
|
||||||
Template.offsets.angle=self.InitOffsetAngle and math.rad(self.InitOffsetAngle) or 0
|
Template.offsets.angle=self.InitOffsetAngle and math.rad(self.InitOffsetAngle) or 0
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.InitFarp then
|
if self.InitFarp then
|
||||||
Template.heliport_callsign_id = self.InitFarpCallsignID
|
Template.heliport_callsign_id = self.InitFarpCallsignID
|
||||||
Template.heliport_frequency = self.InitFarpFreq
|
Template.heliport_frequency = self.InitFarpFreq
|
||||||
Template.heliport_modulation = self.InitFarpModu
|
Template.heliport_modulation = self.InitFarpModu
|
||||||
Template.unitId=nil
|
Template.unitId=nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Increase spawn index counter.
|
-- Increase spawn index counter.
|
||||||
self.SpawnIndex = self.SpawnIndex + 1
|
self.SpawnIndex = self.SpawnIndex + 1
|
||||||
|
|
||||||
-- Name of the spawned static.
|
-- Name of the spawned static.
|
||||||
Template.name = self.InitStaticName or string.format("%s#%05d", self.SpawnTemplatePrefix, self.SpawnIndex)
|
Template.name = self.InitStaticName or string.format("%s#%05d", self.SpawnTemplatePrefix, self.SpawnIndex)
|
||||||
|
|
||||||
-- Add and register the new static.
|
-- Add and register the new static.
|
||||||
local mystatic=_DATABASE:AddStatic(Template.name)
|
local mystatic=_DATABASE:AddStatic(Template.name)
|
||||||
|
|
||||||
-- Debug output.
|
-- Debug output.
|
||||||
self:T(Template)
|
self:T(Template)
|
||||||
|
|
||||||
-- Add static to the game.
|
-- Add static to the game.
|
||||||
local Static=nil --DCS#StaticObject
|
local Static=nil --DCS#StaticObject
|
||||||
|
|
||||||
if self.InitFarp then
|
if self.InitFarp then
|
||||||
|
|
||||||
local TemplateGroup={}
|
local TemplateGroup={}
|
||||||
TemplateGroup.units={}
|
TemplateGroup.units={}
|
||||||
TemplateGroup.units[1]=Template
|
TemplateGroup.units[1]=Template
|
||||||
|
|
||||||
TemplateGroup.visible=true
|
TemplateGroup.visible=true
|
||||||
TemplateGroup.hidden=false
|
TemplateGroup.hidden=false
|
||||||
TemplateGroup.x=Template.x
|
TemplateGroup.x=Template.x
|
||||||
TemplateGroup.y=Template.y
|
TemplateGroup.y=Template.y
|
||||||
TemplateGroup.name=Template.name
|
TemplateGroup.name=Template.name
|
||||||
|
|
||||||
self:T("Spawning FARP")
|
self:T("Spawning FARP")
|
||||||
self:T({Template=Template})
|
self:T({Template=Template})
|
||||||
self:T({TemplateGroup=TemplateGroup})
|
self:T({TemplateGroup=TemplateGroup})
|
||||||
|
|
||||||
-- ED's dirty way to spawn FARPS.
|
-- ED's dirty way to spawn FARPS.
|
||||||
Static=coalition.addGroup(CountryID, -1, TemplateGroup)
|
Static=coalition.addGroup(CountryID, -1, TemplateGroup)
|
||||||
|
|
||||||
@ -499,10 +499,10 @@ function SPAWNSTATIC:_SpawnStatic(Template, CountryID)
|
|||||||
world.onEvent(Event)
|
world.onEvent(Event)
|
||||||
|
|
||||||
else
|
else
|
||||||
self:T("Spawning Static")
|
self:T("Spawning Static")
|
||||||
self:T2({Template=Template})
|
self:T2({Template=Template})
|
||||||
Static=coalition.addStaticObject(CountryID, Template)
|
Static=coalition.addStaticObject(CountryID, Template)
|
||||||
end
|
end
|
||||||
|
|
||||||
return mystatic
|
return mystatic
|
||||||
end
|
end
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
--
|
--
|
||||||
-- ## Example Missions:
|
-- ## Example Missions:
|
||||||
--
|
--
|
||||||
-- Demo missions can be found on [github](https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/develop/Wrapper/Storage).
|
-- Demo missions can be found on [github](https://github.com/FlightControl-Master/MOOSE_Demos/tree/master/Wrapper/Storage).
|
||||||
--
|
--
|
||||||
-- ===
|
-- ===
|
||||||
--
|
--
|
||||||
@ -33,93 +33,93 @@
|
|||||||
-- ===
|
-- ===
|
||||||
--
|
--
|
||||||
-- # The STORAGE Concept
|
-- # The STORAGE Concept
|
||||||
--
|
--
|
||||||
-- The STORAGE class offers an easy-to-use wrapper interface to all DCS API functions of DCS warehouses.
|
-- 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.
|
-- 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, liquids, weapons and other equipment.
|
-- This class allows you to add and remove items to a DCS warehouse, such as aircraft, liquids, weapons and other equipment.
|
||||||
--
|
--
|
||||||
-- # Constructor
|
-- # Constructor
|
||||||
--
|
--
|
||||||
-- 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.
|
-- 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
|
-- You can get the `STORAGE` object from the
|
||||||
--
|
--
|
||||||
-- -- Create a STORAGE instance of the Batumi warehouse
|
-- -- Create a STORAGE instance of the Batumi warehouse
|
||||||
-- local storage=STORAGE:FindByName("Batumi")
|
-- local storage=STORAGE:FindByName("Batumi")
|
||||||
--
|
--
|
||||||
-- An other way to get the `STORAGE` object is to retrieve it from the AIRBASE function `AIRBASE:GetStorage()`
|
-- An other way to get the `STORAGE` object is to retrieve it from the AIRBASE function `AIRBASE:GetStorage()`
|
||||||
--
|
--
|
||||||
-- -- Get storage instance of Batumi airbase
|
-- -- Get storage instance of Batumi airbase
|
||||||
-- local Batumi=AIRBASE:FindByName("Batumi")
|
-- local Batumi=AIRBASE:FindByName("Batumi")
|
||||||
-- local storage=Batumi:GetStorage()
|
-- local storage=Batumi:GetStorage()
|
||||||
--
|
--
|
||||||
-- # Aircraft, Weapons and Equipment
|
-- # Aircraft, Weapons and Equipment
|
||||||
--
|
--
|
||||||
-- ## Adding Items
|
-- ## Adding Items
|
||||||
--
|
--
|
||||||
-- To add aircraft, weapons and/or othe equipment, you can use the @{#STORAGE.AddItem}() function
|
-- To add aircraft, weapons and/or othe equipment, you can use the @{#STORAGE.AddItem}() function
|
||||||
--
|
--
|
||||||
-- storage:AddItem("A-10C", 3)
|
-- storage:AddItem("A-10C", 3)
|
||||||
-- storage:AddItem("weapons.missiles.AIM_120C", 10)
|
-- storage:AddItem("weapons.missiles.AIM_120C", 10)
|
||||||
--
|
--
|
||||||
-- This will add three A-10Cs and ten AIM-120C missiles to the warehouse inventory.
|
-- This will add three A-10Cs and ten AIM-120C missiles to the warehouse inventory.
|
||||||
--
|
--
|
||||||
-- ## Setting Items
|
-- ## Setting Items
|
||||||
--
|
--
|
||||||
-- You can also explicitly set, how many items are in the inventory with the @{#STORAGE.SetItem}() function.
|
-- You can also explicitly set, how many items are in the inventory with the @{#STORAGE.SetItem}() function.
|
||||||
--
|
--
|
||||||
-- ## Removing Items
|
-- ## Removing Items
|
||||||
--
|
--
|
||||||
-- Items can be removed from the inventory with the @{#STORAGE.RemoveItem}() function.
|
-- Items can be removed from the inventory with the @{#STORAGE.RemoveItem}() function.
|
||||||
--
|
--
|
||||||
-- ## Getting Amount
|
-- ## Getting Amount
|
||||||
--
|
--
|
||||||
-- The number of items currently in the inventory can be obtained with the @{#STORAGE.GetItemAmount}() function
|
-- The number of items currently in the inventory can be obtained with the @{#STORAGE.GetItemAmount}() function
|
||||||
--
|
--
|
||||||
-- local N=storage:GetItemAmount("A-10C")
|
-- local N=storage:GetItemAmount("A-10C")
|
||||||
-- env.info(string.format("We currently have %d A-10Cs available", N))
|
-- env.info(string.format("We currently have %d A-10Cs available", N))
|
||||||
--
|
--
|
||||||
-- # Liquids
|
-- # Liquids
|
||||||
--
|
--
|
||||||
-- Liquids can be added and removed by slightly different functions as described below. Currently there are four types of 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`
|
-- * Jet fuel `STORAGE.Liquid.JETFUEL`
|
||||||
-- * Aircraft gasoline `STORAGE.Liquid.GASOLINE`
|
-- * Aircraft gasoline `STORAGE.Liquid.GASOLINE`
|
||||||
-- * MW 50 `STORAGE.Liquid.MW50`
|
-- * MW 50 `STORAGE.Liquid.MW50`
|
||||||
-- * Diesel `STORAGE.Liquid.DIESEL`
|
-- * Diesel `STORAGE.Liquid.DIESEL`
|
||||||
--
|
--
|
||||||
-- ## Adding Liquids
|
-- ## Adding Liquids
|
||||||
--
|
--
|
||||||
-- To add a certain type of liquid, you can use the @{#STORAGE.AddItem}(Type, Amount) function
|
-- 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.JETFUEL, 10000)
|
||||||
-- storage:AddLiquid(STORAGE.Liquid.DIESEL, 20000)
|
-- storage:AddLiquid(STORAGE.Liquid.DIESEL, 20000)
|
||||||
--
|
--
|
||||||
-- This will add 10,000 kg of jet fuel and 20,000 kg of diesel to the inventory.
|
-- This will add 10,000 kg of jet fuel and 20,000 kg of diesel to the inventory.
|
||||||
--
|
--
|
||||||
-- ## Setting Liquids
|
-- ## Setting Liquids
|
||||||
--
|
--
|
||||||
-- You can also explicitly set the amount of liquid with the @{#STORAGE.SetLiquid}(Type, Amount) function.
|
-- You can also explicitly set the amount of liquid with the @{#STORAGE.SetLiquid}(Type, Amount) function.
|
||||||
--
|
--
|
||||||
-- ## Removing Liquids
|
-- ## Removing Liquids
|
||||||
--
|
--
|
||||||
-- Liquids can be removed with @{#STORAGE.RemoveLiquid}(Type, Amount) function.
|
-- Liquids can be removed with @{#STORAGE.RemoveLiquid}(Type, Amount) function.
|
||||||
--
|
--
|
||||||
-- ## Getting Amount
|
-- ## Getting Amount
|
||||||
--
|
--
|
||||||
-- The current amount of a certain liquid can be obtained with the @{#STORAGE.GetLiquidAmount}(Type) function
|
-- The current amount of a certain liquid can be obtained with the @{#STORAGE.GetLiquidAmount}(Type) function
|
||||||
--
|
--
|
||||||
-- local N=storage:GetLiquidAmount(STORAGE.Liquid.DIESEL)
|
-- local N=storage:GetLiquidAmount(STORAGE.Liquid.DIESEL)
|
||||||
-- env.info(string.format("We currently have %d kg of Diesel available", N))
|
-- env.info(string.format("We currently have %d kg of Diesel available", N))
|
||||||
--
|
--
|
||||||
--
|
--
|
||||||
-- # Inventory
|
-- # 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:
|
-- 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()
|
-- local aircraft, liquids, weapons=storage:GetInventory()
|
||||||
--
|
--
|
||||||
-- UTILS.PrintTableToLog(aircraft)
|
-- UTILS.PrintTableToLog(aircraft)
|
||||||
-- UTILS.PrintTableToLog(liquids)
|
-- UTILS.PrintTableToLog(liquids)
|
||||||
-- UTILS.PrintTableToLog(weapons)
|
-- UTILS.PrintTableToLog(weapons)
|
||||||
@ -168,7 +168,7 @@ function STORAGE:New(AirbaseName)
|
|||||||
local self=BASE:Inherit(self, BASE:New()) -- #STORAGE
|
local self=BASE:Inherit(self, BASE:New()) -- #STORAGE
|
||||||
|
|
||||||
self.airbase=Airbase.getByName(AirbaseName)
|
self.airbase=Airbase.getByName(AirbaseName)
|
||||||
|
|
||||||
if Airbase.getWarehouse then
|
if Airbase.getWarehouse then
|
||||||
self.warehouse=self.airbase:getWarehouse()
|
self.warehouse=self.airbase:getWarehouse()
|
||||||
end
|
end
|
||||||
@ -322,7 +322,7 @@ end
|
|||||||
function STORAGE:GetLiquidName(Type)
|
function STORAGE:GetLiquidName(Type)
|
||||||
|
|
||||||
local name="Unknown"
|
local name="Unknown"
|
||||||
|
|
||||||
if Type==STORAGE.Liquid.JETFUEL then
|
if Type==STORAGE.Liquid.JETFUEL then
|
||||||
name = "Jet fuel"
|
name = "Jet fuel"
|
||||||
elseif Type==STORAGE.Liquid.GASOLINE then
|
elseif Type==STORAGE.Liquid.GASOLINE then
|
||||||
@ -411,25 +411,25 @@ function STORAGE:IsUnlimited(Type)
|
|||||||
|
|
||||||
-- Get current amount of type.
|
-- Get current amount of type.
|
||||||
local N=self:GetAmount(Type)
|
local N=self:GetAmount(Type)
|
||||||
|
|
||||||
local unlimited=false
|
local unlimited=false
|
||||||
|
|
||||||
if N>0 then
|
if N>0 then
|
||||||
|
|
||||||
-- Remove one item.
|
-- Remove one item.
|
||||||
self:RemoveAmount(Type, 1)
|
self:RemoveAmount(Type, 1)
|
||||||
|
|
||||||
-- Get amount.
|
-- Get amount.
|
||||||
local n=self:GetAmount(Type)
|
local n=self:GetAmount(Type)
|
||||||
|
|
||||||
-- If amount did not change, it is unlimited.
|
-- If amount did not change, it is unlimited.
|
||||||
unlimited=n==N
|
unlimited=n==N
|
||||||
|
|
||||||
-- Add item back.
|
-- Add item back.
|
||||||
if not unlimited then
|
if not unlimited then
|
||||||
self:AddAmount(Type, 1)
|
self:AddAmount(Type, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Debug info.
|
-- Debug info.
|
||||||
self:I(self.lid..string.format("Type=%s: unlimited=%s (N=%d n=%d)", tostring(Type), tostring(unlimited), N, n))
|
self:I(self.lid..string.format("Type=%s: unlimited=%s (N=%d n=%d)", tostring(Type), tostring(unlimited), N, n))
|
||||||
end
|
end
|
||||||
@ -523,7 +523,7 @@ end
|
|||||||
function STORAGE:GetInventory(Item)
|
function STORAGE:GetInventory(Item)
|
||||||
|
|
||||||
local inventory=self.warehouse:getInventory(Item)
|
local inventory=self.warehouse:getInventory(Item)
|
||||||
|
|
||||||
return inventory.aircraft, inventory.liquids, inventory.weapon
|
return inventory.aircraft, inventory.liquids, inventory.weapon
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user