Made BlocksProjectiles upgradable

This commit is contained in:
reaperrr
2015-09-05 15:01:35 +02:00
parent 1b1e4f1dd2
commit 7e1f29d4c5
4 changed files with 25 additions and 6 deletions

View File

@@ -299,8 +299,6 @@ namespace OpenRA.Traits
public interface INotifyBecomingIdle { void OnBecomingIdle(Actor self); }
public interface INotifyIdle { void TickIdle(Actor self); }
public interface IBlocksProjectilesInfo : ITraitInfo { }
public interface IBlocksProjectiles { }
public interface IRenderInfantrySequenceModifier
{
bool IsModifyingSequence { get; }

View File

@@ -16,6 +16,7 @@ using OpenRA.Effects;
using OpenRA.GameRules;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Effects
@@ -171,7 +172,7 @@ namespace OpenRA.Mods.Common.Effects
var shouldExplode = height.Length <= 0 // Hit the ground
|| ticks++ >= length // Flight length reached/exceeded
|| (info.Blockable && world.ActorMap.GetUnitsAt(cell).Any(a => a.Info.HasTraitInfo<IBlocksProjectilesInfo>())); // Hit a wall or other blocking obstacle
|| BlockedByActor(world, pos); // Hit a wall or other blocking obstacle
if (shouldExplode)
Explode(world);
@@ -211,5 +212,11 @@ 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));
}
}
}

View File

@@ -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
|| (info.Blockable && world.ActorMap.GetUnitsAt(cell).Any(a => a.Info.HasTraitInfo<IBlocksProjectilesInfo>())) // Hit a wall or other blocking obstacle
|| BlockedByActor(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,6 +223,12 @@ 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)

View File

@@ -15,6 +15,14 @@ namespace OpenRA.Mods.Common.Traits
{
// TODO: Add functionality like a customizable Height that is compared to projectile altitude
[Desc("This actor blocks bullets and missiles with 'Blockable' property.")]
public class BlocksProjectilesInfo : TraitInfo<BlocksProjectiles>, IBlocksProjectilesInfo { }
public class BlocksProjectiles : IBlocksProjectiles { }
public class BlocksProjectilesInfo : UpgradableTraitInfo
{
public override object Create(ActorInitializer init) { return new BlocksProjectiles(init.Self, this); }
}
public class BlocksProjectiles : UpgradableTrait<BlocksProjectilesInfo>
{
public BlocksProjectiles(Actor self, BlocksProjectilesInfo info)
: base(info) { }
}
}