Overhaul target line rendering:

- Targets are now defined by the activities
- Queued activities are shown
- Support custom attack colors
This commit is contained in:
Turupawn
2019-07-24 20:54:27 +00:00
committed by Paul Chote
parent bc4dea406d
commit 3240b1e9eb
71 changed files with 433 additions and 269 deletions

View File

@@ -139,13 +139,8 @@ namespace OpenRA.Mods.Common.Activities
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
lastVisibleTarget = Target.FromTargetPositions(target);
var oldUseLastVisibleTarget = useLastVisibleTarget;
useLastVisibleTarget = targetIsHiddenActor || !target.IsValidFor(self);
// Update target lines if required
if (useLastVisibleTarget != oldUseLastVisibleTarget && targetLineColor.HasValue)
self.SetTargetLine(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value, false);
// Target is hidden or dead, and we don't have a fallback position to move towards
if (useLastVisibleTarget && !lastVisibleTarget.IsValidFor(self))
return true;
@@ -228,6 +223,12 @@ namespace OpenRA.Mods.Common.Activities
yield return target;
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
if (targetLineColor.HasValue)
yield return new TargetLineNode(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value);
}
public static int CalculateTurnRadius(int speed, int turnSpeed)
{
// turnSpeed -> divide into 256 to get the number of ticks per complete rotation

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
@@ -24,6 +25,7 @@ namespace OpenRA.Mods.Common.Activities
readonly Rearmable rearmable;
readonly bool forceAttack;
readonly int ticksUntilTurn;
readonly Color? targetLineColor;
Target target;
Target lastVisibleTarget;
@@ -32,11 +34,14 @@ namespace OpenRA.Mods.Common.Activities
Player lastVisibleOwner;
bool useLastVisibleTarget;
bool hasTicked;
bool returnToBase;
public FlyAttack(Actor self, Target target, bool forceAttack)
public FlyAttack(Actor self, Target target, bool forceAttack, Color? targetLineColor)
{
this.target = target;
this.forceAttack = forceAttack;
this.targetLineColor = targetLineColor;
aircraft = self.Trait<Aircraft>();
attackAircraft = self.Trait<AttackAircraft>();
rearmable = self.TraitOrDefault<Rearmable>();
@@ -45,7 +50,7 @@ namespace OpenRA.Mods.Common.Activities
// The target may become hidden between the initial order request and the first tick (e.g. if queued)
// Moving to any position (even if quite stale) is still better than immediately giving up
if ((target.Type == TargetType.Actor && target.Actor.CanBeViewedByPlayer(self.Owner))
|| target.Type == TargetType.FrozenActor || target.Type == TargetType.Terrain)
|| target.Type == TargetType.FrozenActor || target.Type == TargetType.Terrain)
{
lastVisibleTarget = Target.FromPos(target.CenterPosition);
lastVisibleMaximumRange = attackAircraft.GetMaximumRangeVersusTarget(target);
@@ -65,6 +70,8 @@ namespace OpenRA.Mods.Common.Activities
public override bool Tick(Actor self)
{
returnToBase = false;
// Refuse to take off if it would land immediately again.
if (aircraft.ForceLanding)
Cancel(self);
@@ -93,13 +100,8 @@ namespace OpenRA.Mods.Common.Activities
lastVisibleTargetTypes = target.Actor.GetEnabledTargetTypes();
}
var oldUseLastVisibleTarget = useLastVisibleTarget;
useLastVisibleTarget = targetIsHiddenActor || !target.IsValidFor(self);
// Update target lines if required
if (useLastVisibleTarget != oldUseLastVisibleTarget)
self.SetTargetLine(useLastVisibleTarget ? lastVisibleTarget : target, Color.Red, false);
// Target is hidden or dead, and we don't have a fallback position to move towards
if (useLastVisibleTarget && !lastVisibleTarget.IsValidFor(self))
return true;
@@ -109,6 +111,7 @@ namespace OpenRA.Mods.Common.Activities
if (rearmable != null && !useLastVisibleTarget && attackAircraft.Armaments.All(x => x.IsTraitPaused || !x.Weapon.IsValidAgainst(target, self.World, self)))
{
QueueChild(new ReturnToBase(self));
returnToBase = true;
return attackAircraft.Info.AbortOnResupply;
}
@@ -169,5 +172,17 @@ namespace OpenRA.Mods.Common.Activities
if (!autoTarget.HasValidTargetPriority(self, lastVisibleOwner, lastVisibleTargetTypes))
attackAircraft.ClearRequestedTarget();
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
if (targetLineColor != null)
{
if (returnToBase)
foreach (var n in ChildActivity.TargetLineNodes(self))
yield return n;
if (!returnToBase || !attackAircraft.Info.AbortOnResupply)
yield return new TargetLineNode(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value);
}
}
}
}

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System.Collections.Generic;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
@@ -59,7 +60,6 @@ namespace OpenRA.Mods.Common.Activities
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
lastVisibleTarget = Target.FromTargetPositions(target);
var oldUseLastVisibleTarget = useLastVisibleTarget;
useLastVisibleTarget = targetIsHiddenActor || !target.IsValidFor(self);
// If we are ticking again after previously sequencing a MoveWithRange then that move must have completed
@@ -69,10 +69,6 @@ namespace OpenRA.Mods.Common.Activities
wasMovingWithinRange = false;
// Update target lines if required
if (useLastVisibleTarget != oldUseLastVisibleTarget && targetLineColor.HasValue)
self.SetTargetLine(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value, false);
// Target is hidden or dead, and we don't have a fallback position to move towards
if (useLastVisibleTarget && !lastVisibleTarget.IsValidFor(self))
return true;
@@ -94,5 +90,11 @@ namespace OpenRA.Mods.Common.Activities
QueueChild(aircraft.MoveWithinRange(target, minRange, maxRange, checkTarget.CenterPosition, targetLineColor));
return false;
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
if (targetLineColor != null)
yield return new TargetLineNode(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value);
}
}
}

View File

@@ -13,6 +13,7 @@ using System;
using System.Collections.Generic;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Activities
@@ -25,6 +26,7 @@ namespace OpenRA.Mods.Common.Activities
readonly bool assignTargetOnFirstRun;
readonly CPos[] clearCells;
readonly WDist landRange;
readonly Color? targetLineColor;
Target target;
WPos targetPosition;
@@ -32,28 +34,29 @@ namespace OpenRA.Mods.Common.Activities
bool landingInitiated;
bool finishedApproach;
public Land(Actor self, int facing = -1)
public Land(Actor self, int facing = -1, Color? targetLineColor = null)
: this(self, Target.Invalid, new WDist(-1), WVec.Zero, facing, null)
{
assignTargetOnFirstRun = true;
}
public Land(Actor self, Target target, int facing = -1)
: this(self, target, new WDist(-1), WVec.Zero, facing) { }
public Land(Actor self, Target target, int facing = -1, Color? targetLineColor = null)
: this(self, target, new WDist(-1), WVec.Zero, facing, targetLineColor: targetLineColor) { }
public Land(Actor self, Target target, WDist landRange, int facing = -1)
: this(self, target, landRange, WVec.Zero, facing) { }
public Land(Actor self, Target target, WDist landRange, int facing = -1, Color? targetLineColor = null)
: this(self, target, landRange, WVec.Zero, facing, targetLineColor: targetLineColor) { }
public Land(Actor self, Target target, WVec offset, int facing = -1)
: this(self, target, WDist.Zero, offset, facing) { }
public Land(Actor self, Target target, WVec offset, int facing = -1, Color? targetLineColor = null)
: this(self, target, WDist.Zero, offset, facing, targetLineColor: targetLineColor) { }
public Land(Actor self, Target target, WDist landRange, WVec offset, int facing = -1, CPos[] clearCells = null)
public Land(Actor self, Target target, WDist landRange, WVec offset, int facing = -1, CPos[] clearCells = null, Color? targetLineColor = null)
{
aircraft = self.Trait<Aircraft>();
this.target = target;
this.offset = offset;
this.clearCells = clearCells ?? new CPos[0];
this.landRange = landRange.Length >= 0 ? landRange : aircraft.Info.LandRange;
this.targetLineColor = targetLineColor;
// NOTE: desiredFacing = -1 means we should not prefer any particular facing and instead just
// use whatever facing gives us the most direct path to the landing site.
@@ -256,5 +259,11 @@ namespace OpenRA.Mods.Common.Activities
return false;
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
if (targetLineColor != null)
yield return new TargetLineNode(target, targetLineColor.Value);
}
}
}

