Fix massive AI base builder performance issue
Previously, the Refinery placement check would first collect all cells with resources inside the MaxBaseRadius, then perform a full findPos check for each cell until one of them would not return null. The problem was that if all of the cells returned null (for example if there wasn't enough space between base center and resource, or if all suitable space was otherwise occupied), it would basically check all tiles with resources only to fail finding a suitable position and fall back to the normal findPos check. Since nearbyResources already performs a shuffle, I simply made the check use the first cell from the list and use the basic findPos fallback if that cell is null. Closes #4717.
This commit is contained in:
@@ -500,11 +500,11 @@ namespace OpenRA.Mods.Common.AI
|
|||||||
// Try and place the refinery near a resource field
|
// Try and place the refinery near a resource field
|
||||||
var nearbyResources = Map.FindTilesInCircle(baseCenter, Info.MaxBaseRadius)
|
var nearbyResources = Map.FindTilesInCircle(baseCenter, Info.MaxBaseRadius)
|
||||||
.Where(a => resourceTypeIndices.Get(Map.GetTerrainIndex(a)))
|
.Where(a => resourceTypeIndices.Get(Map.GetTerrainIndex(a)))
|
||||||
.Shuffle(Random);
|
.Shuffle(Random).ToList();
|
||||||
|
|
||||||
foreach (var c in nearbyResources)
|
if (nearbyResources.Count > 0)
|
||||||
{
|
{
|
||||||
var found = findPos(c, baseCenter, 0, Info.MaxBaseRadius);
|
var found = findPos(nearbyResources.First(), baseCenter, 0, Info.MaxBaseRadius);
|
||||||
if (found != null)
|
if (found != null)
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user