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
|
// 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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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]
|
||||||
|
|||||||
Reference in New Issue
Block a user