View File

@@ -119,14 +119,22 @@ namespace OpenRA.Mods.Common.Activities
facing = 192;
aircraft.MakeReservation(dest);
QueueChild(new Land(self, Target.FromActor(dest), offset, facing));
QueueChild(new Land(self, Target.FromActor(dest), offset, facing, Color.Green));
QueueChild(new Resupply(self, dest, WDist.Zero, alwaysLand));
return true;
}
QueueChild(new Fly(self, Target.FromActor(dest)));
return true;
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
if (ChildActivity == null)
yield return new TargetLineNode(Target.FromActor(dest), Color.Green);
else
foreach (var n in ChildActivity.TargetLineNodes(self))
yield return n;
}
}
}

View File

@@ -31,6 +31,7 @@ namespace OpenRA.Mods.Common.Activities
readonly IFacing facing;
readonly IPositionable positionable;
readonly bool forceAttack;
readonly Color? targetLineColor;
protected Target target;
Target lastVisibleTarget;
@@ -44,9 +45,10 @@ namespace OpenRA.Mods.Common.Activities
WDist maxRange;
AttackStatus attackStatus = AttackStatus.UnableToAttack;
public Attack(Actor self, Target target, bool allowMovement, bool forceAttack)
public Attack(Actor self, Target target, bool allowMovement, bool forceAttack, Color? targetLineColor = null)
{
this.target = target;
this.targetLineColor = targetLineColor;
this.forceAttack = forceAttack;
attackTraits = self.TraitsImplementing<AttackFrontal>().ToArray();
@@ -100,7 +102,6 @@ namespace OpenRA.Mods.Common.Activities
lastVisibleTargetTypes = target.Actor.GetEnabledTargetTypes();
}
var oldUseLastVisibleTarget = useLastVisibleTarget;
useLastVisibleTarget = targetIsHiddenActor || !target.IsValidFor(self);
// If we are ticking again after previously sequencing a MoveWithRange then that move must have completed
@@ -108,10 +109,6 @@ namespace OpenRA.Mods.Common.Activities
if (wasMovingWithinRange && targetIsHiddenActor)
return true;
// Update target lines if required
if (useLastVisibleTarget != oldUseLastVisibleTarget)
self.SetTargetLine(useLastVisibleTarget ? lastVisibleTarget : target, Color.Red, false);
// Target is hidden or dead, and we don't have a fallback position to move towards
if (useLastVisibleTarget && !lastVisibleTarget.IsValidFor(self))
return true;
@@ -231,5 +228,11 @@ namespace OpenRA.Mods.Common.Activities
if (!autoTarget.HasValidTargetPriority(self, lastVisibleOwner, lastVisibleTargetTypes))
target = Target.Invalid;
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
if (targetLineColor != null)
yield return new TargetLineNode(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value);
}
}
}

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
@@ -24,6 +25,8 @@ namespace OpenRA.Mods.Common.Activities
readonly Actor targetActor;
readonly INotifyHarvesterAction[] notifyHarvesterActions;
Actor proc;
public DeliverResources(Actor self, Actor targetActor = null)
{
movement = self.Trait<IMove>();
@@ -54,10 +57,9 @@ namespace OpenRA.Mods.Common.Activities
return false;
}
var proc = harv.LinkedProc;
proc = harv.LinkedProc;
var iao = proc.Trait<IAcceptResources>();
self.SetTargetLine(Target.FromActor(proc), Color.Green, false);
if (self.Location != proc.Location + iao.DeliveryOffset)
{
foreach (var n in notifyHarvesterActions)
@@ -79,5 +81,13 @@ namespace OpenRA.Mods.Common.Activities
base.Cancel(self, keepQueue);
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
if (proc != null)
yield return new TargetLineNode(Target.FromActor(proc), Color.Green);
else
yield return new TargetLineNode(Target.FromActor(harv.LinkedProc), Color.Green);
}
}
}

View File

