Fix Airstate indice check:
1. the indice square should be the inscribed square of DangerScanRadius circle. 2. Use Map Bounds instead of Map Size
This commit is contained in:
committed by
Gustas Kažukauskas
parent
dc2fa932ea
commit
0fb42b39d9
@@ -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))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user