Merge pull request #2348 from shaji-Dev/master

[ADDED] `Disposition.getSimpleZones`  support for ZONE_POLYGON_BASE
This commit is contained in:
Thomas 2025-07-25 14:47:08 +02:00 committed by GitHub
commit ebecc70693
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 59 additions and 21 deletions

View File

@ -1514,19 +1514,7 @@ end
-- @param #number NumPositions Number of positions to find. -- @param #number NumPositions Number of positions to find.
-- @return #table A table of DCS#Vec2 positions that are clear of map objects within the given PosRadius. nil if no clear positions are found. -- @return #table A table of DCS#Vec2 positions that are clear of map objects within the given PosRadius. nil if no clear positions are found.
function ZONE_RADIUS:GetClearZonePositions(PosRadius, NumPositions) function ZONE_RADIUS:GetClearZonePositions(PosRadius, NumPositions)
local clearPositions = UTILS.GetSimpleZones(self:GetVec3(), self:GetRadius(), PosRadius, NumPositions) return UTILS.GetClearZonePositions(self, PosRadius, NumPositions)
if clearPositions and #clearPositions > 0 then
local validZones = {}
for _, vec2 in pairs(clearPositions) do
if self:IsVec2InZone(vec2) then
table.insert(validZones, vec2)
end
end
if #validZones > 0 then
return validZones
end
end
return nil
end end
@ -1536,14 +1524,7 @@ end
-- @return Core.Point#COORDINATE A random coordinate for a clear zone. nil if no clear positions are found. -- @return Core.Point#COORDINATE A random coordinate for a clear zone. nil if no clear positions are found.
-- @return #number Assigned radius for the found zones. nil if no clear positions are found. -- @return #number Assigned radius for the found zones. nil if no clear positions are found.
function ZONE_RADIUS:GetRandomClearZoneCoordinate(PosRadius, NumPositions) function ZONE_RADIUS:GetRandomClearZoneCoordinate(PosRadius, NumPositions)
local radius = PosRadius or math.min(self.Radius/10, 200) return UTILS.GetRandomClearZoneCoordinate(self, PosRadius, NumPositions)
local clearPositions = self:GetClearZonePositions(radius, NumPositions or 50)
if clearPositions and #clearPositions > 0 then
local randomPosition = clearPositions[math.random(1, #clearPositions)]
return COORDINATE:NewFromVec2(randomPosition), radius
end
return nil
end end
--- Returns a random Vec2 location within the zone. --- Returns a random Vec2 location within the zone.
@ -2524,6 +2505,24 @@ function ZONE_POLYGON_BASE:Flush()
return self return self
end end
--- Search for clear ground spawn zones within this zone. A powerful and efficient function using Disposition to find clear areas for spawning ground units avoiding trees, water and map scenery.
-- @param #number PosRadius Required clear radius around each position.
-- @param #number NumPositions Number of positions to find.
-- @return #table A table of DCS#Vec2 positions that are clear of map objects within the given PosRadius. nil if no clear positions are found.
function ZONE_POLYGON_BASE:GetClearZonePositions(PosRadius, NumPositions)
return UTILS.GetClearZonePositions(self, PosRadius, NumPositions)
end
--- Search for a random clear ground spawn coordinate within this zone. A powerful and efficient function using Disposition to find clear areas for spawning ground units avoiding trees, water and map scenery.
-- @param #number PosRadius (Optional) Required clear radius around each position. (Default is math.min(Radius/10, 200))
-- @param #number NumPositions (Optional) Number of positions to find. (Default 50)
-- @return Core.Point#COORDINATE A random coordinate for a clear zone. nil if no clear positions are found.
-- @return #number Assigned radius for the found zones. nil if no clear positions are found.
function ZONE_POLYGON_BASE:GetRandomClearZoneCoordinate(PosRadius, NumPositions)
return UTILS.GetRandomClearZoneCoordinate(self, PosRadius, NumPositions)
end
--- Smokes the zone boundaries in a color. --- Smokes the zone boundaries in a color.
-- @param #ZONE_POLYGON_BASE self -- @param #ZONE_POLYGON_BASE self
-- @param #boolean UnBound If true, the tyres will be destroyed. -- @param #boolean UnBound If true, the tyres will be destroyed.

View File

@ -4640,3 +4640,42 @@ end
function UTILS.GetSimpleZones(Vec3, SearchRadius, PosRadius, NumPositions) function UTILS.GetSimpleZones(Vec3, SearchRadius, PosRadius, NumPositions)
return Disposition.getSimpleZones(Vec3, SearchRadius, PosRadius, NumPositions) return Disposition.getSimpleZones(Vec3, SearchRadius, PosRadius, NumPositions)
end end
--- Search for clear ground spawn zones within this zone. A powerful and efficient function using Disposition to find clear areas for spawning ground units avoiding trees, water and map scenery.
-- @param Core.Zone#ZONE Zone to search.
-- @param #number (Optional) PosRadius Required clear radius around each position. (Default is math.min(Radius/10, 200))
-- @param #number (Optional) NumPositions Number of positions to find. (Default 50)
-- @return #table A table of DCS#Vec2 positions that are clear of map objects within the given PosRadius. nil if no clear positions are found.
function UTILS.GetClearZonePositions(Zone, PosRadius, NumPositions)
local radius = PosRadius or math.min(Zone:GetRadius()/10, 200)
local clearPositions = UTILS.GetSimpleZones(Zone:GetVec3(), Zone:GetRadius(), radius, NumPositions or 50)
if clearPositions and #clearPositions > 0 then
local validZones = {}
for _, vec2 in pairs(clearPositions) do
if Zone:IsVec2InZone(vec2) then
table.insert(validZones, vec2)
end
end
if #validZones > 0 then
return validZones, radius
end
end
return nil
end
--- Search for a random clear ground spawn coordinate within this zone. A powerful and efficient function using Disposition to find clear areas for spawning ground units avoiding trees, water and map scenery.
-- @param Core.Zone#ZONE Zone to search.
-- @param #number PosRadius (Optional) Required clear radius around each position. (Default is math.min(Radius/10, 200))
-- @param #number NumPositions (Optional) Number of positions to find. (Default 50)
-- @return Core.Point#COORDINATE A random coordinate for a clear zone. nil if no clear positions are found.
-- @return #number Assigned radius for the found zones. nil if no clear positions are found.
function UTILS.GetRandomClearZoneCoordinate(Zone, PosRadius, NumPositions)
local clearPositions = UTILS.GetClearZonePositions(Zone, PosRadius, NumPositions)
if clearPositions and #clearPositions > 0 then
local randomPosition, radius = clearPositions[math.random(1, #clearPositions)]
return COORDINATE:NewFromVec2(randomPosition), radius
end
return nil
end