diff --git a/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs b/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs index 169271d7e5..057bbc6e95 100644 --- a/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs +++ b/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs @@ -169,7 +169,7 @@ namespace OpenRA.Mods.Common.Activities QueueChild(new FlyAttackRun(self, target, lastVisibleMaximumRange)); // Turn to face the target if required. - else if (!attackAircraft.TargetInFiringArc(self, target, 4 * attackAircraft.Info.FacingTolerance)) + else if (!attackAircraft.TargetInFiringArc(self, target, attackAircraft.Info.FacingTolerance)) aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.TurnSpeed); return false; diff --git a/OpenRA.Mods.Common/Activities/Attack.cs b/OpenRA.Mods.Common/Activities/Attack.cs index 9cbb3f1f9a..1711db71a5 100644 --- a/OpenRA.Mods.Common/Activities/Attack.cs +++ b/OpenRA.Mods.Common/Activities/Attack.cs @@ -206,7 +206,7 @@ namespace OpenRA.Mods.Common.Activities return AttackStatus.NeedsToMove; } - if (!attack.TargetInFiringArc(self, target, 4 * attack.Info.FacingTolerance)) + if (!attack.TargetInFiringArc(self, target, attack.Info.FacingTolerance)) { var desiredFacing = (attack.GetTargetPosition(pos, target) - pos).Yaw; attackStatus |= AttackStatus.NeedsToTurn; diff --git a/OpenRA.Mods.Common/Traits/Air/AttackAircraft.cs b/OpenRA.Mods.Common/Traits/Air/AttackAircraft.cs index 4b1b602928..730e243496 100644 --- a/OpenRA.Mods.Common/Traits/Air/AttackAircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/AttackAircraft.cs @@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.Traits if (!base.CanAttack(self, target)) return false; - return TargetInFiringArc(self, target, 4 * base.Info.FacingTolerance); + return TargetInFiringArc(self, target, Info.FacingTolerance); } } } diff --git a/OpenRA.Mods.Common/Traits/Air/AttackBomber.cs b/OpenRA.Mods.Common/Traits/Air/AttackBomber.cs index 7f55041ad0..ece874730e 100644 --- a/OpenRA.Mods.Common/Traits/Air/AttackBomber.cs +++ b/OpenRA.Mods.Common/Traits/Air/AttackBomber.cs @@ -19,8 +19,8 @@ namespace OpenRA.Mods.Common.Traits { public class AttackBomberInfo : AttackBaseInfo { - [Desc("Tolerance for attack angle. Range [0, 128], 128 covers 360 degrees.")] - public readonly new int FacingTolerance = 2; + [Desc("Tolerance for attack angle. Range [0, 512], 512 covers 360 degrees.")] + public readonly new WAngle FacingTolerance = new WAngle(8); public override object Create(ActorInitializer init) { return new AttackBomber(init.Self, this); } } @@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.Traits target = Target.FromPos(target.CenterPosition - new WVec(WDist.Zero, WDist.Zero, dat)); var wasFacingTarget = facingTarget; - facingTarget = TargetInFiringArc(self, target, 4 * info.FacingTolerance); + facingTarget = TargetInFiringArc(self, target, info.FacingTolerance); foreach (var a in Armaments) { diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs index 81d49ca47a..b6ee7d0d57 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs @@ -52,14 +52,14 @@ namespace OpenRA.Mods.Common.Traits public readonly string Voice = "Action"; [Desc("Tolerance for attack angle. Range [0, 128], 128 covers 360 degrees.")] - public readonly int FacingTolerance = 128; + public readonly WAngle FacingTolerance = new WAngle(512); public override void RulesetLoaded(Ruleset rules, ActorInfo ai) { base.RulesetLoaded(rules, ai); - if (FacingTolerance < 0 || FacingTolerance > 128) - throw new YamlException("Facing tolerance must be in range of [0, 128], 128 covers 360 degrees."); + if (FacingTolerance.Angle > 512) + throw new YamlException("Facing tolerance must be in range of [0, 512], 512 covers 360 degrees."); } public override abstract object Create(ActorInitializer init); @@ -126,7 +126,7 @@ namespace OpenRA.Mods.Common.Traits return () => armaments; } - public bool TargetInFiringArc(Actor self, in Target target, int facingTolerance) + public bool TargetInFiringArc(Actor self, in Target target, WAngle facingTolerance) { if (facing == null) return true; diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs b/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs index 48bd574acb..eb702df9b9 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs @@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Traits var armaments = ChooseArmamentsForTarget(target, forceAttack); foreach (var a in armaments) if (target.IsInRange(pos, a.MaxRange()) && (a.Weapon.MinRange == WDist.Zero || !target.IsInRange(pos, a.Weapon.MinRange))) - if (TargetInFiringArc(self, target, 4 * Info.FacingTolerance)) + if (TargetInFiringArc(self, target, Info.FacingTolerance)) return true; return false; diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackFrontal.cs b/OpenRA.Mods.Common/Traits/Attack/AttackFrontal.cs index 6e53c85189..e316ff292f 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackFrontal.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackFrontal.cs @@ -18,8 +18,8 @@ namespace OpenRA.Mods.Common.Traits [Desc("Unit got to face the target")] public class AttackFrontalInfo : AttackBaseInfo, Requires { - [Desc("Tolerance for attack angle. Range [0, 128], 128 covers 360 degrees.")] - public readonly new int FacingTolerance = 0; + [Desc("Tolerance for attack angle. Range [0, 512], 512 covers 360 degrees.")] + public readonly new WAngle FacingTolerance = WAngle.Zero; public override object Create(ActorInitializer init) { return new AttackFrontal(init.Self, this); } } @@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits if (!base.CanAttack(self, target)) return false; - return TargetInFiringArc(self, target, 4 * Info.FacingTolerance); + return TargetInFiringArc(self, target, Info.FacingTolerance); } public override Activity GetAttackActivity(Actor self, AttackSource source, in Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null) diff --git a/OpenRA.Mods.Common/Traits/AutoTarget.cs b/OpenRA.Mods.Common/Traits/AutoTarget.cs index cba778901e..30a6d121ac 100644 --- a/OpenRA.Mods.Common/Traits/AutoTarget.cs +++ b/OpenRA.Mods.Common/Traits/AutoTarget.cs @@ -414,7 +414,7 @@ namespace OpenRA.Mods.Common.Traits if (!armaments.Any()) continue; - if (!allowTurn && !ab.TargetInFiringArc(self, target, 4 * ab.Info.FacingTolerance)) + if (!allowTurn && !ab.TargetInFiringArc(self, target, ab.Info.FacingTolerance)) continue; // Evaluate whether we want to target this actor diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20200503/ReplaceFacingAngles.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20200503/ReplaceFacingAngles.cs index 21be789d91..16d4e8dde4 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20200503/ReplaceFacingAngles.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20200503/ReplaceFacingAngles.cs @@ -35,9 +35,20 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules { "FallsToEarth", new[] { "MaximumSpinSpeed" } }, { "ConyardChronoReturn", new[] { "Facing" } }, { "TDGunboat", new[] { "InitialFacing", "PreviewFacing" } }, - { "AttackPopupTurreted", new[] { "DefaultFacing" } }, { "DropPodsPower", new[] { "PodFacing" } }, { "TiberianSunRefinery", new[] { "DockAngle" } }, + { "AttackAircraft", new[] { "FacingTolerance" } }, + { "AttackBomber", new[] { "FacingTolerance" } }, + { "AttackCharges", new[] { "FacingTolerance" } }, + { "AttackFollow", new[] { "FacingTolerance" } }, + { "AttackFrontal", new[] { "FacingTolerance" } }, + { "AttackGarrisoned", new[] { "FacingTolerance" } }, + { "AttackOmni", new[] { "FacingTolerance" } }, + { "AttackTurreted", new[] { "FacingTolerance" } }, + { "AttackLeap", new[] { "FacingTolerance" } }, + { "AttackPopupTurreted", new[] { "DefaultFacing", "FacingTolerance" } }, + { "AttackTDGunboatTurreted", new[] { "FacingTolerance" } }, + { "AttackTesla", new[] { "FacingTolerance" } }, }; static readonly Dictionary ProjectileFields = new Dictionary() diff --git a/OpenRA.Mods.Common/Util.cs b/OpenRA.Mods.Common/Util.cs index 81b95e3995..7ca5426619 100644 --- a/OpenRA.Mods.Common/Util.cs +++ b/OpenRA.Mods.Common/Util.cs @@ -88,13 +88,13 @@ namespace OpenRA.Mods.Common return negative == 0 ? 0 : 256 - negative; } - public static bool FacingWithinTolerance(WAngle facing, WAngle desiredFacing, int facingTolerance) + public static bool FacingWithinTolerance(WAngle facing, WAngle desiredFacing, WAngle facingTolerance) { - if (facingTolerance == 0 && facing == desiredFacing) + if (facingTolerance.Angle == 0 && facing == desiredFacing) return true; var delta = (desiredFacing - facing).Angle; - return delta <= facingTolerance || delta >= 1024 - facingTolerance; + return delta <= facingTolerance.Angle || delta >= 1024 - facingTolerance.Angle; } public static WPos BetweenCells(World w, CPos from, CPos to) diff --git a/mods/cnc/rules/aircraft.yaml b/mods/cnc/rules/aircraft.yaml index c79afb2af5..22d0c0e6c0 100644 --- a/mods/cnc/rules/aircraft.yaml +++ b/mods/cnc/rules/aircraft.yaml @@ -87,7 +87,7 @@ HELI: AutoTarget: ScanRadius: 4 AttackAircraft: - FacingTolerance: 20 + FacingTolerance: 80 OpportunityFire: false PersistentTargeting: false AttackType: Hover @@ -152,7 +152,7 @@ ORCA: AutoTarget: ScanRadius: 5 AttackAircraft: - FacingTolerance: 20 + FacingTolerance: 80 OpportunityFire: false PersistentTargeting: false AttackType: Hover diff --git a/mods/ra/rules/aircraft.yaml b/mods/ra/rules/aircraft.yaml index b24123b617..6cb19813e3 100644 --- a/mods/ra/rules/aircraft.yaml +++ b/mods/ra/rules/aircraft.yaml @@ -79,7 +79,7 @@ MIG: LocalYaw: -40, 24 PauseOnCondition: !ammo AttackAircraft: - FacingTolerance: 20 + FacingTolerance: 80 PersistentTargeting: false OpportunityFire: False Aircraft: @@ -152,7 +152,7 @@ YAK: MuzzleSequence: muzzle PauseOnCondition: !ammo AttackAircraft: - FacingTolerance: 20 + FacingTolerance: 80 PersistentTargeting: false OpportunityFire: False Aircraft: @@ -276,7 +276,7 @@ HELI: LocalOffset: 0,213,-85, 0,-213,-85 PauseOnCondition: !ammo AttackAircraft: - FacingTolerance: 20 + FacingTolerance: 80 PersistentTargeting: false AttackType: Hover OpportunityFire: False @@ -349,7 +349,7 @@ HIND: MuzzleSequence: muzzle PauseOnCondition: !ammo AttackAircraft: - FacingTolerance: 20 + FacingTolerance: 80 PersistentTargeting: false AttackType: Hover OpportunityFire: False @@ -452,7 +452,7 @@ MH60: MuzzleSequence: muzzle PauseOnCondition: !ammo AttackAircraft: - FacingTolerance: 20 + FacingTolerance: 80 PersistentTargeting: false AttackType: Hover Aircraft: diff --git a/mods/ra/rules/vehicles.yaml b/mods/ra/rules/vehicles.yaml index 764ead055a..56af851bac 100644 --- a/mods/ra/rules/vehicles.yaml +++ b/mods/ra/rules/vehicles.yaml @@ -735,7 +735,7 @@ DTRK: EmptyWeapon: MiniNuke DamageSource: Killer AttackFrontal: - FacingTolerance: 128 + FacingTolerance: 512 Armament@PRIMARY: Weapon: DemoTruckTargeting GrantConditionOnAttack: diff --git a/mods/ts/rules/aircraft.yaml b/mods/ts/rules/aircraft.yaml index dbee1bc427..94764ba7e8 100644 --- a/mods/ts/rules/aircraft.yaml +++ b/mods/ts/rules/aircraft.yaml @@ -154,7 +154,7 @@ ORCA: Weapon: Hellfire PauseOnCondition: !ammo AttackAircraft: - FacingTolerance: 20 + FacingTolerance: 80 PersistentTargeting: false Voice: Attack PauseOnCondition: empdisable @@ -219,7 +219,7 @@ ORCAB: PauseOnCondition: !ammo AttackAircraft: Voice: Attack - FacingTolerance: 20 + FacingTolerance: 80 PersistentTargeting: false PauseOnCondition: empdisable AmmoPool: @@ -372,7 +372,7 @@ SCRIN: PauseOnCondition: !ammo AttackAircraft: Voice: Attack - FacingTolerance: 20 + FacingTolerance: 80 PersistentTargeting: false PauseOnCondition: empdisable AmmoPool: @@ -435,7 +435,7 @@ APACHE: Weapon: HarpyClaw PauseOnCondition: !ammo AttackAircraft: - FacingTolerance: 20 + FacingTolerance: 80 PersistentTargeting: false Voice: Attack PauseOnCondition: empdisable @@ -491,7 +491,7 @@ HUNTER: CruisingCondition: cruising MoveIntoShroud: true AttackAircraft: - FacingTolerance: 128 + FacingTolerance: 512 AttackType: Hover Armament@PRIMARY: Weapon: SuicideBomb