From 8169235d2fb944028f5c8ae7d04094f24b520bb3 Mon Sep 17 00:00:00 2001 From: smiki Date: Sun, 24 Aug 2025 16:27:55 +0200 Subject: [PATCH 1/4] [FIXED] Maintain valid unit positions --- Moose Development/Moose/Utilities/Utils.lua | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/Moose Development/Moose/Utilities/Utils.lua b/Moose Development/Moose/Utilities/Utils.lua index bdbff6b38..989e9ef07 100644 --- a/Moose Development/Moose/Utilities/Utils.lua +++ b/Moose Development/Moose/Utilities/Utils.lua @@ -4921,20 +4921,9 @@ function UTILS.ValidateAndRepositionGroundUnits(Anchor, Positions, MaxRadius, Sp for _, spot in pairs(spots) do local dist = UTILS.VecDist2D(pos, spot) if dist < closestDist then - local skip = false - for _, unit2 in pairs(units) do - local pos2 = { x = unit2.x, y = unit2.z or unit2.y } - local dist2 = UTILS.VecDist2D(spot, pos2) - if dist2 < spacing and isOnLand then - skip = true - break - end - end - if not skip then - closestDist = dist - closestSpot = spot - sid = si - end + closestDist = dist + closestSpot = spot + sid = si end si = si + 1 end From facac821305d6d406b48431f098f68cd56ea030b Mon Sep 17 00:00:00 2001 From: smiki Date: Sun, 24 Aug 2025 16:44:41 +0200 Subject: [PATCH 2/4] [ADDED] WAREHOUSE:SetValidateAndRepositionGroundUnits to use for Brigades --- Moose Development/Moose/Functional/Warehouse.lua | 14 ++++++++++++++ Moose Development/Moose/Utilities/Utils.lua | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Moose Development/Moose/Functional/Warehouse.lua b/Moose Development/Moose/Functional/Warehouse.lua index 2486e74b6..19654ad5e 100644 --- a/Moose Development/Moose/Functional/Warehouse.lua +++ b/Moose Development/Moose/Functional/Warehouse.lua @@ -4247,6 +4247,16 @@ function WAREHOUSE:_AssetItemInfo(asset) self:T3({Template=asset.template}) end +--- This function uses Disposition and other fallback logic to find better ground positions for ground units. +--- NOTE: This is not a spawn randomizer. +--- It will try to find clear ground locations avoiding trees, water, roads, runways, map scenery, statics and other units in the area and modifies the provided positions table. +--- Maintains the original layout and unit positions as close as possible by searching for the next closest valid position to each unit. +--- Uses UTILS.ValidateAndRepositionGroundUnits. +-- @param #boolean Enabled Enable/disable the feature. +function WAREHOUSE:SetValidateAndRepositionGroundUnits(Enabled) + self.ValidateAndRepositionGroundUnits = Enabled +end + --- On after "NewAsset" event. A new asset has been added to the warehouse stock. -- @param #WAREHOUSE self -- @param #string From From state. @@ -5965,6 +5975,10 @@ function WAREHOUSE:_SpawnAssetGroundNaval(alias, asset, request, spawnzone, late template.y = coord.z template.alt = coord.y + if self.ValidateAndRepositionGroundUnits then + UTILS.ValidateAndRepositionGroundUnits(template.units) + end + -- Spawn group. local group=_DATABASE:Spawn(template) --Wrapper.Group#GROUP diff --git a/Moose Development/Moose/Utilities/Utils.lua b/Moose Development/Moose/Utilities/Utils.lua index 989e9ef07..cd94f71b2 100644 --- a/Moose Development/Moose/Utilities/Utils.lua +++ b/Moose Development/Moose/Utilities/Utils.lua @@ -4876,11 +4876,11 @@ end --- NOTE: This is not a spawn randomizer. --- It will try to find clear ground locations avoiding trees, water, roads, runways, map scenery, statics and other units in the area and modifies the provided positions table. --- Maintains the original layout and unit positions as close as possible by searching for the next closest valid position to each unit. --- @param table Positions A table of DCS#Vec2 or DCS#Vec3, can be a units table from the group template. +-- @param #table Positions A table of DCS#Vec2 or DCS#Vec3, can be a units table from the group template. -- @param DCS#Vec2 Anchor (Optional) DCS#Vec2 or DCS#Vec3 as anchor point to calculate offset of the units. -- @param #number MaxRadius (Optional) Max radius to search for valid ground locations in meters. Default is double the max radius of the units. -- @param #number Spacing (Optional) Minimum spacing between units in meters. Default is 5% of the search radius or 5 meters, whichever is larger. -function UTILS.ValidateAndRepositionGroundUnits(Anchor, Positions, MaxRadius, Spacing) +function UTILS.ValidateAndRepositionGroundUnits(Positions, Anchor, MaxRadius, Spacing) local units = Positions Anchor = Anchor or UTILS.GetCenterPoint(units) local gPos = { x = Anchor.x, y = Anchor.z or Anchor.y } From 9adf342dd84e9bcabc3890350cf2d1f90b255c9b Mon Sep 17 00:00:00 2001 From: smiki Date: Sun, 24 Aug 2025 16:45:54 +0200 Subject: [PATCH 3/4] [ADDED] WAREHOUSE:SetValidateAndRepositionGroundUnits to use for Brigades --- Moose Development/Moose/Functional/Warehouse.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Moose Development/Moose/Functional/Warehouse.lua b/Moose Development/Moose/Functional/Warehouse.lua index 19654ad5e..807f57f98 100644 --- a/Moose Development/Moose/Functional/Warehouse.lua +++ b/Moose Development/Moose/Functional/Warehouse.lua @@ -5975,9 +5975,9 @@ function WAREHOUSE:_SpawnAssetGroundNaval(alias, asset, request, spawnzone, late template.y = coord.z template.alt = coord.y - if self.ValidateAndRepositionGroundUnits then + if self.ValidateAndRepositionGroundUnits then UTILS.ValidateAndRepositionGroundUnits(template.units) - end + end -- Spawn group. local group=_DATABASE:Spawn(template) --Wrapper.Group#GROUP From 2c12cfe4fd018da77bee56c5932420ec7b77b4a7 Mon Sep 17 00:00:00 2001 From: smiki Date: Sun, 24 Aug 2025 17:06:45 +0200 Subject: [PATCH 4/4] [ADDED] WAREHOUSE:SetValidateAndRepositionGroundUnits to use for Brigades --- Moose Development/Moose/Core/Spawn.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Moose Development/Moose/Core/Spawn.lua b/Moose Development/Moose/Core/Spawn.lua index 6e95e285b..0d58567a4 100644 --- a/Moose Development/Moose/Core/Spawn.lua +++ b/Moose Development/Moose/Core/Spawn.lua @@ -1849,7 +1849,7 @@ function SPAWN:SpawnWithIndex( SpawnIndex, NoBirth ) if self.SpawnValidateAndRepositionGroundUnits then local units = SpawnTemplate.units local gPos = { x = SpawnTemplate.x, y = SpawnTemplate.y } - UTILS.ValidateAndRepositionGroundUnits(gPos, units, self.SpawnValidateAndRepositionGroundUnitsRadius, self.SpawnValidateAndRepositionGroundUnitsSpacing) + UTILS.ValidateAndRepositionGroundUnits(units, gPos, self.SpawnValidateAndRepositionGroundUnitsRadius, self.SpawnValidateAndRepositionGroundUnitsSpacing) end -- Set country, coalition and category.