mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-08-23 02:08:17 +00:00
SPAWNSTATIC
This commit is contained in:
@@ -433,7 +433,7 @@ do -- Event Handling
|
|||||||
-- reflecting the order of the classes subscribed to the Event to be processed.
|
-- reflecting the order of the classes subscribed to the Event to be processed.
|
||||||
-- @param #BASE self
|
-- @param #BASE self
|
||||||
-- @param #number EventPriority The @{Event} processing Priority.
|
-- @param #number EventPriority The @{Event} processing Priority.
|
||||||
-- @return self
|
-- @return #BASE self
|
||||||
function BASE:SetEventPriority( EventPriority )
|
function BASE:SetEventPriority( EventPriority )
|
||||||
self._.EventPriority = EventPriority
|
self._.EventPriority = EventPriority
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
--
|
--
|
||||||
-- ## Features:
|
-- ## Features:
|
||||||
--
|
--
|
||||||
-- * Spawn new statics from a static already defined using 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 with a custom heading and location.
|
-- * Spawn with a custom heading and location.
|
||||||
-- * Spawn within a zone.
|
-- * Spawn within a zone.
|
||||||
@@ -13,17 +13,14 @@
|
|||||||
--
|
--
|
||||||
-- # Demo Missions
|
-- # Demo Missions
|
||||||
--
|
--
|
||||||
-- ### [SPAWNSTATIC Demo Missions source code](https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/master-release/SPS - Spawning Statics)
|
-- ## [SPAWNSTATIC Demo Missions](https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/master/SPS%20-%20Spawning%20Statics)
|
||||||
--
|
--
|
||||||
-- ### [SPAWNSTATIC Demo Missions, only for beta testers](https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/master/SPS%20-%20Spawning%20Statics)
|
|
||||||
--
|
|
||||||
-- ### [ALL Demo Missions pack of the last release](https://github.com/FlightControl-Master/MOOSE_MISSIONS/releases)
|
|
||||||
--
|
--
|
||||||
-- ===
|
-- ===
|
||||||
--
|
--
|
||||||
-- # YouTube Channel
|
-- # YouTube Channel
|
||||||
--
|
--
|
||||||
-- ### [SPAWNSTATIC YouTube Channel]()
|
-- ## [SPAWNSTATIC YouTube Channel]() [No videos yet!]
|
||||||
--
|
--
|
||||||
-- ===
|
-- ===
|
||||||
--
|
--
|
||||||
@@ -73,40 +70,39 @@
|
|||||||
--
|
--
|
||||||
-- ## **Spawn** methods
|
-- ## **Spawn** methods
|
||||||
--
|
--
|
||||||
-- Groups can be spawned at different times and methods:
|
-- Statics can be spawned at different times and methods:
|
||||||
--
|
--
|
||||||
-- * @{#SPAWNSTATIC.SpawnFromPointVec2}(): Spawn a new group from a POINT_VEC2 coordinate.
|
-- * @{#SPAWNSTATIC.SpawnFromPointVec2}(): Spawn a new group from a POINT_VEC2 coordinate. The group will be spawned at land height.
|
||||||
-- (The group will be spawned at land height ).
|
|
||||||
-- * @{#SPAWNSTATIC.SpawnFromZone}(): Spawn a new group in a @{Zone}.
|
-- * @{#SPAWNSTATIC.SpawnFromZone}(): Spawn a new group in a @{Zone}.
|
||||||
--
|
--
|
||||||
-- @field #SPAWNSTATIC SPAWNSTATIC
|
-- @field #SPAWNSTATIC SPAWNSTATIC
|
||||||
--
|
--
|
||||||
SPAWNSTATIC = {
|
SPAWNSTATIC = {
|
||||||
ClassName = "SPAWNSTATIC",
|
ClassName = "SPAWNSTATIC",
|
||||||
|
SpawnIndex = 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
--- Creates the main object to spawn a @{Static} defined in the mission editor (ME).
|
--- Creates the main object to spawn a @{Static} defined in the mission editor (ME).
|
||||||
-- @param #SPAWNSTATIC self
|
-- @param #SPAWNSTATIC self
|
||||||
-- @param #string SpawnTemplateName Name of the static object in the ME. Each new static will have the name starting with SpawnTemplatePrefix.
|
-- @param #string SpawnTemplateName Name of the static object in the ME. Each new static will have the name starting with this prefix.
|
||||||
-- @param DCS#country.id SpawnCountryID (Optional) The ID of the country.
|
-- @param DCS#country.id SpawnCountryID (Optional) The ID of the country.
|
||||||
-- @param DCS#coalition.side SpawnCoalitionID (Optional) The ID of the coalition.
|
-- @param DCS#coalition.side SpawnCoalitionID (Optional) The ID of the coalition.
|
||||||
-- @return #SPAWNSTATIC self
|
-- @return #SPAWNSTATIC self
|
||||||
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
|
||||||
self:F( { SpawnTemplatePrefix } )
|
|
||||||
|
|
||||||
local TemplateStatic, CoalitionID, CategoryID, CountryID = _DATABASE:GetStaticGroupTemplate( SpawnTemplatePrefix )
|
local TemplateStatic, CoalitionID, CategoryID, CountryID = _DATABASE:GetStaticGroupTemplate(SpawnTemplateName)
|
||||||
|
|
||||||
if TemplateStatic then
|
if TemplateStatic then
|
||||||
self.SpawnTemplatePrefix = SpawnTemplatePrefix
|
self.SpawnTemplatePrefix = SpawnTemplateName
|
||||||
self.TemplateStaticUnit = UTILS.DeepCopy(TemplateStatic.units[1])
|
self.TemplateStaticUnit = UTILS.DeepCopy(TemplateStatic.units[1])
|
||||||
self.CountryID = SpawnCountryID or CountryID
|
self.CountryID = SpawnCountryID or CountryID
|
||||||
self.CategoryID = CategoryID
|
self.CategoryID = CategoryID
|
||||||
self.CoalitionID = SpawnCoalitionID or CoalitionID
|
self.CoalitionID = CoalitionID
|
||||||
self.SpawnIndex = 0
|
self.SpawnIndex = 0
|
||||||
else
|
else
|
||||||
error( "SPAWNSTATIC:New: There is no static declared in the mission editor with SpawnTemplatePrefix = '" .. SpawnTemplatePrefix .. "'" )
|
error( "SPAWNSTATIC:New: There is no static declared in the mission editor with SpawnTemplatePrefix = '" .. tostring(SpawnTemplateName) .. "'" )
|
||||||
end
|
end
|
||||||
|
|
||||||
self:SetEventPriority( 5 )
|
self:SetEventPriority( 5 )
|
||||||
@@ -114,11 +110,22 @@ function SPAWNSTATIC:NewFromStatic(SpawnTemplateName, SpawnCountryID)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Initialize heading of the spawned static.
|
||||||
|
-- @param #SPAWNSTATIC self
|
||||||
|
-- @param #number Heading The heading in degrees.
|
||||||
|
-- @return #SPAWNSTATIC self
|
||||||
|
function SPAWNSTATIC:InitHeading(Heading)
|
||||||
|
self.InitHeading=Heading
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
--- Init link to a unit.
|
--- Init link to a unit.
|
||||||
-- @param #SPAWNSTATIC self
|
-- @param #SPAWNSTATIC self
|
||||||
-- @param #number Heading (Optional) The heading of the static, which is a number in degrees from 0 to 360. Default is the heading of the template.
|
-- @param Wrapper.Unit#UNIT Unit The unit to which the static is linked.
|
||||||
-- @param #string NewName (Optional) The name of the new static.
|
-- @param #number OffsetX Offset in X.
|
||||||
-- @return #SPAWNSTATIC
|
-- @param #number OffsetY Offset in Y.
|
||||||
|
-- @param #number OffsetAngle Offset angle in degrees.
|
||||||
|
-- @return #SPAWNSTATIC self
|
||||||
function SPAWNSTATIC:InitLinkToUnit(Unit, OffsetX, OffsetY, OffsetAngle)
|
function SPAWNSTATIC:InitLinkToUnit(Unit, OffsetX, OffsetY, OffsetAngle)
|
||||||
|
|
||||||
self.InitLinkUnit=Unit
|
self.InitLinkUnit=Unit
|
||||||
@@ -126,16 +133,20 @@ function SPAWNSTATIC:InitLinkToUnit(Unit, OffsetX, OffsetY, OffsetAngle)
|
|||||||
self.InitOffsetY=OffsetX or 0
|
self.InitOffsetY=OffsetX or 0
|
||||||
self.InitOffsetAngle=OffsetAngle or 0
|
self.InitOffsetAngle=OffsetAngle or 0
|
||||||
|
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Spawn a new STATIC object.
|
--- Spawn a new STATIC object.
|
||||||
-- @param #SPAWNSTATIC self
|
-- @param #SPAWNSTATIC self
|
||||||
-- @param #number Heading (Optional) The heading of the static, which is a number in degrees from 0 to 360. Default is the heading of the template.
|
-- @param #number Heading (Optional) The heading of the static, which is a number in degrees from 0 to 360. Default is the heading of the template.
|
||||||
-- @param #string NewName (Optional) The name of the new static.
|
-- @param #string NewName (Optional) The name of the new static.
|
||||||
-- @return #SPAWNSTATIC
|
-- @return Wrapper.Static#STATIC The static spawned.
|
||||||
function SPAWNSTATIC:Spawn( Heading, NewName ) --R2.3
|
function SPAWNSTATIC:Spawn( Heading, NewName ) --R2.3
|
||||||
self:F( { Heading, NewName } )
|
|
||||||
|
|
||||||
|
|
||||||
|
return self:_SpawnStatic(self.TemplateStaticUnit, self.CountryID)
|
||||||
|
|
||||||
|
--[[
|
||||||
local StaticTemplate, CoalitionID, CategoryID, CountryID = _DATABASE:GetStaticGroupTemplate( self.SpawnTemplatePrefix )
|
local StaticTemplate, CoalitionID, CategoryID, CountryID = _DATABASE:GetStaticGroupTemplate( self.SpawnTemplatePrefix )
|
||||||
|
|
||||||
if StaticTemplate then
|
if StaticTemplate then
|
||||||
@@ -156,27 +167,16 @@ function SPAWNSTATIC:Spawn( Heading, NewName ) --R2.3
|
|||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
]]
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Spawns a new static using a given template. Additionally, the country ID needs to be specified, which also determines the coalition of the spawned static.
|
|
||||||
-- @param #SPAWNSTATIC self
|
|
||||||
-- @param #table Template Spawn unit template.
|
|
||||||
-- @param #number CountryID The
|
|
||||||
-- @return #SPAWNSTATIC
|
|
||||||
function SPAWNSTATIC:_SpawnFromTemplate(Template, CountryID)
|
|
||||||
|
|
||||||
local StaticTemplate, CoalitionID, CategoryID, CountryID = _DATABASE:GetStaticGroupTemplate( self.SpawnTemplatePrefix )
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
--- Creates a new @{Static} from a POINT_VEC2.
|
--- Creates a new @{Static} from a POINT_VEC2.
|
||||||
-- @param #SPAWNSTATIC self
|
-- @param #SPAWNSTATIC self
|
||||||
-- @param Core.Point#POINT_VEC2 PointVec2 The 2D coordinate where to spawn the static.
|
-- @param Core.Point#POINT_VEC2 PointVec2 The 2D coordinate where to spawn the static.
|
||||||
-- @param #number Heading The heading of the static, which is a number in degrees from 0 to 360.
|
-- @param #number Heading The heading of the static, which is a number in degrees from 0 to 360.
|
||||||
-- @param #string (optional) The name of the new static.
|
-- @param #string (optional) The name of the new static.
|
||||||
-- @return #SPAWNSTATIC
|
-- @return #SPAWNSTATIC
|
||||||
function SPAWNSTATIC:SpawnFromPointVec2( PointVec2, Heading, NewName ) --R2.1
|
function SPAWNSTATIC:SpawnFromPointVec2(PointVec2, Heading, NewName)
|
||||||
self:F( { PointVec2, Heading, NewName } )
|
self:F( { PointVec2, Heading, NewName } )
|
||||||
|
|
||||||
local StaticTemplate, CoalitionID, CategoryID, CountryID = _DATABASE:GetStaticGroupTemplate( self.SpawnTemplatePrefix )
|
local StaticTemplate, CoalitionID, CategoryID, CountryID = _DATABASE:GetStaticGroupTemplate( self.SpawnTemplatePrefix )
|
||||||
@@ -216,8 +216,22 @@ end
|
|||||||
-- @param #number Heading (Optional) Heading The heading of the static, which is a number in degrees from 0 to 360. Default is 0 degrees.
|
-- @param #number Heading (Optional) Heading The heading of the static, which is a number in degrees from 0 to 360. Default is 0 degrees.
|
||||||
-- @param #string NewName (Optional) The name of the new static.
|
-- @param #string NewName (Optional) The name of the new static.
|
||||||
-- @return Wrapper.Static#STATIC The spawned STATIC object.
|
-- @return Wrapper.Static#STATIC The spawned STATIC object.
|
||||||
function SPAWNSTATIC:SpawnFromCoordinate(Coordinate, Heading, NewName) --R2.4
|
function SPAWNSTATIC:SpawnFromCoordinate(Coordinate, Heading, NewName)
|
||||||
self:F( { PointVec2, Heading, NewName } )
|
|
||||||
|
-- Set up coordinate.
|
||||||
|
self.InitCoordinate=Coordinate
|
||||||
|
|
||||||
|
if Heading then
|
||||||
|
self.InitHeading=Heading
|
||||||
|
end
|
||||||
|
|
||||||
|
if NewName then
|
||||||
|
self.InitName=NewName
|
||||||
|
end
|
||||||
|
|
||||||
|
return self:_SpawnStatic(self.TemplateStaticUnit, self.CountryID)
|
||||||
|
|
||||||
|
--[[
|
||||||
|
|
||||||
local StaticTemplate, CoalitionID, CategoryID, CountryID = _DATABASE:GetStaticGroupTemplate( self.SpawnTemplatePrefix )
|
local StaticTemplate, CoalitionID, CategoryID, CountryID = _DATABASE:GetStaticGroupTemplate( self.SpawnTemplatePrefix )
|
||||||
|
|
||||||
@@ -250,6 +264,8 @@ function SPAWNSTATIC:SpawnFromCoordinate(Coordinate, Heading, NewName) --R2.4
|
|||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
|
]]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -259,14 +275,54 @@ end
|
|||||||
-- @param #number Heading The heading of the static, which is a number in degrees from 0 to 360.
|
-- @param #number Heading The heading of the static, which is a number in degrees from 0 to 360.
|
||||||
-- @param #string NewName (optional) The name of the new static.
|
-- @param #string NewName (optional) The name of the new static.
|
||||||
-- @return #SPAWNSTATIC
|
-- @return #SPAWNSTATIC
|
||||||
function SPAWNSTATIC:SpawnFromZone( Zone, Heading, NewName ) --R2.1
|
function SPAWNSTATIC:SpawnFromZone(Zone, Heading, NewName)
|
||||||
self:F( { Zone, Heading, NewName } )
|
|
||||||
|
|
||||||
|
-- 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
|
||||||
|
|
||||||
|
--- Spawns a new static using a given template. Additionally, the country ID needs to be specified, which also determines the coalition of the spawned static.
|
||||||
|
-- @param #SPAWNSTATIC self
|
||||||
|
-- @param #table Template Spawn unit template.
|
||||||
|
-- @param #number CountryID The country ID.
|
||||||
|
-- @return Wrapper.Static#STATIC The static spawned.
|
||||||
|
function SPAWNSTATIC:_SpawnStatic(Template, CountryID)
|
||||||
|
|
||||||
|
local CountryID=CountryID or self.CountryID
|
||||||
|
|
||||||
|
if self.InitCoordinate then
|
||||||
|
Template.x = self.InitCoordinate.x
|
||||||
|
Template.y = self.InitCoordinate.z
|
||||||
|
Template.alt = self.InitCoordinate.y
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.InitHeading then
|
||||||
|
--Template.heading = math.rad(self.InitHeading)
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.InitLinkUnit then
|
||||||
|
Template.linkUnit=self.InitLinkUnit:GetID()
|
||||||
|
Template.linkOffset=true
|
||||||
|
Template.offsets={}
|
||||||
|
Template.offsets.y=self.InitOffsetY
|
||||||
|
Template.offsets.x=self.InitOffsetX
|
||||||
|
Template.offsets.angle=self.InitOffsetAngle and math.rad(self.InitOffsetAngle) or 0
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Register the new static.
|
||||||
|
--_DATABASE:_RegisterStaticTemplate(Template, self.CoalitionID, self.CategoryID, CountryID)
|
||||||
|
|
||||||
|
-- Add static to the game.
|
||||||
|
local Static=coalition.addStaticObject(CountryID, Template)
|
||||||
|
|
||||||
|
-- Increase spawn index counter.
|
||||||
|
self.SpawnIndex = self.SpawnIndex + 1
|
||||||
|
|
||||||
|
return _DATABASE:FindStatic(Static:getName())
|
||||||
|
end
|
||||||
|
|
||||||
--- Respawns the original @{Static}.
|
--- Respawns the original @{Static}.
|
||||||
-- @param #SPAWNSTATIC self
|
-- @param #SPAWNSTATIC self
|
||||||
-- @param #number delay Delay before respawn in seconds.
|
-- @param #number delay Delay before respawn in seconds.
|
||||||
|
|||||||
Reference in New Issue
Block a user