From 84a6bfaca01be28e8906410ed7144a0ebad72e88 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 12:54:16 +1300 Subject: [PATCH] unhacking most of that mess. --- OpenRa.FileFormats/TileSet.cs | 9 ++++---- OpenRa.FileFormats/Walkability.cs | 4 ++-- OpenRa.Game/Traits/Bridge.cs | 36 +++++++++++++++++++++---------- merge-ra.yaml | 4 ++++ ra.yaml | 21 +++++++++--------- 5 files changed, 47 insertions(+), 27 deletions(-) diff --git a/OpenRa.FileFormats/TileSet.cs b/OpenRa.FileFormats/TileSet.cs index 6f2e05df1d..894a46be4f 100644 --- a/OpenRa.FileFormats/TileSet.cs +++ b/OpenRa.FileFormats/TileSet.cs @@ -8,8 +8,9 @@ namespace OpenRa.FileFormats { public readonly Dictionary tiles = new Dictionary(); - public readonly Dictionary walk = - new Dictionary(); // cjf will fix + public readonly Walkability Walkability = new Walkability(); + public readonly Dictionary walk + = new Dictionary(); string NextLine( StreamReader reader ) { @@ -27,7 +28,7 @@ namespace OpenRa.FileFormats public TileSet( string suffix ) { - Walkability walkability = new Walkability(); + Walkability = new Walkability(); char tileSetChar = char.ToUpperInvariant( suffix[ 1 ] ); StreamReader tileIdFile = new StreamReader( FileSystem.Open( "tileSet.til" ) ); @@ -51,7 +52,7 @@ namespace OpenRa.FileFormats string tilename = string.Format(pattern, i + 1); if (!walk.ContainsKey((ushort)(start + i))) - walk.Add((ushort)(start + i), walkability.GetWalkability(tilename)); + walk.Add((ushort)(start + i), Walkability.GetWalkability(tilename)); using( Stream s = FileSystem.Open( tilename + suffix ) ) { diff --git a/OpenRa.FileFormats/Walkability.cs b/OpenRa.FileFormats/Walkability.cs index 536517a8b6..a94045b6f2 100644 --- a/OpenRa.FileFormats/Walkability.cs +++ b/OpenRa.FileFormats/Walkability.cs @@ -14,9 +14,9 @@ namespace OpenRa.FileFormats public Dictionary TerrainType = new Dictionary(); } - class Walkability + public class Walkability { - public Dictionary walkability + Dictionary walkability = new Dictionary(); public Walkability() diff --git a/OpenRa.Game/Traits/Bridge.cs b/OpenRa.Game/Traits/Bridge.cs index 22a67aff06..34dacffbad 100644 --- a/OpenRa.Game/Traits/Bridge.cs +++ b/OpenRa.Game/Traits/Bridge.cs @@ -11,15 +11,17 @@ namespace OpenRa.Traits { class BridgeInfo : ITraitInfo { + public readonly bool Long = false; public object Create(Actor self) { return new Bridge(self); } } class Bridge : IRender, ICustomTerrain { Dictionary Tiles; - TileTemplate Template; - Dictionary TileSprites; + List> TileSprites = new List>(); + List Templates = new List(); Actor self; + int state; public Bridge(Actor self) { this.self = self; self.RemoveOnDeath = false; } @@ -28,15 +30,14 @@ namespace OpenRa.Traits public IEnumerable Render(Actor self) { - if (Template == null) yield break; - foreach (var t in TileSprites) + foreach (var t in TileSprites[state]) 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; + state = template.Name[template.Name.Length - 1] - 'a'; foreach (var t in replacedTiles.Keys) world.customTerrain[t.X, t.Y] = this; @@ -49,18 +50,31 @@ namespace OpenRa.Traits new Size(Game.CellSize, Game.CellSize))); } - TileSprites = replacedTiles.ToDictionary( - a => a.Key, - a => sprites[new TileReference { tile = (ushort)template.Index, image = (byte)a.Value }]); + var numStates = self.Info.Traits.Get().Long ? 6 : 3; + for (var n = 0; n < numStates; n++) + { + var stateTemplate = world.TileSet.Walkability.GetWalkability(template.Bridge + (char)(n + 'a')); + Templates.Add( stateTemplate ); + + TileSprites.Add(replacedTiles.ToDictionary( + a => a.Key, + a => sprites[new TileReference { tile = (ushort)stateTemplate.Index, image = (byte)a.Value }])); + } self.Health = (int)(self.GetMaxHP() * template.HP); } + public void FinalizeBridges(World world) + { + // go looking for our neighbors + } + public float GetCost(int2 p, UnitMovementType umt) { - return self.Health > 0 - ? TerrainCosts.Cost(umt, Template.TerrainType[Tiles[p]]) - : TerrainCosts.Cost(umt, 1); + // just use the standard walkability from templates.ini. no hackery. + + return TerrainCosts.Cost(umt, + Templates[state].TerrainType[Tiles[p]]); } } } diff --git a/merge-ra.yaml b/merge-ra.yaml index 91a72aedc9..a5e511b71b 100644 --- a/merge-ra.yaml +++ b/merge-ra.yaml @@ -28,3 +28,7 @@ MINV: Warhead: ATMine TriggeredBy: Wheel, Track AvoidFriendly: yes + +BR3: + Bridge: + Long: yes \ No newline at end of file diff --git a/ra.yaml b/ra.yaml index 9d675df2b2..a27e127cbb 100644 --- a/ra.yaml +++ b/ra.yaml @@ -83,6 +83,17 @@ MINV: -Selectable: -Building: +BR3: + Bridge: + Long: yes + Category: Building + Selectable: + BelowUnits: + Building: + Footprint: ____ ____ + Dimensions: 4,2 + HP: 1000 + V2RL: Inherits: ^Vehicle Buildable: @@ -1457,16 +1468,6 @@ BR2: Dimensions: 4,2 HP: 1000 -BR3: - Category: Building - Selectable: - Bridge: - BelowUnits: - Building: - Footprint: ____ ____ - Dimensions: 4,2 - HP: 1000 - T01: Inherits: ^Building Building: