Fix IDE0039

This commit is contained in:
RoosterDragon
2023-02-19 11:56:54 +00:00
committed by abcdefg30
parent 4b3f7034b2
commit d4135d608e
67 changed files with 498 additions and 505 deletions

View File

@@ -280,11 +280,11 @@ namespace OpenRA.Mods.Common.Traits
foreach (var na in notifyAttacks)
na.PreparingAttack(self, target, this, barrel);
Func<WPos> muzzlePosition = () => self.CenterPosition + MuzzleOffset(self, barrel);
Func<WAngle> muzzleFacing = () => MuzzleOrientation(self, barrel).Yaw;
var muzzleOrientation = WRot.FromYaw(muzzleFacing());
WPos MuzzlePosition() => self.CenterPosition + MuzzleOffset(self, barrel);
WAngle MuzzleFacing() => MuzzleOrientation(self, barrel).Yaw;
var muzzleOrientation = WRot.FromYaw(MuzzleFacing());
var passiveTarget = Weapon.TargetActorCenter ? target.CenterPosition : target.Positions.PositionClosestTo(muzzlePosition());
var passiveTarget = Weapon.TargetActorCenter ? target.CenterPosition : target.Positions.PositionClosestTo(MuzzlePosition());
var initialOffset = Weapon.FirstBurstTargetOffset;
if (initialOffset != WVec.Zero)
{
@@ -304,8 +304,8 @@ namespace OpenRA.Mods.Common.Traits
var args = new ProjectileArgs
{
Weapon = Weapon,
Facing = muzzleFacing(),
CurrentMuzzleFacing = muzzleFacing,
Facing = MuzzleFacing(),
CurrentMuzzleFacing = MuzzleFacing,
DamageModifiers = damageModifiers.ToArray(),
@@ -313,8 +313,8 @@ namespace OpenRA.Mods.Common.Traits
RangeModifiers = rangeModifiers.ToArray(),
Source = muzzlePosition(),
CurrentSource = muzzlePosition,
Source = MuzzlePosition(),
CurrentSource = MuzzlePosition,
SourceActor = self,
PassiveTarget = passiveTarget,
GuidedTarget = target

View File

@@ -390,7 +390,7 @@ namespace OpenRA.Mods.Common.Traits
return (null, 0);
// Find the buildable cell that is closest to pos and centered around center
Func<CPos, CPos, int, int, (CPos? Location, int Variant)> findPos = (center, target, minRange, maxRange) =>
(CPos? Location, int Variant) FindPos(CPos center, CPos target, int minRange, int maxRange)
{
var actorVariant = 0;
var buildingVariantInfo = actorInfo.TraitInfoOrDefault<PlaceBuildingVariantsInfo>();
@@ -461,7 +461,7 @@ namespace OpenRA.Mods.Common.Traits
}
return (null, 0);
};
}
var baseCenter = baseBuilder.GetRandomBaseCenter();
@@ -475,7 +475,7 @@ namespace OpenRA.Mods.Common.Traits
var targetCell = closestEnemy != null ? closestEnemy.Location : baseCenter;
return findPos(baseBuilder.DefenseCenter, targetCell, baseBuilder.Info.MinimumDefenseRadius, baseBuilder.Info.MaximumDefenseRadius);
return FindPos(baseBuilder.DefenseCenter, targetCell, baseBuilder.Info.MinimumDefenseRadius, baseBuilder.Info.MaximumDefenseRadius);
case BuildingType.Refinery:
@@ -488,17 +488,17 @@ namespace OpenRA.Mods.Common.Traits
foreach (var r in nearbyResources)
{
var found = findPos(baseCenter, r, baseBuilder.Info.MinBaseRadius, baseBuilder.Info.MaxBaseRadius);
var found = FindPos(baseCenter, r, baseBuilder.Info.MinBaseRadius, baseBuilder.Info.MaxBaseRadius);
if (found.Location != null)
return found;
}
}
// Try and find a free spot somewhere else in the base
return findPos(baseCenter, baseCenter, baseBuilder.Info.MinBaseRadius, baseBuilder.Info.MaxBaseRadius);
return FindPos(baseCenter, baseCenter, baseBuilder.Info.MinBaseRadius, baseBuilder.Info.MaxBaseRadius);
case BuildingType.Building:
return findPos(baseCenter, baseCenter, baseBuilder.Info.MinBaseRadius,
return FindPos(baseCenter, baseCenter, baseBuilder.Info.MinBaseRadius,
distanceToBaseIsImportant ? baseBuilder.Info.MaxBaseRadius : world.Map.Grid.MaximumTileSearchRange);
}

