ore growth moved into ResourceLayer
This commit is contained in:
@@ -61,24 +61,6 @@ namespace OpenRA
|
||||
map.MapTiles[i, j].overlay = newOverlay[i, j];
|
||||
}
|
||||
|
||||
public static void GrowOre(this World world)
|
||||
{
|
||||
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 2: increase density of existing areas */
|
||||
var newDensity = new byte[128, 128];
|
||||
for (int j = minj; j < maxj; j++)
|
||||
for (int i = mini; i < maxi; i++)
|
||||
if (map.ContainsOre(i, j)) newDensity[i, j] = map.GetOreDensity(i, j);
|
||||
|
||||
// for (int j = minj; j < maxj; j++)
|
||||
// for (int i = mini; i < maxi; i++)
|
||||
// if (map.MapTiles[i, j].density < newDensity[i, j])
|
||||
// ++map.MapTiles[i, j].density;
|
||||
}
|
||||
|
||||
static byte GetOreDensity(this Map map, int i, int j)
|
||||
{
|
||||
int sum = 0;
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
class OreGrowthInfo : ITraitInfo
|
||||
@@ -39,14 +41,21 @@ namespace OpenRA.Traits
|
||||
if (--remainingTicks <= 0)
|
||||
{
|
||||
var info = self.Info.Traits.Get<OreGrowthInfo>();
|
||||
|
||||
if (info.Spreads)
|
||||
Ore.SpreadOre(self.World,
|
||||
self.World.SharedRandom,
|
||||
info.Chance);
|
||||
|
||||
if (info.Grows)
|
||||
Ore.GrowOre(self.World);
|
||||
// HACK HACK: we should push "grows" down to the resource.
|
||||
var oreResource = self.World.WorldActor.Info.Traits.WithInterface<ResourceTypeInfo>()
|
||||
.FirstOrDefault(r => r.Name == "Ore");
|
||||
|
||||
if (oreResource != null)
|
||||
{
|
||||
if (info.Spreads)
|
||||
Ore.SpreadOre(self.World,
|
||||
self.World.SharedRandom,
|
||||
info.Chance);
|
||||
|
||||
if (info.Grows)
|
||||
self.World.WorldActor.traits.Get<ResourceLayer>().Grow(oreResource);
|
||||
}
|
||||
|
||||
self.World.Minimap.InvalidateOre();
|
||||
remainingTicks = (int)(info.Interval * 60 * 25);
|
||||
|
||||
@@ -83,8 +83,7 @@ namespace OpenRA.Traits
|
||||
for (int y = map.YOffset; y < map.YOffset + map.Height; y++)
|
||||
for (int x = map.XOffset; x < map.XOffset + map.Width; x++)
|
||||
if (content[x, y].type != null)
|
||||
content[x, y].density = (GetAdjacentCellsWith(content[x, y].type, x, y) *
|
||||
content[x, y].image.Length) / 9;
|
||||
content[x, y].density = GetIdealDensity(x, y);
|
||||
}
|
||||
|
||||
public Sprite[] ChooseContent(ResourceTypeInfo info)
|
||||
@@ -102,6 +101,12 @@ namespace OpenRA.Traits
|
||||
return sum;
|
||||
}
|
||||
|
||||
public int GetIdealDensity(int x, int y)
|
||||
{
|
||||
return (GetAdjacentCellsWith(content[x, y].type, x, y) *
|
||||
content[x, y].image.Length) / 9;
|
||||
}
|
||||
|
||||
public void AddResource(ResourceTypeInfo info, int i, int j, int n)
|
||||
{
|
||||
if (content[i, j].type == null)
|
||||
@@ -129,6 +134,31 @@ namespace OpenRA.Traits
|
||||
return type;
|
||||
}
|
||||
|
||||
public void Destroy(int2 p)
|
||||
{
|
||||
content[p.X, p.Y].type = null;
|
||||
content[p.X, p.Y].image = null;
|
||||
content[p.X, p.Y].density = 0;
|
||||
}
|
||||
|
||||
public void Grow(ResourceTypeInfo info)
|
||||
{
|
||||
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 newDensity = new byte[128, 128];
|
||||
for (int j = minj; j < maxj; j++)
|
||||
for (int i = mini; i < maxi; i++)
|
||||
if (content[i, j].type == info)
|
||||
newDensity[i, j] = (byte)GetIdealDensity(i, j);
|
||||
|
||||
for (int j = minj; j < maxj; j++)
|
||||
for (int i = mini; i < maxi; i++)
|
||||
if (content[i, j].type == info && content[i, j].density < newDensity[i, j])
|
||||
++content[i, j].density;
|
||||
}
|
||||
|
||||
public struct CellContents
|
||||
{
|
||||
public ResourceTypeInfo type;
|
||||
|
||||
Reference in New Issue
Block a user