.Any(), .Count() -> .Count or .Length

This commit is contained in:
Eduardo Cáceres
2022-05-02 13:05:22 +02:00
committed by atlimit8
parent 6eb4fe8980
commit 79f321cb44
138 changed files with 233 additions and 258 deletions

View File

@@ -255,7 +255,7 @@ namespace OpenRA.Mods.Common.Traits
// Require at least one refinery, unless we can't build it.
public bool HasAdequateRefineryCount =>
!Info.RefineryTypes.Any() ||
Info.RefineryTypes.Count == 0 ||
AIUtils.CountBuildingByCommonName(Info.RefineryTypes, player) >= MinimumRefineryCount ||
AIUtils.CountBuildingByCommonName(Info.PowerTypes, player) == 0 ||
AIUtils.CountBuildingByCommonName(Info.ConstructionYardTypes, player) == 0;

View File

@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
this.category = category;
failRetryTicks = baseBuilder.Info.StructureProductionResumeDelay;
minimumExcessPower = baseBuilder.Info.MinimumExcessPower;
if (!baseBuilder.Info.NavalProductionTypes.Any())
if (baseBuilder.Info.NavalProductionTypes.Count == 0)
waterState = WaterCheck.DontCheck;
}
@@ -98,7 +98,7 @@ namespace OpenRA.Mods.Common.Traits
return;
playerBuildings = world.ActorsHavingTrait<Building>().Where(a => a.Owner == player).ToArray();
var excessPowerBonus = baseBuilder.Info.ExcessPowerIncrement * (playerBuildings.Count() / baseBuilder.Info.ExcessPowerIncreaseThreshold.Clamp(1, int.MaxValue));
var excessPowerBonus = baseBuilder.Info.ExcessPowerIncrement * (playerBuildings.Length / baseBuilder.Info.ExcessPowerIncreaseThreshold.Clamp(1, int.MaxValue));
minimumExcessPower = (baseBuilder.Info.MinimumExcessPower + excessPowerBonus).Clamp(baseBuilder.Info.MinimumExcessPower, baseBuilder.Info.MaximumExcessPower);
var active = false;

View File

@@ -115,7 +115,7 @@ namespace OpenRA.Mods.Common.Traits
void QueueCaptureOrders(IBot bot)
{
if (!Info.CapturingActorTypes.Any() || player.WinState != WinState.Undefined)
if (Info.CapturingActorTypes.Count == 0 || player.WinState != WinState.Undefined)
return;
activeCapturers.RemoveAll(unitCannotBeOrderedOrIsIdle);
@@ -151,7 +151,7 @@ namespace OpenRA.Mods.Common.Traits
.OrderByDescending(target => target.GetSellValue())
.Take(maximumCaptureTargetOptions);
if (Info.CapturableActorTypes.Any())
if (Info.CapturableActorTypes.Count > 0)
capturableTargetOptions = capturableTargetOptions.Where(target => Info.CapturableActorTypes.Contains(target.Info.Name.ToLowerInvariant()));
if (!capturableTargetOptions.Any())

View File

@@ -127,7 +127,7 @@ namespace OpenRA.Mods.Common.Traits
// Less harvesters than refineries - build a new harvester
var unitBuilder = requestUnitProduction.FirstOrDefault(Exts.IsTraitEnabled);
if (unitBuilder != null && Info.HarvesterTypes.Any())
if (unitBuilder != null && Info.HarvesterTypes.Count > 0)
{
var harvInfo = AIUtils.GetInfoByCommonName(Info.HarvesterTypes, player);
var harvCountTooLow = AIUtils.CountActorByCommonName(Info.HarvesterTypes, player) < AIUtils.CountBuildingByCommonName(Info.RefineryTypes, player);

View File

@@ -317,7 +317,7 @@ namespace OpenRA.Mods.Common.Traits
.Where(unit => unit.IsIdle && unit.Info.HasTraitInfo<AttackBaseInfo>()
&& !Info.AirUnitsTypes.Contains(unit.Info.Name) && !Info.NavalUnitsTypes.Contains(unit.Info.Name) && !Info.ExcludeFromSquadsTypes.Contains(unit.Info.Name)).ToList();
if (!allEnemyBaseBuilder.Any() || ownUnits.Count < Info.SquadSize)
if (allEnemyBaseBuilder.Count == 0 || ownUnits.Count < Info.SquadSize)
return;
foreach (var b in allEnemyBaseBuilder)
@@ -328,7 +328,7 @@ namespace OpenRA.Mods.Common.Traits
if (AttackOrFleeFuzzy.Rush.CanAttack(ownUnits, enemies))
{
var target = enemies.Any() ? enemies.Random(World.LocalRandom) : b;
var target = enemies.Count > 0 ? enemies.Random(World.LocalRandom) : b;
var rush = GetSquadOfType(SquadType.Rush);
if (rush == null)
rush = RegisterNewSquad(bot, SquadType.Rush, target);

View File

@@ -68,7 +68,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads
FuzzyStateMachine.Update(this);
}
public bool IsValid => Units.Any();
public bool IsValid => Units.Count > 0;
public Actor TargetActor
{

View File

@@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads
var unitsAroundPos = owner.World.FindActorsInCircle(loc, WDist.FromCells(dangerRadius))
.Where(owner.SquadManager.IsPreferredEnemyUnit).ToList();
if (!unitsAroundPos.Any())
if (unitsAroundPos.Count == 0)
return true;
if (CountAntiAirUnits(unitsAroundPos) * MissileUnitMultiplier < owner.Units.Count)