Replace duplicate BlockedByActor with BlocksProjectiles.AnyBlockingActorAt
This commit is contained in:
@@ -167,12 +167,8 @@ namespace OpenRA.Mods.Common.Effects
|
||||
if (info.ContrailLength > 0)
|
||||
contrail.Update(pos);
|
||||
|
||||
var cell = world.Map.CellContaining(pos);
|
||||
var height = world.Map.DistanceAboveTerrain(pos);
|
||||
|
||||
var shouldExplode = height.Length <= 0 // Hit the ground
|
||||
|| ticks++ >= length // Flight length reached/exceeded
|
||||
|| BlockedByActor(world, pos); // Hit a wall or other blocking obstacle
|
||||
var shouldExplode = ticks++ >= length // Flight length reached/exceeded
|
||||
|| (info.Blockable && BlocksProjectiles.AnyBlockingActorAt(world, pos)); // Hit a wall or other blocking obstacle
|
||||
|
||||
if (shouldExplode)
|
||||
Explode(world);
|
||||
@@ -212,11 +208,5 @@ namespace OpenRA.Mods.Common.Effects
|
||||
|
||||
args.Weapon.Impact(Target.FromPos(pos), args.SourceActor, args.DamageModifiers);
|
||||
}
|
||||
|
||||
bool BlockedByActor(World world, WPos pos)
|
||||
{
|
||||
return info.Blockable && world.ActorMap.GetUnitsAt(world.Map.CellContaining(pos))
|
||||
.Any(a => a.TraitsImplementing<BlocksProjectiles>().Any(Exts.IsTraitEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Effects
|
||||
{
|
||||
class MissileInfo : IProjectileInfo
|
||||
public class MissileInfo : IProjectileInfo
|
||||
{
|
||||
public readonly string Image = null;
|
||||
[SequenceReference("Image")] public readonly string Sequence = "idle";
|
||||
@@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.Effects
|
||||
public IEffect Create(ProjectileArgs args) { return new Missile(this, args); }
|
||||
}
|
||||
|
||||
class Missile : IEffect, ISync
|
||||
public class Missile : IEffect, ISync
|
||||
{
|
||||
readonly MissileInfo info;
|
||||
readonly ProjectileArgs args;
|
||||
@@ -201,7 +201,7 @@ namespace OpenRA.Mods.Common.Effects
|
||||
var shouldExplode = (pos.Z < 0) // Hit the ground
|
||||
|| (dist.LengthSquared < info.CloseEnough.LengthSquared) // Within range
|
||||
|| (info.RangeLimit != 0 && ticks > info.RangeLimit) // Ran out of fuel
|
||||
|| BlockedByActor(world, pos) // Hit a wall or other blocking obstacle
|
||||
|| (info.Blockable && BlocksProjectiles.AnyBlockingActorAt(world, pos)) // Hit a wall or other blocking obstacle
|
||||
|| !world.Map.Contains(cell) // This also avoids an IndexOutOfRangeException in GetTerrainInfo below.
|
||||
|| (!string.IsNullOrEmpty(info.BoundToTerrainType) && world.Map.GetTerrainInfo(cell).Type != info.BoundToTerrainType); // Hit incompatible terrain
|
||||
|
||||
@@ -223,12 +223,6 @@ namespace OpenRA.Mods.Common.Effects
|
||||
args.Weapon.Impact(Target.FromPos(pos), args.SourceActor, args.DamageModifiers);
|
||||
}
|
||||
|
||||
bool BlockedByActor(World world, WPos pos)
|
||||
{
|
||||
return info.Blockable && world.ActorMap.GetUnitsAt(world.Map.CellContaining(pos))
|
||||
.Any(a => a.TraitsImplementing<BlocksProjectiles>().Any(Exts.IsTraitEnabled));
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
||||
{
|
||||
if (info.ContrailLength > 0)
|
||||
|
||||
@@ -24,5 +24,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public BlocksProjectiles(Actor self, BlocksProjectilesInfo info)
|
||||
: base(info) { }
|
||||
|
||||
public static bool AnyBlockingActorAt(World world, WPos pos)
|
||||
{
|
||||
return world.ActorMap.GetUnitsAt(world.Map.CellContaining(pos))
|
||||
.Any(a => a.TraitsImplementing<BlocksProjectiles>().Any(Exts.IsTraitEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user