View File

@@ -138,12 +138,12 @@ namespace OpenRA.Mods.Common.Traits
Target FindNextResource(Actor actor, HarvesterTraitWrapper harv)
{
Func<CPos, bool> isValidResource = cell =>
bool IsValidResource(CPos cell) =>
harv.Harvester.CanHarvestCell(cell) &&
claimLayer.CanClaimCell(actor, cell);
var path = harv.Mobile.PathFinder.FindPathToTargetCellByPredicate(
actor, new[] { actor.Location }, isValidResource, BlockedByActor.Stationary,
actor, new[] { actor.Location }, IsValidResource, BlockedByActor.Stationary,
loc => world.FindActorsInCircle(world.Map.CenterOfCell(loc), Info.HarvesterEnemyAvoidanceRadius)
.Where(u => !u.IsDead && actor.Owner.RelationshipWith(u.Owner) == PlayerRelationship.Enemy)
.Sum(u => Math.Max(WDist.Zero.Length, Info.HarvesterEnemyAvoidanceRadius.Length - (world.Map.CenterOfCell(loc) - u.CenterPosition).Length)));

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
@@ -178,7 +177,7 @@ namespace OpenRA.Mods.Common.Traits
return null;
// Find the buildable cell that is closest to pos and centered around center
Func<CPos, CPos, int, int, CPos?> findPos = (center, target, minRange, maxRange) =>
CPos? FindPos(CPos center, CPos target, int minRange, int maxRange)
{
var cells = world.Map.FindTilesInAnnulus(center, minRange, maxRange);
@@ -193,11 +192,11 @@ namespace OpenRA.Mods.Common.Traits
return cell;
return null;
};
}
var baseCenter = GetRandomBaseCenter();
return findPos(baseCenter, baseCenter, Info.MinBaseRadius,
return FindPos(baseCenter, baseCenter, Info.MinBaseRadius,
distanceToBaseIsImportant ? Info.MaxBaseRadius : world.Map.Grid.MaximumTileSearchRange);
}

View File

@@ -74,15 +74,15 @@ namespace OpenRA.Mods.Common.Traits.Render
anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
Func<WRot> orientation = () => body.QuantizeOrientation(WRot.FromYaw(facing()), facings);
Func<WVec> offset = () => body.LocalToWorld(Offset.Rotate(orientation()));
Func<int> zOffset = () =>
WRot Orientation() => body.QuantizeOrientation(WRot.FromYaw(facing()), facings);
WVec Offset() => body.LocalToWorld(this.Offset.Rotate(Orientation()));
int ZOffset()
{
var tmpOffset = offset();
var tmpOffset = Offset();
return tmpOffset.Y + tmpOffset.Z + 1;
};
}
yield return new SpriteActorPreview(anim, offset, zOffset, p);
yield return new SpriteActorPreview(anim, Offset, ZOffset, p);
}
}

View File

