From be741cea5ee1fc3a811cf18320847e145416cf6d Mon Sep 17 00:00:00 2001 From: teinarss Date: Tue, 15 Jan 2019 20:41:43 +0100 Subject: [PATCH] Prevent multiple enumeration of validCells in SpawnMPUnits --- OpenRA.Mods.Common/Traits/World/SpawnMPUnits.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/World/SpawnMPUnits.cs b/OpenRA.Mods.Common/Traits/World/SpawnMPUnits.cs index 47b6e5ee5f..8aea1cd7aa 100644 --- a/OpenRA.Mods.Common/Traits/World/SpawnMPUnits.cs +++ b/OpenRA.Mods.Common/Traits/World/SpawnMPUnits.cs @@ -103,20 +103,20 @@ namespace OpenRA.Mods.Common.Traits { var actorRules = w.Map.Rules.Actors[s.ToLowerInvariant()]; var ip = actorRules.TraitInfo(); - var validCells = supportSpawnCells.Where(c => ip.CanEnterCell(w, null, c)); - if (!validCells.Any()) + var validCell = supportSpawnCells.Shuffle(w.SharedRandom).FirstOrDefault(c => ip.CanEnterCell(w, null, c)); + + if (validCell == CPos.Zero) { Log.Write("debug", "No cells available to spawn starting unit {0} for player {1}".F(s, p)); continue; } - var cell = validCells.Random(w.SharedRandom); - var subCell = ip.SharesCell ? w.ActorMap.FreeSubCell(cell) : 0; + var subCell = ip.SharesCell ? w.ActorMap.FreeSubCell(validCell) : 0; w.CreateActor(s.ToLowerInvariant(), new TypeDictionary { new OwnerInit(p), - new LocationInit(cell), + new LocationInit(validCell), new SubCellInit(subCell), new FacingInit(unitGroup.SupportActorsFacing < 0 ? w.SharedRandom.Next(256) : unitGroup.SupportActorsFacing) });