Fix Waypoint == Startpoint assumption in MapFormat 5.

This commit is contained in:
Paul Chote
2011-02-11 10:20:55 +13:00
parent 8844ca0fdd
commit 6ef330c357
4 changed files with 31 additions and 11 deletions

View File

@@ -264,7 +264,6 @@ namespace OpenRA.Editor
SaveAsClicked(sender, e); SaveAsClicked(sender, e);
else else
{ {
surface1.Map.PlayerCount = surface1.Map.Waypoints.Count;
surface1.Map.Save(loadedMapName); surface1.Map.Save(loadedMapName);
dirty = false; dirty = false;
} }

View File

@@ -163,8 +163,6 @@ namespace OpenRA.Editor
LocationFromMapOffset(int.Parse(kv.Value), MapSize))) LocationFromMapOffset(int.Parse(kv.Value), MapSize)))
.ToArray(); .ToArray();
Map.PlayerCount = wp.Count();
foreach (var kv in wp) foreach (var kv in wp)
Map.Waypoints.Add("spawn" + kv.First, kv.Second); Map.Waypoints.Add("spawn" + kv.First, kv.Second);
} }

View File

@@ -23,6 +23,7 @@ namespace OpenRA.FileFormats
// Yaml map data // Yaml map data
public string Uid { get; protected set; } public string Uid { get; protected set; }
[FieldLoader.Load] public int MapFormat;
[FieldLoader.Load] public bool Selectable; [FieldLoader.Load] public bool Selectable;
[FieldLoader.Load] public bool UseAsShellmap; [FieldLoader.Load] public bool UseAsShellmap;
[FieldLoader.Load] public string RequiresMod; [FieldLoader.Load] public string RequiresMod;
@@ -31,12 +32,15 @@ namespace OpenRA.FileFormats
[FieldLoader.Load] public string Type = "Conquest"; [FieldLoader.Load] public string Type = "Conquest";
[FieldLoader.Load] public string Description; [FieldLoader.Load] public string Description;
[FieldLoader.Load] public string Author; [FieldLoader.Load] public string Author;
[FieldLoader.Load] public int PlayerCount;
[FieldLoader.Load] public string Tileset; [FieldLoader.Load] public string Tileset;
[FieldLoader.Load] public string[] StartPoints;
public int PlayerCount { get { return StartPoints.Count(); } }
[FieldLoader.LoadUsing( "LoadWaypoints" )] [FieldLoader.LoadUsing( "LoadWaypoints" )]
public Dictionary<string, int2> Waypoints = new Dictionary<string, int2>(); public Dictionary<string, int2> Waypoints = new Dictionary<string, int2>();
public IEnumerable<int2> SpawnPoints { get { return Waypoints.Select(kv => kv.Value); } }
public IEnumerable<int2> SpawnPoints{ get { return Waypoints.Where(kv => StartPoints.Contains(kv.Key)).Select(kv => kv.Value); } }
[FieldLoader.Load] public int2 TopLeft; [FieldLoader.Load] public int2 TopLeft;
[FieldLoader.Load] public int2 BottomRight; [FieldLoader.Load] public int2 BottomRight;
@@ -53,6 +57,10 @@ namespace OpenRA.FileFormats
Bounds = Rectangle.FromLTRB(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y); Bounds = Rectangle.FromLTRB(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y);
Uid = ComputeHash(); Uid = ComputeHash();
// Upgrade maps to define StartPoints
if (MapFormat < 5)
StartPoints = Waypoints.Select(kv => kv.Key).ToArray();
} }
string ComputeHash() string ComputeHash()
@@ -75,6 +83,7 @@ namespace OpenRA.FileFormats
string[] loc = wp.Value.Value.Split( ',' ); string[] loc = wp.Value.Value.Split( ',' );
ret.Add( wp.Key, new int2( int.Parse( loc[ 0 ] ), int.Parse( loc[ 1 ] ) ) ); ret.Add( wp.Key, new int2( int.Parse( loc[ 0 ] ), int.Parse( loc[ 1 ] ) ) );
} }
return ret; return ret;
} }
} }

View File

@@ -23,8 +23,6 @@ namespace OpenRA
public class Map : MapStub public class Map : MapStub
{ {
// Yaml map data // Yaml map data
[FieldLoader.Load] public int MapFormat;
public Dictionary<string, PlayerReference> Players = new Dictionary<string, PlayerReference>(); public Dictionary<string, PlayerReference> Players = new Dictionary<string, PlayerReference>();
public Dictionary<string, ActorReference> Actors = new Dictionary<string, ActorReference>(); public Dictionary<string, ActorReference> Actors = new Dictionary<string, ActorReference>();
public List<SmudgeReference> Smudges = new List<SmudgeReference>(); public List<SmudgeReference> Smudges = new List<SmudgeReference>();
@@ -63,7 +61,6 @@ namespace OpenRA
Description = "Describe your map here", Description = "Describe your map here",
Author = "Your name here", Author = "Your name here",
MapSize = new int2(1, 1), MapSize = new int2(1, 1),
PlayerCount = 0,
Tileset = tileset, Tileset = tileset,
MapResources = new TileReference<byte, byte>[1, 1], MapResources = new TileReference<byte, byte>[1, 1],
MapTiles = new TileReference<ushort, byte>[1, 1] MapTiles = new TileReference<ushort, byte>[1, 1]
@@ -229,7 +226,24 @@ namespace OpenRA
MapFormat = 5; MapFormat = 5;
var root = new List<MiniYamlNode>(); var root = new List<MiniYamlNode>();
foreach (var field in new string[] {"Selectable", "MapFormat", "RequiresMod", "Title", "Description", "Author", "PlayerCount", "Tileset", "MapSize", "TopLeft", "BottomRight", "UseAsShellmap", "Type"}) var fields = new string[]
{
"Selectable",
"MapFormat",
"RequiresMod",
"Title",
"Description",
"Author",
"Tileset",
"MapSize",
"TopLeft",
"BottomRight",
"UseAsShellmap",
"Type",
"StartPoints"
};
foreach (var field in fields)
{ {
var f = this.GetType().GetField(field); var f = this.GetType().GetField(field);
if (f.GetValue(this) == null) continue; if (f.GetValue(this) == null) continue;