Remove obsolete files
This commit is contained in:
@@ -1,268 +1,229 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||||
* This file is part of OpenRA.
|
* This file is part of OpenRA.
|
||||||
*
|
*
|
||||||
* OpenRA is free software: you can redistribute it and/or modify
|
* OpenRA is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* OpenRA is distributed in the hope that it will be useful,
|
* OpenRA is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Reflection;
|
||||||
namespace OpenRA.FileFormats
|
|
||||||
{
|
namespace OpenRA.FileFormats
|
||||||
public class OldMap
|
{
|
||||||
{
|
public class Map
|
||||||
public readonly string Title;
|
{
|
||||||
public readonly string Theater;
|
// Yaml map data
|
||||||
public readonly int INIFormat;
|
public int MapFormat = 1;
|
||||||
|
public string Title;
|
||||||
public readonly int MapSize;
|
public string Description;
|
||||||
public readonly int XOffset;
|
public string Author;
|
||||||
public readonly int YOffset;
|
public int PlayerCount;
|
||||||
public int2 Offset { get { return new int2( XOffset, YOffset ); } }
|
public string Preview;
|
||||||
|
public string Tileset;
|
||||||
public readonly int Width;
|
|
||||||
public readonly int Height;
|
public Dictionary<string, ActorReference> Actors = new Dictionary<string, ActorReference>();
|
||||||
public int2 Size { get { return new int2(Width, Height); } }
|
public Dictionary<string, int2> Waypoints = new Dictionary<string, int2>();
|
||||||
|
public Dictionary<string, MiniYaml> Rules = new Dictionary<string, MiniYaml>();
|
||||||
public readonly OldTileReference[ , ] MapTiles;
|
|
||||||
public readonly List<ActorReference> Actors = new List<ActorReference>();
|
// Binary map data
|
||||||
|
public string Tiledata;
|
||||||
public readonly IEnumerable<int2> SpawnPoints;
|
public byte TileFormat = 1;
|
||||||
|
public int2 MapSize;
|
||||||
static string Truncate( string s, int maxLength )
|
|
||||||
{
|
public int2 TopLeft;
|
||||||
return s.Length <= maxLength ? s : s.Substring(0,maxLength );
|
public int2 BottomRight;
|
||||||
}
|
|
||||||
|
public TileReference<ushort,byte>[ , ] MapTiles;
|
||||||
public OldMap(string filename)
|
public TileReference<byte, byte>[ , ] MapResources;
|
||||||
{
|
|
||||||
IniFile file = new IniFile(FileSystem.Open(filename));
|
|
||||||
|
// Temporary compat hacks
|
||||||
IniSection basic = file.GetSection("Basic");
|
public int XOffset {get {return TopLeft.X;}}
|
||||||
Title = basic.GetValue("Name", "(null)");
|
public int YOffset {get {return TopLeft.Y;}}
|
||||||
INIFormat = int.Parse(basic.GetValue("NewINIFormat", "0"));
|
public int Width {get {return BottomRight.X-TopLeft.X;}}
|
||||||
|
public int Height {get {return BottomRight.Y-TopLeft.Y;}}
|
||||||
IniSection map = file.GetSection("Map");
|
public string Theater {get {return Tileset;}}
|
||||||
Theater = Truncate(map.GetValue("Theater", "TEMPERAT"), 8);
|
public IEnumerable<int2> SpawnPoints {get {return Waypoints.Select(kv => kv.Value);}}
|
||||||
|
|
||||||
XOffset = int.Parse(map.GetValue("X", "0"));
|
List<string> SimpleFields = new List<string>() {
|
||||||
YOffset = int.Parse(map.GetValue("Y", "0"));
|
"MapFormat", "Title", "Description", "Author", "PlayerCount", "Tileset", "Tiledata", "Preview", "MapSize", "TopLeft", "BottomRight"
|
||||||
|
};
|
||||||
Width = int.Parse(map.GetValue("Width", "0"));
|
|
||||||
Height = int.Parse(map.GetValue("Height", "0"));
|
public Map() {}
|
||||||
MapSize = (INIFormat == 3) ? 128 : 64;
|
|
||||||
|
public Map(string filename)
|
||||||
MapTiles = new OldTileReference[ MapSize, MapSize ];
|
{
|
||||||
for (int j = 0; j < MapSize; j++)
|
var yaml = MiniYaml.FromFileInPackage(filename);
|
||||||
for (int i = 0; i < MapSize; i++)
|
|
||||||
MapTiles[i, j] = new OldTileReference();
|
// 'Simple' metadata
|
||||||
|
foreach (var field in SimpleFields)
|
||||||
|
{
|
||||||
if (INIFormat == 3) // RA map
|
if (!yaml.ContainsKey(field)) continue;
|
||||||
{
|
FieldLoader.LoadField(this,field,yaml[field].Value);
|
||||||
UnpackRATileData(ReadPackedSection(file.GetSection("MapPack")));
|
}
|
||||||
UnpackRAOverlayData(ReadPackedSection(file.GetSection("OverlayPack")));
|
|
||||||
ReadRATrees(file);
|
// Waypoints
|
||||||
}
|
foreach (var wp in yaml["Waypoints"].Nodes)
|
||||||
else // CNC
|
{
|
||||||
{
|
string[] loc = wp.Value.Value.Split(',');
|
||||||
UnpackCncTileData(FileSystem.Open(filename.Substring(0,filename.Length-4)+".bin"));
|
Waypoints.Add(wp.Key, new int2(int.Parse(loc[0]),int.Parse(loc[1])));
|
||||||
ReadCncOverlay(file);
|
}
|
||||||
ReadCncTrees(file);
|
|
||||||
}
|
// TODO: Players
|
||||||
|
|
||||||
LoadActors(file, "STRUCTURES");
|
// Actors
|
||||||
LoadActors(file, "UNITS");
|
foreach (var kv in yaml["Actors"].Nodes.ToPairs())
|
||||||
LoadActors(file, "INFANTRY");
|
{
|
||||||
|
string[] vals = kv.Second.Split(' ');
|
||||||
SpawnPoints = file.GetSection("Waypoints")
|
string[] loc = vals[2].Split(',');
|
||||||
.Where(kv => int.Parse(kv.Value) > 0)
|
var a = new ActorReference(vals[0], new int2(int.Parse(loc[0]),int.Parse(loc[1])) ,vals[1]);
|
||||||
.Select(kv => Pair.New(int.Parse(kv.Key), new int2(int.Parse(kv.Value) % MapSize, int.Parse(kv.Value) / MapSize)))
|
Actors.Add(kv.First,a);
|
||||||
.Where(a => a.First < 8)
|
}
|
||||||
.Select(a => a.Second)
|
|
||||||
.ToArray();
|
// Rules
|
||||||
}
|
Rules = yaml["Rules"].Nodes;
|
||||||
|
|
||||||
static MemoryStream ReadPackedSection(IniSection mapPackSection)
|
LoadBinaryData(Tiledata);
|
||||||
{
|
}
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (int i = 1; ; i++)
|
|
||||||
{
|
public void Save(string filepath)
|
||||||
string line = mapPackSection.GetValue(i.ToString(), null);
|
{
|
||||||
if (line == null)
|
Dictionary<string, MiniYaml> root = new Dictionary<string, MiniYaml>();
|
||||||
break;
|
var d = new Dictionary<string, MiniYaml>();
|
||||||
|
foreach (var field in SimpleFields)
|
||||||
sb.Append(line.Trim());
|
{
|
||||||
}
|
FieldInfo f = this.GetType().GetField(field);
|
||||||
|
if (f.GetValue(this) == null) continue;
|
||||||
byte[] data = Convert.FromBase64String(sb.ToString());
|
root.Add(field,new MiniYaml(FieldSaver.FormatValue(this,f),null));
|
||||||
List<byte[]> chunks = new List<byte[]>();
|
}
|
||||||
BinaryReader reader = new BinaryReader(new MemoryStream(data));
|
root.Add("Actors",MiniYaml.FromDictionary<string,ActorReference>(Actors));
|
||||||
|
root.Add("Waypoints",MiniYaml.FromDictionary<string,int2>(Waypoints));
|
||||||
try
|
|
||||||
{
|
// TODO: Players
|
||||||
while (true)
|
|
||||||
{
|
root.Add("Rules",new MiniYaml(null,Rules));
|
||||||
uint length = reader.ReadUInt32() & 0xdfffffff;
|
SaveBinaryData(Tiledata);
|
||||||
byte[] dest = new byte[8192];
|
root.WriteToFile(filepath);
|
||||||
byte[] src = reader.ReadBytes((int)length);
|
}
|
||||||
|
|
||||||
/*int actualLength =*/ Format80.DecodeInto(src, dest);
|
static byte ReadByte( Stream s )
|
||||||
|
{
|
||||||
chunks.Add(dest);
|
int ret = s.ReadByte();
|
||||||
}
|
if( ret == -1 )
|
||||||
}
|
throw new NotImplementedException();
|
||||||
catch (EndOfStreamException) { }
|
return (byte)ret;
|
||||||
|
}
|
||||||
MemoryStream ms = new MemoryStream();
|
|
||||||
foreach (byte[] chunk in chunks)
|
static ushort ReadWord(Stream s)
|
||||||
ms.Write(chunk, 0, chunk.Length);
|
{
|
||||||
|
ushort ret = ReadByte(s);
|
||||||
ms.Position = 0;
|
ret |= (ushort)(ReadByte(s) << 8);
|
||||||
|
|
||||||
return ms;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static byte ReadByte( Stream s )
|
public void LoadBinaryData(string filename)
|
||||||
{
|
{
|
||||||
int ret = s.ReadByte();
|
Console.Write("path: {0}",filename);
|
||||||
if( ret == -1 )
|
|
||||||
throw new NotImplementedException();
|
Stream dataStream = FileSystem.Open(filename);
|
||||||
return (byte)ret;
|
|
||||||
}
|
// Load header info
|
||||||
|
byte version = ReadByte(dataStream);
|
||||||
static ushort ReadWord(Stream s)
|
MapSize.X = ReadWord(dataStream);
|
||||||
{
|
MapSize.Y = ReadWord(dataStream);
|
||||||
ushort ret = ReadByte(s);
|
|
||||||
ret |= (ushort)(ReadByte(s) << 8);
|
MapTiles = new TileReference<ushort, byte>[ MapSize.X, MapSize.Y ];
|
||||||
|
MapResources = new TileReference<byte, byte>[ MapSize.X, MapSize.Y ];
|
||||||
return ret;
|
|
||||||
}
|
// Load tile data
|
||||||
|
for( int i = 0 ; i < MapSize.X ; i++ )
|
||||||
void UnpackRATileData( MemoryStream ms )
|
for( int j = 0 ; j < MapSize.Y ; j++ )
|
||||||
{
|
{
|
||||||
for( int i = 0 ; i < MapSize ; i++ )
|
ushort tile = ReadWord(dataStream);
|
||||||
for( int j = 0 ; j < MapSize ; j++ )
|
byte index = ReadByte(dataStream);
|
||||||
MapTiles[j, i].tile = ReadWord(ms);
|
byte image = (index == byte.MaxValue) ? (byte)( i % 4 + ( j % 4 ) * 4 ) : index;
|
||||||
|
MapTiles[i,j] = new TileReference<ushort,byte>(tile,index, image);
|
||||||
for( int i = 0 ; i < MapSize ; i++ )
|
}
|
||||||
for( int j = 0 ; j < MapSize ; j++ )
|
|
||||||
{
|
// Load resource data
|
||||||
MapTiles[j, i].image = (byte)ms.ReadByte();
|
for( int i = 0 ; i < MapSize.X ; i++ )
|
||||||
if( MapTiles[ j, i ].tile == 0xff || MapTiles[ j, i ].tile == 0xffff )
|
for( int j = 0 ; j < MapSize.Y ; j++ )
|
||||||
MapTiles[ j, i ].image = (byte)( i % 4 + ( j % 4 ) * 4 );
|
MapResources[i,j] = new TileReference<byte,byte>(ReadByte(dataStream),ReadByte(dataStream));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public void SaveBinaryData(string filepath)
|
||||||
static string[] raOverlayNames =
|
{
|
||||||
{
|
FileStream dataStream = new FileStream(filepath+".tmp", FileMode.Create, FileAccess.Write);
|
||||||
"sbag", "cycl", "brik", "fenc", "wood",
|
BinaryWriter writer = new BinaryWriter( dataStream );
|
||||||
"gold01", "gold02", "gold03", "gold04",
|
writer.BaseStream.Seek(0, SeekOrigin.Begin);
|
||||||
"gem01", "gem02", "gem03", "gem04",
|
|
||||||
"v12", "v13", "v14", "v15", "v16", "v17", "v18",
|
// File header consists of a version byte, followed by 2 ushorts for width and height
|
||||||
"fpls", "wcrate", "scrate", "barb", "sbag",
|
writer.Write(TileFormat);
|
||||||
};
|
writer.Write((ushort)MapSize.X);
|
||||||
|
writer.Write((ushort)MapSize.Y);
|
||||||
void UnpackRAOverlayData( MemoryStream ms )
|
|
||||||
{
|
// Tile data
|
||||||
for( int i = 0 ; i < MapSize ; i++ )
|
for( int i = 0 ; i < MapSize.X ; i++ )
|
||||||
for( int j = 0 ; j < MapSize ; j++ )
|
for( int j = 0 ; j < MapSize.Y ; j++ )
|
||||||
{
|
{
|
||||||
byte o = ReadByte( ms );
|
writer.Write( MapTiles[i,j].type );
|
||||||
MapTiles[ j, i ].overlay = (o == 255) ? null : raOverlayNames[o];
|
writer.Write( MapTiles[i,j].index );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// Resource data
|
||||||
void ReadRATrees( IniFile file )
|
for( int i = 0 ; i < MapSize.X ; i++ )
|
||||||
{
|
for( int j = 0 ; j < MapSize.Y ; j++ )
|
||||||
IniSection terrain = file.GetSection( "TERRAIN", true );
|
{
|
||||||
if( terrain == null )
|
writer.Write( MapResources[i,j].type );
|
||||||
return;
|
writer.Write( MapResources[i,j].index );
|
||||||
|
}
|
||||||
foreach( KeyValuePair<string, string> kv in terrain )
|
|
||||||
{
|
writer.Flush();
|
||||||
var loc = int.Parse( kv.Key );
|
writer.Close();
|
||||||
Actors.Add( new ActorReference(kv.Value, new int2(loc % MapSize, loc / MapSize), null ) );
|
File.Move(filepath+".tmp",filepath);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public bool IsInMap(int2 xy)
|
||||||
void UnpackCncTileData( Stream ms )
|
{
|
||||||
{
|
return IsInMap(xy.X,xy.Y);
|
||||||
for( int i = 0 ; i < MapSize ; i++ )
|
}
|
||||||
for( int j = 0 ; j < MapSize ; j++ )
|
|
||||||
{
|
public bool IsInMap(int x, int y)
|
||||||
MapTiles[j, i].tile = (byte)ms.ReadByte();
|
{
|
||||||
MapTiles[j, i].image = (byte)ms.ReadByte();
|
return (x >= TopLeft.X && y >= TopLeft.Y && x < BottomRight.X && y < BottomRight.Y);
|
||||||
|
}
|
||||||
if( MapTiles[ j, i ].tile == 0xff )
|
|
||||||
MapTiles[ j, i ].image = (byte)( i % 4 + ( j % 4 ) * 4 );
|
public void DebugContents()
|
||||||
}
|
{
|
||||||
}
|
foreach (var field in SimpleFields)
|
||||||
|
Console.WriteLine("Loaded {0}: {1}", field, this.GetType().GetField(field).GetValue(this));
|
||||||
void ReadCncOverlay( IniFile file )
|
|
||||||
{
|
Console.WriteLine("Loaded Waypoints:");
|
||||||
IniSection overlay = file.GetSection( "OVERLAY", true );
|
foreach (var wp in Waypoints)
|
||||||
if( overlay == null )
|
Console.WriteLine("\t{0} => {1}",wp.Key,wp.Value);
|
||||||
return;
|
|
||||||
|
Console.WriteLine("Loaded Actors:");
|
||||||
foreach( KeyValuePair<string, string> kv in overlay )
|
foreach (var wp in Actors)
|
||||||
{
|
Console.WriteLine("\t{0} => {1} {2} {3}",wp.Key,wp.Value.Name, wp.Value.Owner,wp.Value.Location);
|
||||||
var loc = int.Parse( kv.Key );
|
}
|
||||||
int2 cell = new int2(loc % MapSize, loc / MapSize);
|
}
|
||||||
MapTiles[ cell.X, cell.Y ].overlay = kv.Value.ToLower();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ReadCncTrees( IniFile file )
|
|
||||||
{
|
|
||||||
IniSection terrain = file.GetSection( "TERRAIN", true );
|
|
||||||
if( terrain == null )
|
|
||||||
return;
|
|
||||||
|
|
||||||
foreach( KeyValuePair<string, string> kv in terrain )
|
|
||||||
{
|
|
||||||
var loc = int.Parse( kv.Key );
|
|
||||||
Actors.Add( new ActorReference( kv.Value.Split(',')[0], new int2(loc % MapSize, loc / MapSize),null));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadActors(IniFile file, string section)
|
|
||||||
{
|
|
||||||
foreach (var s in file.GetSection(section, true))
|
|
||||||
{
|
|
||||||
//num=owner,type,health,location,facing,...
|
|
||||||
var parts = s.Value.Split( ',' );
|
|
||||||
var loc = int.Parse(parts[3]);
|
|
||||||
Actors.Add( new ActorReference( parts[1].ToLowerInvariant(), new int2(loc % MapSize, loc / MapSize), parts[0]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsInMap(int2 xy)
|
|
||||||
{
|
|
||||||
return IsInMap(xy.X,xy.Y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsInMap(int x, int y)
|
|
||||||
{
|
|
||||||
return (x >= XOffset && y >= YOffset && x < XOffset + Width && y < YOffset + Height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,229 +0,0 @@
|
|||||||
#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
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace OpenRA.FileFormats
|
|
||||||
{
|
|
||||||
public class Map
|
|
||||||
{
|
|
||||||
// Yaml map data
|
|
||||||
public int MapFormat = 1;
|
|
||||||
public string Title;
|
|
||||||
public string Description;
|
|
||||||
public string Author;
|
|
||||||
public int PlayerCount;
|
|
||||||
public string Preview;
|
|
||||||
public string Tileset;
|
|
||||||
|
|
||||||
public Dictionary<string, ActorReference> Actors = new Dictionary<string, ActorReference>();
|
|
||||||
public Dictionary<string, int2> Waypoints = new Dictionary<string, int2>();
|
|
||||||
public Dictionary<string, MiniYaml> Rules = new Dictionary<string, MiniYaml>();
|
|
||||||
|
|
||||||
// Binary map data
|
|
||||||
public string Tiledata;
|
|
||||||
public byte TileFormat = 1;
|
|
||||||
public int2 MapSize;
|
|
||||||
|
|
||||||
public int2 TopLeft;
|
|
||||||
public int2 BottomRight;
|
|
||||||
|
|
||||||
public TileReference<ushort,byte>[ , ] MapTiles;
|
|
||||||
public TileReference<byte, byte>[ , ] MapResources;
|
|
||||||
|
|
||||||
|
|
||||||
// Temporary compat hacks
|
|
||||||
public int XOffset {get {return TopLeft.X;}}
|
|
||||||
public int YOffset {get {return TopLeft.Y;}}
|
|
||||||
public int Width {get {return BottomRight.X-TopLeft.X;}}
|
|
||||||
public int Height {get {return BottomRight.Y-TopLeft.Y;}}
|
|
||||||
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", "MapSize", "TopLeft", "BottomRight"
|
|
||||||
};
|
|
||||||
|
|
||||||
public Map() {}
|
|
||||||
|
|
||||||
public Map(string filename)
|
|
||||||
{
|
|
||||||
var yaml = MiniYaml.FromFileInPackage(filename);
|
|
||||||
|
|
||||||
// 'Simple' metadata
|
|
||||||
foreach (var field in SimpleFields)
|
|
||||||
{
|
|
||||||
if (!yaml.ContainsKey(field)) continue;
|
|
||||||
FieldLoader.LoadField(this,field,yaml[field].Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Waypoints
|
|
||||||
foreach (var wp in yaml["Waypoints"].Nodes)
|
|
||||||
{
|
|
||||||
string[] loc = wp.Value.Value.Split(',');
|
|
||||||
Waypoints.Add(wp.Key, new int2(int.Parse(loc[0]),int.Parse(loc[1])));
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Players
|
|
||||||
|
|
||||||
// Actors
|
|
||||||
foreach (var kv in yaml["Actors"].Nodes.ToPairs())
|
|
||||||
{
|
|
||||||
string[] vals = kv.Second.Split(' ');
|
|
||||||
string[] loc = vals[2].Split(',');
|
|
||||||
var a = new ActorReference(vals[0], new int2(int.Parse(loc[0]),int.Parse(loc[1])) ,vals[1]);
|
|
||||||
Actors.Add(kv.First,a);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rules
|
|
||||||
Rules = yaml["Rules"].Nodes;
|
|
||||||
|
|
||||||
LoadBinaryData(Tiledata);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void Save(string filepath)
|
|
||||||
{
|
|
||||||
Dictionary<string, MiniYaml> root = new Dictionary<string, MiniYaml>();
|
|
||||||
var d = new Dictionary<string, MiniYaml>();
|
|
||||||
foreach (var field in SimpleFields)
|
|
||||||
{
|
|
||||||
FieldInfo f = this.GetType().GetField(field);
|
|
||||||
if (f.GetValue(this) == null) continue;
|
|
||||||
root.Add(field,new MiniYaml(FieldSaver.FormatValue(this,f),null));
|
|
||||||
}
|
|
||||||
root.Add("Actors",MiniYaml.FromDictionary<string,ActorReference>(Actors));
|
|
||||||
root.Add("Waypoints",MiniYaml.FromDictionary<string,int2>(Waypoints));
|
|
||||||
|
|
||||||
// TODO: Players
|
|
||||||
|
|
||||||
root.Add("Rules",new MiniYaml(null,Rules));
|
|
||||||
SaveBinaryData(Tiledata);
|
|
||||||
root.WriteToFile(filepath);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
MapSize.X = ReadWord(dataStream);
|
|
||||||
MapSize.Y = ReadWord(dataStream);
|
|
||||||
|
|
||||||
MapTiles = new TileReference<ushort, byte>[ MapSize.X, MapSize.Y ];
|
|
||||||
MapResources = new TileReference<byte, byte>[ MapSize.X, MapSize.Y ];
|
|
||||||
|
|
||||||
// Load tile data
|
|
||||||
for( int i = 0 ; i < MapSize.X ; i++ )
|
|
||||||
for( int j = 0 ; j < MapSize.Y ; j++ )
|
|
||||||
{
|
|
||||||
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 < MapSize.X ; i++ )
|
|
||||||
for( int j = 0 ; j < MapSize.Y ; j++ )
|
|
||||||
MapResources[i,j] = new TileReference<byte,byte>(ReadByte(dataStream),ReadByte(dataStream));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SaveBinaryData(string filepath)
|
|
||||||
{
|
|
||||||
FileStream dataStream = new FileStream(filepath+".tmp", FileMode.Create, FileAccess.Write);
|
|
||||||
BinaryWriter writer = new BinaryWriter( dataStream );
|
|
||||||
writer.BaseStream.Seek(0, SeekOrigin.Begin);
|
|
||||||
|
|
||||||
// File header consists of a version byte, followed by 2 ushorts for width and height
|
|
||||||
writer.Write(TileFormat);
|
|
||||||
writer.Write((ushort)MapSize.X);
|
|
||||||
writer.Write((ushort)MapSize.Y);
|
|
||||||
|
|
||||||
// Tile data
|
|
||||||
for( int i = 0 ; i < MapSize.X ; i++ )
|
|
||||||
for( int j = 0 ; j < MapSize.Y ; j++ )
|
|
||||||
{
|
|
||||||
writer.Write( MapTiles[i,j].type );
|
|
||||||
writer.Write( MapTiles[i,j].index );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resource data
|
|
||||||
for( int i = 0 ; i < MapSize.X ; i++ )
|
|
||||||
for( int j = 0 ; j < MapSize.Y ; j++ )
|
|
||||||
{
|
|
||||||
writer.Write( MapResources[i,j].type );
|
|
||||||
writer.Write( MapResources[i,j].index );
|
|
||||||
}
|
|
||||||
|
|
||||||
writer.Flush();
|
|
||||||
writer.Close();
|
|
||||||
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 >= TopLeft.X && y >= TopLeft.Y && x < BottomRight.X && y < BottomRight.Y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DebugContents()
|
|
||||||
{
|
|
||||||
foreach (var field in SimpleFields)
|
|
||||||
Console.WriteLine("Loaded {0}: {1}", field, this.GetType().GetField(field).GetValue(this));
|
|
||||||
|
|
||||||
Console.WriteLine("Loaded Waypoints:");
|
|
||||||
foreach (var wp in Waypoints)
|
|
||||||
Console.WriteLine("\t{0} => {1}",wp.Key,wp.Value);
|
|
||||||
|
|
||||||
Console.WriteLine("Loaded Actors:");
|
|
||||||
foreach (var wp in Actors)
|
|
||||||
Console.WriteLine("\t{0} => {1} {2} {3}",wp.Key,wp.Value.Name, wp.Value.Owner,wp.Value.Location);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
#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 TileReference<T, U>
|
|
||||||
{
|
|
||||||
public T type;
|
|
||||||
public U index;
|
|
||||||
public U image;
|
|
||||||
|
|
||||||
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(); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,44 +1,45 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||||
* This file is part of OpenRA.
|
* This file is part of OpenRA.
|
||||||
*
|
*
|
||||||
* OpenRA is free software: you can redistribute it and/or modify
|
* OpenRA is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* OpenRA is distributed in the hope that it will be useful,
|
* OpenRA is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace OpenRA.FileFormats
|
namespace OpenRA.FileFormats
|
||||||
{
|
{
|
||||||
public struct OldTileReference
|
public struct TileReference<T, U>
|
||||||
{
|
{
|
||||||
public ushort tile;
|
public T type;
|
||||||
public byte image;
|
public U index;
|
||||||
public string overlay;
|
public U image;
|
||||||
public byte smudge;
|
|
||||||
|
public TileReference(T t, U i)
|
||||||
public override int GetHashCode() { return tile.GetHashCode() ^ image.GetHashCode(); }
|
{
|
||||||
|
type = t;
|
||||||
public override bool Equals( object obj )
|
index = i;
|
||||||
{
|
image = i;
|
||||||
if( obj == null )
|
}
|
||||||
return false;
|
|
||||||
|
public TileReference(T t, U i, U im)
|
||||||
OldTileReference r = (OldTileReference)obj;
|
{
|
||||||
return ( r.image == image && r.tile == tile );
|
type = t;
|
||||||
}
|
index = i;
|
||||||
|
image = im;
|
||||||
public static bool operator ==( OldTileReference a, OldTileReference b ) { return a.Equals( b ); }
|
}
|
||||||
public static bool operator !=( OldTileReference a, OldTileReference b ) { return !a.Equals( b ); }
|
|
||||||
}
|
public override int GetHashCode() { return type.GetHashCode() ^ index.GetHashCode(); }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -79,7 +79,6 @@
|
|||||||
<Compile Include="TypeDictionary.cs" />
|
<Compile Include="TypeDictionary.cs" />
|
||||||
<Compile Include="Map\ActorReference.cs" />
|
<Compile Include="Map\ActorReference.cs" />
|
||||||
<Compile Include="Map\Map.cs" />
|
<Compile Include="Map\Map.cs" />
|
||||||
<Compile Include="Map\NewMap.cs" />
|
|
||||||
<Compile Include="Map\TileReference.cs" />
|
<Compile Include="Map\TileReference.cs" />
|
||||||
<Compile Include="Map\Walkability.cs" />
|
<Compile Include="Map\Walkability.cs" />
|
||||||
<Compile Include="Map\Terrain.cs" />
|
<Compile Include="Map\Terrain.cs" />
|
||||||
@@ -101,7 +100,6 @@
|
|||||||
<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" />
|
|
||||||
<Compile Include="Primitives\int2.cs" />
|
<Compile Include="Primitives\int2.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
|||||||
Reference in New Issue
Block a user