From 5ad9eb852c0ad0a8d24651bbf2da2760a93c8735 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Mon, 21 Sep 2015 03:06:50 +0200 Subject: [PATCH] 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. --- OpenRA.Mods.Common/AI/HackyAI.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.Common/AI/HackyAI.cs b/OpenRA.Mods.Common/AI/HackyAI.cs index 35c9720e2f..f5e5ad371c 100644 --- a/OpenRA.Mods.Common/AI/HackyAI.cs +++ b/OpenRA.Mods.Common/AI/HackyAI.cs @@ -500,11 +500,11 @@ namespace OpenRA.Mods.Common.AI // Try and place the refinery near a resource field var nearbyResources = Map.FindTilesInCircle(baseCenter, Info.MaxBaseRadius) .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) return found; }