diff --git a/OpenRa.Game/Traits/Activities/HeliFly.cs b/OpenRa.Game/Traits/Activities/HeliFly.cs index c27de496f1..4f9fb658c6 100644 --- a/OpenRa.Game/Traits/Activities/HeliFly.cs +++ b/OpenRa.Game/Traits/Activities/HeliFly.cs @@ -31,8 +31,12 @@ namespace OpenRa.Game.Traits.Activities } var dist = Dest - self.CenterLocation; - if (float2.WithinEpsilon(float2.Zero, dist, 10)) + if (float2.WithinEpsilon(float2.Zero, dist, 2)) + { + self.CenterLocation = Dest; + self.Location = ((1 / 24f) * self.CenterLocation).ToInt2(); return NextActivity; + } var desiredFacing = Util.GetFacing(dist, unit.Facing); Util.TickFacing(ref unit.Facing, desiredFacing, self.Info.ROT); diff --git a/OpenRa.Game/Traits/Activities/ReturnToBase.cs b/OpenRa.Game/Traits/Activities/ReturnToBase.cs index 69b7477bec..29aad3bc5d 100644 --- a/OpenRa.Game/Traits/Activities/ReturnToBase.cs +++ b/OpenRa.Game/Traits/Activities/ReturnToBase.cs @@ -16,18 +16,12 @@ namespace OpenRa.Game.Traits.Activities float2 w1, w2, w3; /* tangent points to turn circles */ float2 landPoint; - static bool IsReserved(Actor a) - { - var res = a.traits.GetOrDefault(); - return res != null && res.IsReserved; - } - Actor ChooseAirfield(Actor self) { var airfield = Game.world.Actors .Where(a => a.Info == Rules.UnitInfo["AFLD"] /* todo: generalize this */ && a.Owner == self.Owner - && !IsReserved(a)) + && !Reservable.IsReserved(a)) .FirstOrDefault(); if (airfield == null) diff --git a/OpenRa.Game/Traits/Helicopter.cs b/OpenRa.Game/Traits/Helicopter.cs index ccec5d821a..6728521dca 100644 --- a/OpenRa.Game/Traits/Helicopter.cs +++ b/OpenRa.Game/Traits/Helicopter.cs @@ -1,9 +1,11 @@ using OpenRa.Game.Traits.Activities; +using System; namespace OpenRa.Game.Traits { class Helicopter : IOrder, IMovement { + public IDisposable reservation; public Helicopter(Actor self) {} public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) @@ -13,17 +15,43 @@ namespace OpenRa.Game.Traits if (underCursor == null) return new Order("Move", self, null, xy, null); + if (underCursor.Info == Rules.UnitInfo["HPAD"] + && underCursor.Owner == self.Owner + && !Reservable.IsReserved(underCursor)) + return new Order("Enter", self, underCursor, int2.Zero, null); + return null; } public void ResolveOrder( Actor self, Order order ) { + if (reservation != null) + { + reservation.Dispose(); + reservation = null; + } + if (order.OrderString == "Move") { self.CancelActivity(); self.QueueActivity(new HeliFly(Util.CenterOfCell(order.TargetLocation))); + self.QueueActivity(new Turn(self.Info.InitialFacing)); self.QueueActivity(new HeliLand(true)); } + + if (order.OrderString == "Enter") + { + if (Reservable.IsReserved(order.TargetActor)) return; + var res = order.TargetActor.traits.GetOrDefault(); + if (res != null) + reservation = res.Reserve(self); + + self.CancelActivity(); + self.QueueActivity(new HeliFly(order.TargetActor.CenterLocation)); + self.QueueActivity(new Turn(self.Info.InitialFacing)); + self.QueueActivity(new HeliLand(false)); + self.QueueActivity(new Rearm()); + } } public UnitMovementType GetMovementType() { return UnitMovementType.Fly; } diff --git a/OpenRa.Game/Traits/Plane.cs b/OpenRa.Game/Traits/Plane.cs index 5a41c22cf4..f00bbe54d5 100644 --- a/OpenRa.Game/Traits/Plane.cs +++ b/OpenRa.Game/Traits/Plane.cs @@ -19,14 +19,9 @@ namespace OpenRa.Game.Traits return new Order("Move", self, null, xy, null); if (underCursor.Info == Rules.UnitInfo["AFLD"] - && underCursor.Owner == self.Owner) - { - var res = underCursor.traits.GetOrDefault(); - if (res != null && res.IsReserved) - return null; - + && underCursor.Owner == self.Owner + && !Reservable.IsReserved(underCursor)) return new Order("Enter", self, underCursor, int2.Zero, null); - } return null; } @@ -49,12 +44,10 @@ namespace OpenRa.Game.Traits if (order.OrderString == "Enter") { + if (Reservable.IsReserved(order.TargetActor)) return; var res = order.TargetActor.traits.GetOrDefault(); if (res != null) - { - if (res.IsReserved) return; reservation = res.Reserve(self); - } self.CancelActivity(); self.QueueActivity(new ReturnToBase(self, order.TargetActor)); diff --git a/OpenRa.Game/Traits/Reservable.cs b/OpenRa.Game/Traits/Reservable.cs index ca5e628863..b459bc3da7 100644 --- a/OpenRa.Game/Traits/Reservable.cs +++ b/OpenRa.Game/Traits/Reservable.cs @@ -7,8 +7,6 @@ namespace OpenRa.Game.Traits public Reservable(Actor self) { } Actor reservedFor; - public bool IsReserved { get { return reservedFor != null; } } - public void Tick(Actor self) { if (reservedFor == null) @@ -22,5 +20,11 @@ namespace OpenRa.Game.Traits reservedFor = forActor; return new DisposableAction(() => reservedFor = null); } + + public static bool IsReserved(Actor a) + { + var res = a.traits.GetOrDefault(); + return res != null && res.reservedFor != null; + } } }