Remove Map.SpawnPoints.

This commit is contained in:
Paul Chote
2016-03-18 19:53:11 +00:00
parent 65df25b1a4
commit 4a7ef68b39
6 changed files with 36 additions and 35 deletions

View File

@@ -126,8 +126,6 @@ namespace OpenRA
/// </summary> /// </summary>
public WPos ProjectedBottomRight; public WPos ProjectedBottomRight;
public Lazy<CPos[]> SpawnPoints;
// Yaml map data // Yaml map data
[FieldLoader.Ignore] public readonly MiniYaml RuleDefinitions; [FieldLoader.Ignore] public readonly MiniYaml RuleDefinitions;
[FieldLoader.Ignore] public readonly MiniYaml SequenceDefinitions; [FieldLoader.Ignore] public readonly MiniYaml SequenceDefinitions;
@@ -203,8 +201,6 @@ namespace OpenRA
Tiles.Clear(tileRef); Tiles.Clear(tileRef);
SpawnPoints = Exts.Lazy(() => new CPos[0]);
PostInit(); PostInit();
} }
@@ -222,19 +218,6 @@ namespace OpenRA
if (MapFormat != SupportedMapFormat) if (MapFormat != SupportedMapFormat)
throw new InvalidDataException("Map format {0} is not supported.\n File: {1}".F(MapFormat, package.Name)); throw new InvalidDataException("Map format {0} is not supported.\n File: {1}".F(MapFormat, package.Name));
SpawnPoints = Exts.Lazy(() =>
{
var spawns = new List<CPos>();
foreach (var kv in ActorDefinitions.Where(d => d.Value.Value == "mpspawn"))
{
var s = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
spawns.Add(s.InitDict.Get<LocationInit>().Value(null));
}
return spawns.ToArray();
});
RuleDefinitions = LoadRuleSection(yaml, "Rules"); RuleDefinitions = LoadRuleSection(yaml, "Rules");
SequenceDefinitions = LoadRuleSection(yaml, "Sequences"); SequenceDefinitions = LoadRuleSection(yaml, "Sequences");
VoxelSequenceDefinitions = LoadRuleSection(yaml, "VoxelSequences"); VoxelSequenceDefinitions = LoadRuleSection(yaml, "VoxelSequences");

View File

@@ -10,6 +10,7 @@
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
using OpenRA.Traits; using OpenRA.Traits;
@@ -46,14 +47,18 @@ namespace OpenRA.Mods.Common.Lint
if (worldActor.HasTraitInfo<MPStartLocationsInfo>()) if (worldActor.HasTraitInfo<MPStartLocationsInfo>())
{ {
var multiPlayers = players.Count(p => p.Value.Playable); var playerCount = players.Count(p => p.Value.Playable);
var spawns = map.ActorDefinitions.Where(a => a.Value.Value == "mpspawn"); var spawns = new List<CPos>();
var spawnCount = spawns.Count(); foreach (var kv in map.ActorDefinitions.Where(d => d.Value.Value == "mpspawn"))
{
var s = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
spawns.Add(s.InitDict.Get<LocationInit>().Value(null));
}
if (multiPlayers > spawnCount) if (playerCount > spawns.Count)
emitError("The map allows {0} possible players, but defines only {1} spawn points".F(multiPlayers, spawnCount)); emitError("The map allows {0} possible players, but defines only {1} spawn points".F(playerCount, spawns.Count));
if (map.SpawnPoints.Value.Distinct().Count() != spawnCount) if (spawns.Distinct().Count() != spawns.Count)
emitError("Duplicate spawn point locations detected."); emitError("Duplicate spawn point locations detected.");
} }

View File

