Overhaul target line rendering:
- Targets are now defined by the activities - Queued activities are shown - Support custom attack colors
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user