Merge pull request #9270 from reaperrr/upgradable-blockproj
Made BlocksProjectiles upgradable
This commit is contained in:
@@ -299,8 +299,6 @@ namespace OpenRA.Traits
|
|||||||
public interface INotifyBecomingIdle { void OnBecomingIdle(Actor self); }
|
public interface INotifyBecomingIdle { void OnBecomingIdle(Actor self); }
|
||||||
public interface INotifyIdle { void TickIdle(Actor self); }
|
public interface INotifyIdle { void TickIdle(Actor self); }
|
||||||
|
|
||||||
public interface IBlocksProjectilesInfo : ITraitInfo { }
|
|
||||||
public interface IBlocksProjectiles { }
|
|
||||||
public interface IRenderInfantrySequenceModifier
|
public interface IRenderInfantrySequenceModifier
|
||||||
{
|
{
|
||||||
bool IsModifyingSequence { get; }
|
bool IsModifyingSequence { get; }
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ using OpenRA.Effects;
|
|||||||
using OpenRA.GameRules;
|
using OpenRA.GameRules;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Mods.Common.Graphics;
|
using OpenRA.Mods.Common.Graphics;
|
||||||
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Effects
|
namespace OpenRA.Mods.Common.Effects
|
||||||
@@ -166,12 +167,8 @@ namespace OpenRA.Mods.Common.Effects
|
|||||||
if (info.ContrailLength > 0)
|
if (info.ContrailLength > 0)
|
||||||
contrail.Update(pos);
|
contrail.Update(pos);
|
||||||
|
|
||||||
var cell = world.Map.CellContaining(pos);
|
var shouldExplode = ticks++ >= length // Flight length reached/exceeded
|
||||||
var height = world.Map.DistanceAboveTerrain(pos);
|
|| (info.Blockable && BlocksProjectiles.AnyBlockingActorAt(world, pos)); // Hit a wall or other blocking obstacle
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
if (shouldExplode)
|
if (shouldExplode)
|
||||||
Explode(world);
|
Explode(world);
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Effects
|
namespace OpenRA.Mods.Common.Effects
|
||||||
{
|
{
|
||||||
class MissileInfo : IProjectileInfo
|
public class MissileInfo : IProjectileInfo
|
||||||
{
|
{
|
||||||
public readonly string Image = null;
|
public readonly string Image = null;
|
||||||
[SequenceReference("Image")] public readonly string Sequence = "idle";
|
[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); }
|
public IEffect Create(ProjectileArgs args) { return new Missile(this, args); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class Missile : IEffect, ISync
|
public class Missile : IEffect, ISync
|
||||||
{
|
{
|
||||||
readonly MissileInfo info;
|
readonly MissileInfo info;
|
||||||
readonly ProjectileArgs args;
|
readonly ProjectileArgs args;
|
||||||
@@ -201,7 +201,7 @@ namespace OpenRA.Mods.Common.Effects
|
|||||||
var shouldExplode = (pos.Z < 0) // Hit the ground
|
var shouldExplode = (pos.Z < 0) // Hit the ground
|
||||||
|| (dist.LengthSquared < info.CloseEnough.LengthSquared) // Within range
|
|| (dist.LengthSquared < info.CloseEnough.LengthSquared) // Within range
|
||||||
|| (info.RangeLimit != 0 && ticks > info.RangeLimit) // Ran out of fuel
|
|| (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
|
|| (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.
|
|| !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
|
|| (!string.IsNullOrEmpty(info.BoundToTerrainType) && world.Map.GetTerrainInfo(cell).Type != info.BoundToTerrainType); // Hit incompatible terrain
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,20 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
// TODO: Add functionality like a customizable Height that is compared to projectile altitude
|
// TODO: Add functionality like a customizable Height that is compared to projectile altitude
|
||||||
[Desc("This actor blocks bullets and missiles with 'Blockable' property.")]
|
[Desc("This actor blocks bullets and missiles with 'Blockable' property.")]
|
||||||
public class BlocksProjectilesInfo : TraitInfo<BlocksProjectiles>, IBlocksProjectilesInfo { }
|
public class BlocksProjectilesInfo : UpgradableTraitInfo
|
||||||
public class BlocksProjectiles : IBlocksProjectiles { }
|
{
|
||||||
|
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) { }
|
||||||
|
|
||||||
|
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