diff --git a/OpenRA.Mods.RA/Cargo.cs b/OpenRA.Mods.RA/Cargo.cs index b68c9574ac..09bd074f69 100644 --- a/OpenRA.Mods.RA/Cargo.cs +++ b/OpenRA.Mods.RA/Cargo.cs @@ -21,39 +21,57 @@ namespace OpenRA.Mods.RA public readonly int UnloadFacing = 0; } - public class Cargo : IPips, IIssueOrder, IResolveOrder, IOrderCursor + public class Cargo : IPips, IIssueOrder, IResolveOrder, IOrderCursor, IOrderVoice { List cargo = new List(); public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) { - // todo: check if there is an unoccupied `land` tile adjacent - if (mi.Button == MouseButton.Right && underCursor == self && cargo.Count > 0) - { - var unit = underCursor.traits.GetOrDefault(); - if (unit != null && unit.Altitude > 0) return null; - - return new Order("Deploy", self); - } - - return null; + if (mi.Button != MouseButton.Right || underCursor != self) + return null; + + return new Order("Unload", self); } - + public void ResolveOrder(Actor self, Order order) { - if (order.OrderString == "Deploy") + if (order.OrderString == "Unload") { - // todo: eject the units + if (!CanUnload(self)) + return; + self.CancelActivity(); self.QueueActivity(new UnloadCargo()); } } + bool CanUnload(Actor self) + { + if (IsEmpty(self)) + return false; + + // Cannot unload mid-air + var unit = self.traits.GetOrDefault(); + if (unit != null && unit.Altitude > 0) + return false; + + // Todo: Check if there is a free tile to unload to + return true; + } + + public string CursorForOrder(Actor self, Order order) { - return (order.OrderString == "Deploy") ? "deploy" : null; + if (order.OrderString != "Unload") return null; + return CanUnload(self) ? "deploy" : "deploy-blocked"; } + public string VoicePhraseForOrder(Actor self, Order order) + { + if (order.OrderString != "Unload" || IsEmpty(self)) return null; + return "Move"; + } + public bool IsFull(Actor self) { return cargo.Count == self.Info.Traits.Get().Passengers; diff --git a/OpenRA.Mods.RA/Passenger.cs b/OpenRA.Mods.RA/Passenger.cs index d93120cce1..28784c46aa 100644 --- a/OpenRA.Mods.RA/Passenger.cs +++ b/OpenRA.Mods.RA/Passenger.cs @@ -8,6 +8,7 @@ */ #endregion +using OpenRA.Effects; using OpenRA.Mods.RA.Activities; using OpenRA.Traits; using OpenRA.Traits.Activities; @@ -19,10 +20,13 @@ namespace OpenRA.Mods.RA public readonly PipType ColorOfCargoPip = PipType.Green; } - class Passenger : IIssueOrder, IResolveOrder, IOrderCursor + class Passenger : IIssueOrder, IResolveOrder, IOrderCursor, IOrderVoice { public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) { + // Disable cargo support until someone fixes it + return null; + if (mi.Button != MouseButton.Right) return null; @@ -30,26 +34,41 @@ namespace OpenRA.Mods.RA return null; var cargo = underCursor.traits.GetOrDefault(); - if (cargo == null || cargo.IsFull(underCursor)) + if (cargo == null) return null; - // Todo: Use something better for cargo management - //var umt = self.traits.Get().GetMovementType(); - //if (!underCursor.Info.Traits.Get().PassengerTypes.Contains(umt)) - return null; - - //return new Order("EnterTransport", self, underCursor); + // Todo: Check if we can enter the transport + + return new Order("EnterTransport", self, underCursor); + } + + bool CanEnter(Actor self, Actor a) + { + var cargo = a.traits.GetOrDefault(); + return (cargo != null && !cargo.IsFull(a)); } public string CursorForOrder(Actor self, Order order) { - return (order.OrderString == "EnterTransport") ? "enter" : null; + if (order.OrderString != "EnterTransport") return null; + return CanEnter(self, order.TargetActor) ? "enter" : "enter-blocked"; } + public string VoicePhraseForOrder(Actor self, Order order) + { + if (order.OrderString != "EnterTransport" || !CanEnter(self, order.TargetActor)) return null; + return "Move"; + } + public void ResolveOrder(Actor self, Order order) { if (order.OrderString == "EnterTransport") { + if (!CanEnter(self, order.TargetActor)) return; + + if (self.Owner == self.World.LocalPlayer) + self.World.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor))); + self.CancelActivity(); self.QueueActivity(new Move(order.TargetActor.Location, 1)); self.QueueActivity(new EnterTransport(self, order.TargetActor));