Game uses new format. Missing bridges/resources/smudges. Buggy map bounds, actor placement and tile images.

This commit is contained in:
Paul Chote
2010-04-01 19:13:26 +13:00
committed by Bob
parent 382efbcdfb
commit f7e2f414c0
20 changed files with 187 additions and 101 deletions

View File

@@ -26,7 +26,7 @@ using System.Text;
namespace OpenRA.FileFormats
{
public class Map
public class OldMap
{
public readonly string Title;
public readonly string Theater;
@@ -41,7 +41,7 @@ namespace OpenRA.FileFormats
public readonly int Height;
public int2 Size { get { return new int2(Width, Height); } }
public readonly TileReference[ , ] MapTiles;
public readonly OldTileReference[ , ] MapTiles;
public readonly List<ActorReference> Actors = new List<ActorReference>();
public readonly IEnumerable<int2> SpawnPoints;
@@ -51,7 +51,7 @@ namespace OpenRA.FileFormats
return s.Length <= maxLength ? s : s.Substring(0,maxLength );
}
public Map(string filename)
public OldMap(string filename)
{
IniFile file = new IniFile(FileSystem.Open(filename));
@@ -69,10 +69,10 @@ namespace OpenRA.FileFormats
Height = int.Parse(map.GetValue("Height", "0"));
MapSize = (INIFormat == 3) ? 128 : 64;
MapTiles = new TileReference[ MapSize, MapSize ];
MapTiles = new OldTileReference[ MapSize, MapSize ];
for (int j = 0; j < MapSize; j++)
for (int i = 0; i < MapSize; i++)
MapTiles[i, j] = new TileReference();
MapTiles[i, j] = new OldTileReference();
if (INIFormat == 3) // RA map

View File

@@ -27,7 +27,7 @@ using System.Reflection;
namespace OpenRA.FileFormats
{
public class NewMap
public class Map
{
// Yaml map data
public int MapFormat = 1;
@@ -47,17 +47,30 @@ namespace OpenRA.FileFormats
public string Tiledata;
public byte TileFormat = 1;
public int2 Size;
public NewTileReference<ushort,byte>[ , ] MapTiles;
public NewTileReference<byte, byte>[ , ] MapResources;
public TileReference<ushort,byte>[ , ] MapTiles;
public TileReference<byte, byte>[ , ] MapResources;
// Temporary compat hacks
public int MapSize {get {return Size.X;}}
public int XOffset {get {return Bounds[0];}}
public int YOffset {get {return Bounds[1];}}
public int2 Offset { get { return new int2( Bounds[0], Bounds[1] ); } }
public int Width {get {return Bounds[2];}}
public int Height {get {return Bounds[3];}}
public string Theater {get {return Tileset;}}
public IEnumerable<int2> SpawnPoints {get {return Waypoints.Select(kv => kv.Value);}}
List<string> SimpleFields = new List<string>() {
"MapFormat", "Title", "Description", "Author", "PlayerCount", "Tileset", "Tiledata", "Preview", "Size", "Bounds"
};
public NewMap() {}
public Map() {}
public NewMap(string filename)
public Map(string filename)
{
var yaml = MiniYaml.FromFile(filename);
@@ -140,18 +153,23 @@ namespace OpenRA.FileFormats
Size.X = ReadWord(dataStream);
Size.Y = ReadWord(dataStream);
MapTiles = new NewTileReference<ushort, byte>[ Size.X, Size.Y ];
MapResources = new NewTileReference<byte, byte>[ Size.X, Size.Y ];
MapTiles = new TileReference<ushort, byte>[ Size.X, Size.Y ];
MapResources = new TileReference<byte, byte>[ Size.X, Size.Y ];
// Load tile data
for( int i = 0 ; i < Size.X ; i++ )
for( int j = 0 ; j < Size.Y ; j++ )
MapTiles[i, j] = new NewTileReference<ushort,byte>(ReadWord(dataStream),ReadByte(dataStream));
{
ushort tile = ReadWord(dataStream);
byte index = ReadByte(dataStream);
byte image = (index == byte.MaxValue) ? (byte)( i % 4 + ( j % 4 ) * 4 ) : index;
MapTiles[i, j] = new TileReference<ushort,byte>(tile,index, image);
}
// Load resource data
for( int i = 0 ; i < Size.X ; i++ )
for( int j = 0 ; j < Size.Y ; j++ )
MapResources[i, j] = new NewTileReference<byte,byte>(ReadByte(dataStream),ReadByte(dataStream));
MapResources[i, j] = new TileReference<byte,byte>(ReadByte(dataStream),ReadByte(dataStream));
}
public void SaveBinaryData(string filepath)
@@ -186,6 +204,16 @@ namespace OpenRA.FileFormats
File.Move(filepath+".tmp",filepath);
}
public bool IsInMap(int2 xy)
{
return IsInMap(xy.X,xy.Y);
}
public bool IsInMap(int x, int y)
{
return (x >= Bounds[0] && y >= Bounds[1] && x < Bounds[0] + Bounds[2] && y < Bounds[1] + Bounds[3]);
}
public void DebugContents()
{
foreach (var field in SimpleFields)

View File

@@ -20,15 +20,24 @@
namespace OpenRA.FileFormats
{
public struct NewTileReference<T, U>
public struct TileReference<T, U>
{
public T type;
public U index;
public U image;
public NewTileReference(T t, U i)
public TileReference(T t, U i)
{
type = t;
index = i;
image = i;
}
public TileReference(T t, U i, U im)
{
type = t;
index = i;
image = im;
}
public override int GetHashCode() { return type.GetHashCode() ^ index.GetHashCode(); }

View File

@@ -20,7 +20,7 @@
namespace OpenRA.FileFormats
{
public struct TileReference
public struct OldTileReference
{
public ushort tile;
public byte image;
@@ -34,11 +34,11 @@ namespace OpenRA.FileFormats
if( obj == null )
return false;
TileReference r = (TileReference)obj;
OldTileReference r = (OldTileReference)obj;
return ( r.image == image && r.tile == tile );
}
public static bool operator ==( TileReference a, TileReference b ) { return a.Equals( b ); }
public static bool operator !=( TileReference a, TileReference b ) { return !a.Equals( b ); }
public static bool operator ==( OldTileReference a, OldTileReference b ) { return a.Equals( b ); }
public static bool operator !=( OldTileReference a, OldTileReference b ) { return !a.Equals( b ); }
}
}

View File

@@ -85,13 +85,19 @@ namespace OpenRA.FileFormats
tileIdFile.Close();
}
public byte[] GetBytes(TileReference r)
public byte[] GetBytes(TileReference<ushort,byte> r)
{
Terrain tile;
if( tiles.TryGetValue( r.tile, out tile ) )
return tile.TileBitmapBytes[ r.image ];
Log.Write("Attempting to load tile {0} {1}",r.type,r.image);
try {
if( tiles.TryGetValue( r.type, out tile ) )
return tile.TileBitmapBytes[ r.image ];
}
catch (System.ArgumentOutOfRangeException)
{
tiles.TryGetValue( 0xfffe, out tile );
return tile.TileBitmapBytes[ 0 ];
}
byte[] missingTile = new byte[ 24 * 24 ];
for( int i = 0 ; i < missingTile.Length ; i++ )
missingTile[ i ] = 0x36;
@@ -99,13 +105,10 @@ namespace OpenRA.FileFormats
return missingTile;
}
public TerrainType GetTerrainType(TileReference r)
{
if (r.tile == 0xff || r.tile == 0xffff)
r.image = 0;
public TerrainType GetTerrainType(TileReference<ushort,byte> r)
{
try {
return walk[r.tile].TerrainType[r.image];
return walk[r.type].TerrainType[r.image];
}
catch (KeyNotFoundException)
{