Load cnc TEMPERAT maps (other theatres need tileset.til fixes)

This commit is contained in:
Paul Chote
2010-03-02 21:47:16 +13:00
parent 3fd7af5532
commit e841bbd3d2
8 changed files with 2812 additions and 3946 deletions

View File

@@ -28,6 +28,7 @@ namespace OpenRA.FileFormats
{
public class Map
{
public readonly string BinaryPart;
public readonly string Title;
public readonly string Theater;
@@ -59,7 +60,7 @@ namespace OpenRA.FileFormats
IniSection basic = file.GetSection("Basic");
Title = basic.GetValue("Name", "(null)");
BinaryPart = basic.GetValue("BinaryPart", "scm01ea.bin");
IniSection map = file.GetSection("Map");
Theater = Truncate(map.GetValue("Theater", "TEMPERATE"), 8);
@@ -68,11 +69,15 @@ namespace OpenRA.FileFormats
Width = int.Parse(map.GetValue("Width", "0"));
Height = int.Parse(map.GetValue("Height", "0"));
UnpackTileData(ReadPackedSection(file.GetSection("MapPack")));
UnpackOverlayData(ReadPackedSection(file.GetSection("OverlayPack")));
ReadTrees(file);
//UnpackTileData(ReadPackedSection(file.GetSection("MapPack")));
//UnpackOverlayData(ReadPackedSection(file.GetSection("OverlayPack")));
//ReadTrees(file);
UnpackCncTileData(FileSystem.Open(BinaryPart));
SpawnPoints = file.GetSection("Waypoints")
.Select(kv => Pair.New(int.Parse(kv.Key), new int2(int.Parse(kv.Value) % 128, int.Parse(kv.Value) / 128)))
.Where(a => a.First < 8)
@@ -80,6 +85,17 @@ namespace OpenRA.FileFormats
.ToArray();
}
void UnpackCncTileData( Stream ms )
{
for( int i = 0 ; i < 64 ; i++ )
for( int j = 0 ; j < 64 ; j++ )
{
MapTiles[j, i].tile = (byte)ms.ReadByte();
MapTiles[j, i].image = (byte)ms.ReadByte();
Log.Write("Set tile to {0} {1}",MapTiles[j, i].tile,MapTiles[j, i].image);
}
}
static MemoryStream ReadPackedSection(IniSection mapPackSection)
{
StringBuilder sb = new StringBuilder();

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information
#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.
@@ -47,7 +47,7 @@ namespace OpenRA.FileFormats
public class Global
{
public string Map = "scm12ea.ini";
public string Map = "scm01ea.ini";
public string[] Packages = {}; // filename:sha1 pairs.
public string[] Mods = { "ra" }; // mod names
public int OrderLatency = 3;

View File

@@ -105,8 +105,15 @@ namespace OpenRA.FileFormats
{
if (r.tile == 0xff || r.tile == 0xffff)
r.image = 0;
return walk[r.tile].TerrainType[r.image];
try {
return walk[r.tile].TerrainType[r.image];
}
catch (KeyNotFoundException)
{
return 0; // Default zero (walkable)
}
}
}
}