diff --git a/Moose Development/Moose/Core/Database.lua b/Moose Development/Moose/Core/Database.lua index 3e9eea077..bdf743d0d 100644 --- a/Moose Development/Moose/Core/Database.lua +++ b/Moose Development/Moose/Core/Database.lua @@ -44,6 +44,7 @@ DATABASE = { Templates = { Units = {}, Groups = {}, + Statics = {}, ClientsByName = {}, ClientsByID = {}, }, @@ -282,7 +283,7 @@ function DATABASE:Spawn( SpawnTemplate ) SpawnTemplate.CountryID = nil SpawnTemplate.CategoryID = nil - self:_RegisterTemplate( SpawnTemplate, SpawnCoalitionID, SpawnCategoryID, SpawnCountryID ) + self:_RegisterGroupTemplate( SpawnTemplate, SpawnCoalitionID, SpawnCategoryID, SpawnCountryID ) self:T3( SpawnTemplate ) coalition.addGroup( SpawnCountryID, SpawnCategoryID, SpawnTemplate ) @@ -318,7 +319,7 @@ end -- @param #DATABASE self -- @param #table GroupTemplate -- @return #DATABASE self -function DATABASE:_RegisterTemplate( GroupTemplate, CoalitionID, CategoryID, CountryID ) +function DATABASE:_RegisterGroupTemplate( GroupTemplate, CoalitionID, CategoryID, CountryID ) local GroupTemplateName = env.getValueDictByKey(GroupTemplate.name) @@ -396,6 +397,54 @@ function DATABASE:GetGroupTemplate( GroupName ) return GroupTemplate end +--- Private method that registers new Static Templates within the DATABASE Object. +-- @param #DATABASE self +-- @param #table GroupTemplate +-- @return #DATABASE self +function DATABASE:_RegisterStaticTemplate( StaticTemplate, CoalitionID, CategoryID, CountryID ) + + local TraceTable = {} + + local StaticTemplateName = env.getValueDictByKey(StaticTemplate.name) + + self.Templates.Statics[StaticTemplateName] = self.Templates.Statics[StaticTemplateName] or {} + + StaticTemplate.CategoryID = CategoryID + StaticTemplate.CoalitionID = CoalitionID + StaticTemplate.CountryID = CountryID + + self.Templates.Statics[StaticTemplateName].StaticName = StaticTemplateName + self.Templates.Statics[StaticTemplateName].GroupTemplate = StaticTemplate + self.Templates.Statics[StaticTemplateName].UnitTemplate = StaticTemplate.units[1] + self.Templates.Statics[StaticTemplateName].CategoryID = CategoryID + self.Templates.Statics[StaticTemplateName].CoalitionID = CoalitionID + self.Templates.Statics[StaticTemplateName].CountryID = CountryID + + + TraceTable[#TraceTable+1] = "Static" + TraceTable[#TraceTable+1] = self.Templates.Statics[StaticTemplateName].GroupName + + TraceTable[#TraceTable+1] = "Coalition" + TraceTable[#TraceTable+1] = self.Templates.Statics[StaticTemplateName].CoalitionID + TraceTable[#TraceTable+1] = "Category" + TraceTable[#TraceTable+1] = self.Templates.Statics[StaticTemplateName].CategoryID + TraceTable[#TraceTable+1] = "Country" + TraceTable[#TraceTable+1] = self.Templates.Statics[StaticTemplateName].CountryID + + self:E( TraceTable ) +end + + +--- @param #DATABASE self +function DATABASE:GetStaticUnitTemplate( StaticName ) + local StaticTemplate = self.Templates.Statics[StaticName].UnitTemplate + StaticTemplate.SpawnCoalitionID = self.Templates.Statics[StaticName].CoalitionID + StaticTemplate.SpawnCategoryID = self.Templates.Statics[StaticName].CategoryID + StaticTemplate.SpawnCountryID = self.Templates.Statics[StaticName].CountryID + return StaticTemplate +end + + function DATABASE:GetGroupNameFromUnitName( UnitName ) return self.Templates.Units[UnitName].GroupName end @@ -725,7 +774,7 @@ function DATABASE:ForEachClient( IteratorFunction, ... ) return self end - +--- @param #DATABASE self function DATABASE:_RegisterTemplates() self:F2() @@ -781,11 +830,18 @@ function DATABASE:_RegisterTemplates() --self.Units[coa_name][countryName][category] = {} - for group_num, GroupTemplate in pairs(obj_type_data.group) do + for group_num, Template in pairs(obj_type_data.group) do - if GroupTemplate and GroupTemplate.units and type(GroupTemplate.units) == 'table' then --making sure again- this is a valid group - self:_RegisterTemplate( - GroupTemplate, + if obj_type_name ~= "static" and Template and Template.units and type(Template.units) == 'table' then --making sure again- this is a valid group + self:_RegisterGroupTemplate( + Template, + CoalitionSide, + _DATABASECategory[string.lower(CategoryName)], + CountryID + ) + else + self:_RegisterStaticTemplate( + Template, CoalitionSide, _DATABASECategory[string.lower(CategoryName)], CountryID diff --git a/Moose Development/Moose/Core/SpawnStatic.lua b/Moose Development/Moose/Core/SpawnStatic.lua index a891cf2b3..9e744d971 100644 --- a/Moose Development/Moose/Core/SpawnStatic.lua +++ b/Moose Development/Moose/Core/SpawnStatic.lua @@ -43,8 +43,7 @@ ---- SPAWNSTATIC Class --- @type SPAWNSTATIC +--- @type SPAWNSTATIC -- @extends Core.Base#BASE @@ -72,13 +71,6 @@ -- * @{#SPAWNSTATIC.NewFromStatic}(): Creates a new SPAWNSTATIC object given a name that is used as the base of the naming of each spawned Static. -- * @{#SPAWNSTATIC.NewFromType}(): Creates a new SPAWNSTATIC object given a type name and a name to be given when spawned. -- --- ## SPAWNSTATIC **Init**ialization methods --- --- A spawn object will behave differently based on the usage of **initialization** methods, which all start with the **Init** prefix: --- --- * @{#SPAWNSTATIC.InitRandomizePosition}(): Randomizes the position of @{Static}s that are spawned within a **radius band**, given an Outer and Inner radius, from the point that the spawn happens. --- * @{#SPAWNSTATIC.InitRandomizeZones}(): Randomizes the spawning between a predefined list of @{Zone}s that are declared using this function. Each zone can be given a probability factor. --- -- ## SPAWNSTATIC **Spawn** methods -- -- Groups can be spawned at different times and methods: @@ -142,31 +134,45 @@ end --- Creates a new @{Static} from a POINT_VEC2. -- @param #SPAWNSTATIC self --- @param #string SpawnTypeName is the name of the type. +-- @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 #string (optional) The name of the new static. -- @return #SPAWNSTATIC -function SPAWNSTATIC:SpawnFromPointVec2( PointVec2, BaseName ) - self:F( { PointVec2, BaseName } ) +function SPAWNSTATIC:SpawnFromPointVec2( PointVec2, Heading, NewName ) + self:F( { PointVec2, Heading, NewName } ) local CountryName = _DATABASE.COUNTRY_NAME[self.CountryID] - local StaticTemplate + local StaticTemplate = _DATABASE:GetStaticUnitTemplate( self.SpawnTemplatePrefix ) - local Tire = { - ["country"] = CountryName, - ["category"] = "Fortifications", - ["canCargo"] = false, - ["shape_name"] = "H-tyre_B_WF", - ["type"] = "Black_Tyre_WF", - --["unitId"] = Angle + 10000, - ["y"] = Point.y, - ["x"] = Point.x, - ["name"] = string.format( "%s-Tire #%0d", self:GetName(), Angle ), - ["heading"] = 0, - } -- end of ["group"] + StaticTemplate.x = PointVec2:GetLat() + StaticTemplate.y = PointVec2:GetLon() + + StaticTemplate.name = NewName or string.format("%s#%05d", self.SpawnTemplatePrefix, self.SpawnIndex ) + StaticTemplate.heading = ( Heading / 180 ) * math.pi + + StaticTemplate.CountryID = nil + StaticTemplate.CoalitionID = nil + StaticTemplate.CategoryID = nil + + local Static = coalition.addStaticObject( self.CountryID, StaticTemplate ) + + self.SpawnIndex = self.SpawnIndex + 1 - local Group = coalition.addStaticObject( CountryID, Tire ) - - return self + return Static end +--- Creates a new @{Static} from a @{Zone}. +-- @param #SPAWNSTATIC self +-- @param Core.Zone#ZONE_BASE Zone The Zone where to spawn the static. +-- @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. +-- @return #SPAWNSTATIC +function SPAWNSTATIC:SpawnFromZone( Zone, Heading, NewName ) + self:F( { Zone, Heading, NewName } ) + + local Static = self:SpawnFromPointVec2( Zone:GetPointVec2(), Heading, NewName ) + + return Static +end diff --git a/Moose Development/Moose/Core/Zone.lua b/Moose Development/Moose/Core/Zone.lua index 432a360a7..8456729a8 100644 --- a/Moose Development/Moose/Core/Zone.lua +++ b/Moose Development/Moose/Core/Zone.lua @@ -615,7 +615,7 @@ end --- @type ZONE +--- @type ZONE -- @extends Core.Zone#ZONE_RADIUS diff --git a/Moose Mission Setup/Moose.files b/Moose Mission Setup/Moose.files index fac9aa46b..b8084a749 100644 --- a/Moose Mission Setup/Moose.files +++ b/Moose Mission Setup/Moose.files @@ -13,6 +13,7 @@ Core/Point.lua Core/Message.lua Core/Fsm.lua Core/Radio.lua +Core/SpawnStatic.lua Wrapper/Object.lua Wrapper/Identifiable.lua diff --git a/Moose Mission Setup/Moose.lua b/Moose Mission Setup/Moose.lua index 7fc7af669..b81506f59 100644 --- a/Moose Mission Setup/Moose.lua +++ b/Moose Mission Setup/Moose.lua @@ -1,5 +1,5 @@ env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' ) -env.info( 'Moose Generation Timestamp: 20170405_0934' ) +env.info( 'Moose Generation Timestamp: 20170409_0720' ) local base = _G @@ -35,6 +35,7 @@ __Moose.Include( 'Core/Point.lua' ) __Moose.Include( 'Core/Message.lua' ) __Moose.Include( 'Core/Fsm.lua' ) __Moose.Include( 'Core/Radio.lua' ) +__Moose.Include( 'Core/SpawnStatic.lua' ) __Moose.Include( 'Wrapper/Object.lua' ) __Moose.Include( 'Wrapper/Identifiable.lua' ) __Moose.Include( 'Wrapper/Positionable.lua' )