harvest order wired into harvester. crashes with noti since the matching activity is noti.

This commit is contained in:
Chris Forbes
2009-11-03 18:21:02 +13:00
parent 1cb3f1ee10
commit d2ddd40902
4 changed files with 21 additions and 5 deletions

View File

@@ -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;

View File

@@ -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"); } }

View File

@@ -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 );

View File

@@ -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<AcceptsOre>())
&& underCursor.traits.Contains<AcceptsOre>() && !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;
}