Use in parameter for Target
This commit is contained in:
@@ -26,7 +26,7 @@ namespace OpenRA.Activities
|
||||
public readonly Color Color;
|
||||
public readonly Sprite Tile;
|
||||
|
||||
public TargetLineNode(Target target, Color color, Sprite tile = null)
|
||||
public TargetLineNode(in Target target, Color color, Sprite tile = null)
|
||||
{
|
||||
// Note: Not all activities are drawable. In that case, pass Target.Invalid as target,
|
||||
// if "yield break" in TargetLineNode(Actor self) is not feasible.
|
||||
|
||||
@@ -163,7 +163,7 @@ namespace OpenRA.GameRules
|
||||
}
|
||||
|
||||
/// <summary>Checks if the weapon is valid against (can target) the target.</summary>
|
||||
public bool IsValidAgainst(Target target, World world, Actor firedBy)
|
||||
public bool IsValidAgainst(in Target target, World world, Actor firedBy)
|
||||
{
|
||||
if (target.Type == TargetType.Actor)
|
||||
return IsValidAgainst(target.Actor, firedBy);
|
||||
@@ -220,20 +220,24 @@ namespace OpenRA.GameRules
|
||||
}
|
||||
|
||||
/// <summary>Applies all the weapon's warheads to the target.</summary>
|
||||
public void Impact(Target target, WarheadArgs args)
|
||||
public void Impact(in Target target, WarheadArgs args)
|
||||
{
|
||||
var world = args.SourceActor.World;
|
||||
foreach (var warhead in Warheads)
|
||||
{
|
||||
if (warhead.Delay > 0)
|
||||
world.AddFrameEndTask(w => w.Add(new DelayedImpact(warhead.Delay, warhead, target, args)));
|
||||
{
|
||||
// Lambdas can't use 'in' variables, so capture a copy for later
|
||||
var delayedTarget = target;
|
||||
world.AddFrameEndTask(w => w.Add(new DelayedImpact(warhead.Delay, warhead, delayedTarget, args)));
|
||||
}
|
||||
else
|
||||
warhead.DoImpact(target, args);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Applies all the weapon's warheads to the target. Only use for projectile-less, special-case impacts.</summary>
|
||||
public void Impact(Target target, Actor firedBy)
|
||||
public void Impact(in Target target, Actor firedBy)
|
||||
{
|
||||
// The impact will happen immediately at target.CenterPosition.
|
||||
var args = new WarheadArgs
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace OpenRA
|
||||
public readonly string OrderString;
|
||||
public readonly Actor Subject;
|
||||
public readonly bool Queued;
|
||||
public readonly Target Target;
|
||||
public ref readonly Target Target => ref target;
|
||||
public readonly Actor[] GroupedActors;
|
||||
|
||||
public string TargetString;
|
||||
@@ -66,15 +66,18 @@ namespace OpenRA
|
||||
public OrderType Type = OrderType.Fields;
|
||||
|
||||
public bool SuppressVisualFeedback;
|
||||
public Target VisualFeedbackTarget;
|
||||
public ref readonly Target VisualFeedbackTarget => ref visualFeedbackTarget;
|
||||
|
||||
public Player Player { get { return Subject != null ? Subject.Owner : null; } }
|
||||
|
||||
Order(string orderString, Actor subject, Target target, string targetString, bool queued, Actor[] extraActors, CPos extraLocation, uint extraData, Actor[] groupedActors = null)
|
||||
readonly Target target;
|
||||
readonly Target visualFeedbackTarget;
|
||||
|
||||
Order(string orderString, Actor subject, in Target target, string targetString, bool queued, Actor[] extraActors, CPos extraLocation, uint extraData, Actor[] groupedActors = null)
|
||||
{
|
||||
OrderString = orderString ?? "";
|
||||
Subject = subject;
|
||||
Target = target;
|
||||
this.target = target;
|
||||
TargetString = targetString;
|
||||
Queued = queued;
|
||||
ExtraActors = extraActors;
|
||||
@@ -278,9 +281,15 @@ namespace OpenRA
|
||||
public Order(string orderString, Actor subject, bool queued, Actor[] extraActors = null, Actor[] groupedActors = null)
|
||||
: this(orderString, subject, Target.Invalid, null, queued, extraActors, CPos.Zero, 0, groupedActors) { }
|
||||
|
||||
public Order(string orderString, Actor subject, Target target, bool queued, Actor[] extraActors = null, Actor[] groupedActors = null)
|
||||
public Order(string orderString, Actor subject, in Target target, bool queued, Actor[] extraActors = null, Actor[] groupedActors = null)
|
||||
: this(orderString, subject, target, null, queued, extraActors, CPos.Zero, 0, groupedActors) { }
|
||||
|
||||
public Order(string orderString, Actor subject, Target target, Target visualFeedbackTarget, bool queued)
|
||||
: this(orderString, subject, target, null, queued, null, CPos.Zero, 0, null)
|
||||
{
|
||||
this.visualFeedbackTarget = visualFeedbackTarget;
|
||||
}
|
||||
|
||||
public byte[] Serialize()
|
||||
{
|
||||
var minLength = 1 + OrderString.Length + 1;
|
||||
|
||||
@@ -196,15 +196,17 @@ namespace OpenRA.Orders
|
||||
public readonly IOrderTargeter Order;
|
||||
public readonly IIssueOrder Trait;
|
||||
public readonly string Cursor;
|
||||
public readonly Target Target;
|
||||
public ref readonly Target Target => ref target;
|
||||
|
||||
public UnitOrderResult(Actor actor, IOrderTargeter order, IIssueOrder trait, string cursor, Target target)
|
||||
readonly Target target;
|
||||
|
||||
public UnitOrderResult(Actor actor, IOrderTargeter order, IIssueOrder trait, string cursor, in Target target)
|
||||
{
|
||||
Actor = actor;
|
||||
Order = order;
|
||||
Trait = trait;
|
||||
Cursor = cursor;
|
||||
Target = target;
|
||||
this.target = target;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace OpenRA.Traits
|
||||
}
|
||||
|
||||
public static Target FromPos(WPos p) { return new Target(p); }
|
||||
public static Target FromTargetPositions(Target t) { return new Target(t.CenterPosition, t.Positions.ToArray()); }
|
||||
public static Target FromTargetPositions(in Target t) { return new Target(t.CenterPosition, t.Positions.ToArray()); }
|
||||
public static Target FromCell(World w, CPos c, SubCell subCell = SubCell.FullCell) { return new Target(w, c, subCell); }
|
||||
public static Target FromActor(Actor a) { return a != null ? new Target(a) : Invalid; }
|
||||
public static Target FromFrozenActor(FrozenActor fa) { return new Target(fa); }
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace OpenRA.Traits
|
||||
public interface IIssueOrder
|
||||
{
|
||||
IEnumerable<IOrderTargeter> Orders { get; }
|
||||
Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued);
|
||||
Order IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued);
|
||||
}
|
||||
|
||||
[Flags]
|
||||
@@ -147,9 +147,9 @@ namespace OpenRA.Traits
|
||||
{
|
||||
string OrderID { get; }
|
||||
int OrderPriority { get; }
|
||||
bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor);
|
||||
bool CanTarget(Actor self, in Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor);
|
||||
bool IsQueued { get; }
|
||||
bool TargetOverridesSelection(Actor self, Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers);
|
||||
bool TargetOverridesSelection(Actor self, in Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers);
|
||||
}
|
||||
|
||||
public interface IResolveOrder { void ResolveOrder(Actor self, Order order); }
|
||||
@@ -517,7 +517,7 @@ namespace OpenRA.Traits
|
||||
int Delay { get; }
|
||||
bool IsValidAgainst(Actor victim, Actor firedBy);
|
||||
bool IsValidAgainst(FrozenActor victim, Actor firedBy);
|
||||
void DoImpact(Target target, WarheadArgs args);
|
||||
void DoImpact(in Target target, WarheadArgs args);
|
||||
}
|
||||
|
||||
public interface IRulesetLoaded<TInfo> { void RulesetLoaded(Ruleset rules, TInfo info); }
|
||||
|
||||
Reference in New Issue
Block a user