@@ -9,8 +9,10 @@
*/
#endregion
using System.Collections.Generic;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Activities
@@ -56,6 +58,11 @@ namespace OpenRA.Mods.Common.Activities
QueueChild(new TakeOff(self));
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
yield return new TargetLineNode(destination, Color.Yellow);
}
class ReleaseUnit : Activity
{
readonly Carryall carryall;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System.Collections.Generic;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
@@ -75,10 +76,6 @@ namespace OpenRA.Mods.Common.Activities
TickInner(self, target, useLastVisibleTarget);
// Update target lines if required
if (useLastVisibleTarget != oldUseLastVisibleTarget && targetLineColor.HasValue)
self.SetTargetLine(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value, false);
// We need to wait for movement to finish before transitioning to
// the next state or next activity
if (!TickChild(self))
@@ -146,5 +143,11 @@ namespace OpenRA.Mods.Common.Activities
return false;
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
if (targetLineColor != null)
yield return new TargetLineNode(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value);
}
}
}

View File

@@ -9,9 +9,6 @@
*/
#endregion
using System;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;

View File

@@ -27,8 +27,8 @@ namespace OpenRA.Mods.Common.Activities
readonly ResourceClaimLayer claimLayer;
readonly IPathFinder pathFinder;
readonly DomainIndex domainIndex;
readonly Actor deliverActor;
Actor deliverActor;
CPos? orderLocation;
CPos? lastHarvestedCell;
bool hasDeliveredLoad;
@@ -73,6 +73,7 @@ namespace OpenRA.Mods.Common.Activities
{
QueueChild(new DeliverResources(self, deliverActor));
hasDeliveredLoad = true;
deliverActor = null;
}
}
@@ -139,7 +140,6 @@ namespace OpenRA.Mods.Common.Activities
{
var unblockCell = deliveryLoc + harv.Info.UnblockCell;
var moveTo = mobile.NearestMoveableCell(unblockCell, 1, 5);
self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Green, false);
QueueChild(mobile.MoveTo(moveTo, 1));
}
}
@@ -205,6 +205,18 @@ namespace OpenRA.Mods.Common.Activities
yield return Target.FromCell(self.World, self.Location);
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
if (ChildActivity != null)
foreach (var n in ChildActivity.TargetLineNodes(self))
yield return n;
if (orderLocation != null)
yield return new TargetLineNode(Target.FromCell(self.World, orderLocation.Value), Color.Green);
else if (deliverActor != null)
yield return new TargetLineNode(Target.FromActor(deliverActor), Color.Green);
}
CPos GetSearchFromLocation(Actor self)
{
if (harv.LastLinkedProc != null && !harv.LastLinkedProc.IsDead && harv.LastLinkedProc.IsInWorld)

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
@@ -61,7 +62,6 @@ namespace OpenRA.Mods.Common.Activities
foreach (var n in notifyHarvesterActions)
n.MovingToResources(self, targetCell);
self.SetTargetLine(Target.FromCell(self.World, targetCell), Color.Red, false);
QueueChild(move.MoveTo(targetCell, 2));
return false;
}
@@ -106,5 +106,10 @@ namespace OpenRA.Mods.Common.Activities
base.Cancel(self, keepQueue);
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
yield return new TargetLineNode(Target.FromCell(self.World, targetCell), Color.Green);
}
}
}

View File

@@ -13,6 +13,7 @@ using System;
using System.Collections.Generic;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Activities
@@ -104,6 +105,11 @@ namespace OpenRA.Mods.Common.Activities
yield return Target.FromActor(Refinery);
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
yield return new TargetLineNode(Target.FromActor(Refinery), Color.Green);
}
public abstract void OnStateDock(Actor self);
public abstract void OnStateUndock(Actor self);

View File

@@ -92,5 +92,13 @@ namespace OpenRA.Mods.Common.Activities
return Target.None;
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
foreach (var n in getInner().TargetLineNodes(self))
yield return n;
yield break;
}
}
}

View File

