diff --git a/OpenRa.FileFormats/Map.cs b/OpenRa.FileFormats/Map.cs index b013a42673..830cf5364e 100644 --- a/OpenRa.FileFormats/Map.cs +++ b/OpenRa.FileFormats/Map.cs @@ -116,16 +116,18 @@ namespace OpenRa.FileFormats return MapTiles[i, j].overlay < overlayIsOre.Length; } - public bool ContainsOre(int i, int j) + bool ContainsOre(int i, int j) { return HasOverlay(i,j) && overlayIsOre[MapTiles[i,j].overlay]; } - public bool ContainsGem(int i, int j) + bool ContainsGem(int i, int j) { return HasOverlay(i, j) && overlayIsGems[MapTiles[i, j].overlay]; } + public bool ContainsResource(int2 p) { return ContainsGem(p.X,p.Y) || ContainsOre(p.X, p.Y); } + const float oreRate = .02f; const float gemRate = .01f; diff --git a/OpenRa.Game/Cursor.cs b/OpenRa.Game/Cursor.cs index 77049a3e7d..537f223f31 100644 --- a/OpenRa.Game/Cursor.cs +++ b/OpenRa.Game/Cursor.cs @@ -18,6 +18,7 @@ namespace OpenRa.Game public Sprite GetSprite(int frame) { return sequence.GetSprite(frame); } public int2 GetHotspot() { return sequence.Hotspot; } + public static Cursor None { get { return null; } } public static Cursor Default { get { return new Cursor("default"); } } public static Cursor Move { get { return new Cursor("move"); } } public static Cursor Select { get { return new Cursor("select"); } } diff --git a/OpenRa.Game/Order.cs b/OpenRa.Game/Order.cs index 0fe7ec6899..1ee5847d00 100644 --- a/OpenRa.Game/Order.cs +++ b/OpenRa.Game/Order.cs @@ -106,7 +106,7 @@ namespace OpenRa.Game public static Order PlaceBuilding(Player subject, int2 target, string buildingName) { - return new Order(subject, "PlaceBuilding", null, null, target, buildingName, Cursor.Default); + return new Order(subject, "PlaceBuilding", null, null, target, buildingName, Cursor.None); } public static Order DeliverOre(Actor subject, Actor target) @@ -114,6 +114,11 @@ namespace OpenRa.Game return new Order(subject.Owner, "DeliverOre", subject, target, int2.Zero, null, Cursor.Enter); } + public static Order Harvest(Actor subject, int2 target) + { + return new Order(subject.Owner, "Harvest", subject, null, target, null, Cursor.Attack); /* todo: special `harvest` cursor? */ + } + public static Order StartProduction(Player subject, string item) { return new Order(subject, "StartProduction", null, null, int2.Zero, item, Cursor.Default ); diff --git a/OpenRa.Game/Traits/Harvester.cs b/OpenRa.Game/Traits/Harvester.cs index a41b70b40d..4e9ad43f95 100644 --- a/OpenRa.Game/Traits/Harvester.cs +++ b/OpenRa.Game/Traits/Harvester.cs @@ -7,14 +7,22 @@ namespace OpenRa.Game.Traits { class Harvester : IOrder { + const int capacity = 28; + int oreCarried = 0; /* sum of these must not exceed capacity */ + int gemsCarried = 0; + + bool IsFull { get { return oreCarried + gemsCarried == capacity; } } + bool IsEmpty { get { return oreCarried == 0 && gemsCarried == 0; } } + public Order Order(Actor self, int2 xy, bool lmb, Actor underCursor) { if (underCursor != null && underCursor.Owner == self.Owner - && underCursor.traits.Contains()) + && underCursor.traits.Contains() && !IsEmpty) return OpenRa.Game.Order.DeliverOre(self, underCursor); - /* todo: harvest order when on ore */ + if (underCursor == null && Game.map.ContainsResource(xy) && !IsFull) + return OpenRa.Game.Order.Harvest(self, xy); return null; }