diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index 25a2d9b677..ffad0fc90a 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -99,6 +99,7 @@ + diff --git a/OpenRa.Game/Orders/SellOrderGenerator.cs b/OpenRa.Game/Orders/SellOrderGenerator.cs new file mode 100644 index 0000000000..2d6c6274d5 --- /dev/null +++ b/OpenRa.Game/Orders/SellOrderGenerator.cs @@ -0,0 +1,37 @@ +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 SellOrderGenerator : IOrderGenerator + { + public IEnumerable Order(int2 xy, MouseInput mi) + { + var loc = mi.Location + Game.viewport.Location; + var underCursor = Game.FindUnits(loc, loc) + .Where( a => a.traits.Contains() ).FirstOrDefault(); + + if (underCursor != null && !underCursor.Info.Selectable) + underCursor = null; + + if (underCursor == null) + yield break; + + var building = underCursor.traits.Get(); + if (building.unitInfo.Unsellable) + yield break; + + if (underCursor.Owner != Game.LocalPlayer) + yield break; + + yield return new Order("Sell", underCursor, null, int2.Zero, null); + } + + public void Tick() {} + public void Render() {} + } +}