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>();