mines seed ore

This commit is contained in:
Chris Forbes
2009-12-03 19:42:57 +13:00
parent 6b12937793
commit 68a42ac5e4
4 changed files with 37 additions and 10 deletions

View File

@@ -161,6 +161,7 @@
<Compile Include="Traits\RenderUnitRotor.cs" />
<Compile Include="Traits\RenderUnitSpinner.cs" />
<Compile Include="Traits\RenderUnitTurreted.cs" />
<Compile Include="Traits\SeedsOre.cs" />
<Compile Include="Traits\TraitsInterfaces.cs" />
<Compile Include="Traits\Tree.cs" />
<Compile Include="Traits\Turreted.cs" />

View File

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

View File

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

View File

@@ -183,7 +183,7 @@ Selectable=no
[MINE]
Description=Ore Pit
Traits=Building, RenderBuilding
Traits=Building, RenderBuilding, SeedsOre
Footprint=x
Dimensions=1,1
Name=MINE