diff --git a/OpenRa.Game/Traits/Activities/Teleport.cs b/OpenRa.Game/Traits/Activities/Teleport.cs new file mode 100644 index 0000000000..2b6c4362d0 --- /dev/null +++ b/OpenRa.Game/Traits/Activities/Teleport.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using OpenRa.Game.GameRules; + +namespace OpenRa.Game.Traits.Activities +{ + class Teleport : IActivity + { + public IActivity NextActivity { get; set; } + + int2 destination; + + public Teleport(int2 destination) + { + this.destination = destination; + } + + public IActivity Tick(Actor self) + { + var unit = self.traits.Get(); + var mobile = self.traits.Get(); + + //TODO: Something needs to go here to shift the units position. + // Everything i have tried has caused a crash in UnitInfluenceMap. + + //Game.world.AddFrameEndTask(_ => + //{ + Game.UnitInfluence.Remove(self, mobile); + //self.Location = this.destination; + mobile.toCell = this.destination; + Game.UnitInfluence.Add(self, mobile); + + + //}); + + return null; + } + + public void Cancel(Actor self){} + + } +} diff --git a/OpenRa.Game/Traits/ChronoshiftDeploy.cs b/OpenRa.Game/Traits/ChronoshiftDeploy.cs new file mode 100644 index 0000000000..38c542401b --- /dev/null +++ b/OpenRa.Game/Traits/ChronoshiftDeploy.cs @@ -0,0 +1,83 @@ +using OpenRa.Game.GameRules; +using System.Drawing; +namespace OpenRa.Game.Traits +{ + class ChronoshiftDeploy : IOrder, ISpeedModifier, ITick, IPips + { + public ChronoshiftDeploy(Actor self) { } + bool chronoshiftActive = false; // Is the chronoshift engine active? + const int chargeTime = 100; // How many frames between uses? + int remainingChargeTime = 0; + + public void Tick(Actor self) + { + if (remainingChargeTime > 0) + remainingChargeTime--; + } + + public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) + { + if (mi.Button == MouseButton.Left) return null; + + if (chronoshiftActive) + return Order.UsePortableChronoshift(self, xy); + + else if (xy == self.Location && remainingChargeTime <= 0) + return Order.ActivatePortableChronoshift(self); + + return null; + } + + public void ResolveOrder(Actor self, Order order) + { + if (order.OrderString == "ActivatePortableChronoshift" && remainingChargeTime <= 0) + { + chronoshiftActive = true; + self.CancelActivity(); + } + + if (order.OrderString == "UsePortableChronoshift" && CanEnterCell(order.TargetLocation, self)) + { + //self.QueueActivity(new Activities.Teleport(order.TargetLocation)); + Sound.Play("chrotnk1.aud"); + chronoshiftActive = false; + remainingChargeTime = chargeTime; + } + } + + static bool CanEnterCell(int2 c, Actor self) + { + if (!Game.BuildingInfluence.CanMoveHere(c)) return false; + var u = Game.UnitInfluence.GetUnitAt(c); + return (u == null || u == self); + } + + public float GetSpeedModifier() + { + return chronoshiftActive ? 0f : 1f; + } + + public Color GetBorderColor() { return Color.Black; } + public int GetPipCount() { return 5; } + public Color GetColorForPip(int index) + { + // TODO: Check how many pips to display + if ((1 - remainingChargeTime*1.0f / chargeTime) * GetPipCount() < index + 1) + return Color.Transparent; + + switch (index) + { + case 0: + case 1: + return Color.Red; + case 2: + case 3: + return Color.Yellow; + case 4: + return Color.LimeGreen; + } + + return Color.Transparent; + } + } +}