- fixed heisenburg-endianness in map loader
- THERES A BUG in the mix loading; I need another 4 bytes padding to load temperat.mix and snow.mix (not interior.mix, though)
- ShpViewer can now load and view map files
- Copy TEMPERAT, SNOW, INFERIOR (sic) mixes into $(SolutionDir) for this to work
- Left-click to reload tile-ID file, middle-click scrolls
- the tile-id file has some collisions between tile-sets, be careful about ordering if you change anything
git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1081 993157c7-ee19-0410-b2c4-bb4e9862e678
80 lines
2.0 KiB
C#
80 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Drawing;
|
|
|
|
namespace OpenRa.FileFormats
|
|
{
|
|
public class Terrain
|
|
{
|
|
public readonly int Width;
|
|
public readonly int Height;
|
|
public readonly int XDim;
|
|
public readonly int YDim;
|
|
public readonly int NumTiles;
|
|
|
|
readonly byte[] index;
|
|
readonly List<Bitmap> TileBitmaps = new List<Bitmap>();
|
|
|
|
public Terrain( Stream stream, Palette pal )
|
|
{
|
|
BinaryReader reader = new BinaryReader( stream );
|
|
Width = reader.ReadUInt16();
|
|
Height = reader.ReadUInt16();
|
|
|
|
if( Width != 24 || Height != 24 )
|
|
throw new InvalidDataException( string.Format( "{0}x{1}", Width, Height ) );
|
|
|
|
NumTiles = reader.ReadUInt16();
|
|
reader.ReadUInt16();
|
|
XDim = reader.ReadUInt16();
|
|
YDim = reader.ReadUInt16();
|
|
uint FileSize = reader.ReadUInt32();
|
|
uint ImgStart = reader.ReadUInt32();
|
|
reader.ReadUInt32();
|
|
reader.ReadUInt32();
|
|
int IndexEnd = reader.ReadInt32();
|
|
reader.ReadUInt32();
|
|
int IndexStart = reader.ReadInt32();
|
|
|
|
stream.Position = IndexStart;
|
|
index = new byte[ IndexEnd - IndexStart ];
|
|
stream.Read( index, 0, IndexEnd - IndexStart );
|
|
|
|
for( int i = 0 ; i < index.Length ; i++ )
|
|
{
|
|
if( index[ i ] != 255 )
|
|
{
|
|
byte[] tileData = new byte[ 24 * 24 ];
|
|
stream.Position = ImgStart + index[ i ] * 24 * 24;
|
|
stream.Read( tileData, 0, 24 * 24 );
|
|
TileBitmaps.Add( BitmapBuilder.FromBytes( tileData, 24, 24, pal ) );
|
|
}
|
|
else
|
|
TileBitmaps.Add( null );
|
|
}
|
|
}
|
|
|
|
public Bitmap GetTile( int index )
|
|
{
|
|
if( index < TileBitmaps.Count )
|
|
return TileBitmaps[ index ];
|
|
else
|
|
return null;
|
|
}
|
|
|
|
public Bitmap[ , ] GetTiles( int tileNum )
|
|
{
|
|
int startIndex = tileNum * XDim * YDim;
|
|
Bitmap[ , ] ret = new Bitmap[ XDim, YDim ];
|
|
|
|
for( int x = 0 ; x < XDim ; x++ )
|
|
for( int y = 0 ; y < YDim ; y++ )
|
|
ret[ x, y ] = GetTile( startIndex + x + XDim * y );
|
|
|
|
return ret;
|
|
}
|
|
}
|
|
}
|