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, TileTemplate> walk =
new Dictionary<ushort, TileTemplate>(); // cjf will fix
public readonly Walkability Walkability = new Walkability();
public readonly Dictionary<ushort, TileTemplate> walk
= new Dictionary<ushort, TileTemplate>();
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 ) )
{

View File

@@ -14,9 +14,9 @@ namespace OpenRa.FileFormats
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>();
public Walkability()

View File

@@ -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<int2, int> Tiles;
TileTemplate Template;
Dictionary<int2, Sprite> TileSprites;
List<Dictionary<int2, Sprite>> TileSprites = new List<Dictionary<int2,Sprite>>();
List<TileTemplate> Templates = new List<TileTemplate>();
Actor self;
int state;
public Bridge(Actor self) { this.self = self; self.RemoveOnDeath = false; }
@@ -28,15 +30,14 @@ namespace OpenRa.Traits
public IEnumerable<Renderable> 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<int2, int> 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<BridgeInfo>().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]]);
}
}
}

View File

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

21
ra.yaml
View File

@@ -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: