Fix CA1851, assume_method_enumerates_parameters = true
This commit is contained in:
@@ -239,9 +239,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
CPos ChooseRallyLocationNear(Actor producer)
|
||||
{
|
||||
var possibleRallyPoints = world.Map.FindTilesInCircle(producer.Location, Info.RallyPointScanRadius)
|
||||
.Where(c => IsRallyPointValid(c, producer.Info.TraitInfoOrDefault<BuildingInfo>()));
|
||||
.Where(c => IsRallyPointValid(c, producer.Info.TraitInfoOrDefault<BuildingInfo>()))
|
||||
.ToList();
|
||||
|
||||
if (!possibleRallyPoints.Any())
|
||||
if (possibleRallyPoints.Count == 0)
|
||||
{
|
||||
AIUtils.BotDebug("{0} has no possible rallypoint near {1}", producer.Owner, producer.Location);
|
||||
return producer.Location;
|
||||
|
||||
@@ -229,7 +229,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
ActorInfo ChooseBuildingToBuild(ProductionQueue queue)
|
||||
{
|
||||
var buildableThings = queue.BuildableItems();
|
||||
var buildableThings = queue.BuildableItems().ToList();
|
||||
|
||||
// This gets used quite a bit, so let's cache it here
|
||||
var power = GetProducibleBuilding(baseBuilder.Info.PowerTypes, buildableThings,
|
||||
|
||||
@@ -154,12 +154,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (Info.CapturableActorTypes.Count > 0)
|
||||
capturableTargetOptions = capturableTargetOptions.Where(target => Info.CapturableActorTypes.Contains(target.Info.Name.ToLowerInvariant()));
|
||||
|
||||
if (!capturableTargetOptions.Any())
|
||||
var capturableTargetOptionsList = capturableTargetOptions.ToList();
|
||||
if (capturableTargetOptionsList.Count == 0)
|
||||
return;
|
||||
|
||||
foreach (var capturer in capturers)
|
||||
{
|
||||
var targetActor = capturableTargetOptions.MinByOrDefault(target => (target.CenterPosition - capturer.Actor.CenterPosition).LengthSquared);
|
||||
var targetActor = capturableTargetOptionsList.MinByOrDefault(target => (target.CenterPosition - capturer.Actor.CenterPosition).LengthSquared);
|
||||
if (targetActor == null)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -197,7 +197,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
internal Actor FindClosestEnemy(WPos pos)
|
||||
{
|
||||
var units = World.Actors.Where(IsPreferredEnemyUnit);
|
||||
var units = World.Actors.Where(IsPreferredEnemyUnit).ToList();
|
||||
return units.Where(IsNotHiddenUnit).ClosestTo(pos) ?? units.ClosestTo(pos);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,10 +35,9 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads
|
||||
&& mobile.PathFinder.PathExistsForLocomotor(mobile.Locomotor, first.Location, a.Location)
|
||||
&& a.AppearsHostileTo(first));
|
||||
|
||||
if (navalProductions.Any())
|
||||
var nearest = navalProductions.ClosestTo(first);
|
||||
if (nearest != null)
|
||||
{
|
||||
var nearest = navalProductions.ClosestTo(first);
|
||||
|
||||
// Return nearest when it is FAR enough.
|
||||
// If the naval production is within MaxBaseRadius, it implies that
|
||||
// this squad is close to enemy territory and they should expect a naval combat;
|
||||
|
||||
@@ -163,11 +163,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
ActorInfo ChooseRandomUnitToBuild(ProductionQueue queue)
|
||||
{
|
||||
var buildableThings = queue.BuildableItems();
|
||||
if (!buildableThings.Any())
|
||||
return null;
|
||||
|
||||
var unit = buildableThings.Random(world.LocalRandom);
|
||||
return HasAdequateAirUnitReloadBuildings(unit) ? unit : null;
|
||||
var unit = buildableThings.RandomOrDefault(world.LocalRandom);
|
||||
return unit != null && HasAdequateAirUnitReloadBuildings(unit) ? unit : null;
|
||||
}
|
||||
|
||||
ActorInfo ChooseUnitToBuild(ProductionQueue queue)
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (Repairers.Remove(player))
|
||||
{
|
||||
UpdateCondition(self);
|
||||
if (!Repairers.Any())
|
||||
if (Repairers.Count == 0)
|
||||
{
|
||||
Game.Sound.PlayNotification(self.World.Map.Rules, player, "Speech", Info.RepairingStoppedNotification, player.Faction.InternalName);
|
||||
TextNotificationsManager.AddTransientLine(self.Owner, Info.RepairingStoppedTextNotification);
|
||||
|
||||
@@ -111,11 +111,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
CPos? ChooseEmptyCellNear(Actor a, string unit)
|
||||
{
|
||||
var possibleCells = GetSuitableCells(a.Location, unit);
|
||||
if (!possibleCells.Any())
|
||||
return null;
|
||||
|
||||
return possibleCells.Random(self.World.SharedRandom);
|
||||
return GetSuitableCells(a.Location, unit)
|
||||
.Cast<CPos?>()
|
||||
.RandomOrDefault(self.World.SharedRandom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return false;
|
||||
}
|
||||
|
||||
Color MakeValid(float hue, float sat, float val, MersenneTwister random, IEnumerable<Color> terrainColors, IEnumerable<Color> playerColors, Action<string> onError)
|
||||
Color MakeValid(float hue, float sat, float val, MersenneTwister random, IReadOnlyCollection<Color> terrainColors, IReadOnlyCollection<Color> playerColors, Action<string> onError)
|
||||
{
|
||||
// Clamp saturation without triggering a warning
|
||||
// This can only happen due to rounding errors (common) or modified clients (rare)
|
||||
@@ -132,7 +132,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
Color[] IColorPickerManagerInfo.PresetColors => PresetColors;
|
||||
|
||||
Color IColorPickerManagerInfo.RandomPresetColor(MersenneTwister random, IEnumerable<Color> terrainColors, IEnumerable<Color> playerColors)
|
||||
Color IColorPickerManagerInfo.RandomPresetColor(MersenneTwister random, IReadOnlyCollection<Color> terrainColors, IReadOnlyCollection<Color> playerColors)
|
||||
{
|
||||
foreach (var color in PresetColors.Shuffle(random))
|
||||
{
|
||||
@@ -148,13 +148,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return MakeValid(randomHue, randomSat, randomVal, random, terrainColors, playerColors, null);
|
||||
}
|
||||
|
||||
Color IColorPickerManagerInfo.MakeValid(Color color, MersenneTwister random, IEnumerable<Color> terrainColors, IEnumerable<Color> playerColors, Action<string> onError)
|
||||
Color IColorPickerManagerInfo.MakeValid(Color color, MersenneTwister random, IReadOnlyCollection<Color> terrainColors, IReadOnlyCollection<Color> playerColors, Action<string> onError)
|
||||
{
|
||||
var (_, h, s, v) = color.ToAhsv();
|
||||
return MakeValid(h, s, v, random, terrainColors, playerColors, onError);
|
||||
}
|
||||
|
||||
Color IColorPickerManagerInfo.RandomValidColor(MersenneTwister random, IEnumerable<Color> terrainColors, IEnumerable<Color> playerColors)
|
||||
Color IColorPickerManagerInfo.RandomValidColor(MersenneTwister random, IReadOnlyCollection<Color> terrainColors, IReadOnlyCollection<Color> playerColors)
|
||||
{
|
||||
var h = random.NextFloat();
|
||||
var s = float2.Lerp(HsvSaturationRange[0], HsvSaturationRange[1], random.NextFloat());
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void CreateControlGroup(int group)
|
||||
{
|
||||
if (!world.Selection.Actors.Any())
|
||||
if (world.Selection.Actors.Count == 0)
|
||||
return;
|
||||
|
||||
controlGroups[group].Clear();
|
||||
@@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void AddSelectionToControlGroup(int group)
|
||||
{
|
||||
if (!world.Selection.Actors.Any())
|
||||
if (world.Selection.Actors.Count == 0)
|
||||
return;
|
||||
|
||||
RemoveActorsFromAllControlGroups(world.Selection.Actors);
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Actor ignoreActor = null,
|
||||
bool laneBias = true)
|
||||
{
|
||||
return FindPathToTarget(self, sources, target, check, customCost, ignoreActor, laneBias);
|
||||
return FindPathToTarget(self, sources.ToList(), target, check, customCost, ignoreActor, laneBias);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -125,11 +125,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// and calling the existing methods that allow multiple sources and one target.
|
||||
// However there is a case of asymmetry we must handle, an actor may move out of a inaccessible source,
|
||||
// but may not move onto a inaccessible target. We must account for this when performing the swap.
|
||||
var targetsList = targets.ToList();
|
||||
if (targetsList.Count == 0)
|
||||
return NoPath;
|
||||
|
||||
// As targets must be accessible, determine accessible targets in advance so when they becomes the sources
|
||||
// we don't accidentally allow an inaccessible position to become viable.
|
||||
var locomotor = GetActorLocomotor(self);
|
||||
var accessibleTargets = targets
|
||||
var accessibleTargets = targetsList
|
||||
.Where(target =>
|
||||
PathSearch.CellAllowsMovement(self.World, locomotor, target, customCost)
|
||||
&& locomotor.MovementCostToEnterCell(self, target, check, ignoreActor, true) != PathGraph.MovementCostForUnreachableCell)
|
||||
@@ -146,7 +149,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (sourceIsAccessible)
|
||||
{
|
||||
// As both ends are accessible, we can freely swap them.
|
||||
path = FindPathToTarget(self, targets, source, check, customCost, ignoreActor, laneBias);
|
||||
path = FindPathToTarget(self, targetsList, source, check, customCost, ignoreActor, laneBias);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -167,11 +170,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
List<CPos> FindPathToTarget(
|
||||
Actor self, IEnumerable<CPos> sources, CPos target, BlockedByActor check,
|
||||
Actor self, List<CPos> sources, CPos target, BlockedByActor check,
|
||||
Func<CPos, int> customCost, Actor ignoreActor, bool laneBias)
|
||||
{
|
||||
var sourcesList = sources.ToList();
|
||||
if (sourcesList.Count == 0)
|
||||
if (sources.Count == 0)
|
||||
return NoPath;
|
||||
|
||||
var locomotor = GetActorLocomotor(self);
|
||||
@@ -183,9 +185,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return NoPath;
|
||||
|
||||
// When searching from only one source cell, some optimizations are possible.
|
||||
if (sourcesList.Count == 1)
|
||||
if (sources.Count == 1)
|
||||
{
|
||||
var source = sourcesList[0];
|
||||
var source = sources[0];
|
||||
|
||||
// For adjacent cells on the same layer, we can return the path without invoking a full search.
|
||||
if (source.Layer == target.Layer && (source - target).LengthSquared < 3)
|
||||
@@ -204,7 +206,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
// Use a hierarchical path search, which performs a guided unidirectional search.
|
||||
return GetHierarchicalPathFinder(locomotor, check, ignoreActor).FindPath(
|
||||
self, sourcesList, target, check, DefaultHeuristicWeightPercentage, customCost, ignoreActor, laneBias, pathFinderOverlay);
|
||||
self, sources, target, check, DefaultHeuristicWeightPercentage, customCost, ignoreActor, laneBias, pathFinderOverlay);
|
||||
}
|
||||
|
||||
HierarchicalPathFinder GetHierarchicalPathFinder(Locomotor locomotor, BlockedByActor check, Actor ignoreActor)
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public class Selection : ISelection, INotifyCreated, INotifyOwnerChanged, ITick, IGameSaveTraitData
|
||||
{
|
||||
public int Hash { get; private set; }
|
||||
public IEnumerable<Actor> Actors => actors;
|
||||
public IReadOnlyCollection<Actor> Actors => actors;
|
||||
|
||||
readonly HashSet<Actor> actors = new();
|
||||
readonly List<Actor> rolloverActors = new();
|
||||
@@ -91,10 +91,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public virtual void Combine(World world, IEnumerable<Actor> newSelection, bool isCombine, bool isClick)
|
||||
{
|
||||
var newSelectionCollection = newSelection as IReadOnlyCollection<Actor>;
|
||||
newSelectionCollection ??= newSelection.ToList();
|
||||
|
||||
if (isClick)
|
||||
{
|
||||
// TODO: select BEST, not FIRST
|
||||
var adjNewSelection = newSelection.Take(1);
|
||||
var adjNewSelection = newSelectionCollection.Take(1);
|
||||
if (isCombine)
|
||||
actors.SymmetricExceptWith(adjNewSelection);
|
||||
else
|
||||
@@ -106,17 +109,17 @@ namespace OpenRA.Mods.Common.Traits
|
||||
else
|
||||
{
|
||||
if (isCombine)
|
||||
actors.UnionWith(newSelection);
|
||||
actors.UnionWith(newSelectionCollection);
|
||||
else
|
||||
{
|
||||
actors.Clear();
|
||||
actors.UnionWith(newSelection);
|
||||
actors.UnionWith(newSelectionCollection);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateHash();
|
||||
|
||||
foreach (var a in newSelection)
|
||||
foreach (var a in newSelectionCollection)
|
||||
foreach (var sel in a.TraitsImplementing<INotifySelected>())
|
||||
sel.Selected(a);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user