From 8fede9d6ba4e88a05dd01dc98ce59dc284ec4f3d Mon Sep 17 00:00:00 2001 From: abc013 Date: Sat, 31 Oct 2020 15:30:52 +0100 Subject: [PATCH] Add ValidStances checks to BlocksProjectiles and Gate. --- OpenRA.Mods.Common/Projectiles/AreaBeam.cs | 2 +- OpenRA.Mods.Common/Projectiles/Bullet.cs | 2 +- OpenRA.Mods.Common/Projectiles/InstantHit.cs | 2 +- OpenRA.Mods.Common/Projectiles/LaserZap.cs | 2 +- OpenRA.Mods.Common/Projectiles/Missile.cs | 2 +- OpenRA.Mods.Common/Projectiles/Railgun.cs | 2 +- OpenRA.Mods.Common/Traits/BlocksProjectiles.cs | 11 +++++++++-- OpenRA.Mods.Common/Traits/Buildings/Gate.cs | 5 +++++ OpenRA.Mods.Common/TraitsInterfaces.cs | 2 ++ 9 files changed, 22 insertions(+), 8 deletions(-) diff --git a/OpenRA.Mods.Common/Projectiles/AreaBeam.cs b/OpenRA.Mods.Common/Projectiles/AreaBeam.cs index 8f14afda46..3be1a13278 100644 --- a/OpenRA.Mods.Common/Projectiles/AreaBeam.cs +++ b/OpenRA.Mods.Common/Projectiles/AreaBeam.cs @@ -212,7 +212,7 @@ namespace OpenRA.Mods.Common.Projectiles } // Check for blocking actors - if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, tailPos, headPos, info.Width, out var blockedPos)) + if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, args.SourceActor.Owner, tailPos, headPos, info.Width, out var blockedPos)) { headPos = blockedPos; target = headPos; diff --git a/OpenRA.Mods.Common/Projectiles/Bullet.cs b/OpenRA.Mods.Common/Projectiles/Bullet.cs index 181272276a..14355d06c7 100644 --- a/OpenRA.Mods.Common/Projectiles/Bullet.cs +++ b/OpenRA.Mods.Common/Projectiles/Bullet.cs @@ -217,7 +217,7 @@ namespace OpenRA.Mods.Common.Projectiles bool ShouldExplode(World world) { // Check for walls or other blocking obstacles - if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, lastPos, pos, info.Width, out var blockedPos)) + if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, args.SourceActor.Owner, lastPos, pos, info.Width, out var blockedPos)) { pos = blockedPos; return true; diff --git a/OpenRA.Mods.Common/Projectiles/InstantHit.cs b/OpenRA.Mods.Common/Projectiles/InstantHit.cs index a949766620..b56fe22b6f 100644 --- a/OpenRA.Mods.Common/Projectiles/InstantHit.cs +++ b/OpenRA.Mods.Common/Projectiles/InstantHit.cs @@ -72,7 +72,7 @@ namespace OpenRA.Mods.Common.Projectiles target = Target.FromPos(args.PassiveTarget); // Check for blocking actors - if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, args.Source, target.CenterPosition, info.Width, out var blockedPos)) + if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, args.SourceActor.Owner, args.Source, target.CenterPosition, info.Width, out var blockedPos)) target = Target.FromPos(blockedPos); var warheadArgs = new WarheadArgs(args) diff --git a/OpenRA.Mods.Common/Projectiles/LaserZap.cs b/OpenRA.Mods.Common/Projectiles/LaserZap.cs index d6cf8cd707..f476335cc1 100644 --- a/OpenRA.Mods.Common/Projectiles/LaserZap.cs +++ b/OpenRA.Mods.Common/Projectiles/LaserZap.cs @@ -158,7 +158,7 @@ namespace OpenRA.Mods.Common.Projectiles target = args.Weapon.TargetActorCenter ? args.GuidedTarget.CenterPosition : args.GuidedTarget.Positions.PositionClosestTo(source); // Check for blocking actors - if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, source, target, info.Width, out var blockedPos)) + if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, args.SourceActor.Owner, source, target, info.Width, out var blockedPos)) { target = blockedPos; } diff --git a/OpenRA.Mods.Common/Projectiles/Missile.cs b/OpenRA.Mods.Common/Projectiles/Missile.cs index 080376a31a..d7ebaea59f 100644 --- a/OpenRA.Mods.Common/Projectiles/Missile.cs +++ b/OpenRA.Mods.Common/Projectiles/Missile.cs @@ -858,7 +858,7 @@ namespace OpenRA.Mods.Common.Projectiles // Check for walls or other blocking obstacles var shouldExplode = false; - if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, lastPos, pos, info.Width, out var blockedPos)) + if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, args.SourceActor.Owner, lastPos, pos, info.Width, out var blockedPos)) { pos = blockedPos; shouldExplode = true; diff --git a/OpenRA.Mods.Common/Projectiles/Railgun.cs b/OpenRA.Mods.Common/Projectiles/Railgun.cs index d0227b0925..b0d644eaa4 100644 --- a/OpenRA.Mods.Common/Projectiles/Railgun.cs +++ b/OpenRA.Mods.Common/Projectiles/Railgun.cs @@ -148,7 +148,7 @@ namespace OpenRA.Mods.Common.Projectiles void CalculateVectors() { // Check for blocking actors - if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(args.SourceActor.World, target, args.Source, + if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(args.SourceActor.World, args.SourceActor.Owner, target, args.Source, info.BeamWidth, out var blockedPos)) target = blockedPos; diff --git a/OpenRA.Mods.Common/Traits/BlocksProjectiles.cs b/OpenRA.Mods.Common/Traits/BlocksProjectiles.cs index e26df2d928..5783fa54b9 100644 --- a/OpenRA.Mods.Common/Traits/BlocksProjectiles.cs +++ b/OpenRA.Mods.Common/Traits/BlocksProjectiles.cs @@ -10,6 +10,7 @@ #endregion using System.Linq; +using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { @@ -18,6 +19,9 @@ namespace OpenRA.Mods.Common.Traits { public readonly WDist Height = WDist.FromCells(1); + [Desc("Determines what projectiles to block based on their allegiance to the wall owner.")] + public readonly PlayerRelationship ValidRelationships = PlayerRelationship.Ally | PlayerRelationship.Neutral | PlayerRelationship.Enemy; + public override object Create(ActorInitializer init) { return new BlocksProjectiles(init.Self, this); } } @@ -28,6 +32,8 @@ namespace OpenRA.Mods.Common.Traits WDist IBlocksProjectiles.BlockingHeight => Info.Height; + PlayerRelationship IBlocksProjectiles.ValidRelationships { get { return Info.ValidRelationships; } } + public static bool AnyBlockingActorAt(World world, WPos pos) { var dat = world.Map.DistanceAboveTerrain(pos); @@ -38,7 +44,7 @@ namespace OpenRA.Mods.Common.Traits .Any(Exts.IsTraitEnabled)); } - public static bool AnyBlockingActorsBetween(World world, WPos start, WPos end, WDist width, out WPos hit) + public static bool AnyBlockingActorsBetween(World world, Player owner, WPos start, WPos end, WDist width, out WPos hit) { var actors = world.FindBlockingActorsOnLine(start, end, width); var length = (end - start).Length; @@ -46,7 +52,8 @@ namespace OpenRA.Mods.Common.Traits foreach (var a in actors) { var blockers = a.TraitsImplementing() - .Where(Exts.IsTraitEnabled).ToList(); + .Where(Exts.IsTraitEnabled).Where(t => t.ValidRelationships.HasRelationship(a.Owner.RelationshipWith(owner))) + .ToList(); if (!blockers.Any()) continue; diff --git a/OpenRA.Mods.Common/Traits/Buildings/Gate.cs b/OpenRA.Mods.Common/Traits/Buildings/Gate.cs index 8b02a5d0b5..66ebfda57b 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Gate.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Gate.cs @@ -30,6 +30,9 @@ namespace OpenRA.Mods.Common.Traits [Desc("Blocks bullets scaled to open value.")] public readonly WDist BlocksProjectilesHeight = new WDist(640); + [Desc("Determines what projectiles to block based on their allegiance to the gate owner.")] + public readonly PlayerRelationship BlocksProjectilesValidRelationships = PlayerRelationship.Ally | PlayerRelationship.Neutral | PlayerRelationship.Enemy; + public override object Create(ActorInitializer init) { return new Gate(init, this); } } @@ -137,5 +140,7 @@ namespace OpenRA.Mods.Common.Traits } WDist IBlocksProjectiles.BlockingHeight => new WDist(Info.BlocksProjectilesHeight.Length * (OpenPosition - Position) / OpenPosition); + + PlayerRelationship IBlocksProjectiles.ValidRelationships => Info.BlocksProjectilesValidRelationships; } } diff --git a/OpenRA.Mods.Common/TraitsInterfaces.cs b/OpenRA.Mods.Common/TraitsInterfaces.cs index 668a641872..075292f378 100644 --- a/OpenRA.Mods.Common/TraitsInterfaces.cs +++ b/OpenRA.Mods.Common/TraitsInterfaces.cs @@ -47,6 +47,8 @@ namespace OpenRA.Mods.Common.Traits public interface IBlocksProjectiles { WDist BlockingHeight { get; } + + PlayerRelationship ValidRelationships { get; } } [RequireExplicitImplementation]