From 7e992d44c8e91a4c28a6df8d3c75599a1e82ab57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Fri, 18 Sep 2020 20:10:18 +0200 Subject: [PATCH] Fix a crash when refineries share a cell. --- OpenRA.Mods.Common/Traits/Harvester.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Harvester.cs b/OpenRA.Mods.Common/Traits/Harvester.cs index 5d0d68f64a..27bbe76433 100644 --- a/OpenRA.Mods.Common/Traits/Harvester.cs +++ b/OpenRA.Mods.Common/Traits/Harvester.cs @@ -174,25 +174,25 @@ namespace OpenRA.Mods.Common.Traits public Actor ClosestProc(Actor self, Actor ignore) { // Find all refineries and their occupancy count: - var refs = self.World.ActorsWithTrait() + var refineries = self.World.ActorsWithTrait() .Where(r => r.Actor != ignore && r.Actor.Owner == self.Owner && IsAcceptableProcType(r.Actor)) .Select(r => new { Location = r.Actor.Location + r.Trait.DeliveryOffset, Actor = r.Actor, Occupancy = self.World.ActorsHavingTrait(h => h.LinkedProc == r.Actor).Count() - }).ToDictionary(r => r.Location); + }).ToLookup(r => r.Location); // Start a search from each refinery's delivery location: List path; - using (var search = PathSearch.FromPoints(self.World, mobile.Locomotor, self, refs.Values.Select(r => r.Location), self.Location, BlockedByActor.None) - .WithCustomCost(loc => + using (var search = PathSearch.FromPoints(self.World, mobile.Locomotor, self, refineries.Select(r => r.Key), self.Location, BlockedByActor.None) + .WithCustomCost(location => { - if (!refs.ContainsKey(loc)) + if (!refineries.Contains(location)) return 0; - var occupancy = refs[loc].Occupancy; + var occupancy = refineries[location].First().Occupancy; // Too many harvesters clogs up the refinery's delivery location: if (occupancy >= Info.MaxUnloadQueue) @@ -204,7 +204,7 @@ namespace OpenRA.Mods.Common.Traits path = self.World.WorldActor.Trait().FindPath(search); if (path.Count != 0) - return refs[path.Last()].Actor; + return refineries[path.Last()].First().Actor; return null; }