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

@@ -9,6 +9,7 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Cnc.Traits;
@@ -27,6 +28,7 @@ namespace OpenRA.Mods.Cnc.Activities
readonly Mobile mobile;
readonly bool allowMovement;
readonly bool forceAttack;
readonly Color? targetLineColor;
Target target;
Target lastVisibleTarget;
@@ -36,9 +38,10 @@ namespace OpenRA.Mods.Cnc.Activities
BitSet<TargetableType> lastVisibleTargetTypes;
Player lastVisibleOwner;
public LeapAttack(Actor self, Target target, bool allowMovement, bool forceAttack, AttackLeap attack, AttackLeapInfo info)
public LeapAttack(Actor self, Target target, bool allowMovement, bool forceAttack, AttackLeap attack, AttackLeapInfo info, Color? targetLineColor = null)
{
this.target = target;
this.targetLineColor = targetLineColor;
this.info = info;
this.attack = attack;
this.allowMovement = allowMovement;
@@ -88,13 +91,8 @@ namespace OpenRA.Mods.Cnc.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;
@@ -161,5 +159,11 @@ namespace OpenRA.Mods.Cnc.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

@@ -12,6 +12,7 @@
using OpenRA.Activities;
using OpenRA.Mods.Cnc.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Traits
@@ -71,9 +72,9 @@ namespace OpenRA.Mods.Cnc.Traits
leapToken = conditionManager.RevokeCondition(self, leapToken);
}
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)
{
return new LeapAttack(self, newTarget, allowMove, forceAttack, this, info);
return new LeapAttack(self, newTarget, allowMove, forceAttack, this, info, targetLineColor);
}
}
}

View File

@@ -9,9 +9,12 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Traits
@@ -27,9 +30,9 @@ namespace OpenRA.Mods.Cnc.Traits
public AttackTDGunboatTurreted(Actor self, AttackTDGunboatTurretedInfo 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)
{
return new AttackTDGunboatTurretedActivity(self, newTarget, allowMove, forceAttack);
return new AttackTDGunboatTurretedActivity(self, newTarget, allowMove, forceAttack, targetLineColor);
}
class AttackTDGunboatTurretedActivity : Activity
@@ -37,13 +40,15 @@ namespace OpenRA.Mods.Cnc.Traits
readonly AttackTDGunboatTurreted attack;
readonly Target target;
readonly bool forceAttack;
readonly Color? targetLineColor;
bool hasTicked;
public AttackTDGunboatTurretedActivity(Actor self, Target target, bool allowMove, bool forceAttack)
public AttackTDGunboatTurretedActivity(Actor self, Target target, bool allowMove, bool forceAttack, Color? targetLineColor = null)
{
attack = self.Trait<AttackTDGunboatTurreted>();
this.target = target;
this.forceAttack = forceAttack;
this.targetLineColor = targetLineColor;
}
public override bool Tick(Actor self)
@@ -68,6 +73,12 @@ namespace OpenRA.Mods.Cnc.Traits
return false;
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
if (targetLineColor != null)
yield return new TargetLineNode(target, targetLineColor.Value);
}
}
}
}

View File

@@ -9,9 +9,11 @@
*/
#endregion
using System.Collections.Generic;
using OpenRA.Activities;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Traits
@@ -76,9 +78,9 @@ namespace OpenRA.Mods.Cnc.Traits
void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel) { }
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 ChargeAttack(this, newTarget, forceAttack);
return new ChargeAttack(this, newTarget, forceAttack, targetLineColor);
}
class ChargeAttack : Activity, IActivityNotifyStanceChanged
@@ -86,12 +88,14 @@ namespace OpenRA.Mods.Cnc.Traits
readonly AttackTesla attack;
readonly Target target;
readonly bool forceAttack;
readonly Color? targetLineColor;
public ChargeAttack(AttackTesla attack, Target target, bool forceAttack)
public ChargeAttack(AttackTesla attack, Target target, bool forceAttack, Color? targetLineColor = null)
{
this.attack = attack;
this.target = target;
this.forceAttack = forceAttack;
this.targetLineColor = targetLineColor;
}
public override bool Tick(Actor self)
@@ -132,6 +136,12 @@ namespace OpenRA.Mods.Cnc.Traits
Cancel(self, true);
}
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
if (targetLineColor != null)
yield return new TargetLineNode(target, targetLineColor.Value);
}
}
class ChargeFire : Activity