@@ -90,15 +90,15 @@ namespace OpenRA.Mods.Common.Traits.Render
anim.PlayThen(OpeningSequence, () => anim.PlayRepeating(Sequence));
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
Func<WRot> orientation = () => body.QuantizeOrientation(WRot.FromYaw(facing()), facings);
Func<WVec> offset = () => body.LocalToWorld(Offset.Rotate(orientation()));
Func<int> zOffset = () =>
WRot Orientation() => body.QuantizeOrientation(WRot.FromYaw(facing()), facings);
WVec Offset() => body.LocalToWorld(this.Offset.Rotate(Orientation()));
int ZOffset()
{
var tmpOffset = offset();
var tmpOffset = Offset();
return tmpOffset.Y + tmpOffset.Z + 1;
};
}
yield return new SpriteActorPreview(anim, offset, zOffset, p);
yield return new SpriteActorPreview(anim, Offset, ZOffset, p);
}
}

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
@@ -50,15 +49,15 @@ namespace OpenRA.Mods.Common.Traits.Render
anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
var facing = init.GetFacing();
Func<WRot> orientation = () => body.QuantizeOrientation(WRot.FromYaw(facing()), facings);
Func<WVec> turretOffset = () => body.LocalToWorld(t.Offset.Rotate(orientation()));
Func<int> zOffset = () =>
WRot Orientation() => body.QuantizeOrientation(WRot.FromYaw(facing()), facings);
WVec TurretOffset() => body.LocalToWorld(t.Offset.Rotate(Orientation()));
int ZOffset()
{
var tmpOffset = turretOffset();
var tmpOffset = TurretOffset();
return -(tmpOffset.Y + tmpOffset.Z) + 1;
};
}
yield return new SpriteActorPreview(anim, turretOffset, zOffset, p);
yield return new SpriteActorPreview(anim, TurretOffset, ZOffset, p);
}
}

View File

@@ -75,18 +75,18 @@ namespace OpenRA.Mods.Common.Traits.Render
{
rs = init.Self.Trait<RenderSprites>();
Func<bool> paused = () => IsTraitPaused &&
bool Paused() => IsTraitPaused &&
DefaultAnimation.CurrentSequence.Name == NormalizeSequence(init.Self, Info.Sequence);
Func<WVec> subtractDAT = null;
if (info.ForceToGround)
subtractDAT = () => new WVec(0, 0, -init.Self.World.Map.DistanceAboveTerrain(init.Self.CenterPosition).Length);
DefaultAnimation = new Animation(init.World, rs.GetImage(init.Self), baseFacing, paused);
DefaultAnimation = new Animation(init.World, rs.GetImage(init.Self), baseFacing, Paused);
rs.Add(new AnimationWithOffset(DefaultAnimation, subtractDAT, () => IsTraitDisabled), info.Palette, info.IsPlayerPalette);
// Cache the bounds from the default sequence to avoid flickering when the animation changes
boundsAnimation = new Animation(init.World, rs.GetImage(init.Self), baseFacing, paused);
boundsAnimation = new Animation(init.World, rs.GetImage(init.Self), baseFacing, Paused);
boundsAnimation.PlayRepeating(info.Sequence);
}

View File

@@ -55,20 +55,20 @@ namespace OpenRA.Mods.Common.Traits.Render
anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
var facing = init.GetFacing();
Func<WRot> orientation = () => body.QuantizeOrientation(WRot.FromYaw(facing()), facings);
Func<WVec> offset = () => body.LocalToWorld(t.Offset.Rotate(orientation()));
Func<int> zOffset = () =>
WRot Orientation() => body.QuantizeOrientation(WRot.FromYaw(facing()), facings);
WVec Offset() => body.LocalToWorld(t.Offset.Rotate(Orientation()));
int ZOffset()
{
var tmpOffset = offset();
var tmpOffset = Offset();
return -(tmpOffset.Y + tmpOffset.Z) + 1;
};
}
if (IsPlayerPalette)
p = init.WorldRenderer.Palette(Palette + init.Get<OwnerInit>().InternalName);
else if (Palette != null)
p = init.WorldRenderer.Palette(Palette);
yield return new SpriteActorPreview(anim, offset, zOffset, p);
yield return new SpriteActorPreview(anim, Offset, ZOffset, p);
}
}

View File

