Convert overlays (wall, field, crate) to actors. Untested cnc support.
This commit is contained in:
@@ -30,22 +30,7 @@ namespace MapConverter
|
||||
{
|
||||
public class MapConverter
|
||||
{
|
||||
public readonly int INIFormat;
|
||||
|
||||
public readonly int MapSize;
|
||||
public readonly int XOffset;
|
||||
public readonly int YOffset;
|
||||
|
||||
public readonly int Width;
|
||||
public readonly int Height;
|
||||
public Map Map = new Map();
|
||||
|
||||
static string Truncate( string s, int maxLength )
|
||||
{
|
||||
return s.Length <= maxLength ? s : s.Substring(0,maxLength );
|
||||
}
|
||||
|
||||
|
||||
// Mapping from ra overlay index to type string
|
||||
static string[] raOverlayNames =
|
||||
{
|
||||
"sbag", "cycl", "brik", "fenc", "wood",
|
||||
@@ -55,7 +40,9 @@ namespace MapConverter
|
||||
"fpls", "wcrate", "scrate", "barb", "sbag",
|
||||
};
|
||||
|
||||
Dictionary< string, Pair<byte,byte> > resourceMapping = new Dictionary<string, Pair<byte, byte>>() {
|
||||
Dictionary< string, Pair<byte,byte> > overlayResourceMapping = new Dictionary<string, Pair<byte, byte>>()
|
||||
{
|
||||
// RA Gems, Gold
|
||||
{ "gold01", new Pair<byte,byte>(1,0) },
|
||||
{ "gold02", new Pair<byte,byte>(1,1) },
|
||||
{ "gold03", new Pair<byte,byte>(1,2) },
|
||||
@@ -66,32 +53,62 @@ namespace MapConverter
|
||||
{ "gem03", new Pair<byte,byte>(2,2) },
|
||||
{ "gem04", new Pair<byte,byte>(2,3) },
|
||||
|
||||
// TODO Add cnc tiberium
|
||||
// cnc tiberium
|
||||
{ "ti1", new Pair<byte,byte>(1,0) },
|
||||
{ "ti2", new Pair<byte,byte>(1,1) },
|
||||
{ "ti3", new Pair<byte,byte>(1,2) },
|
||||
{ "ti4", new Pair<byte,byte>(1,3) },
|
||||
{ "ti5", new Pair<byte,byte>(1,4) },
|
||||
{ "ti6", new Pair<byte,byte>(1,5) },
|
||||
{ "ti7", new Pair<byte,byte>(1,6) },
|
||||
{ "ti8", new Pair<byte,byte>(1,7) },
|
||||
{ "ti9", new Pair<byte,byte>(1,8) },
|
||||
{ "ti10", new Pair<byte,byte>(1,9) },
|
||||
{ "ti11", new Pair<byte,byte>(1,10) },
|
||||
{ "ti12", new Pair<byte,byte>(1,11) },
|
||||
};
|
||||
|
||||
Dictionary<string, string> overlayActorMapping = new Dictionary<string,string>() {
|
||||
// Fences
|
||||
{"sbag","sbag"},
|
||||
{"cycl","cycl"},
|
||||
{"brik","brik"},
|
||||
{"fenc","fenc"},
|
||||
{"wood","wood"},
|
||||
|
||||
// Fields
|
||||
{"v12","v12"},
|
||||
{"v13","v13"},
|
||||
{"v14","v14"},
|
||||
{"v15","v15"},
|
||||
{"v16","v16"},
|
||||
{"v17","v17"},
|
||||
{"v18","v18"},
|
||||
|
||||
// Crates
|
||||
{"wcrate","crate"},
|
||||
{"scrate","crate"},
|
||||
};
|
||||
|
||||
int MapSize;
|
||||
int ActorCount = 0;
|
||||
public Map Map = new Map();
|
||||
|
||||
public MapConverter(string filename)
|
||||
{
|
||||
Map.Author = "Westwood Studios";
|
||||
|
||||
{
|
||||
IniFile file = new IniFile(FileSystem.Open(filename));
|
||||
|
||||
IniSection basic = file.GetSection("Basic");
|
||||
Map.Title = basic.GetValue("Name", "(null)");
|
||||
|
||||
|
||||
INIFormat = int.Parse(basic.GetValue("NewINIFormat", "0"));
|
||||
|
||||
IniSection map = file.GetSection("Map");
|
||||
Map.Tileset = Truncate(map.GetValue("Theater", "TEMPERAT"), 8);
|
||||
|
||||
XOffset = int.Parse(map.GetValue("X", "0"));
|
||||
YOffset = int.Parse(map.GetValue("Y", "0"));
|
||||
|
||||
Width = int.Parse(map.GetValue("Width", "0"));
|
||||
Height = int.Parse(map.GetValue("Height", "0"));
|
||||
var INIFormat = int.Parse(basic.GetValue("NewINIFormat", "0"));
|
||||
var XOffset = int.Parse(map.GetValue("X", "0"));
|
||||
var YOffset = int.Parse(map.GetValue("Y", "0"));
|
||||
var Width = int.Parse(map.GetValue("Width", "0"));
|
||||
var Height = int.Parse(map.GetValue("Height", "0"));
|
||||
MapSize = (INIFormat == 3) ? 128 : 64;
|
||||
|
||||
Map.Title = basic.GetValue("Name", "(null)");
|
||||
Map.Author = "Westwood Studios";
|
||||
Map.Tileset = Truncate(map.GetValue("Theater", "TEMPERAT"), 8);
|
||||
Map.MapSize.X = MapSize;
|
||||
Map.MapSize.Y = MapSize;
|
||||
Map.TopLeft = new int2 (XOffset, YOffset);
|
||||
@@ -185,8 +202,8 @@ namespace MapConverter
|
||||
void UnpackRATileData( MemoryStream ms )
|
||||
{
|
||||
Map.MapTiles = new TileReference<ushort, byte>[ MapSize, MapSize ];
|
||||
for( int j = 0 ; j < MapSize ; j++ )
|
||||
for( int i = 0 ; i < MapSize ; i++ )
|
||||
for( int i = 0 ; i < MapSize ; i++ )
|
||||
for( int j = 0 ; j < MapSize ; j++ )
|
||||
Map.MapTiles[i,j] = new TileReference<ushort,byte>();
|
||||
|
||||
for( int j = 0 ; j < MapSize ; j++ )
|
||||
@@ -211,10 +228,13 @@ namespace MapConverter
|
||||
byte o = ReadByte( ms );
|
||||
var res = Pair.New((byte)0,(byte)0);
|
||||
|
||||
if (o != 255 && resourceMapping.ContainsKey(raOverlayNames[o]))
|
||||
res = resourceMapping[raOverlayNames[o]];
|
||||
|
||||
if (o != 255 && overlayResourceMapping.ContainsKey(raOverlayNames[o]))
|
||||
res = overlayResourceMapping[raOverlayNames[o]];
|
||||
|
||||
Map.MapResources[i,j] = new TileReference<byte,byte>(res.First, res.Second);
|
||||
|
||||
if (o != 255 && overlayActorMapping.ContainsKey(raOverlayNames[o]))
|
||||
Map.Actors.Add("Actor"+ActorCount++, new ActorReference( overlayActorMapping[raOverlayNames[o]], new int2(i,j), "Neutral"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,39 +243,53 @@ namespace MapConverter
|
||||
IniSection terrain = file.GetSection( "TERRAIN", true );
|
||||
if( terrain == null )
|
||||
return;
|
||||
int a = 0;
|
||||
|
||||
foreach( KeyValuePair<string, string> kv in terrain )
|
||||
{
|
||||
var loc = int.Parse( kv.Key );
|
||||
Map.Actors.Add("Actor"+a++, new ActorReference(kv.Value, new int2(loc % MapSize, loc / MapSize), "Neutral" ) );
|
||||
Map.Actors.Add("Actor"+ActorCount++, new ActorReference(kv.Value.ToLowerInvariant(), new int2(loc % MapSize, loc / MapSize), "Neutral" ) );
|
||||
}
|
||||
}
|
||||
|
||||
void UnpackCncTileData( Stream ms )
|
||||
{
|
||||
/*for( int i = 0 ; i < MapSize ; i++ )
|
||||
Map.MapTiles = new TileReference<ushort, byte>[ MapSize, MapSize ];
|
||||
for( int i = 0 ; i < MapSize ; i++ )
|
||||
for( int j = 0 ; j < MapSize ; j++ )
|
||||
Map.MapTiles[i,j] = new TileReference<ushort,byte>();
|
||||
|
||||
for( int i = 0 ; i < MapSize ; i++ )
|
||||
for( int j = 0 ; j < MapSize ; j++ )
|
||||
{
|
||||
MapTiles[j, i].tile = (byte)ms.ReadByte();
|
||||
MapTiles[j, i].image = (byte)ms.ReadByte();
|
||||
Map.MapTiles[i,j].type = (ushort)ms.ReadByte();
|
||||
Map.MapTiles[i,j].image = (byte)ms.ReadByte();
|
||||
|
||||
if( MapTiles[ j, i ].tile == 0xff )
|
||||
MapTiles[ j, i ].image = (byte)( i % 4 + ( j % 4 ) * 4 );
|
||||
}*/
|
||||
if( Map.MapTiles[i,j].type == 0xff || Map.MapTiles[i,j].type == 0xffff )
|
||||
Map.MapTiles[i,j].image = (byte)( i % 4 + ( j % 4 ) * 4 );
|
||||
}
|
||||
}
|
||||
|
||||
void ReadCncOverlay( IniFile file )
|
||||
{
|
||||
/*IniSection overlay = file.GetSection( "OVERLAY", true );
|
||||
IniSection overlay = file.GetSection( "OVERLAY", true );
|
||||
if( overlay == null )
|
||||
return;
|
||||
|
||||
|
||||
Map.MapResources = new TileReference<byte, byte>[ MapSize, MapSize ];
|
||||
foreach( KeyValuePair<string, string> kv in overlay )
|
||||
{
|
||||
var loc = int.Parse( kv.Key );
|
||||
int2 cell = new int2(loc % MapSize, loc / MapSize);
|
||||
MapTiles[ cell.X, cell.Y ].overlay = kv.Value.ToLower();
|
||||
}*/
|
||||
|
||||
var res = Pair.New((byte)0,(byte)0);
|
||||
if (overlayResourceMapping.ContainsKey(kv.Value.ToLower()))
|
||||
res = overlayResourceMapping[kv.Value.ToLower()];
|
||||
|
||||
Map.MapResources[ cell.X, cell.Y ] = new TileReference<byte,byte>(res.First, res.Second);
|
||||
|
||||
if (overlayActorMapping.ContainsKey(kv.Value.ToLower()))
|
||||
Map.Actors.Add("Actor"+ActorCount++, new ActorReference( overlayActorMapping[kv.Value.ToLower()], new int2(cell.X,cell.Y), "Neutral"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -264,18 +298,16 @@ namespace MapConverter
|
||||
IniSection terrain = file.GetSection( "TERRAIN", true );
|
||||
if( terrain == null )
|
||||
return;
|
||||
|
||||
int a = 0;
|
||||
|
||||
foreach( KeyValuePair<string, string> kv in terrain )
|
||||
{
|
||||
var loc = int.Parse( kv.Key );
|
||||
Map.Actors.Add("Actor"+a++, new ActorReference( kv.Value.Split(',')[0], new int2(loc % MapSize, loc / MapSize),"Neutral"));
|
||||
Map.Actors.Add("Actor"+ActorCount++, new ActorReference( kv.Value.Split(',')[0].ToLowerInvariant(), new int2(loc % MapSize, loc / MapSize),"Neutral"));
|
||||
}
|
||||
}
|
||||
|
||||
void LoadActors(IniFile file, string section)
|
||||
{
|
||||
int a = 0;
|
||||
foreach (var s in file.GetSection(section, true))
|
||||
{
|
||||
//num=owner,type,health,location,facing,...
|
||||
@@ -283,10 +315,15 @@ namespace MapConverter
|
||||
var loc = int.Parse(parts[3]);
|
||||
if (parts[0] == "")
|
||||
parts[0] = "Neutral";
|
||||
Map.Actors.Add("Actor"+a++, new ActorReference( parts[1].ToLowerInvariant(), new int2(loc % MapSize, loc / MapSize), parts[0]));
|
||||
Map.Actors.Add("Actor"+ActorCount++, new ActorReference( parts[1].ToLowerInvariant(), new int2(loc % MapSize, loc / MapSize), parts[0]));
|
||||
}
|
||||
}
|
||||
|
||||
static string Truncate( string s, int maxLength )
|
||||
{
|
||||
return s.Length <= maxLength ? s : s.Substring(0,maxLength );
|
||||
}
|
||||
|
||||
public void Save(string filepath)
|
||||
{
|
||||
Map.Tiledata = filepath+".bin";
|
||||
|
||||
Reference in New Issue
Block a user