diff --git a/OpenRA.FileFormats/TreeReference.cs b/OpenRA.FileFormats/ActorReference.cs similarity index 71% rename from OpenRA.FileFormats/TreeReference.cs rename to OpenRA.FileFormats/ActorReference.cs index 8b54830d19..42a2afd3d0 100644 --- a/OpenRA.FileFormats/TreeReference.cs +++ b/OpenRA.FileFormats/ActorReference.cs @@ -18,23 +18,18 @@ */ #endregion -using System.Drawing; - namespace OpenRA.FileFormats { - public struct TreeReference + public struct ActorReference { - public readonly int X; - public readonly int Y; - public readonly string Image; - - public TreeReference(int xy, string image, int mapSize) + public readonly int2 Location; + public readonly string Name; + public readonly string Owner; + public ActorReference( string name, int2 location, string owner ) { - X = xy % mapSize; - Y = xy / mapSize; - Image = image; + Name = name; + Location = location; + Owner = owner; } - - public Point Location { get { return new Point(X, Y); } } } } diff --git a/OpenRA.FileFormats/Map.cs b/OpenRA.FileFormats/Map.cs index d42d60ea88..d9b0e3d0c3 100644 --- a/OpenRA.FileFormats/Map.cs +++ b/OpenRA.FileFormats/Map.cs @@ -42,7 +42,7 @@ namespace OpenRA.FileFormats public int2 Size { get { return new int2(Width, Height); } } public readonly TileReference[ , ] MapTiles; - public readonly List Trees = new List(); + public readonly List Actors = new List(); public readonly IEnumerable SpawnPoints; @@ -54,9 +54,7 @@ namespace OpenRA.FileFormats public string TileSuffix { get { return "." + Truncate(Theater, 3); } } public Map(IniFile file) - { - - + { IniSection basic = file.GetSection("Basic"); Title = basic.GetValue("Name", "(null)"); BinaryPart = basic.GetValue("BinaryPart", "scm02ea.bin"); @@ -71,7 +69,7 @@ namespace OpenRA.FileFormats if (false) // RA map { - MapSize = 128; + MapSize = 128; } else { @@ -88,8 +86,7 @@ namespace OpenRA.FileFormats { UnpackTileData(ReadPackedSection(file.GetSection("MapPack"))); UnpackOverlayData(ReadPackedSection(file.GetSection("OverlayPack"))); - ReadTrees(file); - + ReadRATrees(file); } else // CNC { @@ -97,6 +94,10 @@ namespace OpenRA.FileFormats ReadCncTrees(file); } + LoadActors(file, "STRUCTURES"); + LoadActors(file, "UNITS"); + LoadActors(file, "INFANTRY"); + SpawnPoints = file.GetSection("Waypoints") .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) @@ -195,14 +196,17 @@ namespace OpenRA.FileFormats MapTiles[ j, i ].overlay = ReadByte( ms ); } - void ReadTrees( IniFile file ) + void ReadRATrees( IniFile file ) { IniSection terrain = file.GetSection( "TERRAIN", true ); if( terrain == null ) return; - + foreach( KeyValuePair kv in terrain ) - Trees.Add( new TreeReference( int.Parse( kv.Key ), kv.Value, MapSize ) ); + { + var loc = int.Parse( kv.Key ); + Actors.Add( new ActorReference(kv.Value, new int2(loc % MapSize, loc / MapSize), null ) ); + } } void ReadCncTrees( IniFile file ) @@ -212,8 +216,21 @@ namespace OpenRA.FileFormats return; foreach( KeyValuePair kv in terrain ) - // HACK: remove the ,none from the end - Trees.Add( new TreeReference( int.Parse( kv.Key ), kv.Value.Substring(0,kv.Value.Length-5), MapSize ) ); + { + var loc = int.Parse( kv.Key ); + Actors.Add( new ActorReference( kv.Value.Substring(0,kv.Value.Length-5), 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(int x, int y) diff --git a/OpenRA.FileFormats/OpenRA.FileFormats.csproj b/OpenRA.FileFormats/OpenRA.FileFormats.csproj index 893ee21c9c..3a83b0f9c9 100644 --- a/OpenRA.FileFormats/OpenRA.FileFormats.csproj +++ b/OpenRA.FileFormats/OpenRA.FileFormats.csproj @@ -1,4 +1,4 @@ - + Debug @@ -90,10 +90,10 @@ - + + + + + + + @@ -21,6 +27,8 @@ + + @@ -105,6 +113,8 @@ + + @@ -183,10 +193,4 @@ - - - - - - \ No newline at end of file