@@ -52,10 +52,10 @@ namespace OpenRA.Mods.Common.Traits.Render
var model = init.World.ModelCache.GetModelSequence(image, Sequence);
var turretOrientation = t.PreviewOrientation(init, orientation, facings);
Func<WVec> barrelOffset = () => body.LocalToWorld(t.Offset + LocalOffset.Rotate(turretOrientation()));
Func<WRot> barrelOrientation = () => LocalOrientation.Rotate(turretOrientation());
WVec BarrelOffset() => body.LocalToWorld(t.Offset + LocalOffset.Rotate(turretOrientation()));
WRot BarrelOrientation() => LocalOrientation.Rotate(turretOrientation());
yield return new ModelAnimation(model, barrelOffset, barrelOrientation, () => false, () => 0, ShowShadow);
yield return new ModelAnimation(model, BarrelOffset, BarrelOrientation, () => false, () => 0, ShowShadow);
}
}

View File

@@ -94,7 +94,7 @@ namespace OpenRA.Mods.Common.Traits
Beacon beacon = null;
var aircraftInRange = new Dictionary<Actor, bool>();
Action<Actor> onEnterRange = a =>
void OnEnterRange(Actor a)
{
// Spawn a camera and remove the beacon when the first plane enters the target area
if (info.CameraActor != null && camera == null && !aircraftInRange.Any(kv => kv.Value))
@@ -112,18 +112,18 @@ namespace OpenRA.Mods.Common.Traits
RemoveBeacon(beacon);
aircraftInRange[a] = true;
};
}
Action<Actor> onExitRange = a =>
void OnExitRange(Actor a)
{
aircraftInRange[a] = false;
// Remove the camera when the final plane leaves the target area
if (!aircraftInRange.Any(kv => kv.Value))
RemoveCamera(camera);
};
}
Action<Actor> onRemovedFromWorld = a =>
void OnRemovedFromWorld(Actor a)
{
aircraftInRange[a] = false;
@@ -135,7 +135,7 @@ namespace OpenRA.Mods.Common.Traits
RemoveCamera(camera);
RemoveBeacon(beacon);
}
};
}
// Create the actors immediately so they can be returned
for (var i = -info.SquadSize / 2; i <= info.SquadSize / 2; i++)
@@ -160,9 +160,9 @@ namespace OpenRA.Mods.Common.Traits
var attack = a.Trait<AttackBomber>();
attack.SetTarget(target + targetOffset);
attack.OnEnteredAttackRange += onEnterRange;
attack.OnExitedAttackRange += onExitRange;
attack.OnRemovedFromWorld += onRemovedFromWorld;
attack.OnEnteredAttackRange += OnEnterRange;
attack.OnExitedAttackRange += OnExitRange;
attack.OnRemovedFromWorld += OnRemovedFromWorld;
}
self.World.AddFrameEndTask(w =>

View File

@@ -119,7 +119,7 @@ namespace OpenRA.Mods.Common.Traits
Beacon beacon = null;
var aircraftInRange = new Dictionary<Actor, bool>();
Action<Actor> onEnterRange = a =>
void OnEnterRange(Actor a)
{
// Spawn a camera and remove the beacon when the first plane enters the target area
if (info.CameraActor != null && camera == null && !aircraftInRange.Any(kv => kv.Value))
@@ -145,18 +145,18 @@ namespace OpenRA.Mods.Common.Traits
}
aircraftInRange[a] = true;
};
}
Action<Actor> onExitRange = a =>
void OnExitRange(Actor a)
{
aircraftInRange[a] = false;
// Remove the camera when the final plane leaves the target area
if (!aircraftInRange.Any(kv => kv.Value))
RemoveCamera(camera);
};
}
Action<Actor> onRemovedFromWorld = a =>
void OnRemovedFromWorld(Actor a)
{
aircraftInRange[a] = false;
@@ -168,7 +168,7 @@ namespace OpenRA.Mods.Common.Traits
RemoveCamera(camera);
RemoveBeacon(beacon);
}
};
}
// Create the actors immediately so they can be returned
for (var i = -info.SquadSize / 2; i <= info.SquadSize / 2; i++)
@@ -221,9 +221,9 @@ namespace OpenRA.Mods.Common.Traits
var drop = a.Trait<ParaDrop>();
drop.SetLZ(w.Map.CellContaining(target + targetOffset), !info.AllowImpassableCells);
drop.OnEnteredDropRange += onEnterRange;
drop.OnExitedDropRange += onExitRange;
drop.OnRemovedFromWorld += onRemovedFromWorld;
drop.OnEnteredDropRange += OnEnterRange;
drop.OnExitedDropRange += OnExitRange;
drop.OnRemovedFromWorld += OnRemovedFromWorld;
var cargo = a.Trait<Cargo>();
foreach (var unit in units.Skip(added).Take(passengersPerPlane))