View File

@@ -117,8 +117,8 @@ namespace OpenRA.Mods.Cnc.Traits
if (!order.Queued)
self.CancelActivity();
self.SetTargetLine(order.Target, Color.Red);
self.QueueActivity(new Infiltrate(self, order.Target, this));
self.ShowTargetLines();
}
}

View File

@@ -141,8 +141,8 @@ namespace OpenRA.Mods.Cnc.Traits
{
if (order.OrderString == "DetonateAttack")
{
self.SetTargetLine(order.Target, Color.Red);
self.QueueActivity(order.Queued, new DetonationSequence(self, this, order.Target));
self.ShowTargetLines();
}
else if (order.OrderString == "Detonate")
self.QueueActivity(order.Queued, new DetonationSequence(self, this));
@@ -248,6 +248,11 @@ namespace OpenRA.Mods.Cnc.Traits
});
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
yield return new TargetLineNode(target, Color.Crimson);
}
void EjectDriver()
{
var driver = self.World.CreateActor(mad.info.DriverActor.ToLowerInvariant(), new TypeDictionary

View File

@@ -112,10 +112,9 @@ namespace OpenRA.Mods.Cnc.Traits
Minefield = GetMinefieldCells(minefieldStart, cell, info.MinefieldDepth)
.Where(p => movement.CanEnterCell(p, null, false)).ToArray();
if (Minefield.Length == 1 && Minefield[0] != self.Location)
self.SetTargetLine(Target.FromCell(self.World, Minefield[0]), Color.Red);
self.QueueActivity(order.Queued, new LayMines(self, Minefield));
if (Minefield.Length == 1 && Minefield[0] != self.Location)
self.ShowTargetLines();
}
}

View File

@@ -114,12 +114,12 @@ namespace OpenRA.Mods.Cnc.Traits
self.CancelActivity();
var cell = self.World.Map.CellContaining(order.Target.CenterPosition);
self.SetTargetLine(order.Target, Color.LawnGreen);
if (maxDistance != null)
self.QueueActivity(move.MoveWithinRange(order.Target, WDist.FromCells(maxDistance.Value)));
self.QueueActivity(move.MoveWithinRange(order.Target, WDist.FromCells(maxDistance.Value), targetLineColor: Color.LawnGreen));
self.QueueActivity(new Teleport(self, cell, maxDistance, Info.KillCargo, Info.FlashScreen, Info.ChronoshiftSound));
self.QueueActivity(move.MoveTo(cell, 5));
self.QueueActivity(move.MoveTo(cell, 5, Color.LawnGreen));
self.ShowTargetLines();
}
}

View File

@@ -183,8 +183,8 @@ namespace OpenRA.Mods.Cnc.Traits
self.World.UpdateMaps(self, this);
}
public Activity MoveTo(CPos cell, int nearEnough) { return null; }
public Activity MoveTo(CPos cell, Actor ignoreActor) { return null; }
public Activity MoveTo(CPos cell, int nearEnough, Color? targetLineColor = null) { return null; }
public Activity MoveTo(CPos cell, Actor ignoreActor, Color? targetLineColor = null) { return null; }
public Activity MoveWithinRange(Target target, WDist range,
WPos? initialTargetPosition = null, Color? targetLineColor = null) { return null; }
public Activity MoveWithinRange(Target target, WDist minRange, WDist maxRange,