diff --git a/OpenRA.Game/Controller.cs b/OpenRA.Game/Controller.cs index 7ce0214c3b..aad916a163 100644 --- a/OpenRA.Game/Controller.cs +++ b/OpenRA.Game/Controller.cs @@ -64,7 +64,7 @@ namespace OpenRA if (voicedActor != null) { - if(voicedActor.traits.GetOrDefault().CanEnterCell(xy.ToInt2())) + if(voicedActor.traits.GetOrDefault().CanEnterCell(xy.ToInt2())) Sound.PlayVoice(isAttack ? "Attack" : "Move", voicedActor); if (isMove) diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 463990bc84..08acffc890 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -236,18 +236,15 @@ namespace OpenRA.Graphics if (Game.Settings.PathDebug) { - var mobile = selectedUnit.traits.GetOrDefault(); + var mobile = selectedUnit.traits.WithInterface().FirstOrDefault(); if (mobile != null) { - var path = mobile.GetCurrentPath(); - var start = selectedUnit.Location; + var path = mobile.GetCurrentPath(selectedUnit); + var start = selectedUnit.CenterLocation; foreach (var step in path) { - lineRenderer.DrawLine( - Game.CellSize * start + new float2(12, 12), - Game.CellSize * step + new float2(12, 12), - Color.Red, Color.Red); + lineRenderer.DrawLine(start, step, Color.Red, Color.Red); start = step; } } diff --git a/OpenRA.Game/Orders/UnitOrderGenerator.cs b/OpenRA.Game/Orders/UnitOrderGenerator.cs index b0be25e591..5e7b484e7b 100644 --- a/OpenRA.Game/Orders/UnitOrderGenerator.cs +++ b/OpenRA.Game/Orders/UnitOrderGenerator.cs @@ -92,7 +92,7 @@ namespace OpenRA.Orders case "Heal": return "heal"; case "C4": return "c4"; case "Move": - if (a.traits.GetOrDefault().CanEnterCell(location)) + if (a.traits.GetOrDefault().CanEnterCell(location)) return "move"; else return "move-blocked"; diff --git a/OpenRA.Game/Traits/Mobile.cs b/OpenRA.Game/Traits/Mobile.cs index dc81a695b1..70ffb12f98 100644 --- a/OpenRA.Game/Traits/Mobile.cs +++ b/OpenRA.Game/Traits/Mobile.cs @@ -33,7 +33,7 @@ namespace OpenRA.Traits public object Create(ActorInitializer init) { return new Mobile(init); } } - public class Mobile : IIssueOrder, IResolveOrder, IOccupySpace, IMovement + public class Mobile : IIssueOrder, IResolveOrder, IOccupySpace, IMove { readonly Actor self; @@ -95,7 +95,7 @@ namespace OpenRA.Traits { if (order.OrderString == "Move") { - if (self.traits.GetOrDefault().CanEnterCell(order.TargetLocation)) + if (self.traits.GetOrDefault().CanEnterCell(order.TargetLocation)) { if( !order.Queued ) self.CancelActivity(); self.QueueActivity(new Activities.Move(order.TargetLocation, 8)); @@ -132,11 +132,12 @@ namespace OpenRA.Traits .GetCost(GetMovementType()) < float.PositiveInfinity; } - public IEnumerable GetCurrentPath() + public IEnumerable GetCurrentPath(Actor self) { var move = self.GetCurrentActivity() as Activities.Move; - if (move == null || move.path == null) return new int2[] { }; - return Enumerable.Reverse(move.path); + if (move == null || move.path == null) return new float2[] { }; + + return Enumerable.Reverse(move.path).Select( c => Game.CellSize * c + new float2(12,12) ); } } } diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 7391301c9e..5eb35fb76a 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -96,10 +96,11 @@ namespace OpenRA.Traits public interface IPaletteModifier { void AdjustPalette(Bitmap b); } public interface IPips { IEnumerable GetPips(Actor self); } public interface ITags { IEnumerable GetTags(); } - public interface IMovement + public interface IMove { UnitMovementType GetMovementType(); bool CanEnterCell(int2 location); + IEnumerable GetCurrentPath(Actor self); } public interface ICrushable diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index 40a5aecd44..eaa8401fd3 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -61,7 +61,7 @@ namespace OpenRA public static bool IsActorCrushableByActor(this World world, Actor a, Actor b) { - var movement = b.traits.GetOrDefault(); + var movement = b.traits.GetOrDefault(); return movement != null && world.IsActorCrushableByMovementType(a, movement.GetMovementType()); } diff --git a/OpenRA.Mods.Aftermath/ChronoshiftDeploy.cs b/OpenRA.Mods.Aftermath/ChronoshiftDeploy.cs index 6bbfd85702..5c357dba98 100644 --- a/OpenRA.Mods.Aftermath/ChronoshiftDeploy.cs +++ b/OpenRA.Mods.Aftermath/ChronoshiftDeploy.cs @@ -61,7 +61,7 @@ namespace OpenRA.Mods.Aftermath return; } - var movement = self.traits.GetOrDefault(); + var movement = self.traits.GetOrDefault(); if (order.OrderString == "ChronoshiftSelf" && movement.CanEnterCell(order.TargetLocation)) { if (self.Owner == self.World.LocalPlayer) diff --git a/OpenRA.Mods.Aftermath/Orders/SetChronoTankDestination.cs b/OpenRA.Mods.Aftermath/Orders/SetChronoTankDestination.cs index e1bc515d4b..7f026bb48f 100644 --- a/OpenRA.Mods.Aftermath/Orders/SetChronoTankDestination.cs +++ b/OpenRA.Mods.Aftermath/Orders/SetChronoTankDestination.cs @@ -56,7 +56,7 @@ namespace OpenRA.Mods.Aftermath.Orders if (!world.LocalPlayer.Shroud.IsExplored(xy)) return "move-blocked"; - var movement = self.traits.GetOrDefault(); + var movement = self.traits.GetOrDefault(); return (movement.CanEnterCell(xy)) ? "chrono-target" : "move-blocked"; } } diff --git a/OpenRA.Mods.RA/Activities/Fly.cs b/OpenRA.Mods.RA/Activities/Fly.cs index 3359a1db49..a85acf7edd 100644 --- a/OpenRA.Mods.RA/Activities/Fly.cs +++ b/OpenRA.Mods.RA/Activities/Fly.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Activities { public class Fly : IActivity { - readonly float2 Pos; + public readonly float2 Pos; bool isCanceled; public Fly(float2 pos) { Pos = pos; } diff --git a/OpenRA.Mods.RA/Activities/HeliFly.cs b/OpenRA.Mods.RA/Activities/HeliFly.cs index ceede06670..fd58e35096 100644 --- a/OpenRA.Mods.RA/Activities/HeliFly.cs +++ b/OpenRA.Mods.RA/Activities/HeliFly.cs @@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Activities { class HeliFly : IActivity { - readonly float2 Dest; + public readonly float2 Dest; public HeliFly(float2 dest) { Dest = dest; diff --git a/OpenRA.Mods.RA/Aircraft.cs b/OpenRA.Mods.RA/Aircraft.cs index 6d06c5f45a..7bfa2167ef 100755 --- a/OpenRA.Mods.RA/Aircraft.cs +++ b/OpenRA.Mods.RA/Aircraft.cs @@ -22,8 +22,9 @@ using System; using System.Collections.Generic; using System.Linq; using OpenRA.GameRules; +using OpenRA.Traits; -namespace OpenRA.Traits +namespace OpenRA.Mods.RA { public class AircraftInfo : ITraitInfo { @@ -34,7 +35,7 @@ namespace OpenRA.Traits public virtual object Create( ActorInitializer init ) { return new Aircraft( init ); } } - public class Aircraft : IOccupySpace, IMovement + public class Aircraft : IMove { [Sync] public int2 Location; @@ -49,12 +50,6 @@ namespace OpenRA.Traits get { return Location; } } - public IEnumerable OccupiedCells() - { - // TODO: make helis on the ground occupy a space. - yield break; - } - public bool AircraftCanEnter(Actor self, Actor a) { var aircraft = self.Info.Traits.Get(); @@ -62,6 +57,14 @@ namespace OpenRA.Traits || aircraft.RepairBuildings.Contains( a.Info.Name ); } + public virtual IEnumerable GetCurrentPath(Actor self) + { + var move = self.GetCurrentActivity() as Activities.Fly; + if (move == null) return new float2[] { }; + + return new float2[] { move.Pos }; + } + public UnitMovementType GetMovementType() { return UnitMovementType.Fly; } public bool CanEnterCell(int2 location) { return true; } } diff --git a/OpenRA.Mods.RA/ChronoshiftPower.cs b/OpenRA.Mods.RA/ChronoshiftPower.cs index d2e5fac483..ea0ef88509 100644 --- a/OpenRA.Mods.RA/ChronoshiftPower.cs +++ b/OpenRA.Mods.RA/ChronoshiftPower.cs @@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA Game.controller.CancelInputMode(); // Ensure the target cell is valid for the unit - var movement = order.TargetActor.traits.GetOrDefault(); + var movement = order.TargetActor.traits.GetOrDefault(); if (!movement.CanEnterCell(order.TargetLocation)) return; @@ -152,7 +152,7 @@ namespace OpenRA.Mods.RA if (!world.LocalPlayer.Shroud.IsExplored(xy)) return "move-blocked"; - var movement = self.traits.GetOrDefault(); + var movement = self.traits.GetOrDefault(); return (movement.CanEnterCell(xy)) ? "chrono-target" : "move-blocked"; } } diff --git a/OpenRA.Mods.RA/Helicopter.cs b/OpenRA.Mods.RA/Helicopter.cs index 86c234d8c1..fc26b1fa87 100644 --- a/OpenRA.Mods.RA/Helicopter.cs +++ b/OpenRA.Mods.RA/Helicopter.cs @@ -19,6 +19,7 @@ #endregion using System; +using System.Collections.Generic; using System.Linq; using OpenRA.Traits.Activities; using OpenRA.GameRules; @@ -37,7 +38,7 @@ namespace OpenRA.Mods.RA public override object Create( ActorInitializer init ) { return new Helicopter( init ); } } - class Helicopter : Aircraft, IIssueOrder, IResolveOrder + class Helicopter : Aircraft, ITick, IIssueOrder, IResolveOrder { public IDisposable reservation; @@ -49,7 +50,7 @@ namespace OpenRA.Mods.RA if (underCursor == null) { - if (self.traits.GetOrDefault().CanEnterCell(xy)) + if (self.traits.GetOrDefault().CanEnterCell(xy)) return new Order("Move", self, xy); } @@ -143,5 +144,13 @@ namespace OpenRA.Mods.RA return float2.FromAngle((float)self.World.SharedRandom.NextDouble() * 3.14f); return (5 / d.LengthSquared) * d; } + + public override IEnumerable GetCurrentPath(Actor self) + { + var move = self.GetCurrentActivity() as Activities.HeliFly; + if (move == null) return new float2[] { }; + + return new float2[] { move.Dest }; + } } } diff --git a/OpenRA.Mods.RA/Minelayer.cs b/OpenRA.Mods.RA/Minelayer.cs index 12068e0733..4e3b9ec787 100644 --- a/OpenRA.Mods.RA/Minelayer.cs +++ b/OpenRA.Mods.RA/Minelayer.cs @@ -61,7 +61,7 @@ namespace OpenRA.Mods.RA if (self.Owner == self.World.LocalPlayer) Game.controller.CancelInputMode(); - var movement = self.traits.Get(); + var movement = self.traits.Get(); minefield = GetMinefieldCells(minefieldStart, order.TargetLocation, self.Info.Traits.Get().MinefieldDepth) @@ -126,7 +126,7 @@ namespace OpenRA.Mods.RA public void Render(World world) { var ml = minelayer.traits.Get(); - var movement = minelayer.traits.Get(); + var movement = minelayer.traits.Get(); var minefield = GetMinefieldCells(ml.minefieldStart, lastMousePos, minelayer.Info.Traits.Get().MinefieldDepth) .Where(p => movement.CanEnterCell(p)).ToArray(); diff --git a/OpenRA.Mods.RA/Passenger.cs b/OpenRA.Mods.RA/Passenger.cs index a4df4ac57c..bf9eb07277 100644 --- a/OpenRA.Mods.RA/Passenger.cs +++ b/OpenRA.Mods.RA/Passenger.cs @@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA if (cargo == null || cargo.IsFull(underCursor)) return null; - var umt = self.traits.Get().GetMovementType(); + var umt = self.traits.Get().GetMovementType(); if (!underCursor.Info.Traits.Get().PassengerTypes.Contains(umt)) return null;