From 1cb3f1ee103dd314ebf4724a756e739e7cc12824 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 3 Nov 2009 18:10:09 +1300 Subject: [PATCH] harvesting support in Map --- OpenRa.FileFormats/Map.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/OpenRa.FileFormats/Map.cs b/OpenRa.FileFormats/Map.cs index 49e996b95a..b013a42673 100644 --- a/OpenRa.FileFormats/Map.cs +++ b/OpenRa.FileFormats/Map.cs @@ -116,12 +116,12 @@ namespace OpenRa.FileFormats return MapTiles[i, j].overlay < overlayIsOre.Length; } - bool ContainsOre(int i, int j) + public bool ContainsOre(int i, int j) { return HasOverlay(i,j) && overlayIsOre[MapTiles[i,j].overlay]; } - bool ContainsGem(int i, int j) + public bool ContainsGem(int i, int j) { return HasOverlay(i, j) && overlayIsGems[MapTiles[i, j].overlay]; } @@ -129,6 +129,17 @@ namespace OpenRa.FileFormats const float oreRate = .02f; const float gemRate = .01f; + public bool Harvest(int2 p, out bool isGems) /* harvests one unit if possible */ + { + isGems = ContainsGem(p.X, p.Y); + if (MapTiles[p.X, p.Y].density == 0) return false; + + if (--MapTiles[p.X, p.Y].density == 0) + MapTiles[p.X, p.Y].overlay = 0xff; + + return true; + } + public void GrowOre( Func canSpreadIntoCell, Random r ) /* todo: deal with ore pits */ { /* phase 1: grow into neighboring regions */