Add ITerrainInfoNotifyMapCreated interface.
This commit is contained in:
@@ -1020,33 +1020,6 @@ namespace OpenRA
|
||||
ProjectedCells = new ProjectedCellRegion(this, tl, br).ToArray();
|
||||
}
|
||||
|
||||
public void FixOpenAreas()
|
||||
{
|
||||
var r = new Random();
|
||||
var tileset = Rules.TileSet;
|
||||
|
||||
for (var j = Bounds.Top; j < Bounds.Bottom; j++)
|
||||
{
|
||||
for (var i = Bounds.Left; i < Bounds.Right; i++)
|
||||
{
|
||||
var type = Tiles[new MPos(i, j)].Type;
|
||||
var index = Tiles[new MPos(i, j)].Index;
|
||||
if (!tileset.Templates.ContainsKey(type))
|
||||
{
|
||||
Console.WriteLine("Unknown Tile ID {0}".F(type));
|
||||
continue;
|
||||
}
|
||||
|
||||
var template = tileset.Templates[type];
|
||||
if (!template.PickAny)
|
||||
continue;
|
||||
|
||||
index = (byte)r.Next(0, template.TilesCount);
|
||||
Tiles[new MPos(i, j)] = new TerrainTile(type, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public byte GetTerrainIndex(CPos cell)
|
||||
{
|
||||
const short InvalidCachedTerrainIndex = -1;
|
||||
|
||||
@@ -14,6 +14,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using OpenRA.FileSystem;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Support;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA
|
||||
@@ -34,6 +35,11 @@ namespace OpenRA
|
||||
float MaxHeightColorBrightness { get; }
|
||||
}
|
||||
|
||||
public interface ITerrainInfoNotifyMapCreated : ITerrainInfo
|
||||
{
|
||||
void MapCreated(Map map);
|
||||
}
|
||||
|
||||
public class TerrainTileInfo
|
||||
{
|
||||
[FieldLoader.Ignore]
|
||||
@@ -140,7 +146,7 @@ namespace OpenRA
|
||||
}
|
||||
}
|
||||
|
||||
public class TileSet : ITerrainInfo
|
||||
public class TileSet : ITerrainInfo, ITerrainInfoNotifyMapCreated
|
||||
{
|
||||
public const string TerrainPaletteInternalName = "terrain";
|
||||
|
||||
@@ -270,5 +276,22 @@ namespace OpenRA
|
||||
float ITerrainInfo.MinHeightColorBrightness { get { return MinHeightColorBrightness; } }
|
||||
float ITerrainInfo.MaxHeightColorBrightness { get { return MaxHeightColorBrightness; } }
|
||||
TerrainTile ITerrainInfo.DefaultTerrainTile { get { return new TerrainTile(Templates.First().Key, 0); } }
|
||||
|
||||
void ITerrainInfoNotifyMapCreated.MapCreated(Map map)
|
||||
{
|
||||
// Randomize PickAny tile variants
|
||||
var r = new MersenneTwister();
|
||||
for (var j = map.Bounds.Top; j < map.Bounds.Bottom; j++)
|
||||
{
|
||||
for (var i = map.Bounds.Left; i < map.Bounds.Right; i++)
|
||||
{
|
||||
var type = map.Tiles[new MPos(i, j)].Type;
|
||||
if (!Templates.TryGetValue(type, out var template) || !template.PickAny)
|
||||
continue;
|
||||
|
||||
map.Tiles[new MPos(i, j)] = new TerrainTile(type, (byte)r.Next(0, template.TilesCount));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user