From 95f3c29e64368d467300ef05d31c8c54c7590cb1 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 3 Jan 2010 13:23:49 +1300 Subject: [PATCH] Teleport using IOrderGenerator --- OpenRa.Game/OpenRa.Game.csproj | 1 + OpenRa.Game/Orders/TeleportOrderGenerator.cs | 35 ++++++++++++++++++++ OpenRa.Game/Traits/ChronoshiftDeploy.cs | 17 ++++------ 3 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 OpenRa.Game/Orders/TeleportOrderGenerator.cs diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index 2ef34ff3af..d5903beeee 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -103,6 +103,7 @@ + diff --git a/OpenRa.Game/Orders/TeleportOrderGenerator.cs b/OpenRa.Game/Orders/TeleportOrderGenerator.cs new file mode 100644 index 0000000000..0c14e694bb --- /dev/null +++ b/OpenRa.Game/Orders/TeleportOrderGenerator.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Drawing; + +namespace OpenRa.Game.Orders +{ + class TeleportOrderGenerator : IOrderGenerator + { + public readonly Actor self; + + public TeleportOrderGenerator(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("Chronoshift", self, null, xy, null); + } + + public void Tick() {} + public void Render() + { + Game.worldRenderer.DrawSelectionBox(self, Color.White, true); + } + } +} diff --git a/OpenRa.Game/Traits/ChronoshiftDeploy.cs b/OpenRa.Game/Traits/ChronoshiftDeploy.cs index 911e93b9ed..2730b979e7 100644 --- a/OpenRa.Game/Traits/ChronoshiftDeploy.cs +++ b/OpenRa.Game/Traits/ChronoshiftDeploy.cs @@ -1,15 +1,15 @@ using System.Collections.Generic; using System.Linq; +using OpenRa.Game.Orders; namespace OpenRa.Game.Traits { class ChronoshiftDeploy : IOrder, ISpeedModifier, ITick, IPips { public ChronoshiftDeploy(Actor self) { } - bool chronoshiftActive = false; // Is the chronoshift engine active? int remainingChargeTime = 0; // How long until we can chronoshift again? int chargeTime = (int)(Rules.Aftermath.ChronoTankDuration * 60 * 25); // How long between shifts? - + public void Tick(Actor self) { if (remainingChargeTime > 0) @@ -20,9 +20,6 @@ namespace OpenRa.Game.Traits { if (mi.Button == MouseButton.Left) return null; - if (chronoshiftActive) - return new Order("Chronoshift", self, null, xy, null); - else if (xy == self.Location && remainingChargeTime <= 0) return new Order("Deploy", self, null, int2.Zero, null); @@ -31,26 +28,26 @@ namespace OpenRa.Game.Traits public void ResolveOrder(Actor self, Order order) { - var movement = self.traits.WithInterface().FirstOrDefault(); if (order.OrderString == "Deploy" && remainingChargeTime <= 0) { - chronoshiftActive = true; + Game.controller.orderGenerator = new TeleportOrderGenerator(self); self.CancelActivity(); } - + + var movement = self.traits.WithInterface().FirstOrDefault(); if (order.OrderString == "Chronoshift" && movement.CanEnterCell(order.TargetLocation)) { + Game.controller.CancelInputMode(); self.CancelActivity(); self.QueueActivity(new Activities.Teleport(order.TargetLocation)); Sound.Play("chrotnk1.aud"); - chronoshiftActive = false; remainingChargeTime = chargeTime; } } public float GetSpeedModifier() { - return chronoshiftActive ? 0f : 1f; + return (Game.controller.orderGenerator is TeleportOrderGenerator) ? 0f : 1f; } // Display 5 pips indicating the current charge status