diff --git a/OpenRA.Game/Traits/Player/Shroud.cs b/OpenRA.Game/Traits/Player/Shroud.cs index 70ba1e51f5..cfb96c0b59 100644 --- a/OpenRA.Game/Traits/Player/Shroud.cs +++ b/OpenRA.Game/Traits/Player/Shroud.cs @@ -274,11 +274,9 @@ namespace OpenRA.Traits public void AddSource(object key, SourceType type, PPos[] projectedCells) { - if (sources.ContainsKey(key)) + if (!sources.TryAdd(key, new ShroudSource(type, projectedCells))) throw new InvalidOperationException("Attempting to add duplicate shroud source"); - sources[key] = new ShroudSource(type, projectedCells); - foreach (var puv in projectedCells) { // Force cells outside the visible bounds invisible @@ -309,7 +307,7 @@ namespace OpenRA.Traits public void RemoveSource(object key) { - if (!sources.TryGetValue(key, out var state)) + if (!sources.Remove(key, out var state)) return; foreach (var puv in state.ProjectedCells) @@ -334,8 +332,6 @@ namespace OpenRA.Traits } } } - - sources.Remove(key); } public void ExploreProjectedCells(IEnumerable cells)