Allow Attack activities to target FrozenActors directly.
Removing the legacy FrozenActor to Actor workaround fixes a number of long-standing bugs. This also prevents units from losing their target when it transforms into a different actor type.
This commit is contained in:
committed by
Oliver Brakmann
parent
0406b89a96
commit
c34dd4b824
@@ -31,6 +31,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Does the attack type require the attacker to enter the target's cell?")]
|
||||
public readonly bool AttackRequiresEnteringCell = false;
|
||||
|
||||
[Desc("Allow firing into the fog to target frozen actors without requiring force-fire.")]
|
||||
public readonly bool TargetFrozenActors = false;
|
||||
|
||||
[VoiceReference] public readonly string Voice = "Action";
|
||||
|
||||
public override abstract object Create(ActorInitializer init);
|
||||
@@ -154,12 +157,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var forceAttack = order.OrderString == forceAttackOrderName;
|
||||
if (forceAttack || order.OrderString == attackOrderName)
|
||||
{
|
||||
var target = self.ResolveFrozenActorOrder(order, Color.Red);
|
||||
if (!target.IsValidFor(self))
|
||||
if (!order.Target.IsValidFor(self))
|
||||
return;
|
||||
|
||||
self.SetTargetLine(target, Color.Red);
|
||||
AttackTarget(target, order.Queued, true, forceAttack);
|
||||
self.SetTargetLine(order.Target, Color.Red);
|
||||
AttackTarget(order.Target, order.Queued, true, forceAttack);
|
||||
}
|
||||
|
||||
if (order.OrderString == "Stop")
|
||||
@@ -417,7 +419,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (a == null)
|
||||
a = armaments.First();
|
||||
|
||||
cursor = !target.IsInRange(self.CenterPosition, a.MaxRange())
|
||||
cursor = !target.IsInRange(self.CenterPosition, a.MaxRange()) ||
|
||||
(!forceAttack && target.Type == TargetType.FrozenActor && !ab.Info.TargetFrozenActors)
|
||||
? ab.Info.OutsideRangeCursor ?? a.Info.OutsideRangeCursor
|
||||
: ab.Info.Cursor ?? a.Info.Cursor;
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
@@ -31,6 +32,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
protected override void Tick(Actor self)
|
||||
{
|
||||
Target = Target.Recalculate(self.Owner);
|
||||
if (IsTraitDisabled)
|
||||
{
|
||||
Target = Target.Invalid;
|
||||
@@ -62,15 +64,17 @@ namespace OpenRA.Mods.Common.Traits
|
||||
class AttackActivity : Activity
|
||||
{
|
||||
readonly AttackFollow attack;
|
||||
readonly RevealsShroud[] revealsShroud;
|
||||
readonly IMove move;
|
||||
readonly Target target;
|
||||
readonly bool forceAttack;
|
||||
Target target;
|
||||
bool hasTicked;
|
||||
|
||||
public AttackActivity(Actor self, Target target, bool allowMove, bool forceAttack)
|
||||
{
|
||||
attack = self.Trait<AttackFollow>();
|
||||
move = allowMove ? self.TraitOrDefault<IMove>() : null;
|
||||
revealsShroud = self.TraitsImplementing<RevealsShroud>().ToArray();
|
||||
|
||||
this.target = target;
|
||||
this.forceAttack = forceAttack;
|
||||
@@ -78,6 +82,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
target = target.Recalculate(self.Owner);
|
||||
if (IsCanceled || !target.IsValidFor(self))
|
||||
return NextActivity;
|
||||
|
||||
@@ -87,6 +92,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var weapon = attack.ChooseArmamentsForTarget(target, forceAttack).FirstOrDefault();
|
||||
if (weapon != null)
|
||||
{
|
||||
// Check that AttackFollow hasn't cancelled the target by modifying attack.Target
|
||||
// Having both this and AttackFollow modify that field is a horrible hack.
|
||||
if (hasTicked && attack.Target.Type == TargetType.Invalid)
|
||||
return NextActivity;
|
||||
|
||||
var targetIsMobile = (target.Type == TargetType.Actor && target.Actor.Info.HasTraitInfo<IMoveInfo>())
|
||||
|| (target.Type == TargetType.FrozenActor && target.FrozenActor.Info.HasTraitInfo<IMoveInfo>());
|
||||
|
||||
@@ -95,10 +105,18 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var maxRange = targetIsMobile ? new WDist(Math.Max(weapon.Weapon.MinRange.Length, modifiedRange.Length - 1024))
|
||||
: modifiedRange;
|
||||
|
||||
// Check that AttackFollow hasn't cancelled the target by modifying attack.Target
|
||||
// Having both this and AttackFollow modify that field is a horrible hack.
|
||||
if (hasTicked && attack.Target.Type == TargetType.Invalid)
|
||||
return NextActivity;
|
||||
// Most actors want to be able to see their target before shooting
|
||||
if (!attack.Info.TargetFrozenActors && !forceAttack && target.Type == TargetType.FrozenActor)
|
||||
{
|
||||
var rs = revealsShroud
|
||||
.Where(Exts.IsTraitEnabled)
|
||||
.MaxByOrDefault(s => s.Range);
|
||||
|
||||
// Default to 2 cells if there are no active traits
|
||||
var sightRange = rs != null ? rs.Range : WDist.FromCells(2);
|
||||
if (sightRange < maxRange)
|
||||
maxRange = sightRange;
|
||||
}
|
||||
|
||||
attack.Target = target;
|
||||
hasTicked = true;
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack)
|
||||
{
|
||||
return new Activities.Attack(self, newTarget, allowMove, forceAttack, info.FacingTolerance);
|
||||
return new Activities.Attack(self, newTarget, allowMove, forceAttack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#endregion
|
||||
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
@@ -32,9 +33,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Some 3rd-party mods rely on this being public
|
||||
public class SetTarget : Activity
|
||||
{
|
||||
readonly Target target;
|
||||
readonly AttackOmni attack;
|
||||
readonly bool allowMove;
|
||||
Target target;
|
||||
|
||||
public SetTarget(AttackOmni attack, Target target, bool allowMove)
|
||||
{
|
||||
@@ -45,6 +46,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
target = target.Recalculate(self.Owner);
|
||||
if (IsCanceled || !target.IsValidFor(self) || !attack.IsReachableTarget(target, allowMove))
|
||||
return NextActivity;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user