@@ -12,6 +12,7 @@
using System.Collections.Generic;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Activities
@@ -62,5 +63,10 @@ namespace OpenRA.Mods.Common.Activities
{
yield return Target.FromPos(end);
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
yield return new TargetLineNode(Target.FromPos(end), Color.Green);
}
}
}

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System.Collections.Generic;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
@@ -55,7 +56,6 @@ namespace OpenRA.Mods.Common.Activities
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
lastVisibleTarget = Target.FromTargetPositions(target);
var oldUseLastVisibleTarget = useLastVisibleTarget;
useLastVisibleTarget = targetIsHiddenActor || !target.IsValidFor(self);
// If we are ticking again after previously sequencing a MoveWithRange then that move must have completed
@@ -65,10 +65,6 @@ namespace OpenRA.Mods.Common.Activities
wasMovingWithinRange = false;
// Update target lines if required
if (useLastVisibleTarget != oldUseLastVisibleTarget && targetLineColor.HasValue)
self.SetTargetLine(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value, false);
// Target is hidden or dead, and we don't have a fallback position to move towards
if (useLastVisibleTarget && !lastVisibleTarget.IsValidFor(self))
return true;
@@ -86,5 +82,11 @@ namespace OpenRA.Mods.Common.Activities
QueueChild(move.MoveWithinRange(target, minRange, maxRange, checkTarget.CenterPosition, targetLineColor));
return false;
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
if (targetLineColor != null)
yield return new TargetLineNode(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value);
}
}
}

View File

@@ -29,6 +29,7 @@ namespace OpenRA.Mods.Common.Activities
readonly WDist nearEnough;
readonly Func<List<CPos>> getPath;
readonly Actor ignoreActor;
readonly Color? targetLineColor;
List<CPos> path;
CPos? destination;
@@ -43,7 +44,7 @@ namespace OpenRA.Mods.Common.Activities
// Scriptable move order
// Ignores lane bias and nearby units
public Move(Actor self, CPos destination)
public Move(Actor self, CPos destination, Color? targetLineColor = null)
{
mobile = self.Trait<Mobile>();
@@ -57,10 +58,12 @@ namespace OpenRA.Mods.Common.Activities
return path;
};
this.destination = destination;
this.targetLineColor = targetLineColor;
nearEnough = WDist.Zero;
}
public Move(Actor self, CPos destination, WDist nearEnough, Actor ignoreActor = null, bool evaluateNearestMovableCell = false)
public Move(Actor self, CPos destination, WDist nearEnough, Actor ignoreActor = null, bool evaluateNearestMovableCell = false,
Color? targetLineColor = null)
{
mobile = self.Trait<Mobile>();
@@ -79,9 +82,10 @@ namespace OpenRA.Mods.Common.Activities
this.nearEnough = nearEnough;
this.ignoreActor = ignoreActor;
this.evaluateNearestMovableCell = evaluateNearestMovableCell;
this.targetLineColor = targetLineColor;
}
public Move(Actor self, CPos destination, SubCell subCell, WDist nearEnough)
public Move(Actor self, CPos destination, SubCell subCell, WDist nearEnough, Color? targetLineColor = null)
{
mobile = self.Trait<Mobile>();
@@ -89,9 +93,10 @@ namespace OpenRA.Mods.Common.Activities
.FindUnitPathToRange(mobile.FromCell, subCell, self.World.Map.CenterOfSubCell(destination, subCell), nearEnough, self);
this.destination = destination;
this.nearEnough = nearEnough;
this.targetLineColor = targetLineColor;
}
public Move(Actor self, Target target, WDist range)
public Move(Actor self, Target target, WDist range, Color? targetLineColor = null)
{
mobile = self.Trait<Mobile>();
@@ -106,9 +111,10 @@ namespace OpenRA.Mods.Common.Activities
destination = null;
nearEnough = range;
this.targetLineColor = targetLineColor;
}
public Move(Actor self, Func<List<CPos>> getPath)
public Move(Actor self, Func<List<CPos>> getPath, Color? targetLineColor = null)
{
mobile = self.Trait<Mobile>();
@@ -116,6 +122,7 @@ namespace OpenRA.Mods.Common.Activities
destination = null;
nearEnough = WDist.Zero;
this.targetLineColor = targetLineColor;
}
static int HashList<T>(List<T> xs)
@@ -261,6 +268,12 @@ namespace OpenRA.Mods.Common.Activities
return Target.None;
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
if (targetLineColor != null)
yield return new TargetLineNode(Target.FromCell(self.World, destination.Value), targetLineColor.Value);
}
abstract class MovePart : Activity
{
protected readonly Move Move;

View File

@@ -99,13 +99,8 @@ namespace OpenRA.Mods.Common.Activities
// Target is equivalent to checkTarget variable in other activities
// value is either lastVisibleTarget or target based on visibility and validity
var targetIsValid = Target.IsValidFor(self);
var oldUseLastVisibleTarget = useLastVisibleTarget;
useLastVisibleTarget = targetIsHiddenActor || !targetIsValid;
// Update target lines if required
if (useLastVisibleTarget != oldUseLastVisibleTarget && targetLineColor.HasValue)
self.SetTargetLine(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value, false);
// Target is hidden or dead, and we don't have a fallback position to move towards
var noTarget = useLastVisibleTarget && !lastVisibleTarget.IsValidFor(self);
@@ -149,5 +144,11 @@ namespace OpenRA.Mods.Common.Activities
return Target.None;
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
if (targetLineColor.HasValue)
yield return new TargetLineNode(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value);
}
}
}

