From 0fb42b39d9102e785622cfb67c1e20889326059b Mon Sep 17 00:00:00 2001 From: dnqbob Date: Sat, 6 Sep 2025 21:28:49 +0800 Subject: [PATCH] Fix Airstate indice check: 1. the indice square should be the inscribed square of DangerScanRadius circle. 2. Use Map Bounds instead of Map Size --- .../Traits/BotModules/Squads/States/AirStates.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/BotModules/Squads/States/AirStates.cs b/OpenRA.Mods.Common/Traits/BotModules/Squads/States/AirStates.cs index 5c3601716d..5a300192e6 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/Squads/States/AirStates.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/Squads/States/AirStates.cs @@ -58,16 +58,20 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads protected static CPos? FindSafePlace(Squad owner, out Actor detectedEnemyTarget, bool needTarget) { var map = owner.World.Map; - var dangerRadius = owner.SquadManager.Info.DangerScanRadius; + var dangerIndiceSideLength = owner.SquadManager.Info.DangerScanRadius * 141 / 100; // ¡Ö DangerScanRadius * sqrt(2) detectedEnemyTarget = null; - var columnCount = (map.MapSize.Width + dangerRadius - 1) / dangerRadius; - var rowCount = (map.MapSize.Height + dangerRadius - 1) / dangerRadius; + var columnCount = (map.Bounds.Width + dangerIndiceSideLength - 1) / dangerIndiceSideLength; + var rowCount = (map.Bounds.Height + dangerIndiceSideLength - 1) / dangerIndiceSideLength; + var xoffset = map.Bounds.X; + var yoffset = map.Bounds.Y; - var checkIndices = Exts.MakeArray(columnCount * rowCount, i => i).Shuffle(owner.World.LocalRandom); - foreach (var i in checkIndices) + // Construct a grid of points as the center of square with side length of dangerDiameter to divide the map and shuffle them to get a random search pattern. + // Make sure when search with DangerScanRadius, covers the whole indice and covers the least cells in other indice. + foreach (var i in Exts.MakeArray(columnCount * rowCount, i => i).Shuffle(owner.World.LocalRandom)) { - var pos = new MPos(i % columnCount * dangerRadius + dangerRadius / 2, i / columnCount * dangerRadius + dangerRadius / 2).ToCPos(map); + var pos = new MPos(xoffset + i % columnCount * dangerIndiceSideLength + (dangerIndiceSideLength >> 1), + yoffset + i / columnCount * dangerIndiceSideLength + (dangerIndiceSideLength >> 1)).ToCPos(map); if (NearToPosSafely(owner, map.CenterOfCell(pos), out detectedEnemyTarget)) {