From 25c95982d73f6c6dd7d7e4dbf08b4688032f81b6 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 2 Apr 2010 14:18:19 +1300 Subject: [PATCH] Bring bridge support back to the level of upstream/master --- OpenRA.Game/Traits/Bridge.cs | 17 ++++------ OpenRA.Game/Traits/World/BridgeLoadHook.cs | 38 ++++++++++++---------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/OpenRA.Game/Traits/Bridge.cs b/OpenRA.Game/Traits/Bridge.cs index 84ea371493..b5c70cf3a4 100644 --- a/OpenRA.Game/Traits/Bridge.cs +++ b/OpenRA.Game/Traits/Bridge.cs @@ -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 Tiles; List> TileSprites = new List>(); List Templates = new List(); @@ -50,8 +48,8 @@ namespace OpenRA.Traits public Bridge(Actor self) { this.self = self; self.RemoveOnDeath = false; } - static string cachedTheater; - static Cache sprites; + static string cachedTileset; + static Cache, Sprite> sprites; public IEnumerable 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( + cachedTileset = world.Map.Tileset; + sprites = new Cache, 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)stateTemplate.Index, (byte)a.Value)])); } self.Health = (int)(self.GetMaxHP() * template.HP); @@ -171,6 +169,5 @@ namespace OpenRA.Traits if (southNeighbour != null) southNeighbour.UpdateState(); } } - */ } } diff --git a/OpenRA.Game/Traits/World/BridgeLoadHook.cs b/OpenRA.Game/Traits/World/BridgeLoadHook.cs index 565bcba226..2b25969a07 100644 --- a/OpenRA.Game/Traits/World/BridgeLoadHook.cs +++ b/OpenRA.Game/Traits/World/BridgeLoadHook.cs @@ -25,25 +25,27 @@ namespace OpenRA.Traits { class BridgeLoadHookInfo : StatelessTraitInfo { } - 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())) - br.FinalizeBridges(w); + foreach (var b in w.Actors.SelectMany(a => a.traits.WithInterface())) + 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(); - 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); } - */ } }