diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index a513bba673..b25d8b6c87 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -161,6 +161,7 @@ + diff --git a/OpenRa.Game/Ore.cs b/OpenRa.Game/Ore.cs index f81b39ebe5..dfbd508b58 100644 --- a/OpenRa.Game/Ore.cs +++ b/OpenRa.Game/Ore.cs @@ -8,9 +8,19 @@ namespace OpenRa.Game { public static class Ore { - /* todo: deal with ore pits */ + public static void AddOre(this Map map, int i, int j) + { + if (Rules.General.OreSpreads) + if (map.ContainsOre(i, j) && map.MapTiles[i, j].density < 12) + map.MapTiles[i, j].density++; + else if (map.MapTiles[i, j].overlay == 0xff) + { + map.MapTiles[i, j].overlay = ChooseOre(); + map.MapTiles[i, j].density = 1; + } + } - static bool CanSpreadInto(int i, int j) + public static bool CanSpreadInto(int i, int j) { if (Game.BuildingInfluence.GetBuildingAt(new int2(i, j)) != null) return false; @@ -72,13 +82,6 @@ namespace OpenRa.Game } } - static IEnumerable AdjacentTiles(int2 p) - { - for (var u = -1; u < 2; u++) - for (var v = -1; v < 2; v++) - yield return new int2(u, v) + p; - } - static byte GetOreDensity(this Map map, int i, int j) { int sum = 0; diff --git a/OpenRa.Game/Traits/SeedsOre.cs b/OpenRa.Game/Traits/SeedsOre.cs new file mode 100644 index 0000000000..f41a34076b --- /dev/null +++ b/OpenRa.Game/Traits/SeedsOre.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenRa.Game.Traits +{ + class SeedsOre : ITick + { + public SeedsOre( Actor self ) {} + + const double OreSeedProbability = .05; + + public void Tick(Actor self) + { + for (var j = -1; j < 2; j++) + for (var i = -1; i < 2; i++) + if (Game.SharedRandom.NextDouble() < OreSeedProbability) + if (Ore.CanSpreadInto(self.Location.X + i, self.Location.Y + j)) + Rules.Map.AddOre(self.Location.X + i, self.Location.Y + j); + } + } +} diff --git a/trees.ini b/trees.ini index 40a1f283aa..437e0b7614 100644 --- a/trees.ini +++ b/trees.ini @@ -183,7 +183,7 @@ Selectable=no [MINE] Description=Ore Pit -Traits=Building, RenderBuilding +Traits=Building, RenderBuilding, SeedsOre Footprint=x Dimensions=1,1 Name=MINE