From d6c2c1931662b642fc177643997336e26582dd88 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Wed, 6 Jan 2010 23:17:12 +1300 Subject: [PATCH] Fix chronoshift + chronotank = crash (Yo Dawg) --- OpenRa.Game/OpenRa.Game.csproj | 3 +- ...hronoshiftSelfDestinationOrderGenerator.cs | 45 +++++++++++++++++++ OpenRa.Game/Traits/ChronoshiftDeploy.cs | 8 +++- 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 OpenRa.Game/Orders/ChronoshiftSelfDestinationOrderGenerator.cs diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index 4aa7ac18d0..939be98dbc 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -96,6 +96,7 @@ + @@ -304,4 +305,4 @@ --> - + \ No newline at end of file diff --git a/OpenRa.Game/Orders/ChronoshiftSelfDestinationOrderGenerator.cs b/OpenRa.Game/Orders/ChronoshiftSelfDestinationOrderGenerator.cs new file mode 100644 index 0000000000..5c949c1c51 --- /dev/null +++ b/OpenRa.Game/Orders/ChronoshiftSelfDestinationOrderGenerator.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Drawing; +using OpenRa.Game.Traits; + +namespace OpenRa.Game.Orders +{ + class ChronoshiftSelfDestinationOrderGenerator : IOrderGenerator + { + public readonly Actor self; + + public ChronoshiftSelfDestinationOrderGenerator(Actor self) + { + this.self = self; + } + + public IEnumerable Order(int2 xy, MouseInput mi) + { + if (mi.Button == MouseButton.Left) + { + Game.controller.CancelInputMode(); + yield break; + } + + yield return new Order("ChronoshiftSelf", self, null, xy, null); + } + + public void Tick() { } + public void Render() + { + Game.worldRenderer.DrawSelectionBox(self, Color.White, true); + } + + public Cursor GetCursor(int2 xy, MouseInput mi) + { + if (!Game.LocalPlayer.Shroud.IsExplored(xy)) + return Cursor.MoveBlocked; + + var movement = self.traits.WithInterface().FirstOrDefault(); + return (movement.CanEnterCell(xy)) ? Cursor.Chronoshift : Cursor.MoveBlocked; + } + } +} diff --git a/OpenRa.Game/Traits/ChronoshiftDeploy.cs b/OpenRa.Game/Traits/ChronoshiftDeploy.cs index 7c4252fc97..089ec5ab54 100644 --- a/OpenRa.Game/Traits/ChronoshiftDeploy.cs +++ b/OpenRa.Game/Traits/ChronoshiftDeploy.cs @@ -30,13 +30,17 @@ namespace OpenRa.Game.Traits { if (order.OrderString == "Deploy") { - Game.controller.orderGenerator = new ChronoshiftDestinationOrderGenerator(self); + Game.controller.orderGenerator = new ChronoshiftSelfDestinationOrderGenerator(self); return; } var movement = self.traits.WithInterface().FirstOrDefault(); - if (order.OrderString == "Chronoshift" && movement.CanEnterCell(order.TargetLocation)) + if (order.OrderString == "ChronoshiftSelf" && movement.CanEnterCell(order.TargetLocation)) { + // Cannot chronoshift into unexplored location + if (!Game.LocalPlayer.Shroud.IsExplored(order.TargetLocation)) + return; + Game.controller.CancelInputMode(); self.CancelActivity(); self.QueueActivity(new Activities.Teleport(order.TargetLocation));