Converter for ra maps -> new format.
This commit is contained in:
@@ -19,11 +19,9 @@ namespace MapConverter
|
|||||||
foreach (var folder in manifest.Folders) FileSystem.Mount(folder);
|
foreach (var folder in manifest.Folders) FileSystem.Mount(folder);
|
||||||
foreach (var pkg in manifest.Packages) FileSystem.Mount(pkg);
|
foreach (var pkg in manifest.Packages) FileSystem.Mount(pkg);
|
||||||
|
|
||||||
var map = new NewMap(args[2]);
|
var converter = new MapConverter(args[1]);
|
||||||
map.DebugContents();
|
converter.Map.DebugContents();
|
||||||
|
converter.Save(args[2]);
|
||||||
//var map = new IniMap(args[1]);
|
|
||||||
//map.Save(args[2]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,141 +28,62 @@ using OpenRA.FileFormats;
|
|||||||
|
|
||||||
namespace MapConverter
|
namespace MapConverter
|
||||||
{
|
{
|
||||||
public class MapData
|
public class MapConverter
|
||||||
{
|
{
|
||||||
// General info
|
|
||||||
public int MapFormat;
|
|
||||||
public string Title;
|
|
||||||
public string Description;
|
|
||||||
public string Author;
|
|
||||||
public int Players;
|
|
||||||
|
|
||||||
// 'Simple' map data
|
|
||||||
public string Tileset;
|
|
||||||
public int2 Size;
|
|
||||||
public int[] Bounds;
|
|
||||||
|
|
||||||
// 'Complex' map data
|
|
||||||
public string TileData;
|
|
||||||
public string ResourceData;
|
|
||||||
public string[] Waypoints;
|
|
||||||
public string[] Actors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class IniMap
|
|
||||||
{
|
|
||||||
public readonly string Title;
|
|
||||||
public readonly string Theater;
|
|
||||||
public readonly int INIFormat;
|
public readonly int INIFormat;
|
||||||
|
|
||||||
public readonly int MapSize;
|
public readonly int MapSize;
|
||||||
public readonly int XOffset;
|
public readonly int XOffset;
|
||||||
public readonly int YOffset;
|
public readonly int YOffset;
|
||||||
public int2 Offset { get { return new int2( XOffset, YOffset ); } }
|
|
||||||
|
|
||||||
public readonly int Width;
|
public readonly int Width;
|
||||||
public readonly int Height;
|
public readonly int Height;
|
||||||
public int2 Size { get { return new int2(Width, Height); } }
|
public NewMap Map = new NewMap();
|
||||||
|
|
||||||
public readonly TileReference[ , ] MapTiles;
|
|
||||||
public readonly List<ActorReference> Actors = new List<ActorReference>();
|
|
||||||
|
|
||||||
public readonly IEnumerable<int2> SpawnPoints;
|
|
||||||
|
|
||||||
static string Truncate( string s, int maxLength )
|
static string Truncate( string s, int maxLength )
|
||||||
{
|
{
|
||||||
return s.Length <= maxLength ? s : s.Substring(0,maxLength );
|
return s.Length <= maxLength ? s : s.Substring(0,maxLength );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Save(string filename)
|
|
||||||
|
static string[] raOverlayNames =
|
||||||
{
|
{
|
||||||
Dictionary< string, Pair<byte,byte> > resourceMapping = new Dictionary<string, Pair<byte, byte>>() {
|
"sbag", "cycl", "brik", "fenc", "wood",
|
||||||
{ "gold01", new Pair<byte,byte>(1,0) },
|
"gold01", "gold02", "gold03", "gold04",
|
||||||
{ "gold02", new Pair<byte,byte>(1,1) },
|
"gem01", "gem02", "gem03", "gem04",
|
||||||
{ "gold03", new Pair<byte,byte>(1,2) },
|
"v12", "v13", "v14", "v15", "v16", "v17", "v18",
|
||||||
{ "gold04", new Pair<byte,byte>(1,3) },
|
"fpls", "wcrate", "scrate", "barb", "sbag",
|
||||||
|
};
|
||||||
|
|
||||||
{ "gem01", new Pair<byte,byte>(2,0) },
|
Dictionary< string, Pair<byte,byte> > resourceMapping = new Dictionary<string, Pair<byte, byte>>() {
|
||||||
{ "gem02", new Pair<byte,byte>(2,1) },
|
{ "gold01", new Pair<byte,byte>(1,0) },
|
||||||
{ "gem03", new Pair<byte,byte>(2,2) },
|
{ "gold02", new Pair<byte,byte>(1,1) },
|
||||||
{ "gem04", new Pair<byte,byte>(2,3) },
|
{ "gold03", new Pair<byte,byte>(1,2) },
|
||||||
};
|
{ "gold04", new Pair<byte,byte>(1,3) },
|
||||||
|
|
||||||
// Metadata
|
{ "gem01", new Pair<byte,byte>(2,0) },
|
||||||
var data = new MapData();
|
{ "gem02", new Pair<byte,byte>(2,1) },
|
||||||
data.MapFormat = 1;
|
{ "gem03", new Pair<byte,byte>(2,2) },
|
||||||
data.Title = Title;
|
{ "gem04", new Pair<byte,byte>(2,3) },
|
||||||
data.Players = SpawnPoints.Count();
|
|
||||||
data.Author = "Westwood Studios";
|
// TODO Add cnc tiberium
|
||||||
data.Description = "";
|
};
|
||||||
data.Tileset = Theater;
|
|
||||||
data.Bounds = new int[] {XOffset, YOffset, Width, Height};
|
|
||||||
data.Size = new int2(MapSize,MapSize);
|
|
||||||
|
|
||||||
|
|
||||||
// Tile data is stored as a base-64 encoded stream of
|
public MapConverter(string filename)
|
||||||
// {(2-byte) tile index, (1-byte) image index} pairs
|
|
||||||
MemoryStream tiles = new MemoryStream();
|
|
||||||
BinaryWriter writer = new BinaryWriter( tiles );
|
|
||||||
|
|
||||||
for( int i = 0 ; i < MapSize ; i++ )
|
|
||||||
for( int j = 0 ; j < MapSize ; j++ )
|
|
||||||
{
|
|
||||||
writer.Write( MapTiles[j,i].tile );
|
|
||||||
// Semi-hack: Convert clear and water tiles to "pick an image for me" magic number
|
|
||||||
byte image = (MapTiles[ j, i ].tile == 0xff || MapTiles[ j, i ].tile == 0xffff) ? byte.MaxValue : MapTiles[j,i].image;
|
|
||||||
writer.Write(image);
|
|
||||||
}
|
|
||||||
writer.Flush();
|
|
||||||
data.TileData = Convert.ToBase64String(tiles.ToArray());
|
|
||||||
|
|
||||||
// Resource data is stored as a base-64 encoded stream of
|
|
||||||
// {(1-byte) resource index, (1-byte) image index} pairs
|
|
||||||
MemoryStream resources = new MemoryStream();
|
|
||||||
writer = new BinaryWriter( resources );
|
|
||||||
|
|
||||||
for( int i = 0 ; i < MapSize ; i++ )
|
|
||||||
for( int j = 0 ; j < MapSize ; j++ )
|
|
||||||
{
|
|
||||||
byte type = 0;
|
|
||||||
byte image = 0;
|
|
||||||
if (MapTiles[j,i].overlay != null)
|
|
||||||
{
|
|
||||||
var res = resourceMapping[MapTiles[j,i].overlay];
|
|
||||||
type = res.First;
|
|
||||||
image = res.Second;
|
|
||||||
}
|
|
||||||
|
|
||||||
writer.Write(type);
|
|
||||||
writer.Write(image);
|
|
||||||
}
|
|
||||||
writer.Flush();
|
|
||||||
data.ResourceData = Convert.ToBase64String(resources.ToArray());
|
|
||||||
|
|
||||||
// Spawn points
|
|
||||||
int s = 0;
|
|
||||||
data.Waypoints = SpawnPoints.Select(t => "spawn{0}={1}|{2}".F(s++,t.X,t.Y)).ToArray();
|
|
||||||
|
|
||||||
// Actors
|
|
||||||
s = 0;
|
|
||||||
data.Actors = Actors.Select(t=>"actor{0}={1}|{2}|{3}".F(s++,t.Name,t.Location.X,t.Location.Y)).ToArray();
|
|
||||||
|
|
||||||
Dictionary<string, MiniYaml> Nodes = new Dictionary<string,MiniYaml>();
|
|
||||||
Nodes.Add("MAP",FieldSaver.Save(data));
|
|
||||||
Nodes.WriteToFile(filename);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public IniMap(string filename)
|
|
||||||
{
|
{
|
||||||
|
Map.Author = "Westwood Studios";
|
||||||
|
|
||||||
IniFile file = new IniFile(FileSystem.Open(filename));
|
IniFile file = new IniFile(FileSystem.Open(filename));
|
||||||
|
|
||||||
IniSection basic = file.GetSection("Basic");
|
IniSection basic = file.GetSection("Basic");
|
||||||
Title = basic.GetValue("Name", "(null)");
|
Map.Title = basic.GetValue("Name", "(null)");
|
||||||
|
|
||||||
|
|
||||||
INIFormat = int.Parse(basic.GetValue("NewINIFormat", "0"));
|
INIFormat = int.Parse(basic.GetValue("NewINIFormat", "0"));
|
||||||
|
|
||||||
IniSection map = file.GetSection("Map");
|
IniSection map = file.GetSection("Map");
|
||||||
Theater = Truncate(map.GetValue("Theater", "TEMPERAT"), 8);
|
Map.Tileset = Truncate(map.GetValue("Theater", "TEMPERAT"), 8);
|
||||||
|
|
||||||
XOffset = int.Parse(map.GetValue("X", "0"));
|
XOffset = int.Parse(map.GetValue("X", "0"));
|
||||||
YOffset = int.Parse(map.GetValue("Y", "0"));
|
YOffset = int.Parse(map.GetValue("Y", "0"));
|
||||||
@@ -171,11 +92,9 @@ namespace MapConverter
|
|||||||
Height = int.Parse(map.GetValue("Height", "0"));
|
Height = int.Parse(map.GetValue("Height", "0"));
|
||||||
MapSize = (INIFormat == 3) ? 128 : 64;
|
MapSize = (INIFormat == 3) ? 128 : 64;
|
||||||
|
|
||||||
MapTiles = new TileReference[ MapSize, MapSize ];
|
Map.Size.X = MapSize;
|
||||||
for (int j = 0; j < MapSize; j++)
|
Map.Size.Y = MapSize;
|
||||||
for (int i = 0; i < MapSize; i++)
|
Map.Bounds = new int[] {XOffset, YOffset, Width, Height};
|
||||||
MapTiles[i, j] = new TileReference();
|
|
||||||
|
|
||||||
|
|
||||||
if (INIFormat == 3) // RA map
|
if (INIFormat == 3) // RA map
|
||||||
{
|
{
|
||||||
@@ -194,12 +113,16 @@ namespace MapConverter
|
|||||||
LoadActors(file, "UNITS");
|
LoadActors(file, "UNITS");
|
||||||
LoadActors(file, "INFANTRY");
|
LoadActors(file, "INFANTRY");
|
||||||
|
|
||||||
SpawnPoints = file.GetSection("Waypoints")
|
var wp = file.GetSection("Waypoints")
|
||||||
.Where(kv => int.Parse(kv.Value) > 0)
|
.Where(kv => int.Parse(kv.Value) > 0)
|
||||||
.Select(kv => Pair.New(int.Parse(kv.Key), new int2(int.Parse(kv.Value) % MapSize, int.Parse(kv.Value) / MapSize)))
|
.Select(kv => Pair.New(int.Parse(kv.Key), new int2(int.Parse(kv.Value) % MapSize, int.Parse(kv.Value) / MapSize)))
|
||||||
.Where(a => a.First < 8)
|
.Where(a => a.First < 8)
|
||||||
.Select(a => a.Second)
|
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
|
Map.PlayerCount = wp.Count();
|
||||||
|
|
||||||
|
foreach (var kv in wp)
|
||||||
|
Map.Waypoints.Add("spawn"+kv.First, kv.Second);
|
||||||
}
|
}
|
||||||
|
|
||||||
static MemoryStream ReadPackedSection(IniSection mapPackSection)
|
static MemoryStream ReadPackedSection(IniSection mapPackSection)
|
||||||
@@ -260,35 +183,37 @@ namespace MapConverter
|
|||||||
|
|
||||||
void UnpackRATileData( MemoryStream ms )
|
void UnpackRATileData( MemoryStream ms )
|
||||||
{
|
{
|
||||||
|
Map.MapTiles = new NewTileReference<ushort, byte>[ MapSize, MapSize ];
|
||||||
for( int i = 0 ; i < MapSize ; i++ )
|
for( int i = 0 ; i < MapSize ; i++ )
|
||||||
for( int j = 0 ; j < MapSize ; j++ )
|
for( int j = 0 ; j < MapSize ; j++ )
|
||||||
MapTiles[j, i].tile = ReadWord(ms);
|
Map.MapTiles[j, i] = new NewTileReference<ushort,byte>();
|
||||||
|
|
||||||
|
for( int i = 0 ; i < MapSize ; i++ )
|
||||||
|
for( int j = 0 ; j < MapSize ; j++ )
|
||||||
|
Map.MapTiles[j, i].type = ReadWord(ms);
|
||||||
|
|
||||||
for( int i = 0 ; i < MapSize ; i++ )
|
for( int i = 0 ; i < MapSize ; i++ )
|
||||||
for( int j = 0 ; j < MapSize ; j++ )
|
for( int j = 0 ; j < MapSize ; j++ )
|
||||||
{
|
{
|
||||||
MapTiles[j, i].image = (byte)ms.ReadByte();
|
Map.MapTiles[j, i].index = (byte)ms.ReadByte();
|
||||||
if( MapTiles[ j, i ].tile == 0xff || MapTiles[ j, i ].tile == 0xffff )
|
if( Map.MapTiles[ j, i ].type == 0xff || Map.MapTiles[ j, i ].type == 0xffff )
|
||||||
MapTiles[ j, i ].image = (byte)( i % 4 + ( j % 4 ) * 4 );
|
Map.MapTiles[ j, i ].index = byte.MaxValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static string[] raOverlayNames =
|
|
||||||
{
|
|
||||||
"sbag", "cycl", "brik", "fenc", "wood",
|
|
||||||
"gold01", "gold02", "gold03", "gold04",
|
|
||||||
"gem01", "gem02", "gem03", "gem04",
|
|
||||||
"v12", "v13", "v14", "v15", "v16", "v17", "v18",
|
|
||||||
"fpls", "wcrate", "scrate", "barb", "sbag",
|
|
||||||
};
|
|
||||||
|
|
||||||
void UnpackRAOverlayData( MemoryStream ms )
|
void UnpackRAOverlayData( MemoryStream ms )
|
||||||
{
|
{
|
||||||
|
Map.MapResources = new NewTileReference<byte, byte>[ MapSize, MapSize ];
|
||||||
for( int i = 0 ; i < MapSize ; i++ )
|
for( int i = 0 ; i < MapSize ; i++ )
|
||||||
for( int j = 0 ; j < MapSize ; j++ )
|
for( int j = 0 ; j < MapSize ; j++ )
|
||||||
{
|
{
|
||||||
byte o = ReadByte( ms );
|
byte o = ReadByte( ms );
|
||||||
MapTiles[ j, i ].overlay = (o == 255) ? null : raOverlayNames[o];
|
var res = Pair.New((byte)0,(byte)0);
|
||||||
|
|
||||||
|
if (o != 255 && resourceMapping.ContainsKey(raOverlayNames[o]))
|
||||||
|
res = resourceMapping[raOverlayNames[o]];
|
||||||
|
|
||||||
|
Map.MapResources[j, i] = new NewTileReference<byte,byte>(res.First, res.Second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,17 +222,17 @@ namespace MapConverter
|
|||||||
IniSection terrain = file.GetSection( "TERRAIN", true );
|
IniSection terrain = file.GetSection( "TERRAIN", true );
|
||||||
if( terrain == null )
|
if( terrain == null )
|
||||||
return;
|
return;
|
||||||
|
int a = 0;
|
||||||
foreach( KeyValuePair<string, string> kv in terrain )
|
foreach( KeyValuePair<string, string> kv in terrain )
|
||||||
{
|
{
|
||||||
var loc = int.Parse( kv.Key );
|
var loc = int.Parse( kv.Key );
|
||||||
Actors.Add( new ActorReference(kv.Value, new int2(loc % MapSize, loc / MapSize), null ) );
|
Map.Actors.Add("Actor"+a++, new ActorReference(kv.Value, new int2(loc % MapSize, loc / MapSize), null ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnpackCncTileData( Stream ms )
|
void UnpackCncTileData( Stream ms )
|
||||||
{
|
{
|
||||||
for( int i = 0 ; i < MapSize ; i++ )
|
/*for( int i = 0 ; i < MapSize ; i++ )
|
||||||
for( int j = 0 ; j < MapSize ; j++ )
|
for( int j = 0 ; j < MapSize ; j++ )
|
||||||
{
|
{
|
||||||
MapTiles[j, i].tile = (byte)ms.ReadByte();
|
MapTiles[j, i].tile = (byte)ms.ReadByte();
|
||||||
@@ -315,12 +240,12 @@ namespace MapConverter
|
|||||||
|
|
||||||
if( MapTiles[ j, i ].tile == 0xff )
|
if( MapTiles[ j, i ].tile == 0xff )
|
||||||
MapTiles[ j, i ].image = (byte)( i % 4 + ( j % 4 ) * 4 );
|
MapTiles[ j, i ].image = (byte)( i % 4 + ( j % 4 ) * 4 );
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadCncOverlay( IniFile file )
|
void ReadCncOverlay( IniFile file )
|
||||||
{
|
{
|
||||||
IniSection overlay = file.GetSection( "OVERLAY", true );
|
/*IniSection overlay = file.GetSection( "OVERLAY", true );
|
||||||
if( overlay == null )
|
if( overlay == null )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -329,7 +254,7 @@ namespace MapConverter
|
|||||||
var loc = int.Parse( kv.Key );
|
var loc = int.Parse( kv.Key );
|
||||||
int2 cell = new int2(loc % MapSize, loc / MapSize);
|
int2 cell = new int2(loc % MapSize, loc / MapSize);
|
||||||
MapTiles[ cell.X, cell.Y ].overlay = kv.Value.ToLower();
|
MapTiles[ cell.X, cell.Y ].overlay = kv.Value.ToLower();
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -339,32 +264,30 @@ namespace MapConverter
|
|||||||
if( terrain == null )
|
if( terrain == null )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
int a = 0;
|
||||||
foreach( KeyValuePair<string, string> kv in terrain )
|
foreach( KeyValuePair<string, string> kv in terrain )
|
||||||
{
|
{
|
||||||
var loc = int.Parse( kv.Key );
|
var loc = int.Parse( kv.Key );
|
||||||
Actors.Add( new ActorReference( kv.Value.Split(',')[0], new int2(loc % MapSize, loc / MapSize),null));
|
Map.Actors.Add("Actor"+a++, new ActorReference( kv.Value.Split(',')[0], new int2(loc % MapSize, loc / MapSize),null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadActors(IniFile file, string section)
|
void LoadActors(IniFile file, string section)
|
||||||
{
|
{
|
||||||
|
int a = 0;
|
||||||
foreach (var s in file.GetSection(section, true))
|
foreach (var s in file.GetSection(section, true))
|
||||||
{
|
{
|
||||||
//num=owner,type,health,location,facing,...
|
//num=owner,type,health,location,facing,...
|
||||||
var parts = s.Value.Split( ',' );
|
var parts = s.Value.Split( ',' );
|
||||||
var loc = int.Parse(parts[3]);
|
var loc = int.Parse(parts[3]);
|
||||||
Actors.Add( new ActorReference( parts[1].ToLowerInvariant(), new int2(loc % MapSize, loc / MapSize), parts[0]));
|
Map.Actors.Add("Actor"+a++, new ActorReference( parts[1].ToLowerInvariant(), new int2(loc % MapSize, loc / MapSize), parts[0]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsInMap(int2 xy)
|
public void Save(string filepath)
|
||||||
{
|
{
|
||||||
return IsInMap(xy.X,xy.Y);
|
Map.Tiledata = filepath+".bin";
|
||||||
}
|
Map.Save(filepath+".yaml");
|
||||||
|
|
||||||
public bool IsInMap(int x, int y)
|
|
||||||
{
|
|
||||||
return (x >= XOffset && y >= YOffset && x < XOffset + Width && y < YOffset + Height);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
@@ -36,7 +35,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Main.cs" />
|
<Compile Include="Main.cs" />
|
||||||
<Compile Include="AssemblyInfo.cs" />
|
<Compile Include="AssemblyInfo.cs" />
|
||||||
<Compile Include="IniMap.cs" />
|
<Compile Include="MapConverter.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
@@ -28,31 +28,34 @@ namespace OpenRA.FileFormats
|
|||||||
{
|
{
|
||||||
public class NewMap
|
public class NewMap
|
||||||
{
|
{
|
||||||
// General info
|
// Yaml map data
|
||||||
public byte MapFormat = 1;
|
public int MapFormat = 1;
|
||||||
public string Title;
|
public string Title;
|
||||||
public string Description;
|
public string Description;
|
||||||
public string Author;
|
public string Author;
|
||||||
public int PlayerCount;
|
public int PlayerCount;
|
||||||
public string Preview;
|
public string Preview;
|
||||||
|
|
||||||
// 'Simple' map data
|
|
||||||
public string Tiledata;
|
|
||||||
public byte TileFormat = 1;
|
|
||||||
public string Tileset;
|
|
||||||
public int2 Size;
|
|
||||||
public int[] Bounds;
|
public int[] Bounds;
|
||||||
|
public string Tileset;
|
||||||
|
|
||||||
// 'Complex' map data
|
|
||||||
public TileReference[ , ] MapTiles;
|
|
||||||
public Dictionary<string, ActorReference> Actors = new Dictionary<string, ActorReference>();
|
public Dictionary<string, ActorReference> Actors = new Dictionary<string, ActorReference>();
|
||||||
public Dictionary<string, int2> Waypoints = new Dictionary<string, int2>();
|
public Dictionary<string, int2> Waypoints = new Dictionary<string, int2>();
|
||||||
public Dictionary<string, MiniYaml> Rules = new Dictionary<string, MiniYaml>();
|
public Dictionary<string, MiniYaml> Rules = new Dictionary<string, MiniYaml>();
|
||||||
|
|
||||||
|
// Binary map data
|
||||||
|
public string Tiledata;
|
||||||
|
public byte TileFormat = 1;
|
||||||
|
public int2 Size;
|
||||||
|
public NewTileReference<ushort,byte>[ , ] MapTiles;
|
||||||
|
public NewTileReference<byte, byte>[ , ] MapResources;
|
||||||
|
|
||||||
|
|
||||||
List<string> SimpleFields = new List<string>() {
|
List<string> SimpleFields = new List<string>() {
|
||||||
"MapFormat", "Title", "Description", "Author", "PlayerCount", "Tileset", "Size", "Tiledata", "Preview", "Bounds"
|
"MapFormat", "Title", "Description", "Author", "PlayerCount", "Tileset", "Tiledata", "Preview", "Bounds"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public NewMap() {}
|
||||||
|
|
||||||
public NewMap(string filename)
|
public NewMap(string filename)
|
||||||
{
|
{
|
||||||
var yaml = MiniYaml.FromFile(filename);
|
var yaml = MiniYaml.FromFile(filename);
|
||||||
@@ -84,12 +87,61 @@ namespace OpenRA.FileFormats
|
|||||||
|
|
||||||
// Rules
|
// Rules
|
||||||
Rules = yaml["Rules"].Nodes;
|
Rules = yaml["Rules"].Nodes;
|
||||||
|
|
||||||
|
LoadBinaryData(Tiledata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void Save(string filepath)
|
||||||
|
{
|
||||||
|
// Do stuff
|
||||||
|
|
||||||
|
SaveBinaryData(Tiledata);
|
||||||
|
}
|
||||||
|
|
||||||
|
static byte ReadByte( Stream s )
|
||||||
|
{
|
||||||
|
int ret = s.ReadByte();
|
||||||
|
if( ret == -1 )
|
||||||
|
throw new NotImplementedException();
|
||||||
|
return (byte)ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ushort ReadWord(Stream s)
|
||||||
|
{
|
||||||
|
ushort ret = ReadByte(s);
|
||||||
|
ret |= (ushort)(ReadByte(s) << 8);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadBinaryData(string filename)
|
||||||
|
{
|
||||||
|
Console.Write("path: {0}",filename);
|
||||||
|
|
||||||
|
Stream dataStream = FileSystem.Open(filename);
|
||||||
|
|
||||||
|
// Load header info
|
||||||
|
byte version = ReadByte(dataStream);
|
||||||
|
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 ];
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
}
|
||||||
|
|
||||||
public void SaveBinaryData(string filepath)
|
public void SaveBinaryData(string filepath)
|
||||||
{
|
{
|
||||||
|
|
||||||
FileStream dataStream = new FileStream(filepath+".tmp", FileMode.Create, FileAccess.Write);
|
FileStream dataStream = new FileStream(filepath+".tmp", FileMode.Create, FileAccess.Write);
|
||||||
BinaryWriter writer = new BinaryWriter( dataStream );
|
BinaryWriter writer = new BinaryWriter( dataStream );
|
||||||
writer.BaseStream.Seek(0, SeekOrigin.Begin);
|
writer.BaseStream.Seek(0, SeekOrigin.Begin);
|
||||||
@@ -99,39 +151,24 @@ namespace OpenRA.FileFormats
|
|||||||
writer.Write((ushort)Size.X);
|
writer.Write((ushort)Size.X);
|
||||||
writer.Write((ushort)Size.Y);
|
writer.Write((ushort)Size.Y);
|
||||||
|
|
||||||
// Tile data is stored as a base-64 encoded stream of
|
// Tile data
|
||||||
// {(2-byte) tile index, (1-byte) image index} pairs
|
|
||||||
for( int i = 0 ; i < Size.X ; i++ )
|
for( int i = 0 ; i < Size.X ; i++ )
|
||||||
for( int j = 0 ; j < Size.Y ; j++ )
|
for( int j = 0 ; j < Size.Y ; j++ )
|
||||||
{
|
{
|
||||||
writer.Write( MapTiles[j,i].tile );
|
writer.Write( MapTiles[j,i].type );
|
||||||
// Semi-hack: Convert clear and water tiles to "pick an image for me" magic number
|
writer.Write( MapTiles[ j, i ].index );
|
||||||
byte image = (MapTiles[ j, i ].tile == 0xff || MapTiles[ j, i ].tile == 0xffff) ? byte.MaxValue : MapTiles[j,i].image;
|
|
||||||
writer.Write(image);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resource data
|
||||||
// TODO: Need a proper resources array to write
|
|
||||||
/*
|
|
||||||
// Resource data is stored as a base-64 encoded stream of
|
|
||||||
// {(1-byte) resource index, (1-byte) image index} pairs
|
|
||||||
for( int i = 0 ; i < Size.X ; i++ )
|
for( int i = 0 ; i < Size.X ; i++ )
|
||||||
for( int j = 0 ; j < Size.Y ; j++ )
|
for( int j = 0 ; j < Size.Y ; j++ )
|
||||||
{
|
{
|
||||||
byte type = 0;
|
writer.Write( MapResources[j,i].type );
|
||||||
byte image = 0;
|
writer.Write( MapResources[j,i].index );
|
||||||
if (MapTiles[j,i].overlay != null)
|
|
||||||
{
|
|
||||||
var res = resourceMapping[MapTiles[j,i].overlay];
|
|
||||||
type = res.First;
|
|
||||||
image = res.Second;
|
|
||||||
}
|
|
||||||
|
|
||||||
writer.Write(type);
|
|
||||||
writer.Write(image);
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
writer.Flush();
|
writer.Flush();
|
||||||
|
writer.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DebugContents()
|
public void DebugContents()
|
||||||
|
|||||||
36
OpenRA.FileFormats/Map/NewTileReference.cs
Normal file
36
OpenRA.FileFormats/Map/NewTileReference.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||||
|
* This file is part of OpenRA.
|
||||||
|
*
|
||||||
|
* OpenRA is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* OpenRA is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace OpenRA.FileFormats
|
||||||
|
{
|
||||||
|
public struct NewTileReference<T, U>
|
||||||
|
{
|
||||||
|
public T type;
|
||||||
|
public U index;
|
||||||
|
|
||||||
|
public NewTileReference(T t, U i)
|
||||||
|
{
|
||||||
|
type = t;
|
||||||
|
index = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode() { return type.GetHashCode() ^ index.GetHashCode(); }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -102,6 +102,7 @@
|
|||||||
<Compile Include="FileFormats\Format80.cs" />
|
<Compile Include="FileFormats\Format80.cs" />
|
||||||
<Compile Include="FileFormats\IniFile.cs" />
|
<Compile Include="FileFormats\IniFile.cs" />
|
||||||
<Compile Include="Graphics\ShpReader.cs" />
|
<Compile Include="Graphics\ShpReader.cs" />
|
||||||
|
<Compile Include="Map\NewTileReference.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
|||||||
BIN
mods/ra/testmap.bin
Normal file
BIN
mods/ra/testmap.bin
Normal file
Binary file not shown.
@@ -4,9 +4,8 @@ Description:
|
|||||||
Author: Me
|
Author: Me
|
||||||
PlayerCount: 2
|
PlayerCount: 2
|
||||||
Tileset: TEMPERAT
|
Tileset: TEMPERAT
|
||||||
Size: 100,97
|
|
||||||
TileData: testmap.bin
|
|
||||||
Preview: testmap.png
|
Preview: testmap.png
|
||||||
|
Tiledata: testmap.bin
|
||||||
|
|
||||||
Waypoints:
|
Waypoints:
|
||||||
spawn0: 36,75
|
spawn0: 36,75
|
||||||
|
|||||||
Reference in New Issue
Block a user