Fix IDE0074
This commit is contained in:
committed by
Pavel Penev
parent
cbd0583289
commit
bd2b3d9793
@@ -453,8 +453,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// If all are out of ammo, just use valid armament with highest range
|
||||
armaments = armaments.OrderByDescending(x => x.MaxRange());
|
||||
var a = armaments.FirstOrDefault(x => !x.IsTraitPaused);
|
||||
if (a == null)
|
||||
a = armaments.First();
|
||||
a ??= armaments.First();
|
||||
|
||||
var outOfRange = !target.IsInRange(self.CenterPosition, a.MaxRange()) ||
|
||||
(!forceAttack && target.Type == TargetType.FrozenActor && !ab.Info.TargetFrozenActors);
|
||||
@@ -491,8 +490,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// If all are out of ammo, just use valid armament with highest range
|
||||
armaments = armaments.OrderByDescending(x => x.MaxRange());
|
||||
var a = armaments.FirstOrDefault(x => !x.IsTraitPaused);
|
||||
if (a == null)
|
||||
a = armaments.First();
|
||||
a ??= armaments.First();
|
||||
|
||||
cursor = !target.IsInRange(self.CenterPosition, a.MaxRange())
|
||||
? ab.Info.OutsideRangeCursor ?? a.Info.OutsideRangeCursor
|
||||
|
||||
@@ -272,16 +272,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (Info.AirUnitsTypes.Contains(a.Info.Name))
|
||||
{
|
||||
var air = GetSquadOfType(SquadType.Air);
|
||||
if (air == null)
|
||||
air = RegisterNewSquad(bot, SquadType.Air);
|
||||
air ??= RegisterNewSquad(bot, SquadType.Air);
|
||||
|
||||
air.Units.Add(a);
|
||||
}
|
||||
else if (Info.NavalUnitsTypes.Contains(a.Info.Name))
|
||||
{
|
||||
var ships = GetSquadOfType(SquadType.Naval);
|
||||
if (ships == null)
|
||||
ships = RegisterNewSquad(bot, SquadType.Naval);
|
||||
ships ??= RegisterNewSquad(bot, SquadType.Naval);
|
||||
|
||||
ships.Units.Add(a);
|
||||
}
|
||||
@@ -336,8 +334,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var target = enemies.Count > 0 ? enemies.Random(World.LocalRandom) : b;
|
||||
var rush = GetSquadOfType(SquadType.Rush);
|
||||
if (rush == null)
|
||||
rush = RegisterNewSquad(bot, SquadType.Rush, target);
|
||||
rush ??= RegisterNewSquad(bot, SquadType.Rush, target);
|
||||
|
||||
foreach (var a3 in ownUnits)
|
||||
rush.Units.Add(a3);
|
||||
@@ -350,8 +347,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
void ProtectOwn(IBot bot, Actor attacker)
|
||||
{
|
||||
var protectSq = GetSquadOfType(SquadType.Protection);
|
||||
if (protectSq == null)
|
||||
protectSq = RegisterNewSquad(bot, SquadType.Protection, attacker);
|
||||
protectSq ??= RegisterNewSquad(bot, SquadType.Protection, attacker);
|
||||
|
||||
if (!protectSq.IsTargetValid)
|
||||
protectSq.TargetActor = attacker;
|
||||
|
||||
@@ -45,8 +45,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (r.IsTraitDisabled)
|
||||
continue;
|
||||
|
||||
if (acceptedReplacements == null)
|
||||
acceptedReplacements = new HashSet<string>();
|
||||
acceptedReplacements ??= new HashSet<string>();
|
||||
|
||||
acceptedReplacements.UnionWith(r.Info.Types);
|
||||
}
|
||||
|
||||
@@ -84,8 +84,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
void INotifyLineBuildSegmentsChanged.SegmentAdded(Actor self, Actor segment)
|
||||
{
|
||||
if (segments == null)
|
||||
segments = new HashSet<Actor>();
|
||||
segments ??= new HashSet<Actor>();
|
||||
|
||||
segments.Add(segment);
|
||||
}
|
||||
|
||||
@@ -120,8 +120,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public bool CanEnterCell(World world, Actor self, CPos cell, SubCell subCell = SubCell.FullCell, Actor ignoreActor = null, BlockedByActor check = BlockedByActor.All)
|
||||
{
|
||||
// PERF: Avoid repeated trait queries on the hot path
|
||||
if (locomotor == null)
|
||||
locomotor = world.WorldActor.TraitsImplementing<Locomotor>()
|
||||
locomotor ??= world.WorldActor.TraitsImplementing<Locomotor>()
|
||||
.SingleOrDefault(l => l.Info.Name == Locomotor);
|
||||
|
||||
return locomotor.MovementCostToEnterCell(
|
||||
@@ -131,8 +130,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public bool CanStayInCell(World world, CPos cell)
|
||||
{
|
||||
// PERF: Avoid repeated trait queries on the hot path
|
||||
if (locomotor == null)
|
||||
locomotor = world.WorldActor.TraitsImplementing<Locomotor>()
|
||||
locomotor ??= world.WorldActor.TraitsImplementing<Locomotor>()
|
||||
.SingleOrDefault(l => l.Info.Name == Locomotor);
|
||||
|
||||
if (cell.Layer == CustomMovementLayerType.Tunnel)
|
||||
|
||||
@@ -57,8 +57,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
mo.MarkFailed(self.Owner, objectiveID);
|
||||
|
||||
// Players, NonCombatants, and IsAlliedWith are all fixed once the game starts, so we can cache the result.
|
||||
if (otherPlayers == null)
|
||||
otherPlayers = self.World.Players.Where(p => !p.NonCombatant && !p.IsAlliedWith(self.Owner)).ToArray();
|
||||
otherPlayers ??= self.World.Players.Where(p => !p.NonCombatant && !p.IsAlliedWith(self.Owner)).ToArray();
|
||||
|
||||
if (otherPlayers.Length == 0) return;
|
||||
|
||||
|
||||
@@ -29,9 +29,8 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
// Per-actor queue
|
||||
var queue = ai.TraitInfos<ProductionQueueInfo>().FirstOrDefault(q => ProductionType == q.Type);
|
||||
|
||||
// No queues available - check for classic production queues
|
||||
if (queue == null)
|
||||
queue = rules.Actors[SystemActors.Player].TraitInfos<ProductionQueueInfo>().FirstOrDefault(q => ProductionType == q.Type);
|
||||
// If no queues available - check for classic production queues
|
||||
queue ??= rules.Actors[SystemActors.Player].TraitInfos<ProductionQueueInfo>().FirstOrDefault(q => ProductionType == q.Type);
|
||||
|
||||
if (queue == null)
|
||||
throw new YamlException($"Can't find a queue with ProductionType '{ProductionType}'");
|
||||
@@ -67,12 +66,9 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
queue = self.TraitsImplementing<ProductionQueue>()
|
||||
.FirstOrDefault(q => Info.ProductionType == q.Info.Type);
|
||||
|
||||
if (queue == null)
|
||||
{
|
||||
// No queues available - check for classic production queues
|
||||
queue = self.Owner.PlayerActor.TraitsImplementing<ProductionQueue>()
|
||||
.FirstOrDefault(q => Info.ProductionType == q.Info.Type);
|
||||
}
|
||||
// If no queues available - check for classic production queues
|
||||
queue ??= self.Owner.PlayerActor.TraitsImplementing<ProductionQueue>()
|
||||
.FirstOrDefault(q => Info.ProductionType == q.Info.Type);
|
||||
}
|
||||
|
||||
void ITick.Tick(Actor self)
|
||||
|
||||
@@ -101,8 +101,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
|
||||
if (selected && self.World.LocalPlayer != null)
|
||||
{
|
||||
if (developerMode == null)
|
||||
developerMode = self.World.LocalPlayer.PlayerActor.Trait<DeveloperMode>();
|
||||
developerMode ??= self.World.LocalPlayer.PlayerActor.Trait<DeveloperMode>();
|
||||
|
||||
if (developerMode.PathDebug)
|
||||
yield return new TargetLineRenderable(ActivityTargetPath(self), Color.Green, 1, 2);
|
||||
|
||||
Reference in New Issue
Block a user