diff --git a/Moose Development/Moose/Functional/Spawn.lua b/Moose Development/Moose/Functional/Spawn.lua index a4c4182d5..64d8855b1 100644 --- a/Moose Development/Moose/Functional/Spawn.lua +++ b/Moose Development/Moose/Functional/Spawn.lua @@ -51,6 +51,7 @@ -- * @{#SPAWN.InitUnControlled}(): Spawn plane groups uncontrolled. -- * @{#SPAWN.InitArray}(): Make groups visible before they are actually activated, and order these groups like a batallion in an array. -- * @{#SPAWN.InitRepeat}(): Re-spawn groups when they land at the home base. Similar methods are @{#SPAWN.InitRepeatOnLanding} and @{#SPAWN.InitRepeatOnEngineShutDown}. +-- * @{#SPAWN.InitRandomizePosition}(): Randomizes the position of @{Group}s that are spawned within a **radius band**, given an Outer and Inner radius, from the point that the spawn happens. -- * @{#SPAWN.InitRandomizeUnits}(): Randomizes the @{Unit}s in the @{Group} that is spawned within a **radius band**, given an Outer and Inner radius. -- * @{#SPAWN.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. -- * @{#SPAWN.InitAIOn}(): Turns the AI On when spawning the new @{Group} object. @@ -118,7 +119,8 @@ -- -- Hereby the change log: -- --- 2017-03-14: SPAWN:**InitKeepUnitNames()** added. +-- 2017-03-14: SPAWN:**InitKeepUnitNames()** added. +-- 2017-03-14: SPAWN:**InitRandomizePosition( RandomizePosition, OuterRadious, InnerRadius )** added. -- -- 2017-02-04: SPAWN:InitUnControlled( **UnControlled** ) replaces SPAWN:InitUnControlled(). -- @@ -351,6 +353,27 @@ function SPAWN:InitRandomizeRoute( SpawnStartPoint, SpawnEndPoint, SpawnRadius, return self end +--- Randomizes the position of @{Group}s that are spawned within a **radius band**, given an Outer and Inner radius, from the point that the spawn happens. +-- @param #SPAWN self +-- @param #boolean RandomizePosition If true, SPAWN will perform the randomization of the @{Group}s position between a given outer and inner radius. +-- @param Dcs.DCSTypes#Distance OuterRadius (optional) The outer radius in meters where the new group will be spawned. +-- @param Dcs.DCSTypes#Distance InnerRadius (optional) The inner radius in meters where the new group will NOT be spawned. +-- @return #SPAWN +function SPAWN:InitRandomizePosition( RandomizePosition, OuterRadius, InnerRadius ) + self:F( { self.SpawnTemplatePrefix, RandomizePosition, OuterRadius, InnerRadius } ) + + self.SpawnRandomizePosition = RandomizePosition or false + self.SpawnRandomizePositionOuterRadius = OuterRadius or 0 + self.SpawnRandomizePositionInnerRadius = InnerRadius or 0 + + for GroupID = 1, self.SpawnMaxGroups do + self:_RandomizeRoute( GroupID ) + end + + return self +end + + --- Randomizes the UNITs that are spawned within a radius band given an Outer and Inner radius. -- @param #SPAWN self -- @param #boolean RandomizeUnits If true, SPAWN will perform the randomization of the @{UNIT}s position within the group between a given outer and inner radius. @@ -667,6 +690,20 @@ function SPAWN:SpawnWithIndex( SpawnIndex ) local PointVec3 = POINT_VEC3:New( SpawnTemplate.route.points[1].x, SpawnTemplate.route.points[1].alt, SpawnTemplate.route.points[1].y ) self:T( { "Current point of ", self.SpawnTemplatePrefix, PointVec3 } ) + + -- If RandomizePosition, then Randomize the formation in the zone band, keeping the template. + if self.SpawnRandomizePosition then + local RandomVec2 = PointVec3:GetRandomVec2InRadius( self.SpawnRandomizePositionOuterRadius, self.SpawnRandomizePositionInnerRadius ) + local CurrentX = SpawnTemplate.units[1].x + local CurrentY = SpawnTemplate.units[1].y + SpawnTemplate.x = RandomVec2.x + SpawnTemplate.y = RandomVec2.y + for UnitID = 1, #SpawnTemplate.units do + SpawnTemplate.units[UnitID].x = SpawnTemplate.units[UnitID].x + ( RandomVec2.x - CurrentX ) + SpawnTemplate.units[UnitID].y = SpawnTemplate.units[UnitID].y + ( RandomVec2.y - CurrentY ) + self:T( 'SpawnTemplate.units['..UnitID..'].x = ' .. SpawnTemplate.units[UnitID].x .. ', SpawnTemplate.units['..UnitID..'].y = ' .. SpawnTemplate.units[UnitID].y ) + end + end -- If RandomizeUnits, then Randomize the formation at the start point. if self.SpawnRandomizeUnits then diff --git a/Moose Mission Setup/Moose Mission Update/l10n/DEFAULT/Moose.lua b/Moose Mission Setup/Moose Mission Update/l10n/DEFAULT/Moose.lua index dbbe274bb..2917fc379 100644 --- a/Moose Mission Setup/Moose Mission Update/l10n/DEFAULT/Moose.lua +++ b/Moose Mission Setup/Moose Mission Update/l10n/DEFAULT/Moose.lua @@ -1,5 +1,5 @@ env.info( '*** MOOSE STATIC INCLUDE START *** ' ) -env.info( 'Moose Generation Timestamp: 20170314_0643' ) +env.info( 'Moose Generation Timestamp: 20170314_0908' ) local base = _G Include = {} @@ -20351,6 +20351,7 @@ end -- * @{#SPAWN.InitUnControlled}(): Spawn plane groups uncontrolled. -- * @{#SPAWN.InitArray}(): Make groups visible before they are actually activated, and order these groups like a batallion in an array. -- * @{#SPAWN.InitRepeat}(): Re-spawn groups when they land at the home base. Similar methods are @{#SPAWN.InitRepeatOnLanding} and @{#SPAWN.InitRepeatOnEngineShutDown}. +-- * @{#SPAWN.InitRandomizePosition}(): Randomizes the position of @{Group}s that are spawned within a **radius band**, given an Outer and Inner radius, from the point that the spawn happens. -- * @{#SPAWN.InitRandomizeUnits}(): Randomizes the @{Unit}s in the @{Group} that is spawned within a **radius band**, given an Outer and Inner radius. -- * @{#SPAWN.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. -- * @{#SPAWN.InitAIOn}(): Turns the AI On when spawning the new @{Group} object. @@ -20418,7 +20419,8 @@ end -- -- Hereby the change log: -- --- 2017-03-14: SPAWN:**InitKeepUnitNames()** added. +-- 2017-03-14: SPAWN:**InitKeepUnitNames()** added. +-- 2017-03-14: SPAWN:**InitRandomizePosition( RandomizePosition, OuterRadious, InnerRadius )** added. -- -- 2017-02-04: SPAWN:InitUnControlled( **UnControlled** ) replaces SPAWN:InitUnControlled(). -- @@ -20651,6 +20653,27 @@ function SPAWN:InitRandomizeRoute( SpawnStartPoint, SpawnEndPoint, SpawnRadius, return self end +--- Randomizes the position of @{Group}s that are spawned within a **radius band**, given an Outer and Inner radius, from the point that the spawn happens. +-- @param #SPAWN self +-- @param #boolean RandomizePosition If true, SPAWN will perform the randomization of the @{Group}s position between a given outer and inner radius. +-- @param Dcs.DCSTypes#Distance OuterRadius (optional) The outer radius in meters where the new group will be spawned. +-- @param Dcs.DCSTypes#Distance InnerRadius (optional) The inner radius in meters where the new group will NOT be spawned. +-- @return #SPAWN +function SPAWN:InitRandomizePosition( RandomizePosition, OuterRadius, InnerRadius ) + self:F( { self.SpawnTemplatePrefix, RandomizePosition, OuterRadius, InnerRadius } ) + + self.SpawnRandomizePosition = RandomizePosition or false + self.SpawnRandomizePositionOuterRadius = OuterRadius or 0 + self.SpawnRandomizePositionInnerRadius = InnerRadius or 0 + + for GroupID = 1, self.SpawnMaxGroups do + self:_RandomizeRoute( GroupID ) + end + + return self +end + + --- Randomizes the UNITs that are spawned within a radius band given an Outer and Inner radius. -- @param #SPAWN self -- @param #boolean RandomizeUnits If true, SPAWN will perform the randomization of the @{UNIT}s position within the group between a given outer and inner radius. @@ -20967,6 +20990,20 @@ function SPAWN:SpawnWithIndex( SpawnIndex ) local PointVec3 = POINT_VEC3:New( SpawnTemplate.route.points[1].x, SpawnTemplate.route.points[1].alt, SpawnTemplate.route.points[1].y ) self:T( { "Current point of ", self.SpawnTemplatePrefix, PointVec3 } ) + + -- If RandomizePosition, then Randomize the formation in the zone band, keeping the template. + if self.SpawnRandomizePosition then + local RandomVec2 = PointVec3:GetRandomVec2InRadius( self.SpawnRandomizePositionOuterRadius, self.SpawnRandomizePositionInnerRadius ) + local CurrentX = SpawnTemplate.units[1].x + local CurrentY = SpawnTemplate.units[1].y + SpawnTemplate.x = RandomVec2.x + SpawnTemplate.y = RandomVec2.y + for UnitID = 1, #SpawnTemplate.units do + SpawnTemplate.units[UnitID].x = SpawnTemplate.units[UnitID].x + ( RandomVec2.x - CurrentX ) + SpawnTemplate.units[UnitID].y = SpawnTemplate.units[UnitID].y + ( RandomVec2.y - CurrentY ) + self:T( 'SpawnTemplate.units['..UnitID..'].x = ' .. SpawnTemplate.units[UnitID].x .. ', SpawnTemplate.units['..UnitID..'].y = ' .. SpawnTemplate.units[UnitID].y ) + end + end -- If RandomizeUnits, then Randomize the formation at the start point. if self.SpawnRandomizeUnits then diff --git a/Moose Mission Setup/Moose.lua b/Moose Mission Setup/Moose.lua index dbbe274bb..2917fc379 100644 --- a/Moose Mission Setup/Moose.lua +++ b/Moose Mission Setup/Moose.lua @@ -1,5 +1,5 @@ env.info( '*** MOOSE STATIC INCLUDE START *** ' ) -env.info( 'Moose Generation Timestamp: 20170314_0643' ) +env.info( 'Moose Generation Timestamp: 20170314_0908' ) local base = _G Include = {} @@ -20351,6 +20351,7 @@ end -- * @{#SPAWN.InitUnControlled}(): Spawn plane groups uncontrolled. -- * @{#SPAWN.InitArray}(): Make groups visible before they are actually activated, and order these groups like a batallion in an array. -- * @{#SPAWN.InitRepeat}(): Re-spawn groups when they land at the home base. Similar methods are @{#SPAWN.InitRepeatOnLanding} and @{#SPAWN.InitRepeatOnEngineShutDown}. +-- * @{#SPAWN.InitRandomizePosition}(): Randomizes the position of @{Group}s that are spawned within a **radius band**, given an Outer and Inner radius, from the point that the spawn happens. -- * @{#SPAWN.InitRandomizeUnits}(): Randomizes the @{Unit}s in the @{Group} that is spawned within a **radius band**, given an Outer and Inner radius. -- * @{#SPAWN.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. -- * @{#SPAWN.InitAIOn}(): Turns the AI On when spawning the new @{Group} object. @@ -20418,7 +20419,8 @@ end -- -- Hereby the change log: -- --- 2017-03-14: SPAWN:**InitKeepUnitNames()** added. +-- 2017-03-14: SPAWN:**InitKeepUnitNames()** added. +-- 2017-03-14: SPAWN:**InitRandomizePosition( RandomizePosition, OuterRadious, InnerRadius )** added. -- -- 2017-02-04: SPAWN:InitUnControlled( **UnControlled** ) replaces SPAWN:InitUnControlled(). -- @@ -20651,6 +20653,27 @@ function SPAWN:InitRandomizeRoute( SpawnStartPoint, SpawnEndPoint, SpawnRadius, return self end +--- Randomizes the position of @{Group}s that are spawned within a **radius band**, given an Outer and Inner radius, from the point that the spawn happens. +-- @param #SPAWN self +-- @param #boolean RandomizePosition If true, SPAWN will perform the randomization of the @{Group}s position between a given outer and inner radius. +-- @param Dcs.DCSTypes#Distance OuterRadius (optional) The outer radius in meters where the new group will be spawned. +-- @param Dcs.DCSTypes#Distance InnerRadius (optional) The inner radius in meters where the new group will NOT be spawned. +-- @return #SPAWN +function SPAWN:InitRandomizePosition( RandomizePosition, OuterRadius, InnerRadius ) + self:F( { self.SpawnTemplatePrefix, RandomizePosition, OuterRadius, InnerRadius } ) + + self.SpawnRandomizePosition = RandomizePosition or false + self.SpawnRandomizePositionOuterRadius = OuterRadius or 0 + self.SpawnRandomizePositionInnerRadius = InnerRadius or 0 + + for GroupID = 1, self.SpawnMaxGroups do + self:_RandomizeRoute( GroupID ) + end + + return self +end + + --- Randomizes the UNITs that are spawned within a radius band given an Outer and Inner radius. -- @param #SPAWN self -- @param #boolean RandomizeUnits If true, SPAWN will perform the randomization of the @{UNIT}s position within the group between a given outer and inner radius. @@ -20967,6 +20990,20 @@ function SPAWN:SpawnWithIndex( SpawnIndex ) local PointVec3 = POINT_VEC3:New( SpawnTemplate.route.points[1].x, SpawnTemplate.route.points[1].alt, SpawnTemplate.route.points[1].y ) self:T( { "Current point of ", self.SpawnTemplatePrefix, PointVec3 } ) + + -- If RandomizePosition, then Randomize the formation in the zone band, keeping the template. + if self.SpawnRandomizePosition then + local RandomVec2 = PointVec3:GetRandomVec2InRadius( self.SpawnRandomizePositionOuterRadius, self.SpawnRandomizePositionInnerRadius ) + local CurrentX = SpawnTemplate.units[1].x + local CurrentY = SpawnTemplate.units[1].y + SpawnTemplate.x = RandomVec2.x + SpawnTemplate.y = RandomVec2.y + for UnitID = 1, #SpawnTemplate.units do + SpawnTemplate.units[UnitID].x = SpawnTemplate.units[UnitID].x + ( RandomVec2.x - CurrentX ) + SpawnTemplate.units[UnitID].y = SpawnTemplate.units[UnitID].y + ( RandomVec2.y - CurrentY ) + self:T( 'SpawnTemplate.units['..UnitID..'].x = ' .. SpawnTemplate.units[UnitID].x .. ', SpawnTemplate.units['..UnitID..'].y = ' .. SpawnTemplate.units[UnitID].y ) + end + end -- If RandomizeUnits, then Randomize the formation at the start point. if self.SpawnRandomizeUnits then diff --git a/Moose Test Missions/SPA - Spawning/SPA-350 - Spawn at Vec3 position RandomzePosition/SPA-350 - Spawn at Vec3 position RandomzePosition.lua b/Moose Test Missions/SPA - Spawning/SPA-350 - Spawn at Vec3 position RandomzePosition/SPA-350 - Spawn at Vec3 position RandomzePosition.lua new file mode 100644 index 000000000..e3ea49632 --- /dev/null +++ b/Moose Test Missions/SPA - Spawning/SPA-350 - Spawn at Vec3 position RandomzePosition/SPA-350 - Spawn at Vec3 position RandomzePosition.lua @@ -0,0 +1,73 @@ +--- +-- Name: SPA-350 - Spawn at Vec3 position RandomzePosition +-- Author: FlightControl +-- Date Created: 14 Mar 2017 +-- +-- # Situation: +-- +-- Ground troops, Airplanes, Helicopters and Ships are spawning from Vec3 points. +-- The API InitRandomizePosition is tested here, ensure that groups are replaced within a 900 to 1000 zone band at random positions. +-- +-- # Test cases: +-- +-- 1. Observe the random positioning of the groups. There should be no scattering of units. +-- + +local Iterations = 10 +local Iteration = 1 + +GroundZones = { "GroundZone1", "GroundZone2", "GroundZone3" } +GroundRandomizeZones = { "GroundRandomizeZone1", "GroundRandomizeZone2", "GroundRandomizeZone3" } +AirplaneZones = { "AirplaneZone1", "AirplaneZone2", "AirplaneZone3" } +HelicopterZones = { "HelicopterZone1", "HelicopterZone2", "HelicopterZone3" } +ShipZones = { "ShipZone1", "ShipZone2", "ShipZone3" } + +HeightLimit = 500 + +SpawnGrounds = SPAWN:New("Ground"):InitLimit( 20, 10 ):InitRandomizePosition( true , 1000, 900 ) +SpawnRandomizeGrounds = SPAWN:New("GroundRandomize"):InitLimit( 20, 10 ):InitRandomizePosition( true , 1000, 900 ) +SpawnAirplanes = SPAWN:New("Airplane"):InitLimit( 20, 10 ):InitRandomizePosition( true , 1000, 900 ) +SpawnHelicopters = SPAWN:New("Helicopter"):InitLimit( 20, 10 ):InitRandomizePosition( true , 1000, 900 ) +SpawnShips = SPAWN:New("Ship"):InitLimit( 20, 10 ):InitRandomizePosition( true , 1000, 900 ) + +--- Spawns these groups slowly. +SCHEDULER:New( nil, + + function( Interation, Iterations ) + do + -- Spawn Ground + local ZoneName = GroundZones[ math.random( 1, 3 ) ] + local SpawnVec3 = POINT_VEC3:NewFromVec3( ZONE:New( ZoneName ):GetVec3() ) + SpawnGrounds:SpawnFromVec3( SpawnVec3:GetVec3() ) + end + + do + -- Spawn Ground Randomize + local ZoneName = GroundRandomizeZones[ math.random( 1, 3 ) ] + local SpawnVec3 = POINT_VEC3:NewFromVec3( ZONE:New( ZoneName ):GetVec3() ) + SpawnRandomizeGrounds:SpawnFromVec3( SpawnVec3:GetVec3() ) + end + + do + -- Spawn Airplanes + local ZoneName = AirplaneZones[ math.random( 1, 3 ) ] + local SpawnVec3 = POINT_VEC3:NewFromVec3( ZONE:New( ZoneName ):GetVec3() ) + SpawnAirplanes:SpawnFromVec3( SpawnVec3:GetVec3() ) + end + + do + -- Spawn Helicopters + local ZoneName = HelicopterZones[ math.random( 1, 3 ) ] + local SpawnVec3 = POINT_VEC3:NewFromVec3( ZONE:New( ZoneName ):GetVec3() ) + SpawnHelicopters:SpawnFromVec3( SpawnVec3:GetVec3() ) + end + + do + -- Spawn Ships + local ZoneName = ShipZones[ math.random( 1, 3 ) ] + local SpawnVec3 = POINT_VEC3:NewFromVec3( ZONE:New( ZoneName ):GetVec3() ) + SpawnShips:SpawnFromVec3( SpawnVec3:GetVec3() ) + end + + end, {}, 0, 15, 0.5 +) diff --git a/Moose Test Missions/SPA - Spawning/SPA-350 - Spawn at Vec3 position RandomzePosition/SPA-350 - Spawn at Vec3 position RandomzePosition.miz b/Moose Test Missions/SPA - Spawning/SPA-350 - Spawn at Vec3 position RandomzePosition/SPA-350 - Spawn at Vec3 position RandomzePosition.miz new file mode 100644 index 000000000..6cf5ce6df Binary files /dev/null and b/Moose Test Missions/SPA - Spawning/SPA-350 - Spawn at Vec3 position RandomzePosition/SPA-350 - Spawn at Vec3 position RandomzePosition.miz differ diff --git a/docs/Documentation/Cargo.html b/docs/Documentation/Cargo.html index efcd3f237..59202c294 100644 --- a/docs/Documentation/Cargo.html +++ b/docs/Documentation/Cargo.html @@ -2425,7 +2425,6 @@ The UNIT carrying the package.
Limits the Maximum amount of Units that can be alive at the same time, and the maximum amount of groups that can be spawned.
+Randomizes the position of Groups that are spawned within a radius band, given an Outer and Inner radius, from the point that the spawn happens.
Randomizes the position of Groups that are spawned within a radius band, given an Outer and Inner radius, from the point that the spawn happens.
+ +#boolean RandomizePosition :
+If true, SPAWN will perform the randomization of the Groups position between a given outer and inner radius.
Dcs.DCSTypes#Distance OuterRadius :
+(optional) The outer radius in meters where the new group will be spawned.
Dcs.DCSTypes#Distance InnerRadius :
+(optional) The inner radius in meters where the new group will NOT be spawned.
Overwrite unit names by default with group name.
-By default, no InitLimit
+Sets the randomization flag of new Spawned units to false.
+ +Flag that indicates if all the Groups of the SpawnGroup need to be visible when Spawned.
+When the first Spawn executes, all the Groups need to be made visible before start.