diff --git a/OpenRa.Game/Controller.cs b/OpenRa.Game/Controller.cs index b8ae8cf7f2..b0d321995c 100644 --- a/OpenRa.Game/Controller.cs +++ b/OpenRa.Game/Controller.cs @@ -184,6 +184,8 @@ namespace OpenRa.Game case "PlaceBuilding": return Cursor.Default; case "Sell": return Cursor.Sell; case "NoSell": return Cursor.SellBlocked; + case "Repair": return Cursor.Repair; + case "NoRepair": return Cursor.RepairBlocked; default: return null; } diff --git a/OpenRa.Game/Cursor.cs b/OpenRa.Game/Cursor.cs index 9c3d5b0f28..6a7d341fef 100644 --- a/OpenRa.Game/Cursor.cs +++ b/OpenRa.Game/Cursor.cs @@ -28,5 +28,7 @@ namespace OpenRa.Game public static Cursor Heal { get { return new Cursor("heal"); } } public static Cursor Sell { get { return new Cursor("sell"); } } public static Cursor SellBlocked { get { return new Cursor("sell-blocked"); } } + public static Cursor Repair { get { return new Cursor("repair"); } } + public static Cursor RepairBlocked { get { return new Cursor("repair-blocked"); } } } } diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index 665f3501a2..e32fe8d1d5 100755 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -135,6 +135,8 @@ namespace OpenRa.Game Game.LocalPlayer = Game.players[(Game.LocalPlayer.Index + 1) % 4]; if (e.KeyCode == Keys.F3) Game.controller.orderGenerator = new SellOrderGenerator(); + if (e.KeyCode == Keys.F4) + Game.controller.orderGenerator = new RepairOrderGenerator(); if (!Game.chat.isChatting) if (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9) diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index ffad0fc90a..53863fbbc8 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -99,6 +99,7 @@ + diff --git a/OpenRa.Game/Orders/RepairOrderGenerator.cs b/OpenRa.Game/Orders/RepairOrderGenerator.cs new file mode 100644 index 0000000000..d4c366d1fb --- /dev/null +++ b/OpenRa.Game/Orders/RepairOrderGenerator.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using OpenRa.Game.GameRules; +using OpenRa.Game.Traits; + +namespace OpenRa.Game.Orders +{ + class RepairOrderGenerator : IOrderGenerator + { + public IEnumerable Order(int2 xy, MouseInput mi) + { + if (!mi.IsFake && mi.Button == MouseButton.Right) + { + Game.controller.CancelInputMode(); + yield break; + } + + var loc = mi.Location + Game.viewport.Location; + var underCursor = Game.FindUnits(loc, loc) + .Where(a => a.Owner == Game.LocalPlayer + && a.traits.Contains() + && a.Info.Selectable).FirstOrDefault(); + + var building = underCursor != null ? underCursor.Info as BuildingInfo : null; + + if (building == null || !building.Repairable) + { + yield return new Order("NoRepair", Game.LocalPlayer.PlayerActor, null, int2.Zero, null); + yield break; + } + + yield return new Order("Repair", underCursor, null, int2.Zero, null); + } + + public void Tick() {} + + public void Render() {} + } +} diff --git a/OpenRa.Game/RepairBuilding.cs b/OpenRa.Game/RepairBuilding.cs new file mode 100644 index 0000000000..06088e3fb2 --- /dev/null +++ b/OpenRa.Game/RepairBuilding.cs @@ -0,0 +1,60 @@ +using System.Collections.Generic; +using OpenRa.Game.GameRules; +using OpenRa.Game.Traits; + +namespace OpenRa.Game +{ + class RepairBuilding : IOrderGenerator + { + readonly Actor Producer; + readonly BuildingInfo Building; + + public RepairBuilding(Actor producer, string name) + { + Producer = producer; + Building = (BuildingInfo)Rules.UnitInfo[name]; + } + + public IEnumerable Order(int2 xy, MouseInput mi) + { + if (mi.Button == MouseButton.Left) + { + var actorBuilding = Game.FindUnits(xy.ToFloat2(), xy.ToFloat2()) + .FirstOrDefault(a => a.traits.Contains()); + + yield return new Order("RepairBuilding", Producer.Owner.PlayerActor, null, xy, Building.Name); + } + else // rmb + { + Game.world.AddFrameEndTask(_ => { Game.controller.orderGenerator = null; }); + } + } + + public void Tick() + { + //var producing = Producer.traits.Get().CurrentItem(Rules.UnitCategory[Building.Name]); + //if (producing == null || producing.Item != Building.Name || producing.RemainingTime != 0) + //Game.world.AddFrameEndTask(_ => { Game.controller.orderGenerator = null; }); + + + //const int ticksPerPoint = 15; + //const int hpPerPoint = 8; + //int remainingTicks = ticksPerPoint; + + // if (--remainingTicks == 0) + // { + // self.Health += hpPerPoint; + + // if (self.Health >= self.Info.Strength) + // { + // self.Health = self.Info.Strength; + // return NextActivity; + // } + } + + public void Render() + { + //Game.worldRenderer.uiOverlay.DrawBuildingGrid(Building); + } + } +}