Use in parameter for Target

This commit is contained in:
teinarss
2020-08-19 20:47:59 +02:00
committed by abcdefg30
parent 13a8b6bda2
commit 13581c030d
113 changed files with 259 additions and 240 deletions

View File

@@ -31,13 +31,13 @@ namespace OpenRA.Mods.Common.Activities
bool useLastVisibleTarget;
readonly List<WPos> positionBuffer = new List<WPos>();
public Fly(Actor self, Target t, WDist nearEnough, WPos? initialTargetPosition = null, Color? targetLineColor = null)
public Fly(Actor self, in Target t, WDist nearEnough, WPos? initialTargetPosition = null, Color? targetLineColor = null)
: this(self, t, initialTargetPosition, targetLineColor)
{
this.nearEnough = nearEnough;
}
public Fly(Actor self, Target t, WPos? initialTargetPosition = null, Color? targetLineColor = null)
public Fly(Actor self, in Target t, WPos? initialTargetPosition = null, Color? targetLineColor = null)
{
aircraft = self.Trait<Aircraft>();
target = t;
@@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.Activities
lastVisibleTarget = Target.FromPos(initialTargetPosition.Value);
}
public Fly(Actor self, Target t, WDist minRange, WDist maxRange,
public Fly(Actor self, in Target t, WDist minRange, WDist maxRange,
WPos? initialTargetPosition = null, Color? targetLineColor = null)
: this(self, t, initialTargetPosition, targetLineColor)
{

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Activities
bool hasTicked;
bool returnToBase;
public FlyAttack(Actor self, AttackSource source, Target target, bool forceAttack, Color? targetLineColor)
public FlyAttack(Actor self, AttackSource source, in Target target, bool forceAttack, Color? targetLineColor)
{
this.source = source;
this.target = target;
@@ -211,7 +211,7 @@ namespace OpenRA.Mods.Common.Activities
WDist exitRange;
bool targetIsVisibleActor;
public FlyAttackRun(Actor self, Target t, WDist exitRange)
public FlyAttackRun(Actor self, in Target t, WDist exitRange)
{
ChildHasPriority = false;
@@ -254,7 +254,7 @@ namespace OpenRA.Mods.Common.Activities
WDist exitRange;
readonly AttackAircraft attackAircraft;
public StrafeAttackRun(Actor self, AttackAircraft attackAircraft, Target t, WDist exitRange)
public StrafeAttackRun(Actor self, AttackAircraft attackAircraft, in Target t, WDist exitRange)
{
ChildHasPriority = false;

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Activities
bool useLastVisibleTarget;
bool wasMovingWithinRange;
public FlyFollow(Actor self, Target target, WDist minRange, WDist maxRange,
public FlyFollow(Actor self, in Target target, WDist minRange, WDist maxRange,
WPos? initialTargetPosition, Color? targetLineColor = null)
{
this.target = target;

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Activities
this.endingDelay = endingDelay;
}
public FlyOffMap(Actor self, Target target, int endingDelay = 25)
public FlyOffMap(Actor self, in Target target, int endingDelay = 25)
: this(self, endingDelay)
{
this.target = target;

View File

@@ -40,16 +40,16 @@ namespace OpenRA.Mods.Common.Activities
assignTargetOnFirstRun = true;
}
public Land(Actor self, Target target, WAngle? facing = null, Color? targetLineColor = null)
public Land(Actor self, in Target target, WAngle? facing = null, Color? targetLineColor = null)
: this(self, target, new WDist(-1), WVec.Zero, facing, targetLineColor: targetLineColor) { }
public Land(Actor self, Target target, WDist landRange, WAngle? facing = null, Color? targetLineColor = null)
public Land(Actor self, in Target target, WDist landRange, WAngle? facing = null, Color? targetLineColor = null)
: this(self, target, landRange, WVec.Zero, facing, targetLineColor: targetLineColor) { }
public Land(Actor self, Target target, WVec offset, WAngle? facing = null, Color? targetLineColor = null)
public Land(Actor self, in Target target, WVec offset, WAngle? facing = null, Color? targetLineColor = null)
: this(self, target, WDist.Zero, offset, facing, targetLineColor: targetLineColor) { }
public Land(Actor self, Target target, WDist landRange, WVec offset, WAngle? facing = null, CPos[] clearCells = null, Color? targetLineColor = null)
public Land(Actor self, in Target target, WDist landRange, WVec offset, WAngle? facing = null, CPos[] clearCells = null, Color? targetLineColor = null)
{
aircraft = self.Trait<Aircraft>();
this.target = target;

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Activities
WDist maxRange;
AttackStatus attackStatus = AttackStatus.UnableToAttack;
public Attack(Actor self, Target target, bool allowMovement, bool forceAttack, Color? targetLineColor = null)
public Attack(Actor self, in Target target, bool allowMovement, bool forceAttack, Color? targetLineColor = null)
{
this.target = target;
this.targetLineColor = targetLineColor;
@@ -64,8 +64,11 @@ namespace OpenRA.Mods.Common.Activities
|| target.Type == TargetType.FrozenActor || target.Type == TargetType.Terrain)
{
lastVisibleTarget = Target.FromPos(target.CenterPosition);
// Lambdas can't use 'in' variables, so capture a copy for later
var rangeTarget = target;
lastVisibleMaximumRange = attackTraits.Where(x => !x.IsTraitDisabled)
.Min(x => x.GetMaximumRangeVersusTarget(target));
.Min(x => x.GetMaximumRangeVersusTarget(rangeTarget));
if (target.Type == TargetType.Actor)
{

View File

@@ -22,13 +22,13 @@ namespace OpenRA.Mods.Common.Activities
Actor enterActor;
CaptureManager enterCaptureManager;
public CaptureActor(Actor self, Target target)
public CaptureActor(Actor self, in Target target)
: base(self, target, Color.Crimson)
{
manager = self.Trait<CaptureManager>();
}
protected override void TickInner(Actor self, Target target, bool targetIsDeadOrHiddenActor)
protected override void TickInner(Actor self, in Target target, bool targetIsDeadOrHiddenActor)
{
if (target.Type == TargetType.Actor && enterActor != target.Actor)
{

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Activities
assignTargetOnFirstRun = true;
}
public DeliverUnit(Actor self, Target destination, WDist deliverRange)
public DeliverUnit(Actor self, in Target destination, WDist deliverRange)
{
this.destination = destination;
this.deliverRange = deliverRange;

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Activities
Actor enterActor;
IDemolishable[] enterDemolishables;
public Demolish(Actor self, Target target, EnterBehaviour enterBehaviour, int delay,
public Demolish(Actor self, in Target target, EnterBehaviour enterBehaviour, int delay,
int flashes, int flashesDelay, int flashInterval, BitSet<DamageType> damageTypes)
: base(self, target, Color.Crimson)
{

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Activities
readonly int payload;
readonly int playerExperience;
public DonateCash(Actor self, Target target, int payload, int playerExperience)
public DonateCash(Actor self, in Target target, int payload, int playerExperience)
: base(self, target, Color.Yellow)
{
this.payload = payload;

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Activities
Actor enterActor;
GainsExperience enterGainsExperience;
public DonateExperience(Actor self, Target target, int level, int playerExperience)
public DonateExperience(Actor self, in Target target, int level, int playerExperience)
: base(self, target, Color.Yellow)
{
this.level = level;

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Activities
bool useLastVisibleTarget;
EnterState lastState = EnterState.Approaching;
protected Enter(Actor self, Target target, Color? targetLineColor = null)
protected Enter(Actor self, in Target target, Color? targetLineColor = null)
{
move = self.Trait<IMove>();
this.target = target;
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Activities
/// Called early in the activity tick to allow subclasses to update state.
/// Call Cancel(self, true) if it is no longer valid to enter
/// </summary>
protected virtual void TickInner(Actor self, Target target, bool targetIsDeadOrHiddenActor) { }
protected virtual void TickInner(Actor self, in Target target, bool targetIsDeadOrHiddenActor) { }
/// <summary>
/// Called when the actor is ready to transition from approaching to entering the target actor.

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Activities
bool useLastVisibleTarget;
bool wasMovingWithinRange;
public Follow(Actor self, Target target, WDist minRange, WDist maxRange,
public Follow(Actor self, in Target target, WDist minRange, WDist maxRange,
WPos? initialTargetPosition, Color? targetLineColor = null)
{
this.target = target;

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Activities
protected CPos lastVisibleTargetLocation;
bool useLastVisibleTarget;
public MoveAdjacentTo(Actor self, Target target, WPos? initialTargetPosition = null, Color? targetLineColor = null)
public MoveAdjacentTo(Actor self, in Target target, WPos? initialTargetPosition = null, Color? targetLineColor = null)
{
this.target = target;
this.targetLineColor = targetLineColor;

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Activities
readonly WDist maxRange;
readonly WDist minRange;
public MoveWithinRange(Actor self, Target target, WDist minRange, WDist maxRange,
public MoveWithinRange(Actor self, in Target target, WDist minRange, WDist maxRange,
WPos? initialTargetPosition = null, Color? targetLineColor = null)
: base(self, target, initialTargetPosition, targetLineColor)
{

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Activities
readonly WDist targetMovementThreshold;
WPos targetStartPos;
public VisualMoveIntoTarget(Actor self, Target target, WDist targetMovementThreshold, Color? targetLineColor = null)
public VisualMoveIntoTarget(Actor self, in Target target, WDist targetMovementThreshold, Color? targetLineColor = null)
{
mobile = self.Trait<Mobile>();
this.target = target;

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Activities
BridgeHut enterHut;
LegacyBridgeHut enterLegacyHut;
public RepairBridge(Actor self, Target target, EnterBehaviour enterBehaviour, string notification)
public RepairBridge(Actor self, in Target target, EnterBehaviour enterBehaviour, string notification)
: base(self, target, Color.Yellow)
{
this.enterBehaviour = enterBehaviour;

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Activities
IHealth enterHealth;
EngineerRepairable enterEngineerRepariable;
public RepairBuilding(Actor self, Target target, EngineerRepairInfo info)
public RepairBuilding(Actor self, in Target target, EngineerRepairInfo info)
: base(self, target, Color.Yellow)
{
this.info = info;

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Activities
Cargo enterCargo;
Aircraft enterAircraft;
public RideTransport(Actor self, Target target)
public RideTransport(Actor self, in Target target)
: base(self, target, Color.Green)
{
passenger = self.Trait<Passenger>();

View File

@@ -151,7 +151,7 @@ namespace OpenRA.Mods.Common.Activities
readonly Target target;
readonly Color? targetLineColor;
public IssueOrderAfterTransform(string orderString, Target target, Color? targetLineColor = null)
public IssueOrderAfterTransform(string orderString, in Target target, Color? targetLineColor = null)
{
this.orderString = orderString;
this.target = target;

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Activities
assignTargetOnFirstRun = true;
}
public UnloadCargo(Actor self, Target destination, WDist unloadRange, bool unloadAll = true)
public UnloadCargo(Actor self, in Target destination, WDist unloadRange, bool unloadAll = true)
{
this.self = self;
cargo = self.Trait<Cargo>();

View File

@@ -33,9 +33,9 @@ namespace OpenRA.Mods.Common.Orders
public string OrderID { get; private set; }
public int OrderPriority { get; private set; }
public bool TargetOverridesSelection(Actor self, Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers) { return true; }
public bool TargetOverridesSelection(Actor self, in Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers) { return true; }
public bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
public bool CanTarget(Actor self, in Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
{
if (target.Type != TargetType.Actor)
return false;

View File

@@ -70,10 +70,7 @@ namespace OpenRA.Mods.Common.Orders
if (repairBuilding == null)
yield break;
yield return new Order(orderId, underCursor, Target.FromActor(repairBuilding), mi.Modifiers.HasModifier(Modifiers.Shift))
{
VisualFeedbackTarget = Target.FromActor(underCursor)
};
yield return new Order(orderId, underCursor, Target.FromActor(repairBuilding), Target.FromActor(underCursor), mi.Modifiers.HasModifier(Modifiers.Shift));
}
protected override void Tick(World world)

View File

@@ -32,12 +32,12 @@ namespace OpenRA.Mods.Common.Orders
public string OrderID { get; private set; }
public int OrderPriority { get; private set; }
public bool? ForceAttack = null;
public bool TargetOverridesSelection(Actor self, Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers) { return true; }
public bool TargetOverridesSelection(Actor self, in Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers) { return true; }
public abstract bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor);
public abstract bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor);
public bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
public bool CanTarget(Actor self, in Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
{
var type = target.Type;
if (type != TargetType.Actor && type != TargetType.FrozenActor)

View File

@@ -875,20 +875,20 @@ namespace OpenRA.Mods.Common.Traits
return new Fly(self, Target.FromCell(self.World, cell), WDist.FromCells(nearEnough), targetLineColor: targetLineColor);
}
public Activity MoveWithinRange(Target target, WDist range,
public Activity MoveWithinRange(in Target target, WDist range,
WPos? initialTargetPosition = null, Color? targetLineColor = null)
{
return new Fly(self, target, WDist.Zero, range, initialTargetPosition, targetLineColor);
}
public Activity MoveWithinRange(Target target, WDist minRange, WDist maxRange,
public Activity MoveWithinRange(in Target target, WDist minRange, WDist maxRange,
WPos? initialTargetPosition = null, Color? targetLineColor = null)
{
return new Fly(self, target, minRange, maxRange,
initialTargetPosition, targetLineColor);
}
public Activity MoveFollow(Actor self, Target target, WDist minRange, WDist maxRange,
public Activity MoveFollow(Actor self, in Target target, WDist minRange, WDist maxRange,
WPos? initialTargetPosition = null, Color? targetLineColor = null)
{
return new FlyFollow(self, target, minRange, maxRange,
@@ -934,13 +934,13 @@ namespace OpenRA.Mods.Common.Traits
}
}
public Activity MoveToTarget(Actor self, Target target,
public Activity MoveToTarget(Actor self, in Target target,
WPos? initialTargetPosition = null, Color? targetLineColor = null)
{
return new Fly(self, target, initialTargetPosition, targetLineColor);
}
public Activity MoveIntoTarget(Actor self, Target target)
public Activity MoveIntoTarget(Actor self, in Target target)
{
return new Land(self, target);
}
@@ -978,9 +978,11 @@ namespace OpenRA.Mods.Common.Traits
}
}
public bool CanEnterTargetNow(Actor self, Target target)
public bool CanEnterTargetNow(Actor self, in Target target)
{
if (target.Positions.Any(p => self.World.ActorMap.GetActorsAt(self.World.Map.CellContaining(p)).Any(a => a != self && a != target.Actor)))
// Lambdas can't use 'in' variables, so capture a copy for later
var targetActor = target;
if (target.Positions.Any(p => self.World.ActorMap.GetActorsAt(self.World.Map.CellContaining(p)).Any(a => a != self && a != targetActor.Actor)))
return false;
MakeReservation(target.Actor);
@@ -1015,7 +1017,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
public Order IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (!IsTraitDisabled &&
(order.OrderID == "Enter" || order.OrderID == "Move" || order.OrderID == "Land" || order.OrderID == "ForceEnter"))
@@ -1250,7 +1252,7 @@ namespace OpenRA.Mods.Common.Traits
OrderID = "Move";
}
public bool TargetOverridesSelection(Actor self, Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers)
public bool TargetOverridesSelection(Actor self, in Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers)
{
// Always prioritise orders over selecting other peoples actors or own actors that are already selected
if (target.Type == TargetType.Actor && (target.Actor.Owner != self.Owner || self.World.Selection.Contains(target.Actor)))
@@ -1259,7 +1261,7 @@ namespace OpenRA.Mods.Common.Traits
return modifiers.HasModifier(TargetModifiers.ForceMove);
}
public virtual bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
public virtual bool CanTarget(Actor self, in Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
{
if (target.Type != TargetType.Terrain || (aircraft.requireForceMove && !modifiers.HasModifier(TargetModifiers.ForceMove)))
return false;

View File

@@ -48,12 +48,12 @@ namespace OpenRA.Mods.Common.Traits
aircraftInfo = self.Info.TraitInfo<AircraftInfo>();
}
public override Activity GetAttackActivity(Actor self, AttackSource source, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
public override Activity GetAttackActivity(Actor self, AttackSource source, in Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
{
return new FlyAttack(self, source, newTarget, forceAttack, targetLineColor);
}
protected override bool CanAttack(Actor self, Target target)
protected override bool CanAttack(Actor self, in Target target)
{
// Don't fire while landed or when outside the map.
if (self.World.Map.DistanceAboveTerrain(self.CenterPosition).Length < aircraftInfo.MinAirborneAltitude

View File

@@ -89,7 +89,7 @@ namespace OpenRA.Mods.Common.Traits
OnRemovedFromWorld(self);
}
public override Activity GetAttackActivity(Actor self, AttackSource source, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor)
public override Activity GetAttackActivity(Actor self, AttackSource source, in Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor)
{
throw new NotImplementedException("AttackBomber requires a scripted target");
}

View File

@@ -96,13 +96,13 @@ namespace OpenRA.Mods.Common.Traits
RemainingTicks = Info.ReloadDelay;
}
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel)
void INotifyAttack.Attacking(Actor self, in Target target, Armament a, Barrel barrel)
{
if (a != null && Info.Armaments.Contains(a.Info.Name))
TakeAmmo(self, 1);
}
void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel) { }
void INotifyAttack.PreparingAttack(Actor self, in Target target, Armament a, Barrel barrel) { }
void UpdateCondition(Actor self)
{

View File

@@ -229,7 +229,7 @@ namespace OpenRA.Mods.Common.Traits
a();
}
protected virtual bool CanFire(Actor self, Target target)
protected virtual bool CanFire(Actor self, in Target target)
{
if (IsReloading || IsTraitPaused)
return false;
@@ -249,7 +249,7 @@ namespace OpenRA.Mods.Common.Traits
// Note: facing is only used by the legacy positioning code
// The world coordinate model uses Actor.Orientation
public virtual Barrel CheckFire(Actor self, IFacing facing, Target target)
public virtual Barrel CheckFire(Actor self, IFacing facing, in Target target)
{
if (!CanFire(self, target))
return null;
@@ -271,7 +271,7 @@ namespace OpenRA.Mods.Common.Traits
return barrel;
}
protected virtual void FireBarrel(Actor self, IFacing facing, Target target, Barrel barrel)
protected virtual void FireBarrel(Actor self, IFacing facing, in Target target, Barrel barrel)
{
foreach (var na in notifyAttacks)
na.PreparingAttack(self, target, this, barrel);
@@ -316,6 +316,8 @@ namespace OpenRA.Mods.Common.Traits
GuidedTarget = target
};
// Lambdas can't use 'in' variables, so capture a copy for later
var delayedTarget = target;
ScheduleDelayedAction(Info.FireDelay, () =>
{
if (args.Weapon.Projectile != null)
@@ -331,14 +333,14 @@ namespace OpenRA.Mods.Common.Traits
Game.Sound.Play(SoundType.World, args.Weapon.StartBurstReport, self.World, self.CenterPosition);
foreach (var na in notifyAttacks)
na.Attacking(self, target, this, barrel);
na.Attacking(self, delayedTarget, this, barrel);
Recoil = Info.Recoil;
}
});
}
protected virtual void UpdateBurst(Actor self, Target target)
protected virtual void UpdateBurst(Actor self, in Target target)
{
if (--Burst > 0)
{

View File

@@ -126,7 +126,7 @@ namespace OpenRA.Mods.Common.Traits
return () => armaments;
}
public bool TargetInFiringArc(Actor self, Target target, int facingTolerance)
public bool TargetInFiringArc(Actor self, in Target target, int facingTolerance)
{
if (facing == null)
return true;
@@ -141,7 +141,7 @@ namespace OpenRA.Mods.Common.Traits
return Util.FacingWithinTolerance(facing.Facing, delta.Yaw, facingTolerance);
}
protected virtual bool CanAttack(Actor self, Target target)
protected virtual bool CanAttack(Actor self, in Target target)
{
if (!self.IsInWorld || IsTraitDisabled || IsTraitPaused)
return false;
@@ -162,7 +162,7 @@ namespace OpenRA.Mods.Common.Traits
return true;
}
public virtual void DoAttack(Actor self, Target target)
public virtual void DoAttack(Actor self, in Target target)
{
if (!CanAttack(self, target))
return;
@@ -186,7 +186,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order is AttackOrderTargeter)
return new Order(order.OrderID, self, target, queued);
@@ -226,9 +226,9 @@ namespace OpenRA.Mods.Common.Traits
return order.OrderString == attackOrderName || order.OrderString == forceAttackOrderName ? Info.Voice : null;
}
public abstract Activity GetAttackActivity(Actor self, AttackSource source, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null);
public abstract Activity GetAttackActivity(Actor self, AttackSource source, in Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null);
public bool HasAnyValidWeapons(Target t, bool checkForCenterTargetingWeapons = false)
public bool HasAnyValidWeapons(in Target t, bool checkForCenterTargetingWeapons = false)
{
if (IsTraitDisabled)
return false;
@@ -247,7 +247,7 @@ namespace OpenRA.Mods.Common.Traits
return false;
}
public virtual WPos GetTargetPosition(WPos pos, Target target)
public virtual WPos GetTargetPosition(WPos pos, in Target target)
{
return HasAnyValidWeapons(target, true) ? target.CenterPosition : target.Positions.PositionClosestTo(pos);
}
@@ -298,7 +298,7 @@ namespace OpenRA.Mods.Common.Traits
return max;
}
public WDist GetMinimumRangeVersusTarget(Target target)
public WDist GetMinimumRangeVersusTarget(in Target target)
{
if (IsTraitDisabled)
return WDist.Zero;
@@ -324,7 +324,7 @@ namespace OpenRA.Mods.Common.Traits
return min != WDist.MaxValue ? min : WDist.Zero;
}
public WDist GetMaximumRangeVersusTarget(Target target)
public WDist GetMaximumRangeVersusTarget(in Target target)
{
if (IsTraitDisabled)
return WDist.Zero;
@@ -382,7 +382,7 @@ namespace OpenRA.Mods.Common.Traits
&& a.Weapon.IsValidAgainst(t, self.World, self));
}
public void AttackTarget(Target target, AttackSource source, bool queued, bool allowMove, bool forceAttack = false, Color? targetLineColor = null)
public void AttackTarget(in Target target, AttackSource source, bool queued, bool allowMove, bool forceAttack = false, Color? targetLineColor = null)
{
if (IsTraitDisabled)
return;
@@ -395,9 +395,9 @@ namespace OpenRA.Mods.Common.Traits
OnResolveAttackOrder(self, activity, target, queued, forceAttack);
}
public virtual void OnResolveAttackOrder(Actor self, Activity activity, Target target, bool queued, bool forceAttack) { }
public virtual void OnResolveAttackOrder(Actor self, Activity activity, in Target target, bool queued, bool forceAttack) { }
public bool IsReachableTarget(Target target, bool allowMove)
public bool IsReachableTarget(in Target target, bool allowMove)
{
return HasAnyValidWeapons(target)
&& (target.IsInRange(self.CenterPosition, GetMaximumRangeVersusTarget(target)) || (allowMove && self.Info.HasTraitInfo<IMoveInfo>()));
@@ -427,9 +427,9 @@ namespace OpenRA.Mods.Common.Traits
public string OrderID { get; private set; }
public int OrderPriority { get; private set; }
public bool TargetOverridesSelection(Actor self, Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers) { return true; }
public bool TargetOverridesSelection(Actor self, in Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers) { return true; }
bool CanTargetActor(Actor self, Target target, ref TargetModifiers modifiers, ref string cursor)
bool CanTargetActor(Actor self, in Target target, ref TargetModifiers modifiers, ref string cursor)
{
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
@@ -505,7 +505,7 @@ namespace OpenRA.Mods.Common.Traits
return true;
}
public bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
public bool CanTarget(Actor self, in Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
{
switch (target.Type)
{

View File

@@ -63,14 +63,14 @@ namespace OpenRA.Mods.Common.Traits
base.Tick(self);
}
protected override bool CanAttack(Actor self, Target target)
protected override bool CanAttack(Actor self, in Target target)
{
charging = base.CanAttack(self, target) && IsReachableTarget(target, true);
return ChargeLevel >= info.ChargeLevel && charging;
}
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel) { ChargeLevel = 0; }
void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel) { }
void INotifyAttack.Attacking(Actor self, in Target target, Armament a, Barrel barrel) { ChargeLevel = 0; }
void INotifyAttack.PreparingAttack(Actor self, in Target target, Armament a, Barrel barrel) { }
void INotifySold.Selling(Actor self) { ChargeLevel = 0; }
void INotifySold.Sold(Actor self) { }
}

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits
bool opportunityForceAttack;
bool opportunityTargetIsPersistentTarget;
public void SetRequestedTarget(Actor self, Target target, bool isForceAttack = false)
public void SetRequestedTarget(Actor self, in Target target, bool isForceAttack = false)
{
RequestedTarget = target;
requestedForceAttack = isForceAttack;
@@ -79,7 +79,7 @@ namespace OpenRA.Mods.Common.Traits
base.Created(self);
}
protected bool CanAimAtTarget(Actor self, Target target, bool forceAttack)
protected bool CanAimAtTarget(Actor self, in Target target, bool forceAttack)
{
if (target.Type == TargetType.Actor && !target.Actor.CanBeViewedByPlayer(self.Owner))
return false;
@@ -154,12 +154,12 @@ namespace OpenRA.Mods.Common.Traits
base.Tick(self);
}
public override Activity GetAttackActivity(Actor self, AttackSource source, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
public override Activity GetAttackActivity(Actor self, AttackSource source, in Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
{
return new AttackActivity(self, newTarget, allowMove, forceAttack, targetLineColor);
}
public override void OnResolveAttackOrder(Actor self, Activity activity, Target target, bool queued, bool forceAttack)
public override void OnResolveAttackOrder(Actor self, Activity activity, in Target target, bool queued, bool forceAttack)
{
// We can improve responsiveness for turreted actors by preempting
// the last order (usually a move) and setting the target immediately
@@ -228,7 +228,7 @@ namespace OpenRA.Mods.Common.Traits
bool wasMovingWithinRange;
bool hasTicked;
public AttackActivity(Actor self, Target target, bool allowMove, bool forceAttack, Color? targetLineColor = null)
public AttackActivity(Actor self, in Target target, bool allowMove, bool forceAttack, Color? targetLineColor = null)
{
attack = self.Trait<AttackFollow>();
move = allowMove ? self.TraitOrDefault<IMove>() : null;

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Traits
Info = info;
}
protected override bool CanAttack(Actor self, Target target)
protected override bool CanAttack(Actor self, in Target target)
{
if (!base.CanAttack(self, target))
return false;
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits
return TargetInFiringArc(self, target, 4 * Info.FacingTolerance);
}
public override Activity GetAttackActivity(Actor self, AttackSource source, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
public override Activity GetAttackActivity(Actor self, AttackSource source, in Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
{
return new Activities.Attack(self, newTarget, allowMove, forceAttack, targetLineColor);
}

View File

@@ -143,7 +143,7 @@ namespace OpenRA.Mods.Common.Traits
return coords.Value.LocalToWorld(p.Offset.Rotate(bodyOrientation));
}
public override void DoAttack(Actor self, Target target)
public override void DoAttack(Actor self, in Target target)
{
if (!CanAttack(self, target))
return;

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits
public AttackOmni(Actor self, AttackOmniInfo info)
: base(self, info) { }
public override Activity GetAttackActivity(Actor self, AttackSource source, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
public override Activity GetAttackActivity(Actor self, AttackSource source, in Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
{
return new SetTarget(this, newTarget, allowMove, forceAttack, targetLineColor);
}
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits
readonly Color? targetLineColor;
Target target;
public SetTarget(AttackOmni attack, Target target, bool allowMove, bool forceAttack, Color? targetLineColor = null)
public SetTarget(AttackOmni attack, in Target target, bool allowMove, bool forceAttack, Color? targetLineColor = null)
{
this.target = target;
this.targetLineColor = targetLineColor;

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits
turrets = self.TraitsImplementing<Turreted>().Where(t => info.Turrets.Contains(t.Info.Turret)).ToArray();
}
protected override bool CanAttack(Actor self, Target target)
protected override bool CanAttack(Actor self, in Target target)
{
if (target.Type == TargetType.Invalid)
return false;

View File

@@ -312,7 +312,7 @@ namespace OpenRA.Mods.Common.Traits
Attack(self, target, allowMove);
}
void Attack(Actor self, Target target, bool allowMove)
void Attack(Actor self, in Target target, bool allowMove)
{
foreach (var ab in ActiveAttackBases)
ab.AttackTarget(target, AttackSource.AutoTarget, false, allowMove);

View File

@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID == OrderID)
return new Order(order.OrderID, self, false);

View File

@@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Traits
get { yield return new RallyPointOrderTargeter(Info.Cursor); }
}
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
public Order IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID == OrderID)
{
@@ -140,11 +140,11 @@ namespace OpenRA.Mods.Common.Traits
public string OrderID { get { return "SetRallyPoint"; } }
public int OrderPriority { get { return 0; } }
public bool TargetOverridesSelection(Actor self, Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers) { return true; }
public bool TargetOverridesSelection(Actor self, in Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers) { return true; }
public bool ForceSet { get; private set; }
public bool IsQueued { get; protected set; }
public bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
public bool CanTarget(Actor self, in Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
{
if (target.Type != TargetType.Terrain)
return false;

View File

@@ -93,7 +93,7 @@ namespace OpenRA.Mods.Common.Traits
}
// Note: Returns a valid order even if the unit can't move to the target
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID == "Enter" || order.OrderID == "Move")
return new Order(order.OrderID, self, target, queued);
@@ -168,7 +168,7 @@ namespace OpenRA.Mods.Common.Traits
{
readonly TransformsIntoAircraft aircraft;
public bool TargetOverridesSelection(Actor self, Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers)
public bool TargetOverridesSelection(Actor self, in Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers)
{
// Always prioritise orders over selecting other peoples actors or own actors that are already selected
if (target.Type == TargetType.Actor && (target.Actor.Owner != self.Owner || self.World.Selection.Contains(target.Actor)))
@@ -186,7 +186,7 @@ namespace OpenRA.Mods.Common.Traits
public int OrderPriority { get { return 4; } }
public bool IsQueued { get; protected set; }
public bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
public bool CanTarget(Actor self, in Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
{
if (target.Type != TargetType.Terrain || (aircraft.Info.RequiresForceMove && !modifiers.HasModifier(TargetModifiers.ForceMove)))
return false;

View File

@@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Traits
return self.CurrentActivity is Transform || transforms.Any(t => !t.IsTraitDisabled && !t.IsTraitPaused);
}
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID == "EnterTunnel")
return new Order(order.OrderID, self, target, queued) { SuppressVisualFeedback = true };

View File

@@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits
}
// Note: Returns a valid order even if the unit can't move to the target
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order is MoveOrderTargeter)
return new Order("Move", self, target, queued);
@@ -159,7 +159,7 @@ namespace OpenRA.Mods.Common.Traits
{
readonly TransformsIntoMobile mobile;
readonly bool rejectMove;
public bool TargetOverridesSelection(Actor self, Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers)
public bool TargetOverridesSelection(Actor self, in Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers)
{
// Always prioritise orders over selecting other peoples actors or own actors that are already selected
if (target.Type == TargetType.Actor && (target.Actor.Owner != self.Owner || self.World.Selection.Contains(target.Actor)))
@@ -178,7 +178,7 @@ namespace OpenRA.Mods.Common.Traits
public int OrderPriority { get { return 4; } }
public bool IsQueued { get; protected set; }
public bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
public bool CanTarget(Actor self, in Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
{
if (rejectMove || target.Type != TargetType.Terrain || (mobile.Info.RequiresForceMove && !modifiers.HasModifier(TargetModifiers.ForceMove)))
return false;

View File

@@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID == "EnterTransport")
return new Order(order.OrderID, self, target, queued);

View File

@@ -95,7 +95,7 @@ namespace OpenRA.Mods.Common.Traits
return Info.RepairActors.Contains(target.Info.Name);
}
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID == "Repair")
return new Order(order.OrderID, self, target, queued);

View File

@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
public Order IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID != "CaptureActor")
return null;

View File

@@ -208,7 +208,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
public Order IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID == "Unload")
return new Order(order.OrderID, self, queued);

View File

@@ -285,7 +285,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID == "PickupUnit" || order.OrderID == "DeliverUnit" || order.OrderID == "Unload")
return new Order(order.OrderID, self, target, queued);
@@ -383,7 +383,7 @@ namespace OpenRA.Mods.Common.Traits
public string OrderID { get { return "DeliverUnit"; } }
public int OrderPriority { get { return 6; } }
public bool IsQueued { get; protected set; }
public bool TargetOverridesSelection(Actor self, Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers) { return true; }
public bool TargetOverridesSelection(Actor self, in Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers) { return true; }
public CarryallDeliverUnitTargeter(AircraftInfo aircraftInfo, CarryallInfo info)
{
@@ -391,7 +391,7 @@ namespace OpenRA.Mods.Common.Traits
this.info = info;
}
public bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
public bool CanTarget(Actor self, in Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
{
if (!info.AllowDropOff || !modifiers.HasModifier(TargetModifiers.ForceMove))
return false;

View File

@@ -108,9 +108,9 @@ namespace OpenRA.Mods.Common.Traits
public void Uncloak(int time) { remainingTime = Math.Max(remainingTime, time); }
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel) { if (Info.UncloakOn.HasFlag(UncloakType.Attack)) Uncloak(); }
void INotifyAttack.Attacking(Actor self, in Target target, Armament a, Barrel barrel) { if (Info.UncloakOn.HasFlag(UncloakType.Attack)) Uncloak(); }
void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel) { }
void INotifyAttack.PreparingAttack(Actor self, in Target target, Armament a, Barrel barrel) { }
void INotifyDamage.Damaged(Actor self, AttackInfo e)
{

View File

@@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
bool TargetChanged(Target lastTarget, Target target)
bool TargetChanged(in Target lastTarget, in Target target)
{
// Invalidate reveal changing the target.
if (lastTarget.Type == TargetType.FrozenActor && target.Type == TargetType.Actor)
@@ -120,7 +120,7 @@ namespace OpenRA.Mods.Common.Traits
return false;
}
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel)
void INotifyAttack.Attacking(Actor self, in Target target, Armament a, Barrel barrel)
{
if (IsTraitDisabled || IsTraitPaused)
return;
@@ -157,7 +157,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel) { }
void INotifyAttack.PreparingAttack(Actor self, in Target target, Armament a, Barrel barrel) { }
protected override void TraitDisabled(Actor self)
{

View File

@@ -172,7 +172,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
public Order IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID == "GrantConditionOnDeploy")
return new Order(order.OrderID, self, target, queued);

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Mods.Common.Traits
get { yield return new DeliversCashOrderTargeter(info); }
}
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
public Order IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID != "DeliverCash")
return null;

View File

@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
public Order IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID != "DeliverExperience")
return null;

View File

@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Traits
get { yield return new DemolitionOrderTargeter(info); }
}
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
public Order IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID != "C4")
return null;

View File

@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
public Order IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID != "EngineerRepair")
return null;

View File

@@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.Traits
return !requireForceMove || modifiers.HasModifier(TargetModifiers.ForceMove);
}
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
public Order IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID != "EnterTunnel")
return null;

View File

@@ -294,7 +294,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID == "Deliver" || order.OrderID == "Harvest")
return new Order(order.OrderID, self, target, queued);
@@ -364,9 +364,9 @@ namespace OpenRA.Mods.Common.Traits
public string OrderID { get { return "Harvest"; } }
public int OrderPriority { get { return 10; } }
public bool IsQueued { get; protected set; }
public bool TargetOverridesSelection(Actor self, Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers) { return true; }
public bool TargetOverridesSelection(Actor self, in Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers) { return true; }
public bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
public bool CanTarget(Actor self, in Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
{
if (target.Type != TargetType.Terrain)
return false;

View File

@@ -88,13 +88,13 @@ namespace OpenRA.Mods.Common.Traits
Panic();
}
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel)
void INotifyAttack.Attacking(Actor self, in Target target, Armament a, Barrel barrel)
{
if (self.World.SharedRandom.Next(100) < info.AttackPanicChance)
Panic();
}
void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel) { }
void INotifyAttack.PreparingAttack(Actor self, in Target target, Armament a, Barrel barrel) { }
int ISpeedModifier.GetSpeedModifier()
{

View File

@@ -602,19 +602,19 @@ namespace OpenRA.Mods.Common.Traits
return WrapMove(new Move(self, cell, WDist.FromCells(nearEnough), ignoreActor, evaluateNearestMovableCell, targetLineColor));
}
public Activity MoveWithinRange(Target target, WDist range,
public Activity MoveWithinRange(in Target target, WDist range,
WPos? initialTargetPosition = null, Color? targetLineColor = null)
{
return WrapMove(new MoveWithinRange(self, target, WDist.Zero, range, initialTargetPosition, targetLineColor));
}
public Activity MoveWithinRange(Target target, WDist minRange, WDist maxRange,
public Activity MoveWithinRange(in Target target, WDist minRange, WDist maxRange,
WPos? initialTargetPosition = null, Color? targetLineColor = null)
{
return WrapMove(new MoveWithinRange(self, target, minRange, maxRange, initialTargetPosition, targetLineColor));
}
public Activity MoveFollow(Actor self, Target target, WDist minRange, WDist maxRange,
public Activity MoveFollow(Actor self, in Target target, WDist minRange, WDist maxRange,
WPos? initialTargetPosition = null, Color? targetLineColor = null)
{
return WrapMove(new Follow(self, target, minRange, maxRange, initialTargetPosition, targetLineColor));
@@ -675,7 +675,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
public Activity MoveToTarget(Actor self, Target target,
public Activity MoveToTarget(Actor self, in Target target,
WPos? initialTargetPosition = null, Color? targetLineColor = null)
{
if (target.Type == TargetType.Invalid)
@@ -684,7 +684,7 @@ namespace OpenRA.Mods.Common.Traits
return WrapMove(new MoveAdjacentTo(self, target, initialTargetPosition, targetLineColor));
}
public Activity MoveIntoTarget(Actor self, Target target)
public Activity MoveIntoTarget(Actor self, in Target target)
{
if (target.Type == TargetType.Invalid)
return null;
@@ -711,7 +711,7 @@ namespace OpenRA.Mods.Common.Traits
return NearestMoveableCell(target, 1, 10);
}
public bool CanEnterTargetNow(Actor self, Target target)
public bool CanEnterTargetNow(Actor self, in Target target)
{
if (target.Type == TargetType.FrozenActor && !target.FrozenActor.IsValid)
return false;
@@ -904,7 +904,7 @@ namespace OpenRA.Mods.Common.Traits
}
// Note: Returns a valid order even if the unit can't move to the target
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order is MoveOrderTargeter)
return new Order("Move", self, target, queued);
@@ -968,7 +968,7 @@ namespace OpenRA.Mods.Common.Traits
readonly Mobile mobile;
readonly LocomotorInfo locomotorInfo;
readonly bool rejectMove;
public bool TargetOverridesSelection(Actor self, Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers)
public bool TargetOverridesSelection(Actor self, in Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers)
{
// Always prioritise orders over selecting other peoples actors or own actors that are already selected
if (target.Type == TargetType.Actor && (target.Actor.Owner != self.Owner || self.World.Selection.Contains(target.Actor)))
@@ -988,7 +988,7 @@ namespace OpenRA.Mods.Common.Traits
public int OrderPriority { get { return 4; } }
public bool IsQueued { get; protected set; }
public bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
public bool CanTarget(Actor self, in Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
{
if (rejectMove || target.Type != TargetType.Terrain || (mobile.requireForceMove && !modifiers.HasModifier(TargetModifiers.ForceMove)))
return false;

View File

@@ -85,7 +85,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
public Order IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID == "EnterTransport")
return new Order(order.OrderID, self, target, queued);

View File

@@ -66,13 +66,13 @@ namespace OpenRA.Mods.Common.Traits
});
}
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel)
void INotifyAttack.Attacking(Actor self, in Target target, Armament a, Barrel barrel)
{
if (Info.ResetOnFire)
remainingTicks = Util.ApplyPercentageModifiers(Info.Delay, modifiers.Select(m => m.GetReloadAmmoModifier()));
}
void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel) { }
void INotifyAttack.PreparingAttack(Actor self, in Target target, Armament a, Barrel barrel) { }
void ITick.Tick(Actor self)
{

View File

@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Traits.Render
wsb.PlayCustomAnimation(self, Info.Sequence);
}
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel)
void INotifyAttack.Attacking(Actor self, in Target target, Armament a, Barrel barrel)
{
if (a == armament && Info.DelayRelativeTo == AttackDelayType.Attack)
{
@@ -76,7 +76,7 @@ namespace OpenRA.Mods.Common.Traits.Render
}
}
void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel)
void INotifyAttack.PreparingAttack(Actor self, in Target target, Armament a, Barrel barrel)
{
if (a == armament && Info.DelayRelativeTo == AttackDelayType.Preparation)
{

View File

@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Traits.Render
overlay.PlayThen(info.Sequence, () => attacking = false);
}
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel)
void INotifyAttack.Attacking(Actor self, in Target target, Armament a, Barrel barrel)
{
if (info.DelayRelativeTo == AttackDelayType.Attack)
{
@@ -76,7 +76,7 @@ namespace OpenRA.Mods.Common.Traits.Render
}
}
void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel)
void INotifyAttack.PreparingAttack(Actor self, in Target target, Armament a, Barrel barrel)
{
if (info.DelayRelativeTo == AttackDelayType.Preparation)
{

View File

@@ -133,7 +133,7 @@ namespace OpenRA.Mods.Common.Traits.Render
}
}
public void Attacking(Actor self, Target target, Armament a)
public void Attacking(Actor self, in Target target, Armament a)
{
var info = GetDisplayInfo();
if (!info.AttackSequences.TryGetValue(a.Info.Name, out var sequence))
@@ -146,12 +146,12 @@ namespace OpenRA.Mods.Common.Traits.Render
}
}
void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel)
void INotifyAttack.PreparingAttack(Actor self, in Target target, Armament a, Barrel barrel)
{
Attacking(self, target, a);
}
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel) { }
void INotifyAttack.Attacking(Actor self, in Target target, Armament a, Barrel barrel) { }
void ITick.Tick(Actor self)
{

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits.Render
}
}
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel)
void INotifyAttack.Attacking(Actor self, in Target target, Armament a, Barrel barrel)
{
if (a == null || barrel == null || !armaments.Contains(a))
return;
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits.Render
anims[barrel].Animation.PlayThen(sequence, () => visible[barrel] = false);
}
void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel) { }
void INotifyAttack.PreparingAttack(Actor self, in Target target, Armament a, Barrel barrel) { }
IEnumerable<IRenderable> IRender.Render(Actor self, WorldRenderer wr)
{

View File

@@ -64,13 +64,13 @@ namespace OpenRA.Mods.Common.Traits.Render
PlayAttackAnimation(self);
}
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel)
void INotifyAttack.Attacking(Actor self, in Target target, Armament a, Barrel barrel)
{
if (!IsTraitDisabled && a == armament && Info.DelayRelativeTo == AttackDelayType.Attack)
NotifyAttack(self);
}
void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel)
void INotifyAttack.PreparingAttack(Actor self, in Target target, Armament a, Barrel barrel)
{
if (!IsTraitDisabled && a == armament && Info.DelayRelativeTo == AttackDelayType.Preparation)
NotifyAttack(self);

View File

@@ -79,7 +79,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID == "Repair")
return new Order(order.OrderID, self, target, queued);

View File

@@ -68,7 +68,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID == "RepairNear")
return new Order(order.OrderID, self, target, queued);

View File

@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Traits
get { yield return new RepairBridgeOrderTargeter(info); }
}
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
public Order IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID == "RepairBridge")
return new Order(order.OrderID, self, target, queued);

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits
this.info = info;
}
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel)
void INotifyAttack.Attacking(Actor self, in Target target, Armament a, Barrel barrel)
{
if (IsTraitDisabled)
return;
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
Player GetTargetPlayer(Target target)
Player GetTargetPlayer(in Target target)
{
if (target.Type == TargetType.Actor)
return target.Actor.Owner;
@@ -74,6 +74,6 @@ namespace OpenRA.Mods.Common.Traits
return null;
}
void INotifyAttack.PreparingAttack(Actor self, OpenRA.Traits.Target target, Armament a, Barrel barrel) { }
void INotifyAttack.PreparingAttack(Actor self, in Target target, Armament a, Barrel barrel) { }
}
}

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits.Sound
Game.Sound.Play(SoundType.World, info.Sounds, self.World, self.CenterPosition);
}
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel)
void INotifyAttack.Attacking(Actor self, in Target target, Armament a, Barrel barrel)
{
if (info.DelayRelativeTo == AttackDelayType.Attack)
{
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Traits.Sound
}
}
void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel)
void INotifyAttack.PreparingAttack(Actor self, in Target target, Armament a, Barrel barrel)
{
if (info.DelayRelativeTo == AttackDelayType.Preparation)
{

View File

@@ -108,7 +108,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
public Order IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID == "DeployTransform")
return new Order(order.OrderID, self, queued);

View File

@@ -250,7 +250,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
public bool FaceTarget(Actor self, Target target)
public bool FaceTarget(Actor self, in Target target)
{
if (IsTraitDisabled || IsTraitPaused || attack == null || attack.IsTraitDisabled || attack.IsTraitPaused)
return false;

View File

@@ -110,8 +110,8 @@ namespace OpenRA.Mods.Common.Traits
[RequireExplicitImplementation]
public interface INotifyAttack
{
void Attacking(Actor self, Target target, Armament a, Barrel barrel);
void PreparingAttack(Actor self, Target target, Armament a, Barrel barrel);
void Attacking(Actor self, in Target target, Armament a, Barrel barrel);
void PreparingAttack(Actor self, in Target target, Armament a, Barrel barrel);
}
[RequireExplicitImplementation]
@@ -143,7 +143,7 @@ namespace OpenRA.Mods.Common.Traits
public interface INotifySupportPower { void Charged(Actor self); void Activated(Actor self); }
public interface INotifyBuildingPlaced { void BuildingPlaced(Actor self); }
public interface INotifyBurstComplete { void FiredBurst(Actor self, Target target, Armament a); }
public interface INotifyBurstComplete { void FiredBurst(Actor self, in Target target, Armament a); }
public interface INotifyChat { bool OnChat(string from, string message); }
public interface INotifyProduction { void UnitProduced(Actor self, Actor other, CPos exit); }
public interface INotifyOtherProduction { void UnitProducedByOther(Actor self, Actor producer, Actor produced, string productionType, TypeDictionary init); }
@@ -414,21 +414,21 @@ namespace OpenRA.Mods.Common.Traits
{
Activity MoveTo(CPos cell, int nearEnough = 0, Actor ignoreActor = null,
bool evaluateNearestMovableCell = false, Color? targetLineColor = null);
Activity MoveWithinRange(Target target, WDist range,
Activity MoveWithinRange(in Target target, WDist range,
WPos? initialTargetPosition = null, Color? targetLineColor = null);
Activity MoveWithinRange(Target target, WDist minRange, WDist maxRange,
Activity MoveWithinRange(in Target target, WDist minRange, WDist maxRange,
WPos? initialTargetPosition = null, Color? targetLineColor = null);
Activity MoveFollow(Actor self, Target target, WDist minRange, WDist maxRange,
Activity MoveFollow(Actor self, in Target target, WDist minRange, WDist maxRange,
WPos? initialTargetPosition = null, Color? targetLineColor = null);
Activity MoveToTarget(Actor self, Target target,
Activity MoveToTarget(Actor self, in Target target,
WPos? initialTargetPosition = null, Color? targetLineColor = null);
Activity ReturnToCell(Actor self);
Activity MoveIntoTarget(Actor self, Target target);
Activity MoveIntoTarget(Actor self, in Target target);
Activity VisualMove(Actor self, WPos fromPos, WPos toPos);
int EstimatedMoveDuration(Actor self, WPos fromPos, WPos toPos);
CPos NearestMoveableCell(CPos target);
MovementType CurrentMovementTypes { get; set; }
bool CanEnterTargetNow(Actor self, Target target);
bool CanEnterTargetNow(Actor self, in Target target);
}
public interface IWrapMove

View File

@@ -162,7 +162,7 @@ namespace OpenRA.Mods.Common
return cells.SelectMany(c => Neighbours(c, allowDiagonal)).Distinct();
}
public static IEnumerable<CPos> AdjacentCells(World w, Target target)
public static IEnumerable<CPos> AdjacentCells(World w, in Target target)
{
var cells = target.Positions.Select(p => w.Map.CellContaining(p)).Distinct();
return ExpandFootprint(cells, true);

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Warheads
public readonly WDist Range = WDist.FromCells(1);
public override void DoImpact(Target target, WarheadArgs args)
public override void DoImpact(in Target target, WarheadArgs args)
{
var firedBy = args.SourceActor;
var actors = target.Type == TargetType.Actor ? new[] { target.Actor } :

View File

@@ -87,7 +87,7 @@ namespace OpenRA.Mods.Common.Warheads
return true;
}
public override void DoImpact(Target target, WarheadArgs args)
public override void DoImpact(in Target target, WarheadArgs args)
{
if (target.Type == TargetType.Invalid)
return;

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Warheads
}
// TODO: Allow maximum resource splatter to be defined. (Per tile, and in total).
public override void DoImpact(Target target, WarheadArgs args)
public override void DoImpact(in Target target, WarheadArgs args)
{
if (target.Type == TargetType.Invalid)
return;

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Warheads
return base.IsValidAgainst(victim, firedBy);
}
public override void DoImpact(Target target, WarheadArgs args)
public override void DoImpact(in Target target, WarheadArgs args)
{
var firedBy = args.SourceActor;

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Warheads
public readonly int[] Size = { 0, 0 };
// TODO: Allow maximum resource removal to be defined. (Per tile, and in total).
public override void DoImpact(Target target, WarheadArgs args)
public override void DoImpact(in Target target, WarheadArgs args)
{
if (target.Type == TargetType.Invalid)
return;

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Warheads
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(Weapon.ToLowerInvariant()));
}
public override void DoImpact(Target target, WarheadArgs args)
public override void DoImpact(in Target target, WarheadArgs args)
{
if (target.Type == TargetType.Invalid)
return;

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Warheads
[Desc("Duration of the flashing, measured in ticks. Set to -1 to default to the `Length` of the `FlashPaletteEffect`.")]
public readonly int Duration = 0;
public override void DoImpact(Target target, WarheadArgs args)
public override void DoImpact(in Target target, WarheadArgs args)
{
foreach (var flash in args.SourceActor.World.WorldActor.TraitsImplementing<FlashPaletteEffect>())
if (flash.Info.Type == FlashType)

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Warheads
public readonly WDist Range = WDist.FromCells(1);
public override void DoImpact(Target target, WarheadArgs args)
public override void DoImpact(in Target target, WarheadArgs args)
{
var firedBy = args.SourceActor;
var actors = target.Type == TargetType.Actor ? new[] { target.Actor } :

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Warheads
[Desc("Percentual chance the smudge is created.")]
public readonly int Chance = 100;
public override void DoImpact(Target target, WarheadArgs args)
public override void DoImpact(in Target target, WarheadArgs args)
{
if (target.Type == TargetType.Invalid)
return;

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Warheads
[Desc("Shake multipliers by the X and Y axis, comma-separated.")]
public readonly float2 Multiplier = new float2(0, 0);
public override void DoImpact(Target target, WarheadArgs args)
public override void DoImpact(in Target target, WarheadArgs args)
{
args.SourceActor.World.WorldActor.Trait<ScreenShaker>().AddEffect(Duration, target.CenterPosition, Intensity, Multiplier);
}

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Mods.Common.Warheads
}
/// <summary>Applies the warhead's effect against the target.</summary>
public abstract void DoImpact(Target target, WarheadArgs args);
public abstract void DoImpact(in Target target, WarheadArgs args);
/// <summary>Checks if the warhead is valid against (can do something to) the actor.</summary>
public virtual bool IsValidAgainst(Actor victim, Actor firedBy)