Use CellLayer for custom terrain.
This commit is contained in:
@@ -113,7 +113,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
[FieldLoader.Ignore] public Lazy<TileReference<ushort, byte>[,]> MapTiles;
|
[FieldLoader.Ignore] public Lazy<TileReference<ushort, byte>[,]> MapTiles;
|
||||||
[FieldLoader.Ignore] public Lazy<TileReference<byte, byte>[,]> MapResources;
|
[FieldLoader.Ignore] public Lazy<TileReference<byte, byte>[,]> MapResources;
|
||||||
[FieldLoader.Ignore] public int[,] CustomTerrain;
|
[FieldLoader.Ignore] public CellLayer<int> CustomTerrain;
|
||||||
|
|
||||||
[FieldLoader.Ignore] Lazy<Ruleset> rules;
|
[FieldLoader.Ignore] Lazy<Ruleset> rules;
|
||||||
public Ruleset Rules { get { return rules != null ? rules.Value : null; } }
|
public Ruleset Rules { get { return rules != null ? rules.Value : null; } }
|
||||||
@@ -257,9 +257,9 @@ namespace OpenRA
|
|||||||
var br = new CPos(Bounds.Right - 1, Bounds.Bottom - 1);
|
var br = new CPos(Bounds.Right - 1, Bounds.Bottom - 1);
|
||||||
Cells = new CellRegion(tl, br);
|
Cells = new CellRegion(tl, br);
|
||||||
|
|
||||||
CustomTerrain = new int[MapSize.X, MapSize.Y];
|
CustomTerrain = new CellLayer<int>(this);
|
||||||
foreach (var cell in Cells)
|
foreach (var cell in Cells)
|
||||||
CustomTerrain[cell.X, cell.Y] = -1;
|
CustomTerrain[cell] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ruleset PreloadRules()
|
public Ruleset PreloadRules()
|
||||||
@@ -548,7 +548,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public int GetTerrainIndex(CPos cell)
|
public int GetTerrainIndex(CPos cell)
|
||||||
{
|
{
|
||||||
var custom = CustomTerrain[cell.X, cell.Y];
|
var custom = CustomTerrain[cell];
|
||||||
var tileSet = Rules.TileSets[Tileset];
|
var tileSet = Rules.TileSets[Tileset];
|
||||||
return custom != -1 ? custom : tileSet.GetTerrainIndex(MapTiles.Value[cell.X, cell.Y]);
|
return custom != -1 ? custom : tileSet.GetTerrainIndex(MapTiles.Value[cell.X, cell.Y]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
CellContents CreateResourceCell(ResourceType t, CPos cell)
|
CellContents CreateResourceCell(ResourceType t, CPos cell)
|
||||||
{
|
{
|
||||||
world.Map.CustomTerrain[cell.X, cell.Y] = world.TileSet.GetTerrainIndex(t.Info.TerrainType);
|
world.Map.CustomTerrain[cell] = world.TileSet.GetTerrainIndex(t.Info.TerrainType);
|
||||||
|
|
||||||
return new CellContents
|
return new CellContents
|
||||||
{
|
{
|
||||||
@@ -190,7 +190,7 @@ namespace OpenRA.Traits
|
|||||||
if (--c.Density < 0)
|
if (--c.Density < 0)
|
||||||
{
|
{
|
||||||
content[cell] = EmptyCell;
|
content[cell] = EmptyCell;
|
||||||
world.Map.CustomTerrain[cell.X, cell.Y] = -1;
|
world.Map.CustomTerrain[cell] = -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
content[cell] = c;
|
content[cell] = c;
|
||||||
@@ -209,7 +209,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
// Clear cell
|
// Clear cell
|
||||||
content[cell] = EmptyCell;
|
content[cell] = EmptyCell;
|
||||||
world.Map.CustomTerrain[cell.X, cell.Y] = -1;
|
world.Map.CustomTerrain[cell] = -1;
|
||||||
|
|
||||||
if (!dirty.Contains(cell))
|
if (!dirty.Contains(cell))
|
||||||
dirty.Add(cell);
|
dirty.Add(cell);
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
// Set the initial custom terrain types
|
// Set the initial custom terrain types
|
||||||
foreach (var c in footprint.Keys)
|
foreach (var c in footprint.Keys)
|
||||||
self.World.Map.CustomTerrain[c.X, c.Y] = GetTerrainType(c);
|
self.World.Map.CustomTerrain[c] = GetTerrainType(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetTerrainType(CPos cell)
|
int GetTerrainType(CPos cell)
|
||||||
@@ -204,7 +204,7 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
// Update map
|
// Update map
|
||||||
foreach (var c in footprint.Keys)
|
foreach (var c in footprint.Keys)
|
||||||
self.World.Map.CustomTerrain[c.X, c.Y] = GetTerrainType(c);
|
self.World.Map.CustomTerrain[c] = GetTerrainType(c);
|
||||||
|
|
||||||
// If this bridge repair operation connects two pathfinding domains,
|
// If this bridge repair operation connects two pathfinding domains,
|
||||||
// update the domain index.
|
// update the domain index.
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.RA.Buildings
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Don't place under other buildings or custom terrain
|
// Don't place under other buildings or custom terrain
|
||||||
if (bi.GetBuildingAt(c) != self || map.CustomTerrain[c.X, c.Y] != -1)
|
if (bi.GetBuildingAt(c) != self || map.CustomTerrain[c] != -1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var index = Game.CosmeticRandom.Next(template.TilesCount);
|
var index = Game.CosmeticRandom.Next(template.TilesCount);
|
||||||
@@ -77,7 +77,7 @@ namespace OpenRA.Mods.RA.Buildings
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Don't place under other buildings or custom terrain
|
// Don't place under other buildings or custom terrain
|
||||||
if (bi.GetBuildingAt(c) != self || map.CustomTerrain[c.X, c.Y] != -1)
|
if (bi.GetBuildingAt(c) != self || map.CustomTerrain[c] != -1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
layer.AddTile(c, new TileReference<ushort, byte>(template.Id, (byte)i));
|
layer.AddTile(c, new TileReference<ushort, byte>(template.Id, (byte)i));
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
public void AddTile(CPos cell, TileReference<ushort, byte> tile)
|
public void AddTile(CPos cell, TileReference<ushort, byte> tile)
|
||||||
{
|
{
|
||||||
map.CustomTerrain[cell.X, cell.Y] = tileset.GetTerrainIndex(tile);
|
map.CustomTerrain[cell] = tileset.GetTerrainIndex(tile);
|
||||||
|
|
||||||
// Terrain tiles define their origin at the topleft
|
// Terrain tiles define their origin at the topleft
|
||||||
var s = theater.TileSprite(tile);
|
var s = theater.TileSprite(tile);
|
||||||
|
|||||||
Reference in New Issue
Block a user