View File

@@ -12,6 +12,7 @@
using System.Collections.Generic;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Activities
@@ -20,14 +21,16 @@ namespace OpenRA.Mods.Common.Activities
{
readonly Mobile mobile;
readonly Target target;
readonly Color? targetLineColor;
readonly WDist targetMovementThreshold;
WPos targetStartPos;
public VisualMoveIntoTarget(Actor self, Target target, WDist targetMovementThreshold)
public VisualMoveIntoTarget(Actor self, Target target, WDist targetMovementThreshold, Color? targetLineColor = null)
{
mobile = self.Trait<Mobile>();
this.target = target;
this.targetMovementThreshold = targetMovementThreshold;
this.targetLineColor = targetLineColor;
}
protected override void OnFirstRun(Actor self)
@@ -76,5 +79,11 @@ namespace OpenRA.Mods.Common.Activities
{
yield return target;
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
if (targetLineColor != null)
yield return new TargetLineNode(target, targetLineColor.Value);
}
}
}

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System.Collections.Generic;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
@@ -79,7 +80,7 @@ namespace OpenRA.Mods.Common.Activities
switch (state)
{
case PickupState.Intercept:
QueueChild(movement.MoveWithinRange(Target.FromActor(cargo), WDist.FromCells(4), targetLineColor: Color.Yellow));
QueueChild(movement.MoveWithinRange(Target.FromActor(cargo), WDist.FromCells(4)));
state = PickupState.LockCarryable;
return false;
@@ -110,6 +111,11 @@ namespace OpenRA.Mods.Common.Activities
return true;
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
yield return new TargetLineNode(Target.FromActor(cargo), Color.Yellow);
}
class AttachUnit : Activity
{
readonly Actor cargo;

View File

@@ -149,6 +149,15 @@ namespace OpenRA.Mods.Common.Activities
base.Cancel(self, keepQueue);
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
if (ChildActivity == null)
yield return new TargetLineNode(host, Color.Green);
else
foreach (var n in ChildActivity.TargetLineNodes(self))
yield return n;
}
void OnResupplyEnding(Actor self)
{
if (aircraft != null)

View File

@@ -9,7 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.Common.Traits.Render;
@@ -149,16 +149,24 @@ namespace OpenRA.Mods.Common.Activities
{
readonly string orderString;
readonly Target target;
readonly Color? targetLineColor;
public IssueOrderAfterTransform(string orderString, Target target)
public IssueOrderAfterTransform(string orderString, Target target, Color? targetLineColor = null)
{
this.orderString = orderString;
this.target = target;
this.targetLineColor = targetLineColor;
}
public Order IssueOrderForTransformedActor(Actor newActor)
{
return new Order(orderString, newActor, target, true);
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
if (targetLineColor != null)
yield return new TargetLineNode(target, targetLineColor.Value);
}
}
}

View File

@@ -122,7 +122,6 @@ namespace OpenRA.Mods.Common.Activities
actor.CancelActivity();
pos.SetVisualPosition(actor, spawn);
actor.QueueActivity(move.MoveIntoWorld(actor, exitSubCell.Value.First, exitSubCell.Value.Second));
actor.SetTargetLine(Target.FromCell(w, exitSubCell.Value.First, exitSubCell.Value.Second), Color.Green, false);
w.Add(actor);
});
}