Use CellLayer for terrain.

This commit is contained in:
Paul Chote
2014-05-17 02:25:49 +12:00
parent ad730a44c3
commit 997216aef0
12 changed files with 93 additions and 79 deletions

View File

@@ -98,7 +98,7 @@ namespace OpenRA.Mods.RA
{
var dx = cell - self.Location;
var index = dx.X + self.World.TileSet.Templates[template].Size.X * dx.Y;
return self.World.TileSet.GetTerrainIndex(new TileReference<ushort, byte>(template, (byte)index));
return self.World.TileSet.GetTerrainIndex(new TerrainTile(template, (byte)index));
}
public void LinkNeighbouringBridges(World world, BridgeLayer bridges)
@@ -121,7 +121,7 @@ namespace OpenRA.Mods.RA
IRenderable[] TemplateRenderables(WorldRenderer wr, PaletteReference palette, ushort template)
{
return footprint.Select(c => (IRenderable)(new SpriteRenderable(
wr.Theater.TileSprite(new TileReference<ushort, byte>(template, c.Value)),
wr.Theater.TileSprite(new TerrainTile(template, c.Value)),
c.Key.CenterPosition, WVec.Zero, -512, palette, 1f, true))).ToArray();
}

View File

@@ -51,9 +51,14 @@ namespace OpenRA.Mods.RA
// Loop through the map looking for templates to overlay
for (var i = w.Map.Bounds.Left; i < w.Map.Bounds.Right; i++)
{
for (var j = w.Map.Bounds.Top; j < w.Map.Bounds.Bottom; j++)
if (bridgeTypes.Keys.Contains(w.Map.MapTiles.Value[i, j].Type))
ConvertBridgeToActor(w, new CPos(i, j));
{
var cell = new CPos(i, j);
if (bridgeTypes.Keys.Contains(w.Map.MapTiles.Value[cell].Type))
ConvertBridgeToActor(w, cell);
}
}
// Link adjacent (long)-bridges so that artwork is updated correctly
foreach (var b in w.Actors.SelectMany(a => a.TraitsImplementing<Bridge>()))
@@ -67,8 +72,8 @@ namespace OpenRA.Mods.RA
return;
// Correlate the tile "image" aka subtile with its position to find the template origin
var tile = w.Map.MapTiles.Value[cell.X, cell.Y].Type;
var index = w.Map.MapTiles.Value[cell.X, cell.Y].Index;
var tile = w.Map.MapTiles.Value[cell].Type;
var index = w.Map.MapTiles.Value[cell].Index;
var template = w.TileSet.Templates[tile];
var ni = cell.X - index % template.Size.X;
var nj = cell.Y - index / template.Size.X;
@@ -90,8 +95,8 @@ namespace OpenRA.Mods.RA
var subtile = new CPos(ni + ind % template.Size.X, nj + ind / template.Size.X);
// This isn't the bridge you're looking for
if (!w.Map.IsInMap(subtile) || w.Map.MapTiles.Value[subtile.X, subtile.Y].Type != tile ||
w.Map.MapTiles.Value[subtile.X, subtile.Y].Index != ind)
if (!w.Map.IsInMap(subtile) || w.Map.MapTiles.Value[subtile].Type != tile ||
w.Map.MapTiles.Value[subtile].Index != ind)
continue;
subTiles.Add(subtile, ind);

View File

@@ -61,7 +61,7 @@ namespace OpenRA.Mods.RA.Buildings
continue;
var index = Game.CosmeticRandom.Next(template.TilesCount);
layer.AddTile(c, new TileReference<ushort, byte>(template.Id, (byte)index));
layer.AddTile(c, new TerrainTile(template.Id, (byte)index));
}
return;
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.RA.Buildings
if (bi.GetBuildingAt(c) != self || map.CustomTerrain[c] != -1)
continue;
layer.AddTile(c, new TileReference<ushort, byte>(template.Id, (byte)i));
layer.AddTile(c, new TerrainTile(template.Id, (byte)i));
}
}
}

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA
dirty = new Dictionary<CPos, Sprite>();
}
public void AddTile(CPos cell, TileReference<ushort, byte> tile)
public void AddTile(CPos cell, TerrainTile tile)
{
map.CustomTerrain[cell] = tileset.GetTerrainIndex(tile);