Add ValidStances checks to BlocksProjectiles and Gate.

This commit is contained in:
abc013
2020-10-31 15:30:52 +01:00
committed by teinarss
parent d10c592987
commit 8fede9d6ba
9 changed files with 22 additions and 8 deletions

View File

@@ -212,7 +212,7 @@ namespace OpenRA.Mods.Common.Projectiles
} }
// Check for blocking actors // 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; headPos = blockedPos;
target = headPos; target = headPos;

View File

@@ -217,7 +217,7 @@ namespace OpenRA.Mods.Common.Projectiles
bool ShouldExplode(World world) bool ShouldExplode(World world)
{ {
// Check for walls or other blocking obstacles // 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; pos = blockedPos;
return true; return true;

View File

@@ -72,7 +72,7 @@ namespace OpenRA.Mods.Common.Projectiles
target = Target.FromPos(args.PassiveTarget); target = Target.FromPos(args.PassiveTarget);
// Check for blocking actors // 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); target = Target.FromPos(blockedPos);
var warheadArgs = new WarheadArgs(args) var warheadArgs = new WarheadArgs(args)

View File

@@ -158,7 +158,7 @@ namespace OpenRA.Mods.Common.Projectiles
target = args.Weapon.TargetActorCenter ? args.GuidedTarget.CenterPosition : args.GuidedTarget.Positions.PositionClosestTo(source); target = args.Weapon.TargetActorCenter ? args.GuidedTarget.CenterPosition : args.GuidedTarget.Positions.PositionClosestTo(source);
// Check for blocking actors // 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; target = blockedPos;
} }

View File

@@ -858,7 +858,7 @@ namespace OpenRA.Mods.Common.Projectiles
// Check for walls or other blocking obstacles // Check for walls or other blocking obstacles
var shouldExplode = false; 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; pos = blockedPos;
shouldExplode = true; shouldExplode = true;

View File

@@ -148,7 +148,7 @@ namespace OpenRA.Mods.Common.Projectiles
void CalculateVectors() void CalculateVectors()
{ {
// Check for blocking actors // 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)) info.BeamWidth, out var blockedPos))
target = blockedPos; target = blockedPos;

View File

@@ -10,6 +10,7 @@
#endregion #endregion
using System.Linq; using System.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
@@ -18,6 +19,9 @@ namespace OpenRA.Mods.Common.Traits
{ {
public readonly WDist Height = WDist.FromCells(1); 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); } 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; WDist IBlocksProjectiles.BlockingHeight => Info.Height;
PlayerRelationship IBlocksProjectiles.ValidRelationships { get { return Info.ValidRelationships; } }
public static bool AnyBlockingActorAt(World world, WPos pos) public static bool AnyBlockingActorAt(World world, WPos pos)
{ {
var dat = world.Map.DistanceAboveTerrain(pos); var dat = world.Map.DistanceAboveTerrain(pos);
@@ -38,7 +44,7 @@ namespace OpenRA.Mods.Common.Traits
.Any(Exts.IsTraitEnabled)); .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 actors = world.FindBlockingActorsOnLine(start, end, width);
var length = (end - start).Length; var length = (end - start).Length;
@@ -46,7 +52,8 @@ namespace OpenRA.Mods.Common.Traits
foreach (var a in actors) foreach (var a in actors)
{ {
var blockers = a.TraitsImplementing<IBlocksProjectiles>() var blockers = a.TraitsImplementing<IBlocksProjectiles>()
.Where(Exts.IsTraitEnabled).ToList(); .Where(Exts.IsTraitEnabled).Where(t => t.ValidRelationships.HasRelationship(a.Owner.RelationshipWith(owner)))
.ToList();
if (!blockers.Any()) if (!blockers.Any())
continue; continue;

View File

@@ -30,6 +30,9 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Blocks bullets scaled to open value.")] [Desc("Blocks bullets scaled to open value.")]
public readonly WDist BlocksProjectilesHeight = new WDist(640); 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); } 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); WDist IBlocksProjectiles.BlockingHeight => new WDist(Info.BlocksProjectilesHeight.Length * (OpenPosition - Position) / OpenPosition);
PlayerRelationship IBlocksProjectiles.ValidRelationships => Info.BlocksProjectilesValidRelationships;
} }
} }

View File

@@ -47,6 +47,8 @@ namespace OpenRA.Mods.Common.Traits
public interface IBlocksProjectiles public interface IBlocksProjectiles
{ {
WDist BlockingHeight { get; } WDist BlockingHeight { get; }
PlayerRelationship ValidRelationships { get; }
} }
[RequireExplicitImplementation] [RequireExplicitImplementation]