diff --git a/OpenRA.Mods.Common/Activities/Attack.cs b/OpenRA.Mods.Common/Activities/Attack.cs index 3c8fb2a94f..19955e3928 100644 --- a/OpenRA.Mods.Common/Activities/Attack.cs +++ b/OpenRA.Mods.Common/Activities/Attack.cs @@ -74,6 +74,8 @@ namespace OpenRA.Mods.Common.Activities return NextActivity; } + protected virtual bool IgnoresVisibility { get { return false; } } + protected virtual AttackStatus TickAttack(Actor self, AttackBase attack) { if (IsCanceled) @@ -90,7 +92,7 @@ namespace OpenRA.Mods.Common.Activities // HACK: This would otherwise break targeting frozen actors // The problem is that Shroud.IsTargetable returns false (as it should) for // frozen actors, but we do want to explicitly target the underlying actor here. - if (!attack.Info.IgnoresVisibility && type == TargetType.Actor + if (!IgnoresVisibility && type == TargetType.Actor && !Target.Actor.Info.HasTraitInfo() && !Target.Actor.CanBeViewedByPlayer(self.Owner)) return AttackStatus.UnableToAttack; diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 6f06730afd..83247023a3 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -592,6 +592,7 @@ + diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs index acd7e34a86..99e39291b7 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs @@ -31,9 +31,6 @@ 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("Does not care about shroud or fog. Enables the actor to launch an attack against a target even if he has no visibility of it.")] - public readonly bool IgnoresVisibility = false; - [VoiceReference] public readonly string Voice = "Action"; public override abstract object Create(ActorInitializer init); diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20180923/RemoveAttackIgnoresVisibility.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20180923/RemoveAttackIgnoresVisibility.cs new file mode 100644 index 0000000000..cb9dfdd7f4 --- /dev/null +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20180923/RemoveAttackIgnoresVisibility.cs @@ -0,0 +1,66 @@ +#region Copyright & License Information +/* + * Copyright 2007-2018 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenRA.Mods.Common.UpdateRules.Rules +{ + public class RemoveAttackIgnoresVisibility : UpdateRule + { + public override string Name { get { return "IgnoresVisibility has been removed from Attack* traits."; } } + public override string Description + { + get + { + return "The IgnoresVisibility flag has been removed from the Attack* traits as part of a\n" + + "wider rework of the fog-targeting behaviour. Mods that rely on this logic must\n" + + "implement their own Attack* trait, similar to the AttackSwallow trait."; + } + } + + static readonly string[] Traits = + { + "AttackFrontal", + "AttackFollow", + "AttackTurreted", + "AttackOmni", + "AttackBomber", + "AttackPopupTurreted", + "AttackTesla", + "AttackSwallow" + }; + + readonly List locations = new List(); + + public override IEnumerable AfterUpdate(ModData modData) + { + if (locations.Any()) + yield return "The IgnoresVisibility flag has been removed from the targeting logic on the following actors:\n" + + UpdateUtils.FormatMessageList(locations) + "\n\n" + + "You may wish to enable TargetFrozenActors, or implement a custom Attack* trait like AttackSwallow\n" + + "if you require visibility to be completely ignored."; + + locations.Clear(); + } + + public override IEnumerable UpdateActorNode(ModData modData, MiniYamlNode actorNode) + { + foreach (var trait in Traits) + foreach (var t in actorNode.ChildrenMatching(trait)) + if (t.RemoveNodes("IgnoresVisibility") > 0) + locations.Add("{0} ({1})".F(actorNode.Key, actorNode.Location.Filename)); + + yield break; + } + } +} diff --git a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs index 347559cc41..e5b647f04b 100644 --- a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs +++ b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs @@ -110,6 +110,7 @@ namespace OpenRA.Mods.Common.UpdateRules new RemoveResourceExplodeModifier(), new DefineLevelUpImageDefault(), new RemovedAutoCarryallCircleTurnSpeed(), + new RemoveAttackIgnoresVisibility(), }) }; diff --git a/OpenRA.Mods.D2k/Traits/AttackSwallow.cs b/OpenRA.Mods.D2k/Traits/AttackSwallow.cs index e28c30cac8..97cf011ebe 100644 --- a/OpenRA.Mods.D2k/Traits/AttackSwallow.cs +++ b/OpenRA.Mods.D2k/Traits/AttackSwallow.cs @@ -11,6 +11,8 @@ using System.Collections.Generic; using System.Linq; +using OpenRA.Activities; +using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Traits; using OpenRA.Mods.D2k.Activities; using OpenRA.Traits; @@ -67,5 +69,19 @@ namespace OpenRA.Mods.D2k.Traits self.CancelActivity(); self.QueueActivity(new SwallowActor(self, target, a, facing)); } + + public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack) + { + return new SwallowTarget(self, newTarget, allowMove, forceAttack, Info.FacingTolerance); + } + + public class SwallowTarget : Attack + { + public SwallowTarget(Actor self, Target target, bool allowMovement, bool forceAttack, int facingTolerance) + : base(self, target, allowMovement, forceAttack, facingTolerance) { } + + // Worms ignore visibility, so don't need to recalculate targets + protected override bool IgnoresVisibility { get { return true; } } + } } } diff --git a/mods/d2k/rules/arrakis.yaml b/mods/d2k/rules/arrakis.yaml index 313cc1640f..77bf97f978 100644 --- a/mods/d2k/rules/arrakis.yaml +++ b/mods/d2k/rules/arrakis.yaml @@ -104,7 +104,6 @@ sandworm: UseLocation: true AttackSwallow: AttackRequiresEnteringCell: true - IgnoresVisibility: true AttackingCondition: attacking Armament: Weapon: WormJaw