ore spreading ported
This commit is contained in:
@@ -26,43 +26,6 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
public static class Ore
|
public static class Ore
|
||||||
{
|
{
|
||||||
public static void SpreadOre(this World world, Random r, float chance)
|
|
||||||
{
|
|
||||||
var map = world.Map;
|
|
||||||
|
|
||||||
var mini = map.XOffset; var maxi = map.XOffset + map.Width;
|
|
||||||
var minj = map.YOffset; var maxj = map.YOffset + map.Height;
|
|
||||||
|
|
||||||
/* phase 1: grow into neighboring regions */
|
|
||||||
var newOverlay = new byte[128, 128];
|
|
||||||
for (int j = minj; j < maxj; j++)
|
|
||||||
for (int i = mini; i < maxi; i++)
|
|
||||||
{
|
|
||||||
newOverlay[i, j] = 0xff;
|
|
||||||
if (!map.HasOverlay(i, j)
|
|
||||||
&& r.NextDouble() < chance
|
|
||||||
&& map.GetOreDensity(i, j) > 0
|
|
||||||
&& world.IsCellBuildable(new int2(i,j), UnitMovementType.Wheel))
|
|
||||||
newOverlay[i, j] = ChooseOre();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int j = minj; j < maxj; j++)
|
|
||||||
for (int i = mini; i < maxi; i++)
|
|
||||||
if (newOverlay[i, j] != 0xff)
|
|
||||||
map.MapTiles[i, j].overlay = newOverlay[i, j];
|
|
||||||
}
|
|
||||||
|
|
||||||
static byte GetOreDensity(this Map map, int i, int j)
|
|
||||||
{
|
|
||||||
int sum = 0;
|
|
||||||
for (var u = -1; u < 2; u++)
|
|
||||||
for (var v = -1; v < 2; v++)
|
|
||||||
if (map.ContainsOre(i + u, j + v))
|
|
||||||
++sum;
|
|
||||||
sum = (sum * 4 + 2) / 3;
|
|
||||||
return (byte)sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool HasOverlay(this Map map, int i, int j)
|
static bool HasOverlay(this Map map, int i, int j)
|
||||||
{
|
{
|
||||||
return map.MapTiles[i, j].overlay < overlayIsOre.Length;
|
return map.MapTiles[i, j].overlay < overlayIsOre.Length;
|
||||||
@@ -83,13 +46,6 @@ namespace OpenRA
|
|||||||
return map.ContainsGem(p.X, p.Y) || map.ContainsOre(p.X, p.Y);
|
return map.ContainsGem(p.X, p.Y) || map.ContainsOre(p.X, p.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static byte ore = 5;
|
|
||||||
static byte ChooseOre()
|
|
||||||
{
|
|
||||||
if (++ore > 8) ore = 5;
|
|
||||||
return ore;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool[] overlayIsOre =
|
static bool[] overlayIsOre =
|
||||||
{
|
{
|
||||||
false, false, false, false, false,
|
false, false, false, false, false,
|
||||||
|
|||||||
@@ -49,9 +49,8 @@ namespace OpenRA.Traits
|
|||||||
if (oreResource != null)
|
if (oreResource != null)
|
||||||
{
|
{
|
||||||
if (info.Spreads)
|
if (info.Spreads)
|
||||||
Ore.SpreadOre(self.World,
|
self.World.WorldActor.traits.Get<ResourceLayer>().Spread(oreResource,
|
||||||
self.World.SharedRandom,
|
self.World.SharedRandom, info.Chance);
|
||||||
info.Chance);
|
|
||||||
|
|
||||||
if (info.Grows)
|
if (info.Grows)
|
||||||
self.World.WorldActor.traits.Get<ResourceLayer>().Grow(oreResource);
|
self.World.WorldActor.traits.Get<ResourceLayer>().Grow(oreResource);
|
||||||
|
|||||||
@@ -159,6 +159,32 @@ namespace OpenRA.Traits
|
|||||||
++content[i, j].density;
|
++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 struct CellContents
|
||||||
{
|
{
|
||||||
public ResourceTypeInfo type;
|
public ResourceTypeInfo type;
|
||||||
|
|||||||
Reference in New Issue
Block a user