Skip to content

Commit

Permalink
AI - Increase distance limits for Naval Area marker generation (#6048)
Browse files Browse the repository at this point in the history
  • Loading branch information
relent0r authored May 26, 2024
1 parent 0298a8e commit 6625471
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog/snippets/ai.6048.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- (#6048) Increase maximum distances for Naval Area marker generation to improve AI naval presence on certain maps.
32 changes: 23 additions & 9 deletions lua/sim/MarkerUtilities/NavalAreas.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ end
---@param distance number
---@param thresholdSize number
---@param thresholdArea number
local function GenerateForExpansion(expansion, distance, thresholdSize, thresholdArea)
local function GenerateForExpansion(expansion, distance, thresholdSize, thresholdArea, maximumCount)
-- local imports to make debugging easier
local NavUtils = import("/lua/sim/navutils.lua")

local position = expansion.position
local points, count = NavUtils.GetPositionsInRadius('Water', position, distance, thresholdSize, { })
if points then
local unsortedExpansionMarkers = {}
for k = 1, count do
local point = points[k]

Expand Down Expand Up @@ -83,9 +84,20 @@ local function GenerateForExpansion(expansion, distance, thresholdSize, threshol
Type = 'Naval Area',
}

-- keep track of the marker
MarkerCount = MarkerCount + 1
Markers[MarkerCount] = marker
table.insert(unsortedExpansionMarkers, marker)
end
table.sort(unsortedExpansionMarkers,function(a,b) return VDist3Sq(position,a.position)<VDist3Sq(position,b.position) end)
if maximumCount then
for k = 1, maximumCount do
MarkerCount = MarkerCount + 1
Markers[MarkerCount] = unsortedExpansionMarkers[k]

end
else
for k = 1, count do
MarkerCount = MarkerCount + 1
Markers[MarkerCount] = unsortedExpansionMarkers[k]
end
end
end
end
Expand Down Expand Up @@ -135,7 +147,7 @@ function Generate()
if mapSize > 1024 then
thresholdDistance = 30
end
GenerateForExpansion(smallExpansions[k], thresholdDistance, thresholdSize, thresholdArea)
GenerateForExpansion(smallExpansions[k], thresholdDistance, thresholdSize, thresholdArea, 2)
end

-- generate for large expansions
Expand All @@ -144,16 +156,18 @@ function Generate()
if mapSize > 1024 then
thresholdDistance = 50
end
GenerateForExpansion(largeExpansions[k], thresholdDistance, thresholdSize, thresholdArea)
GenerateForExpansion(largeExpansions[k], thresholdDistance, thresholdSize, thresholdArea, 4)
end

-- generate for spawn locations
for k = 1, spawnCount do
local thresholdDistance = 40
if mapSize > 1024 then
thresholdDistance = 50
if mapSize >= 2048 then
thresholdDistance = 650
elseif mapSize >= 1024 then
thresholdDistance = 150
end
GenerateForExpansion(spawns[k], thresholdDistance, thresholdSize, thresholdArea)
GenerateForExpansion(spawns[k], thresholdDistance, thresholdSize, thresholdArea, 6)
end

import("/lua/sim/markerutilities.lua").OverwriteMarkerByType('Naval Area', Markers)
Expand Down

0 comments on commit 6625471

Please sign in to comment.