Bring bridge support back to the level of upstream/master

This commit is contained in:
Paul Chote
2010-04-02 14:18:19 +13:00
committed by Bob
parent a493577c8b
commit 25c95982d7
2 changed files with 27 additions and 28 deletions

View File

@@ -36,10 +36,8 @@ namespace OpenRA.Traits
public object Create(Actor self) { return new Bridge(self); }
}
class Bridge // : IRender, ICustomTerrain, INotifyDamage
class Bridge: IRender, ICustomTerrain, INotifyDamage
{
public Bridge(Actor self) { }
/*
Dictionary<int2, int> Tiles;
List<Dictionary<int2, Sprite>> TileSprites = new List<Dictionary<int2,Sprite>>();
List<TileTemplate> Templates = new List<TileTemplate>();
@@ -50,8 +48,8 @@ namespace OpenRA.Traits
public Bridge(Actor self) { this.self = self; self.RemoveOnDeath = false; }
static string cachedTheater;
static Cache<TileReference, Sprite> sprites;
static string cachedTileset;
static Cache<TileReference<ushort,byte>, Sprite> sprites;
public IEnumerable<Renderable> Render(Actor self)
{
@@ -89,10 +87,10 @@ namespace OpenRA.Traits
foreach (var t in replacedTiles.Keys)
world.customTerrain[t.X, t.Y] = this;
if (cachedTheater != world.Map.Theater)
if (cachedTileset != world.Map.Tileset)
{
cachedTheater = world.Map.Theater;
sprites = new Cache<TileReference, Sprite>(
cachedTileset = world.Map.Tileset;
sprites = new Cache<TileReference<ushort,byte>, Sprite>(
x => SheetBuilder.SharedInstance.Add(world.TileSet.GetBytes(x),
new Size(Game.CellSize, Game.CellSize)));
}
@@ -105,7 +103,7 @@ namespace OpenRA.Traits
TileSprites.Add(replacedTiles.ToDictionary(
a => a.Key,
a => sprites[new TileReference { tile = (ushort)stateTemplate.Index, image = (byte)a.Value }]));
a => sprites[new TileReference<ushort,byte>((ushort)stateTemplate.Index, (byte)a.Value)]));
}
self.Health = (int)(self.GetMaxHP() * template.HP);
@@ -171,6 +169,5 @@ namespace OpenRA.Traits
if (southNeighbour != null) southNeighbour.UpdateState();
}
}
*/
}
}

View File

@@ -25,25 +25,27 @@ namespace OpenRA.Traits
{
class BridgeLoadHookInfo : StatelessTraitInfo<BridgeLoadHook> { }
class BridgeLoadHook// : ILoadWorldHook
class BridgeLoadHook : ILoadWorldHook
{
/*static void MakeBridges(World w)
static void MakeBridges(World w)
{
var mini = w.Map.XOffset; var maxi = w.Map.XOffset + w.Map.Width;
var minj = w.Map.YOffset; var maxj = w.Map.YOffset + w.Map.Height;
for (var j = minj; j < maxj; j++)
for (var i = mini; i < maxi; i++)
if (IsBridge(w, w.Map.MapTiles[i, j].tile))
var tl = w.Map.TopLeft;
var br = w.Map.BottomRight;
for (int i = tl.X; i < br.X; i++)
for (int j = tl.Y; j < br.Y; j++)
if (IsBridge(w, w.Map.MapTiles[i, j].type))
ConvertBridgeToActor(w, i, j);
foreach (var br in w.Actors.SelectMany(a => a.traits.WithInterface<Bridge>()))
br.FinalizeBridges(w);
foreach (var b in w.Actors.SelectMany(a => a.traits.WithInterface<Bridge>()))
b.FinalizeBridges(w);
}
static void ConvertBridgeToActor(World w, int i, int j)
{
var tile = w.Map.MapTiles[i, j].tile;
Log.Write("Converting bridge at {0} {1}",i,j);
var tile = w.Map.MapTiles[i, j].type;
var image = w.Map.MapTiles[i, j].image;
var template = w.TileSet.walk[tile];
@@ -52,20 +54,21 @@ namespace OpenRA.Traits
var nj = j - image / template.Size.X;
var replacedTiles = new Dictionary<int2, int>();
for (var y = nj; y < nj + template.Size.Y; y++)
for (var x = ni; x < ni + template.Size.X; x++)
for (var x = ni; x < ni + template.Size.X; x++)
for (var y = nj; y < nj + template.Size.Y; y++)
{
var n = (x - ni) + template.Size.X * (y - nj);
if (!template.TerrainType.ContainsKey(n)) continue;
if (w.Map.IsInMap(x, y))
if (w.Map.MapTiles[x, y].tile == tile
&& w.Map.MapTiles[x, y].image == n)
if (w.Map.MapTiles[x, y].type == tile
&& w.Map.MapTiles[x, y].index == n)
{
// stash it
replacedTiles[new int2(x, y)] = w.Map.MapTiles[x, y].image;
replacedTiles[new int2(x, y)] = w.Map.MapTiles[x, y].index;
// remove the tile from the actual map
w.Map.MapTiles[x, y].tile = 0xfffe;
w.Map.MapTiles[x, y].type = 0xfffe;
w.Map.MapTiles[x, y].index = 0;
w.Map.MapTiles[x, y].image = 0;
}
}
@@ -84,6 +87,5 @@ namespace OpenRA.Traits
}
public void WorldLoaded(World w) { MakeBridges(w); }
*/
}
}