unhacking most of that mess.

This commit is contained in:
Chris Forbes
2010-01-19 12:54:16 +13:00
parent df8f37c5e4
commit 84a6bfaca0
5 changed files with 47 additions and 27 deletions

View File

@@ -8,8 +8,9 @@ namespace OpenRa.FileFormats
{ {
public readonly Dictionary<ushort, Terrain> tiles = new Dictionary<ushort, Terrain>(); public readonly Dictionary<ushort, Terrain> tiles = new Dictionary<ushort, Terrain>();
public readonly Dictionary<ushort, TileTemplate> walk = public readonly Walkability Walkability = new Walkability();
new Dictionary<ushort, TileTemplate>(); // cjf will fix public readonly Dictionary<ushort, TileTemplate> walk
= new Dictionary<ushort, TileTemplate>();
string NextLine( StreamReader reader ) string NextLine( StreamReader reader )
{ {
@@ -27,7 +28,7 @@ namespace OpenRa.FileFormats
public TileSet( string suffix ) public TileSet( string suffix )
{ {
Walkability walkability = new Walkability(); Walkability = new Walkability();
char tileSetChar = char.ToUpperInvariant( suffix[ 1 ] ); char tileSetChar = char.ToUpperInvariant( suffix[ 1 ] );
StreamReader tileIdFile = new StreamReader( FileSystem.Open( "tileSet.til" ) ); StreamReader tileIdFile = new StreamReader( FileSystem.Open( "tileSet.til" ) );
@@ -51,7 +52,7 @@ namespace OpenRa.FileFormats
string tilename = string.Format(pattern, i + 1); string tilename = string.Format(pattern, i + 1);
if (!walk.ContainsKey((ushort)(start + i))) 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 ) ) using( Stream s = FileSystem.Open( tilename + suffix ) )
{ {

View File

@@ -14,9 +14,9 @@ namespace OpenRa.FileFormats
public Dictionary<int, int> TerrainType = new Dictionary<int, int>(); public Dictionary<int, int> TerrainType = new Dictionary<int, int>();
} }
class Walkability public class Walkability
{ {
public Dictionary<string, TileTemplate> walkability Dictionary<string, TileTemplate> walkability
= new Dictionary<string,TileTemplate>(); = new Dictionary<string,TileTemplate>();
public Walkability() public Walkability()

View File

@@ -11,15 +11,17 @@ namespace OpenRa.Traits
{ {
class BridgeInfo : ITraitInfo class BridgeInfo : ITraitInfo
{ {
public readonly bool Long = false;
public object Create(Actor self) { return new Bridge(self); } public object Create(Actor self) { return new Bridge(self); }
} }
class Bridge : IRender, ICustomTerrain class Bridge : IRender, ICustomTerrain
{ {
Dictionary<int2, int> Tiles; Dictionary<int2, int> Tiles;
TileTemplate Template; List<Dictionary<int2, Sprite>> TileSprites = new List<Dictionary<int2,Sprite>>();
Dictionary<int2, Sprite> TileSprites; List<TileTemplate> Templates = new List<TileTemplate>();
Actor self; Actor self;
int state;
public Bridge(Actor self) { this.self = self; self.RemoveOnDeath = false; } public Bridge(Actor self) { this.self = self; self.RemoveOnDeath = false; }
@@ -28,15 +30,14 @@ namespace OpenRa.Traits
public IEnumerable<Renderable> Render(Actor self) public IEnumerable<Renderable> Render(Actor self)
{ {
if (Template == null) yield break; foreach (var t in TileSprites[state])
foreach (var t in TileSprites)
yield return new Renderable(t.Value, Game.CellSize * t.Key, PaletteType.Gold); yield return new Renderable(t.Value, Game.CellSize * t.Key, PaletteType.Gold);
} }
public void SetTiles(World world, TileTemplate template, Dictionary<int2, int> replacedTiles) public void SetTiles(World world, TileTemplate template, Dictionary<int2, int> replacedTiles)
{ {
Template = template;
Tiles = replacedTiles; Tiles = replacedTiles;
state = template.Name[template.Name.Length - 1] - 'a';
foreach (var t in replacedTiles.Keys) foreach (var t in replacedTiles.Keys)
world.customTerrain[t.X, t.Y] = this; world.customTerrain[t.X, t.Y] = this;
@@ -49,18 +50,31 @@ namespace OpenRa.Traits
new Size(Game.CellSize, Game.CellSize))); new Size(Game.CellSize, Game.CellSize)));
} }
TileSprites = replacedTiles.ToDictionary( var numStates = self.Info.Traits.Get<BridgeInfo>().Long ? 6 : 3;
a => a.Key, for (var n = 0; n < numStates; n++)
a => sprites[new TileReference { tile = (ushort)template.Index, image = (byte)a.Value }]); {
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); self.Health = (int)(self.GetMaxHP() * template.HP);
} }
public void FinalizeBridges(World world)
{
// go looking for our neighbors
}
public float GetCost(int2 p, UnitMovementType umt) public float GetCost(int2 p, UnitMovementType umt)
{ {
return self.Health > 0 // just use the standard walkability from templates.ini. no hackery.
? TerrainCosts.Cost(umt, Template.TerrainType[Tiles[p]])
: TerrainCosts.Cost(umt, 1); return TerrainCosts.Cost(umt,
Templates[state].TerrainType[Tiles[p]]);
} }
} }
} }

View File

@@ -28,3 +28,7 @@ MINV:
Warhead: ATMine Warhead: ATMine
TriggeredBy: Wheel, Track TriggeredBy: Wheel, Track
AvoidFriendly: yes AvoidFriendly: yes
BR3:
Bridge:
Long: yes

21
ra.yaml
View File

@@ -83,6 +83,17 @@ MINV:
-Selectable: -Selectable:
-Building: -Building:
BR3:
Bridge:
Long: yes
Category: Building
Selectable:
BelowUnits:
Building:
Footprint: ____ ____
Dimensions: 4,2
HP: 1000
V2RL: V2RL:
Inherits: ^Vehicle Inherits: ^Vehicle
Buildable: Buildable:
@@ -1457,16 +1468,6 @@ BR2:
Dimensions: 4,2 Dimensions: 4,2
HP: 1000 HP: 1000
BR3:
Category: Building
Selectable:
Bridge:
BelowUnits:
Building:
Footprint: ____ ____
Dimensions: 4,2
HP: 1000
T01: T01:
Inherits: ^Building Inherits: ^Building
Building: Building: