Overhaul target line rendering:
- Targets are now defined by the activities - Queued activities are shown - Support custom attack colors
This commit is contained in:
@@ -830,14 +830,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
#region Implement IMove
|
||||
|
||||
public Activity MoveTo(CPos cell, int nearEnough)
|
||||
public Activity MoveTo(CPos cell, int nearEnough, Color? targetLineColor = null)
|
||||
{
|
||||
return new Fly(self, Target.FromCell(self.World, cell));
|
||||
return new Fly(self, Target.FromCell(self.World, cell), targetLineColor: targetLineColor);
|
||||
}
|
||||
|
||||
public Activity MoveTo(CPos cell, Actor ignoreActor)
|
||||
public Activity MoveTo(CPos cell, Actor ignoreActor, Color? targetLineColor = null)
|
||||
{
|
||||
return new Fly(self, Target.FromCell(self.World, cell));
|
||||
return new Fly(self, Target.FromCell(self.World, cell), targetLineColor: targetLineColor);
|
||||
}
|
||||
|
||||
public Activity MoveWithinRange(Target target, WDist range,
|
||||
@@ -993,8 +993,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
UnReserve();
|
||||
|
||||
var target = Target.FromCell(self.World, cell);
|
||||
self.SetTargetLine(target, Color.Green);
|
||||
self.QueueActivity(order.Queued, new Fly(self, target));
|
||||
self.QueueActivity(order.Queued, new Fly(self, target, targetLineColor: Color.Green));
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
else if (orderString == "Land")
|
||||
{
|
||||
@@ -1007,8 +1007,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
var target = Target.FromCell(self.World, cell);
|
||||
|
||||
self.SetTargetLine(target, Color.Green);
|
||||
self.QueueActivity(order.Queued, new Land(self, target));
|
||||
self.QueueActivity(order.Queued, new Land(self, target, targetLineColor: Color.Green));
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
else if (orderString == "Enter" || orderString == "ForceEnter" || orderString == "Repair")
|
||||
{
|
||||
@@ -1029,13 +1029,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!order.Queued)
|
||||
UnReserve();
|
||||
|
||||
self.SetTargetLine(Target.FromActor(targetActor), Color.Green);
|
||||
|
||||
// Aircraft with TakeOffOnResupply would immediately take off again, so there's no point in automatically forcing
|
||||
// them to land on a resupplier. For aircraft without it, it makes more sense to land than to idle above a
|
||||
// free resupplier.
|
||||
var forceLand = isForceEnter || !Info.TakeOffOnResupply;
|
||||
self.QueueActivity(order.Queued, new ReturnToBase(self, targetActor, forceLand));
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
else if (orderString == "Stop")
|
||||
{
|
||||
@@ -1077,9 +1076,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
.Rotate(WRot.FromFacing(self.World.SharedRandom.Next(256)));
|
||||
var target = Target.FromPos(self.CenterPosition + offset);
|
||||
|
||||
self.CancelActivity();
|
||||
self.SetTargetLine(target, Color.Green, false);
|
||||
self.QueueActivity(new Fly(self, target));
|
||||
self.QueueActivity(false, new Fly(self, target));
|
||||
self.ShowTargetLines();
|
||||
UnReserve();
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
@@ -44,9 +45,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
aircraftInfo = self.Info.TraitInfo<AircraftInfo>();
|
||||
}
|
||||
|
||||
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack)
|
||||
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
|
||||
{
|
||||
return new FlyAttack(self, newTarget, forceAttack);
|
||||
return new FlyAttack(self, newTarget, forceAttack, targetLineColor);
|
||||
}
|
||||
|
||||
protected override bool CanAttack(Actor self, Target target)
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
@@ -85,7 +86,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
OnRemovedFromWorld(self);
|
||||
}
|
||||
|
||||
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack)
|
||||
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor)
|
||||
{
|
||||
throw new NotImplementedException("AttackBomber requires a scripted target");
|
||||
}
|
||||
|
||||
@@ -30,6 +30,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public readonly string OutsideRangeCursor = null;
|
||||
|
||||
[Desc("Color to use for the target line.")]
|
||||
public readonly Color TargetLineColor = Color.Red;
|
||||
|
||||
[Desc("Does the attack type require the attacker to enter the target's cell?")]
|
||||
public readonly bool AttackRequiresEnteringCell = false;
|
||||
|
||||
@@ -196,8 +199,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!order.Target.IsValidFor(self))
|
||||
return;
|
||||
|
||||
self.SetTargetLine(order.Target, Color.Red);
|
||||
AttackTarget(order.Target, order.Queued, true, forceAttack);
|
||||
AttackTarget(order.Target, order.Queued, true, forceAttack, Info.TargetLineColor);
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
|
||||
if (order.OrderString == "Stop")
|
||||
@@ -221,7 +224,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return order.OrderString == attackOrderName || order.OrderString == forceAttackOrderName ? Info.Voice : null;
|
||||
}
|
||||
|
||||
public abstract Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack);
|
||||
public abstract Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null);
|
||||
|
||||
public bool HasAnyValidWeapons(Target t, bool checkForCenterTargetingWeapons = false)
|
||||
{
|
||||
@@ -388,7 +391,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
&& a.Weapon.IsValidAgainst(t, self.World, self));
|
||||
}
|
||||
|
||||
public void AttackTarget(Target target, bool queued, bool allowMove, bool forceAttack = false)
|
||||
public void AttackTarget(Target target, bool queued, bool allowMove, bool forceAttack = false, Color? targetLineColor = null)
|
||||
{
|
||||
if (IsTraitDisabled)
|
||||
return;
|
||||
@@ -399,7 +402,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!queued)
|
||||
self.CancelActivity();
|
||||
|
||||
var activity = GetAttackActivity(self, target, allowMove, forceAttack);
|
||||
var activity = GetAttackActivity(self, target, allowMove, forceAttack, targetLineColor);
|
||||
self.QueueActivity(activity);
|
||||
OnQueueAttackActivity(self, activity, target, allowMove, forceAttack);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Primitives;
|
||||
@@ -151,9 +152,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
base.Tick(self);
|
||||
}
|
||||
|
||||
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack)
|
||||
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
|
||||
{
|
||||
return new AttackActivity(self, newTarget, allowMove, forceAttack);
|
||||
return new AttackActivity(self, newTarget, allowMove, forceAttack, targetLineColor);
|
||||
}
|
||||
|
||||
public override void OnQueueAttackActivity(Actor self, Activity activity, Target target, bool allowMove, bool forceAttack)
|
||||
@@ -213,6 +214,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
readonly RevealsShroud[] revealsShroud;
|
||||
readonly IMove move;
|
||||
readonly bool forceAttack;
|
||||
readonly Color? targetLineColor;
|
||||
|
||||
Target target;
|
||||
Target lastVisibleTarget;
|
||||
@@ -224,7 +226,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
bool wasMovingWithinRange;
|
||||
bool hasTicked;
|
||||
|
||||
public AttackActivity(Actor self, Target target, bool allowMove, bool forceAttack)
|
||||
public AttackActivity(Actor self, Target target, bool allowMove, bool forceAttack, Color? targetLineColor = null)
|
||||
{
|
||||
attack = self.Trait<AttackFollow>();
|
||||
move = allowMove ? self.TraitOrDefault<IMove>() : null;
|
||||
@@ -232,6 +234,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
this.target = target;
|
||||
this.forceAttack = forceAttack;
|
||||
this.targetLineColor = targetLineColor;
|
||||
|
||||
// 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
|
||||
@@ -290,7 +293,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
|
||||
var oldUseLastVisibleTarget = useLastVisibleTarget;
|
||||
var maxRange = lastVisibleMaximumRange;
|
||||
var minRange = lastVisibleMinimumRange;
|
||||
useLastVisibleTarget = targetIsHiddenActor || !target.IsValidFor(self);
|
||||
@@ -313,10 +315,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
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;
|
||||
@@ -339,7 +337,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return true;
|
||||
|
||||
wasMovingWithinRange = true;
|
||||
QueueChild(move.MoveWithinRange(target, minRange, maxRange, checkTarget.CenterPosition, Color.Red));
|
||||
QueueChild(move.MoveWithinRange(target, minRange, maxRange, checkTarget.CenterPosition));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -358,6 +356,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!autoTarget.HasValidTargetPriority(self, lastVisibleOwner, lastVisibleTargetTypes))
|
||||
attack.ClearRequestedTarget();
|
||||
}
|
||||
|
||||
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
|
||||
{
|
||||
if (targetLineColor != null)
|
||||
yield return new TargetLineNode(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#endregion
|
||||
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
@@ -41,9 +42,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return TargetInFiringArc(self, target, Info.FacingTolerance);
|
||||
}
|
||||
|
||||
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack)
|
||||
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
|
||||
{
|
||||
return new Activities.Attack(self, newTarget, allowMove, forceAttack);
|
||||
return new Activities.Attack(self, newTarget, allowMove, forceAttack, targetLineColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,10 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
@@ -25,9 +27,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public AttackOmni(Actor self, AttackOmniInfo info)
|
||||
: base(self, info) { }
|
||||
|
||||
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack)
|
||||
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
|
||||
{
|
||||
return new SetTarget(this, newTarget, allowMove, forceAttack);
|
||||
return new SetTarget(this, newTarget, allowMove, forceAttack, targetLineColor);
|
||||
}
|
||||
|
||||
// Some 3rd-party mods rely on this being public
|
||||
@@ -36,11 +38,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
readonly AttackOmni attack;
|
||||
readonly bool allowMove;
|
||||
readonly bool forceAttack;
|
||||
readonly Color? targetLineColor;
|
||||
Target target;
|
||||
|
||||
public SetTarget(AttackOmni attack, Target target, bool allowMove, bool forceAttack)
|
||||
public SetTarget(AttackOmni attack, Target target, bool allowMove, bool forceAttack, Color? targetLineColor = null)
|
||||
{
|
||||
this.target = target;
|
||||
this.targetLineColor = targetLineColor;
|
||||
this.attack = attack;
|
||||
this.allowMove = allowMove;
|
||||
this.forceAttack = forceAttack;
|
||||
@@ -77,6 +81,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
target = Target.Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
|
||||
{
|
||||
if (targetLineColor != null)
|
||||
yield return new TargetLineNode(target, targetLineColor.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,9 +77,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return;
|
||||
|
||||
var targetLocation = move.NearestMoveableCell(cell);
|
||||
self.SetTargetLine(Target.FromCell(self.World, targetLocation), Color.Red);
|
||||
var assaultMoving = order.OrderString == "AssaultMove";
|
||||
self.QueueActivity(new AttackMoveActivity(self, () => move.MoveTo(targetLocation, 1), assaultMoving));
|
||||
self.QueueActivity(new AttackMoveActivity(self, () => move.MoveTo(targetLocation, 1, targetLineColor: Color.Red), assaultMoving));
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,8 +311,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
void Attack(Actor self, Target target, bool allowMove)
|
||||
{
|
||||
self.SetTargetLine(target, Color.Red, false);
|
||||
|
||||
foreach (var ab in ActiveAttackBases)
|
||||
ab.AttackTarget(target, false, allowMove);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public readonly string Image = "rallypoint";
|
||||
|
||||
[Desc("Width (in pixels) of the rallypoint line.")]
|
||||
public readonly int LineWidth = 2;
|
||||
|
||||
[SequenceReference("Image")]
|
||||
public readonly string FlagSequence = "flag";
|
||||
|
||||
|
||||
@@ -103,8 +103,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return;
|
||||
|
||||
var target = Target.FromCell(self.World, cell);
|
||||
|
||||
self.SetTargetLine(target, Color.Green);
|
||||
}
|
||||
else if (order.OrderString == "Enter")
|
||||
{
|
||||
@@ -114,10 +112,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return;
|
||||
|
||||
var targetActor = order.Target.Actor;
|
||||
|
||||
// We only want to set a target line if the order will (most likely) succeed
|
||||
if (Reservable.IsAvailableFor(targetActor, self))
|
||||
self.SetTargetLine(Target.FromActor(targetActor), Color.Green);
|
||||
}
|
||||
|
||||
var currentTransform = self.CurrentActivity as Transform;
|
||||
@@ -130,10 +124,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!order.Queued && activity.NextActivity != null)
|
||||
activity.NextActivity.Cancel(self);
|
||||
|
||||
activity.Queue(new IssueOrderAfterTransform(order.OrderString, order.Target));
|
||||
activity.Queue(new IssueOrderAfterTransform(order.OrderString, order.Target, Color.Green));
|
||||
|
||||
if (currentTransform == null)
|
||||
self.QueueActivity(order.Queued, activity);
|
||||
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
|
||||
string IOrderVoice.VoicePhraseForOrder(Actor self, Order order)
|
||||
|
||||
@@ -93,17 +93,17 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (transform == null && currentTransform == null)
|
||||
return;
|
||||
|
||||
self.SetTargetLine(order.Target, Color.Green);
|
||||
|
||||
// Manually manage the inner activity queue
|
||||
var activity = currentTransform ?? transform.GetTransformActivity(self);
|
||||
if (!order.Queued && activity.NextActivity != null)
|
||||
activity.NextActivity.Cancel(self);
|
||||
|
||||
activity.Queue(new IssueOrderAfterTransform(order.OrderString, order.Target));
|
||||
activity.Queue(new IssueOrderAfterTransform(order.OrderString, order.Target, Color.Green));
|
||||
|
||||
if (currentTransform == null)
|
||||
self.QueueActivity(order.Queued, activity);
|
||||
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
|
||||
string IOrderVoice.VoicePhraseForOrder(Actor self, Order order)
|
||||
|
||||
@@ -107,17 +107,17 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (transform == null && currentTransform == null)
|
||||
return;
|
||||
|
||||
self.SetTargetLine(Target.FromCell(self.World, cell), Color.Green);
|
||||
|
||||
// Manually manage the inner activity queue
|
||||
var activity = currentTransform ?? transform.GetTransformActivity(self);
|
||||
if (!order.Queued && activity.NextActivity != null)
|
||||
activity.NextActivity.Cancel(self);
|
||||
|
||||
activity.Queue(new IssueOrderAfterTransform("Move", order.Target));
|
||||
activity.Queue(new IssueOrderAfterTransform("Move", order.Target, Color.Green));
|
||||
|
||||
if (currentTransform == null)
|
||||
self.QueueActivity(order.Queued, activity);
|
||||
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
else if (order.OrderString == "Stop")
|
||||
{
|
||||
|
||||
@@ -117,17 +117,17 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (transform == null && currentTransform == null)
|
||||
return;
|
||||
|
||||
self.SetTargetLine(order.Target, Color.Green);
|
||||
|
||||
// Manually manage the inner activity queue
|
||||
var activity = currentTransform ?? transform.GetTransformActivity(self);
|
||||
if (!order.Queued && activity.NextActivity != null)
|
||||
activity.NextActivity.Cancel(self);
|
||||
|
||||
activity.Queue(new IssueOrderAfterTransform(order.OrderString, order.Target));
|
||||
activity.Queue(new IssueOrderAfterTransform(order.OrderString, order.Target, Color.Green));
|
||||
|
||||
if (currentTransform == null)
|
||||
self.QueueActivity(order.Queued, activity);
|
||||
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
|
||||
string IOrderVoice.VoicePhraseForOrder(Actor self, Order order)
|
||||
|
||||
@@ -111,17 +111,17 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (transform == null && currentTransform == null)
|
||||
return;
|
||||
|
||||
self.SetTargetLine(order.Target, Color.Green);
|
||||
|
||||
// Manually manage the inner activity queue
|
||||
var activity = currentTransform ?? transform.GetTransformActivity(self);
|
||||
if (!order.Queued && activity.NextActivity != null)
|
||||
activity.NextActivity.Cancel(self);
|
||||
|
||||
activity.Queue(new IssueOrderAfterTransform(order.OrderString, order.Target));
|
||||
activity.Queue(new IssueOrderAfterTransform(order.OrderString, order.Target, Color.Green));
|
||||
|
||||
if (currentTransform == null)
|
||||
self.QueueActivity(order.Queued, activity);
|
||||
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
|
||||
string IOrderVoice.VoicePhraseForOrder(Actor self, Order order)
|
||||
|
||||
@@ -98,8 +98,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!order.Queued)
|
||||
self.CancelActivity();
|
||||
|
||||
self.SetTargetLine(order.Target, Color.Red);
|
||||
self.QueueActivity(new CaptureActor(self, order.Target));
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
|
||||
protected override void TraitEnabled(Actor self) { captureManager.RefreshCaptures(self); }
|
||||
|
||||
@@ -297,8 +297,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return;
|
||||
|
||||
var targetLocation = move.NearestMoveableCell(cell);
|
||||
self.SetTargetLine(Target.FromCell(self.World, targetLocation), Color.Yellow);
|
||||
self.QueueActivity(order.Queued, new DeliverUnit(self, order.Target, Info.DropRange));
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
else if (order.OrderString == "Unload")
|
||||
{
|
||||
@@ -316,8 +316,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!order.Queued)
|
||||
self.CancelActivity();
|
||||
|
||||
self.SetTargetLine(order.Target, Color.Yellow);
|
||||
self.QueueActivity(order.Queued, new PickupUnit(self, order.Target.Actor, Info.BeforeLoadDelay));
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,8 +76,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!order.Queued)
|
||||
self.CancelActivity();
|
||||
|
||||
self.SetTargetLine(order.Target, Color.Yellow);
|
||||
self.QueueActivity(new DonateCash(self, order.Target, info.Payload, info.PlayerExperience));
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
|
||||
void INotifyCashTransfer.OnAcceptingCash(Actor self, Actor donor) { }
|
||||
|
||||
@@ -87,8 +87,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!order.Queued)
|
||||
self.CancelActivity();
|
||||
|
||||
self.SetTargetLine(order.Target, Color.Yellow);
|
||||
self.QueueActivity(new DonateExperience(self, order.Target, gainsExperience.Level, info.PlayerExperience));
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
|
||||
public class DeliversExperienceOrderTargeter : UnitOrderTargeter
|
||||
|
||||
@@ -86,9 +86,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!order.Queued)
|
||||
self.CancelActivity();
|
||||
|
||||
self.SetTargetLine(order.Target, Color.Red);
|
||||
self.QueueActivity(new Demolish(self, order.Target, info.EnterBehaviour, info.DetonationDelay,
|
||||
info.Flashes, info.FlashesDelay, info.FlashInterval));
|
||||
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
|
||||
public string VoicePhraseForOrder(Actor self, Order order)
|
||||
|
||||
@@ -95,8 +95,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!order.Queued)
|
||||
self.CancelActivity();
|
||||
|
||||
self.SetTargetLine(order.Target, Color.Yellow);
|
||||
self.QueueActivity(new RepairBuilding(self, order.Target, Info));
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
|
||||
class EngineerRepairOrderTargeter : UnitOrderTargeter
|
||||
|
||||
@@ -85,9 +85,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!order.Queued)
|
||||
self.CancelActivity();
|
||||
|
||||
self.SetTargetLine(Target.FromCell(self.World, tunnel.Exit.Value), Color.Green);
|
||||
self.QueueActivity(move.MoveTo(tunnel.Entrance, tunnel.NearEnough));
|
||||
self.QueueActivity(move.MoveTo(tunnel.Exit.Value, tunnel.NearEnough));
|
||||
self.QueueActivity(move.MoveTo(tunnel.Entrance, tunnel.NearEnough, targetLineColor: Color.Green));
|
||||
self.QueueActivity(move.MoveTo(tunnel.Exit.Value, tunnel.NearEnough, targetLineColor: Color.Green));
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
|
||||
IEnumerable<VariableObserver> IObservesVariables.GetVariableObservers()
|
||||
|
||||
@@ -53,10 +53,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (target.Type != TargetType.Actor)
|
||||
return;
|
||||
|
||||
self.SetTargetLine(target, Color.Yellow);
|
||||
|
||||
var range = target.Actor.Info.TraitInfo<GuardableInfo>().Range;
|
||||
self.QueueActivity(new AttackMoveActivity(self, () => move.MoveFollow(self, target, WDist.Zero, range, targetLineColor: Color.Yellow)));
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
|
||||
public string VoicePhraseForOrder(Actor self, Order order)
|
||||
|
||||
@@ -149,24 +149,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
self.World.AddFrameEndTask(w => self.QueueActivity(new FindAndDeliverResources(self)));
|
||||
}
|
||||
|
||||
public void SetProcLines(Actor proc)
|
||||
{
|
||||
if (proc == null || proc.IsDead)
|
||||
return;
|
||||
|
||||
var linkedHarvs = proc.World.ActorsHavingTrait<Harvester>(h => h.LinkedProc == proc)
|
||||
.Select(a => Target.FromActor(a))
|
||||
.ToList();
|
||||
|
||||
proc.SetTargetLines(linkedHarvs, Color.Gold);
|
||||
}
|
||||
|
||||
public void LinkProc(Actor self, Actor proc)
|
||||
{
|
||||
var oldProc = LinkedProc;
|
||||
LinkedProc = proc;
|
||||
SetProcLines(oldProc);
|
||||
SetProcLines(proc);
|
||||
}
|
||||
|
||||
public void UnlinkProc(Actor self, Actor proc)
|
||||
@@ -345,10 +330,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
loc = self.Location;
|
||||
}
|
||||
|
||||
self.SetTargetLine(Target.FromCell(self.World, loc), Color.Red);
|
||||
|
||||
// FindResources takes care of calling INotifyHarvesterAction
|
||||
self.QueueActivity(order.Queued, new FindAndDeliverResources(self, loc));
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
else if (order.OrderString == "Deliver")
|
||||
{
|
||||
@@ -362,8 +346,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (iao == null || !iao.AllowDocking || !IsAcceptableProcType(targetActor))
|
||||
return;
|
||||
|
||||
self.SetTargetLine(order.Target, Color.Green);
|
||||
self.QueueActivity(order.Queued, new FindAndDeliverResources(self, targetActor));
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -314,8 +314,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (moveTo.HasValue)
|
||||
{
|
||||
self.CancelActivity();
|
||||
self.SetTargetLine(Target.FromCell(self.World, moveTo.Value), Color.Green, false);
|
||||
self.QueueActivity(new Move(self, moveTo.Value, WDist.Zero));
|
||||
self.ShowTargetLines();
|
||||
|
||||
Log.Write("debug", "OnNudge #{0} from {1} to {2}",
|
||||
self.ActorID, self.Location, moveTo.Value);
|
||||
@@ -527,14 +527,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return inner;
|
||||
}
|
||||
|
||||
public Activity MoveTo(CPos cell, int nearEnough)
|
||||
public Activity MoveTo(CPos cell, int nearEnough, Color? targetLineColor = null)
|
||||
{
|
||||
return WrapMove(new Move(self, cell, WDist.FromCells(nearEnough), null));
|
||||
return WrapMove(new Move(self, cell, WDist.FromCells(nearEnough), targetLineColor: targetLineColor));
|
||||
}
|
||||
|
||||
public Activity MoveTo(CPos cell, Actor ignoreActor)
|
||||
public Activity MoveTo(CPos cell, Actor ignoreActor, Color? targetLineColor = null)
|
||||
{
|
||||
return WrapMove(new Move(self, cell, WDist.Zero, ignoreActor));
|
||||
return WrapMove(new Move(self, cell, WDist.Zero, ignoreActor, targetLineColor: targetLineColor));
|
||||
}
|
||||
|
||||
public Activity MoveWithinRange(Target target, WDist range,
|
||||
@@ -805,8 +805,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!order.Queued)
|
||||
self.CancelActivity();
|
||||
|
||||
self.SetTargetLine(Target.FromCell(self.World, cell), Color.Green);
|
||||
self.QueueActivity(order.Queued, WrapMove(new Move(self, cell, WDist.FromCells(8), null, true)));
|
||||
self.QueueActivity(order.Queued, WrapMove(new Move(self, cell, WDist.FromCells(8), null, true, Color.Green)));
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
|
||||
// TODO: This should only cancel activities queued by this trait
|
||||
|
||||
@@ -162,8 +162,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!order.Queued)
|
||||
self.CancelActivity();
|
||||
|
||||
self.SetTargetLine(order.Target, Color.Green);
|
||||
self.QueueActivity(new EnterTransport(self, order.Target));
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
|
||||
public bool Reserve(Actor self, Cargo cargo)
|
||||
|
||||
@@ -43,7 +43,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var exit = CPos.Zero;
|
||||
var exitLocation = CPos.Zero;
|
||||
var target = Target.Invalid;
|
||||
|
||||
// Clone the initializer dictionary for the new actor
|
||||
var td = new TypeDictionary();
|
||||
@@ -70,7 +69,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
exitLocation = rp.Value != null ? rp.Value.Location : exit;
|
||||
target = Target.FromCell(self.World, exitLocation);
|
||||
|
||||
td.Add(new LocationInit(exit));
|
||||
td.Add(new CenterPositionInit(spawn));
|
||||
@@ -94,8 +92,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
|
||||
newUnit.SetTargetLine(target, rp.Value != null ? Color.Red : Color.Green, false);
|
||||
|
||||
if (!self.IsDead)
|
||||
foreach (var t in self.TraitsImplementing<INotifyProduction>())
|
||||
t.UnitProduced(self, newUnit, exit);
|
||||
|
||||
@@ -93,8 +93,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (move != null)
|
||||
newUnit.QueueActivity(move.MoveTo(destination, 2));
|
||||
|
||||
newUnit.SetTargetLine(Target.FromCell(self.World, destination), Color.Green, false);
|
||||
|
||||
if (!self.IsDead)
|
||||
foreach (var t in self.TraitsImplementing<INotifyProduction>())
|
||||
t.UnitProduced(self, newUnit, destination);
|
||||
|
||||
@@ -103,7 +103,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var exit = CPos.Zero;
|
||||
var exitLocation = CPos.Zero;
|
||||
var target = Target.Invalid;
|
||||
|
||||
var info = (ProductionParadropInfo)Info;
|
||||
var actorType = info.ActorType;
|
||||
@@ -124,7 +123,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var initialFacing = exitinfo.Facing < 0 ? (to - spawn).Yaw.Facing : exitinfo.Facing;
|
||||
|
||||
exitLocation = rp.Value != null ? rp.Value.Location : exit;
|
||||
target = Target.FromCell(self.World, exitLocation);
|
||||
|
||||
td.Add(new LocationInit(exit));
|
||||
td.Add(new CenterPositionInit(spawn));
|
||||
@@ -149,8 +147,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
|
||||
newUnit.SetTargetLine(target, rp.Value != null ? Color.Red : Color.Green, false);
|
||||
|
||||
if (!self.IsDead)
|
||||
foreach (var t in self.TraitsImplementing<INotifyProduction>())
|
||||
t.UnitProduced(self, newUnit, exit);
|
||||
|
||||
@@ -10,24 +10,31 @@
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Renders target lines between order waypoints.")]
|
||||
public class DrawLineToTargetInfo : ITraitInfo
|
||||
{
|
||||
[Desc("Delay (in ticks) before the target lines disappear.")]
|
||||
public readonly int Delay = 60;
|
||||
|
||||
[Desc("Width (in pixels) of the target lines.")]
|
||||
public readonly int LineWidth = 2;
|
||||
|
||||
[Desc("Width (in pixels) of the end node markers.")]
|
||||
public readonly int MarkerWidth = 3;
|
||||
|
||||
public virtual object Create(ActorInitializer init) { return new DrawLineToTarget(init.Self, this); }
|
||||
}
|
||||
|
||||
public class DrawLineToTarget : IRenderAboveShroudWhenSelected, INotifySelected, INotifyBecomingIdle, INotifyOwnerChanged
|
||||
public class DrawLineToTarget : IRenderAboveShroudWhenSelected, INotifySelected
|
||||
{
|
||||
readonly DrawLineToTargetInfo info;
|
||||
List<Target> targets;
|
||||
Color c;
|
||||
int lifetime;
|
||||
|
||||
public DrawLineToTarget(Actor self, DrawLineToTargetInfo info)
|
||||
@@ -35,25 +42,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void SetTarget(Actor self, Target target, Color c, bool display)
|
||||
{
|
||||
targets = new List<Target> { target };
|
||||
this.c = c;
|
||||
|
||||
if (display)
|
||||
lifetime = info.Delay;
|
||||
}
|
||||
|
||||
public void SetTargets(Actor self, List<Target> targets, Color c, bool display)
|
||||
{
|
||||
this.targets = targets;
|
||||
this.c = c;
|
||||
|
||||
if (display)
|
||||
lifetime = info.Delay;
|
||||
}
|
||||
|
||||
void INotifySelected.Selected(Actor a)
|
||||
public void ShowTargetLines(Actor a)
|
||||
{
|
||||
if (a.IsIdle)
|
||||
return;
|
||||
@@ -62,65 +51,57 @@ namespace OpenRA.Mods.Common.Traits
|
||||
lifetime = info.Delay;
|
||||
}
|
||||
|
||||
void INotifySelected.Selected(Actor a)
|
||||
{
|
||||
ShowTargetLines(a);
|
||||
}
|
||||
|
||||
IEnumerable<IRenderable> IRenderAboveShroudWhenSelected.RenderAboveShroud(Actor self, WorldRenderer wr)
|
||||
{
|
||||
var force = Game.GetModifierKeys().HasModifier(Modifiers.Alt);
|
||||
if ((lifetime <= 0 || --lifetime <= 0) && !force)
|
||||
if (self.Owner != self.World.LocalPlayer)
|
||||
yield break;
|
||||
|
||||
// Players want to see the lines when in waypoint mode.
|
||||
var force = Game.GetModifierKeys().HasModifier(Modifiers.Shift);
|
||||
|
||||
if (--lifetime <= 0 && !force)
|
||||
yield break;
|
||||
|
||||
if (!(force || Game.Settings.Game.DrawTargetLine))
|
||||
yield break;
|
||||
|
||||
if (targets == null || targets.Count == 0)
|
||||
yield break;
|
||||
|
||||
foreach (var target in targets)
|
||||
var prev = self.CenterPosition;
|
||||
var a = self.CurrentActivity;
|
||||
for (; a != null; a = a.NextActivity)
|
||||
{
|
||||
if (target.Type == TargetType.Invalid)
|
||||
if (a.IsCanceling)
|
||||
continue;
|
||||
|
||||
yield return new TargetLineRenderable(new[] { self.CenterPosition, target.CenterPosition }, c);
|
||||
foreach (var n in a.TargetLineNodes(self))
|
||||
{
|
||||
if (n.Target.Type != TargetType.Invalid)
|
||||
{
|
||||
yield return new TargetLineRenderable(new[] { prev, n.Target.CenterPosition }, n.Color, info.LineWidth, info.MarkerWidth);
|
||||
prev = n.Target.CenterPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool IRenderAboveShroudWhenSelected.SpatiallyPartitionable { get { return false; } }
|
||||
|
||||
void INotifyBecomingIdle.OnBecomingIdle(Actor self)
|
||||
{
|
||||
targets = null;
|
||||
}
|
||||
|
||||
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||
{
|
||||
targets = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class LineTargetExts
|
||||
{
|
||||
public static void SetTargetLines(this Actor self, List<Target> targets, Color color)
|
||||
public static void ShowTargetLines(this Actor self)
|
||||
{
|
||||
var line = self.TraitOrDefault<DrawLineToTarget>();
|
||||
if (line != null)
|
||||
self.World.AddFrameEndTask(w => line.SetTargets(self, targets, color, false));
|
||||
}
|
||||
|
||||
public static void SetTargetLine(this Actor self, Target target, Color color)
|
||||
{
|
||||
self.SetTargetLine(target, color, true);
|
||||
}
|
||||
|
||||
public static void SetTargetLine(this Actor self, Target target, Color color, bool display)
|
||||
{
|
||||
if (!self.Owner.IsAlliedWith(self.World.LocalPlayer))
|
||||
return;
|
||||
|
||||
if (self.Disposed)
|
||||
if (self.Owner != self.World.LocalPlayer)
|
||||
return;
|
||||
|
||||
// Draw after frame end so that all the queueing of activities are done before drawing.
|
||||
var line = self.TraitOrDefault<DrawLineToTarget>();
|
||||
if (line != null)
|
||||
line.SetTarget(self, target, color, display);
|
||||
self.World.AddFrameEndTask(w => line.ShowTargetLines(self));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,8 +123,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!CanRepairAt(order.Target.Actor) || (!CanRepair() && !CanRearm()))
|
||||
return;
|
||||
|
||||
self.SetTargetLine(order.Target, Color.Green);
|
||||
self.QueueActivity(order.Queued, new Resupply(self, order.Target.Actor, new WDist(512)));
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
|
||||
IEnumerable<VariableObserver> IObservesVariables.GetVariableObservers()
|
||||
|
||||
@@ -102,8 +102,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!order.Queued)
|
||||
self.CancelActivity();
|
||||
|
||||
self.SetTargetLine(order.Target, Color.Green);
|
||||
self.QueueActivity(new Resupply(self, order.Target.Actor, Info.CloseEnough));
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
|
||||
public Actor FindRepairBuilding(Actor self)
|
||||
|
||||
@@ -105,8 +105,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!order.Queued)
|
||||
self.CancelActivity();
|
||||
|
||||
self.SetTargetLine(order.Target, Color.Yellow);
|
||||
self.QueueActivity(new RepairBridge(self, order.Target, info.EnterBehaviour, info.RepairNotification));
|
||||
self.ShowTargetLines();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user