Fix CA1851, assume_method_enumerates_parameters = true

This commit is contained in:
RoosterDragon
2023-07-14 20:30:08 +01:00
committed by abcdefg30
parent 3275875ae5
commit 93a97d5d6f
37 changed files with 108 additions and 96 deletions

View File

@@ -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;

View File

@@ -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,

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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)