using System; using System.Collections.Generic; using System.Linq; using System.Text; using OpenRa.Graphics; using OpenRa.FileFormats; using IjwFramework.Collections; using System.Drawing; namespace OpenRa.Traits { class BridgeInfo : OwnedActorInfo, ITraitInfo { public object Create(Actor self) { return new Bridge(self); } } class Bridge : IRender, ICustomTerrain { Dictionary Tiles; TileTemplate Template; Dictionary TileSprites; public Bridge(Actor self) { self.RemoveOnDeath = false; } static string cachedTheater; static Cache sprites; public IEnumerable Render(Actor self) { if (Template == null) yield break; foreach (var t in TileSprites) yield return new Renderable(t.Value, Game.CellSize * t.Key, PaletteType.Gold); } public void SetTiles(World world, TileTemplate template, Dictionary replacedTiles) { Template = template; Tiles = replacedTiles; foreach (var t in replacedTiles.Keys) world.customTerrain[t.X, t.Y] = this; if (cachedTheater != world.Map.Theater) { cachedTheater = world.Map.Theater; sprites = new Cache( x => SheetBuilder.Add(world.TileSet.GetBytes(x), new Size(Game.CellSize, Game.CellSize))); } TileSprites = replacedTiles.ToDictionary( a => a.Key, a => sprites[new TileReference { tile = (ushort)template.Index, image = (byte)a.Value }]); } public float GetCost(int2 p, UnitMovementType umt) { throw new NotImplementedException(); var origTile = Tiles[p]; // if this explodes, then SetTiles did something horribly wrong. return float.PositiveInfinity; } } }