@@ -38,7 +38,10 @@ namespace OpenRA.Mods.Common.Traits
public void WorldLoaded(World world, WorldRenderer wr) public void WorldLoaded(World world, WorldRenderer wr)
{ {
var spawns = world.Map.SpawnPoints.Value; var spawns = world.Actors.Where(a => a.Info.Name == "mpspawn")
.Select(a => a.Location)
.ToArray();
var taken = world.LobbyInfo.Clients.Where(c => c.SpawnPoint != 0 && c.Slot != null) var taken = world.LobbyInfo.Clients.Where(c => c.SpawnPoint != 0 && c.Slot != null)
.Select(c => spawns[c.SpawnPoint - 1]).ToList(); .Select(c => spawns[c.SpawnPoint - 1]).ToList();
var available = spawns.Except(taken).ToList(); var available = spawns.Except(taken).ToList();

View File

@@ -35,6 +35,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
public Map Map; public Map Map;
public List<string> Players = new List<string>(); public List<string> Players = new List<string>();
public MapPlayers MapPlayers; public MapPlayers MapPlayers;
int spawnCount;
public bool ValidateArguments(string[] args) public bool ValidateArguments(string[] args)
{ {
@@ -81,12 +82,13 @@ namespace OpenRA.Mods.Common.UtilityCommands
LoadSmudges(file, "SMUDGE"); LoadSmudges(file, "SMUDGE");
var waypoints = file.GetSection("Waypoints"); var waypoints = file.GetSection("Waypoints");
LoadWaypoints(Map, waypoints, MapSize); LoadWaypoints(waypoints);
// Create default player definitions only if there are no players to import // Create default player definitions only if there are no players to import
MapPlayers = new MapPlayers(Map.Rules, (Players.Count == 0) ? Map.SpawnPoints.Value.Length : 0); MapPlayers = new MapPlayers(Map.Rules, Players.Count == 0 ? spawnCount : 0);
foreach (var p in Players) foreach (var p in Players)
LoadPlayer(file, p); LoadPlayer(file, p);
Map.PlayerDefinitions = MapPlayers.ToMiniYaml(); Map.PlayerDefinitions = MapPlayers.ToMiniYaml();
} }
@@ -235,13 +237,13 @@ namespace OpenRA.Mods.Common.UtilityCommands
return new int2(offset % mapSize, offset / mapSize); return new int2(offset % mapSize, offset / mapSize);
} }
static void LoadWaypoints(Map map, IniSection waypointSection, int mapSize) void LoadWaypoints(IniSection waypointSection)
{ {
var actorCount = map.ActorDefinitions.Count; var actorCount = Map.ActorDefinitions.Count;
var wps = waypointSection var wps = waypointSection
.Where(kv => Exts.ParseIntegerInvariant(kv.Value) > 0) .Where(kv => Exts.ParseIntegerInvariant(kv.Value) > 0)
.Select(kv => Pair.New(Exts.ParseIntegerInvariant(kv.Key), .Select(kv => Pair.New(Exts.ParseIntegerInvariant(kv.Key),
LocationFromMapOffset(Exts.ParseIntegerInvariant(kv.Value), mapSize))); LocationFromMapOffset(Exts.ParseIntegerInvariant(kv.Value), MapSize)));
// Add waypoint actors // Add waypoint actors
foreach (var kv in wps) foreach (var kv in wps)
@@ -254,7 +256,8 @@ namespace OpenRA.Mods.Common.UtilityCommands
new OwnerInit("Neutral") new OwnerInit("Neutral")
}; };
map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save())); Map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
spawnCount++;
} }
else else
{ {
@@ -264,7 +267,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
new OwnerInit("Neutral") new OwnerInit("Neutral")
}; };
map.ActorDefinitions.Add(new MiniYamlNode("waypoint" + kv.First, ar.Save())); Map.ActorDefinitions.Add(new MiniYamlNode("waypoint" + kv.First, ar.Save()));
} }
} }
} }

View File

@@ -62,7 +62,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var br = new PPos(width, height + maxTerrainHeight); var br = new PPos(width, height + maxTerrainHeight);
map.SetBounds(tl, br); map.SetBounds(tl, br);
map.PlayerDefinitions = new MapPlayers(map.Rules, map.SpawnPoints.Value.Length).ToMiniYaml(); map.PlayerDefinitions = new MapPlayers(map.Rules, 0).ToMiniYaml();
map.FixOpenAreas(); map.FixOpenAreas();
Action<string> afterSave = uid => Action<string> afterSave = uid =>

View File

@@ -263,6 +263,7 @@ namespace OpenRA.Mods.D2k.UtilityCommands
Size mapSize; Size mapSize;
TileSet tileSet; TileSet tileSet;
List<TerrainTemplateInfo> tileSetsFromYaml; List<TerrainTemplateInfo> tileSetsFromYaml;
int playerCount;
D2kMapImporter(string filename, string tileset, Ruleset rules) D2kMapImporter(string filename, string tileset, Ruleset rules)
{ {
@@ -293,13 +294,12 @@ namespace OpenRA.Mods.D2k.UtilityCommands
public static Map Import(string filename, string mod, string tileset, Ruleset rules) public static Map Import(string filename, string mod, string tileset, Ruleset rules)
{ {
var map = new D2kMapImporter(filename, tileset, rules).map; var importer = new D2kMapImporter(filename, tileset, rules);
var map = importer.map;
if (map == null) if (map == null)
return null; return null;
map.RequiresMod = mod; map.RequiresMod = mod;
var players = new MapPlayers(map.Rules, map.SpawnPoints.Value.Length);
map.PlayerDefinitions = players.ToMiniYaml();
return map; return map;
} }
@@ -324,6 +324,9 @@ namespace OpenRA.Mods.D2k.UtilityCommands
// Each frame is a tile from the Dune 2000 tileset files, with the Frame ID being the index of the tile in the original file // Each frame is a tile from the Dune 2000 tileset files, with the Frame ID being the index of the tile in the original file
tileSetsFromYaml = tileSet.Templates.Where(t => t.Value.Frames != null tileSetsFromYaml = tileSet.Templates.Where(t => t.Value.Frames != null
&& t.Value.Images[0].ToLower() == tilesetName.ToLower()).Select(ts => ts.Value).ToList(); && t.Value.Images[0].ToLower() == tilesetName.ToLower()).Select(ts => ts.Value).ToList();
var players = new MapPlayers(map.Rules, playerCount);
map.PlayerDefinitions = players.ToMiniYaml();
} }
void FillMap() void FillMap()
@@ -356,7 +359,11 @@ namespace OpenRA.Mods.D2k.UtilityCommands
new LocationInit(locationOnMap), new LocationInit(locationOnMap),
new OwnerInit(kvp.Second) new OwnerInit(kvp.Second)
}; };
map.ActorDefinitions.Add(new MiniYamlNode("Actor" + map.ActorDefinitions.Count, a.Save())); map.ActorDefinitions.Add(new MiniYamlNode("Actor" + map.ActorDefinitions.Count, a.Save()));
if (kvp.First == "mpspawn")
playerCount++;
} }
} }
} }