View File

@@ -115,13 +115,13 @@ namespace OpenRA.Mods.Common.Traits
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
var turretFacing = LocalFacingFromInit(init);
Func<WRot> world = () => WRot.FromYaw(turretFacing()).Rotate(orientation());
WRot World() => WRot.FromYaw(turretFacing()).Rotate(orientation());
if (facings == 0)
return world;
return World;
// Quantize orientation to match a rendered sprite
// Implies no pitch or roll
return () => WRot.FromYaw(body.QuantizeFacing(world().Yaw, facings));
return () => WRot.FromYaw(body.QuantizeFacing(World().Yaw, facings));
}
public override object Create(ActorInitializer init) { return new Turreted(init, this); }

View File

@@ -207,7 +207,7 @@ namespace OpenRA.Mods.Common.Traits
public MiniYaml Save()
{
Func<object, bool> saveInit = init =>
bool SaveInit(ActorInit init)
{
if (init is FactionInit factionInit && factionInit.Value == Owner.Faction)
return false;
@@ -218,9 +218,9 @@ namespace OpenRA.Mods.Common.Traits
// TODO: Other default values will need to be filtered
// here after we have built a properties panel
return true;
};
}
return reference.Save(saveInit);
return reference.Save(SaveInit);
}
WPos PreviewPosition(World world, ActorReference actor)

View File

@@ -303,12 +303,12 @@ namespace OpenRA.Mods.Common.Traits
if (check > BlockedByActor.None)
{
Func<Actor, bool> checkTransient = otherActor => IsBlockedBy(self, otherActor, ignoreActor, cell, check, GetCache(cell).CellFlag);
bool CheckTransient(Actor otherActor) => IsBlockedBy(self, otherActor, ignoreActor, cell, check, GetCache(cell).CellFlag);
if (!sharesCell)
return world.ActorMap.AnyActorsAt(cell, SubCell.FullCell, checkTransient) ? SubCell.Invalid : SubCell.FullCell;
return world.ActorMap.AnyActorsAt(cell, SubCell.FullCell, CheckTransient) ? SubCell.Invalid : SubCell.FullCell;
return world.ActorMap.FreeSubCell(cell, preferredSubCell, checkTransient);
return world.ActorMap.FreeSubCell(cell, preferredSubCell, CheckTransient);
}
if (!sharesCell)

View File

@@ -26,14 +26,14 @@ namespace OpenRA.Mods.Common.Traits
{
var missingImages = new HashSet<string>();
var failed = false;
Action<uint, string> onMissingImage = (id, f) =>
void OnMissingImage(uint id, string f)
{
onError($"\tTemplate `{id}` references sprite `{f}` that does not exist.");
missingImages.Add(f);
failed = true;
};
}
var tileCache = new DefaultTileCache((DefaultTerrain)terrainInfo, onMissingImage);
var tileCache = new DefaultTileCache((DefaultTerrain)terrainInfo, OnMissingImage);
foreach (var t in terrainInfo.Templates)
{
var templateInfo = (DefaultTerrainTemplateInfo)t.Value;