Add ValidStances checks to BlocksProjectiles and Gate.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<IBlocksProjectiles>()
|
||||
.Where(Exts.IsTraitEnabled).ToList();
|
||||
.Where(Exts.IsTraitEnabled).Where(t => t.ValidRelationships.HasRelationship(a.Owner.RelationshipWith(owner)))
|
||||
.ToList();
|
||||
|
||||
if (!blockers.Any())
|
||||
continue;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public interface IBlocksProjectiles
|
||||
{
|
||||
WDist BlockingHeight { get; }
|
||||
|
||||
PlayerRelationship ValidRelationships { get; }
|
||||
}
|
||||
|
||||
[RequireExplicitImplementation]
|
||||
|
||||
Reference in New Issue
Block a user