Use in parameter for Target
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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) { }
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user