ore spreading ported

This commit is contained in:
Chris Forbes
2010-03-03 21:07:03 +13:00
parent 5d7772ac9a
commit 6c229f3273
3 changed files with 28 additions and 47 deletions

View File

@@ -49,9 +49,8 @@ namespace OpenRA.Traits
if (oreResource != null)
{
if (info.Spreads)
Ore.SpreadOre(self.World,
self.World.SharedRandom,
info.Chance);
self.World.WorldActor.traits.Get<ResourceLayer>().Spread(oreResource,
self.World.SharedRandom, info.Chance);
if (info.Grows)
self.World.WorldActor.traits.Get<ResourceLayer>().Grow(oreResource);

View File

@@ -159,6 +159,32 @@ namespace OpenRA.Traits
++content[i, j].density;
}
public void Spread(ResourceTypeInfo info, Random r, float chance)
{
var map = w.Map;
var mini = map.XOffset; var maxi = map.XOffset + map.Width;
var minj = map.YOffset; var maxj = map.YOffset + map.Height;
var growMask = new bool[128, 128];
for (int j = minj; j < maxj; j++)
for (int i = mini; i < maxi; i++)
if (content[i,j].type == null
&& r.NextDouble() < chance
&& GetAdjacentCellsWith(info, i,j ) > 0
&& w.IsCellBuildable(new int2(i, j), UnitMovementType.Wheel))
growMask[i, j] = true;
for (int j = minj; j < maxj; j++)
for (int i = mini; i < maxi; i++)
if (growMask[i, j])
{
content[i, j].type = info;
content[i, j].image = ChooseContent(info);
content[i, j].density = 0;
}
}
public struct CellContents
{
public ResourceTypeInfo type;