diff --git a/OpenRA.Game/Traits/Mobile.cs b/OpenRA.Game/Traits/Mobile.cs index 38a26d7ba1..6945f7535c 100644 --- a/OpenRA.Game/Traits/Mobile.cs +++ b/OpenRA.Game/Traits/Mobile.cs @@ -121,7 +121,7 @@ namespace OpenRA.Traits { if (order.OrderString == "Move") { - if (self.traits.GetOrDefault().CanEnterCell(order.TargetLocation)) + if (CanEnterCell(order.TargetLocation)) { if (self.Owner == self.World.LocalPlayer) self.World.AddFrameEndTask(w => diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 8c5a7cda1e..cc5fbca88b 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -99,13 +99,18 @@ namespace OpenRA.Traits public interface IPaletteModifier { void AdjustPalette(Bitmap b); } public interface IPips { IEnumerable GetPips(Actor self); } public interface ITags { IEnumerable GetTags(); } - public interface IMove + + public interface ITeleportable /* crap name! */ { bool CanEnterCell(int2 location); + void SetPosition(Actor self, int2 cell); + } + + public interface IMove : ITeleportable + { float MovementCostForCell(Actor self, int2 cell); float MovementSpeedForCell(Actor self, int2 cell); IEnumerable GetCurrentPath(Actor self); - void SetPosition(Actor self, int2 cell); } public interface IOffsetCenterLocation { float2 CenterOffset { get; } } diff --git a/OpenRA.Mods.RA/Crate.cs b/OpenRA.Mods.RA/Crate.cs index 83e657f7b9..d5f47cb5c5 100644 --- a/OpenRA.Mods.RA/Crate.cs +++ b/OpenRA.Mods.RA/Crate.cs @@ -31,12 +31,12 @@ namespace OpenRA.Mods.RA class CrateInfo : ITraitInfo, ITraitPrerequisite { public readonly int Lifetime = 5; // Seconds - public readonly string[] TerrainTypes = {}; + public readonly string[] TerrainTypes = { }; public object Create(ActorInitializer init) { return new Crate(init, this); } } - // IMove is required for paradrop - class Crate : ITick, IOccupySpace, IMove + // ITeleportable is required for paradrop + class Crate : ITick, IOccupySpace, ITeleportable { readonly Actor self; [Sync] @@ -81,30 +81,23 @@ namespace OpenRA.Mods.RA } if (++ticks >= self.Info.Traits.Get().Lifetime * 25) - self.World.AddFrameEndTask(w => w.Remove(self)); + self.World.AddFrameEndTask(w => w.Remove(self)); var seq = self.World.GetTerrainInfo(cell).IsWater ? "water" : "idle"; if (seq != self.traits.Get().anim.CurrentSequence.Name) self.traits.Get().anim.PlayRepeating(seq); } - - public int2 TopLeft {get { return Location; }} + + public int2 TopLeft { get { return Location; } } int2[] noCells = new int2[] { }; public IEnumerable OccupiedCells() { return noCells; } - public bool CanEnterCell(int2 cell) { return MovementCostForCell(self, cell) < float.PositiveInfinity; } - - public float MovementCostForCell(Actor self, int2 cell) + public bool CanEnterCell(int2 cell) { - if (!self.World.Map.IsInMap(cell.X,cell.Y)) - return float.PositiveInfinity; - + if (!self.World.Map.IsInMap(cell.X, cell.Y)) return false; var type = self.World.GetTerrainType(cell); - return Info.TerrainTypes.Contains(type) ? 0f : float.PositiveInfinity; + return Info.TerrainTypes.Contains(type); } - - public float MovementSpeedForCell(Actor self, int2 cell) { return 1; } - public IEnumerable GetCurrentPath(Actor self) { return new float2[] {}; } public void SetPosition(Actor self, int2 cell) { diff --git a/OpenRA.Mods.RA/Effects/Parachute.cs b/OpenRA.Mods.RA/Effects/Parachute.cs index cb1024cef7..19b1bc6f9f 100644 --- a/OpenRA.Mods.RA/Effects/Parachute.cs +++ b/OpenRA.Mods.RA/Effects/Parachute.cs @@ -59,7 +59,7 @@ namespace OpenRA.Mods.RA.Effects var loc = Traits.Util.CellContaining(location); cargo.CancelActivity(); - var mobile = cargo.traits.WithInterface().FirstOrDefault(); + var mobile = cargo.traits.GetOrDefault(); if (mobile != null) mobile.SetPosition(cargo, loc); diff --git a/OpenRA.Mods.RA/ParaDrop.cs b/OpenRA.Mods.RA/ParaDrop.cs index 22034d3316..6d4ec53261 100644 --- a/OpenRA.Mods.RA/ParaDrop.cs +++ b/OpenRA.Mods.RA/ParaDrop.cs @@ -67,9 +67,9 @@ namespace OpenRA.Mods.RA } } - bool IsSuitableCell(Actor self, int2 p) + bool IsSuitableCell(Actor actorToDrop, int2 p) { - return self.traits.WithInterface().FirstOrDefault().CanEnterCell(p); + return actorToDrop.traits.Get().CanEnterCell(p); } void FinishedDropping(Actor self)