Fix Map.GetSpawnPoints to return CPos.

This commit is contained in:
Paul Chote
2014-03-14 20:42:44 +13:00
parent 3392d00294
commit 63068d5a7c
4 changed files with 10 additions and 9 deletions

View File

@@ -228,12 +228,12 @@ namespace OpenRA
Uid = ComputeHash(); Uid = ComputeHash();
} }
public int2[] GetSpawnPoints() public CPos[] GetSpawnPoints()
{ {
return Actors.Value.Values return Actors.Value.Values
.Where(a => a.Type == "mpspawn") .Where(a => a.Type == "mpspawn")
.Select(a => a.InitDict.Get<LocationInit>().value) .Select(a => (CPos)a.InitDict.Get<LocationInit>().value)
.ToArray(); .ToArray();
} }
public void Save(string toPath) public void Save(string toPath)

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Widgets
public class MapPreviewWidget : Widget public class MapPreviewWidget : Widget
{ {
public Func<Map> Map = () => null; public Func<Map> Map = () => null;
public Func<Dictionary<int2, Session.Client>> SpawnClients = () => new Dictionary<int2, Session.Client>(); public Func<Dictionary<CPos, Session.Client>> SpawnClients = () => new Dictionary<CPos, Session.Client>();
public Action<MouseInput> OnMouseDown = _ => {}; public Action<MouseInput> OnMouseDown = _ => {};
public bool IgnoreMouseInput = false; public bool IgnoreMouseInput = false;
public bool ShowSpawnPoints = true; public bool ShowSpawnPoints = true;
@@ -75,7 +75,7 @@ namespace OpenRA.Widgets
tooltipContainer.Value.RemoveTooltip(); tooltipContainer.Value.RemoveTooltip();
} }
public int2 ConvertToPreview(int2 point) public int2 ConvertToPreview(CPos point)
{ {
var map = Map(); var map = Map();
return new int2(MapRect.X + (int)(PreviewScale*(point.X - map.Bounds.Left)) , MapRect.Y + (int)(PreviewScale*(point.Y - map.Bounds.Top))); return new int2(MapRect.X + (int)(PreviewScale*(point.X - map.Bounds.Left)) , MapRect.Y + (int)(PreviewScale*(point.Y - map.Bounds.Top)));

View File

@@ -28,9 +28,10 @@ namespace OpenRA.Mods.RA
public void WorldLoaded(World world, WorldRenderer wr) public void WorldLoaded(World world, WorldRenderer wr)
{ {
var spawns = world.Map.GetSpawnPoints();
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 => (CPos) world.Map.GetSpawnPoints()[c.SpawnPoint-1]).ToList(); .Select(c => spawns[c.SpawnPoint-1]).ToList();
var available = world.Map.GetSpawnPoints().Select(c => (CPos)c).Except(taken).ToList(); var available = spawns.Except(taken).ToList();
// Set spawn // Set spawn
foreach (var kv in world.LobbyInfo.Slots) foreach (var kv in world.LobbyInfo.Slots)
@@ -41,7 +42,7 @@ namespace OpenRA.Mods.RA
var client = world.LobbyInfo.ClientInSlot(kv.Key); var client = world.LobbyInfo.ClientInSlot(kv.Key);
var spid = (client == null || client.SpawnPoint == 0) var spid = (client == null || client.SpawnPoint == 0)
? ChooseSpawnPoint(world, available, taken) ? ChooseSpawnPoint(world, available, taken)
: (CPos)world.Map.GetSpawnPoints()[client.SpawnPoint-1]; : world.Map.GetSpawnPoints()[client.SpawnPoint-1];
Start.Add(player, spid); Start.Add(player, spid);
} }

View File

@@ -130,7 +130,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
color.AttachPanel(colorChooser, onExit); color.AttachPanel(colorChooser, onExit);
} }
public static Dictionary<int2, Session.Client> GetSpawnClients(OrderManager orderManager, Map map) public static Dictionary<CPos, Session.Client> GetSpawnClients(OrderManager orderManager, Map map)
{ {
var spawns = map.GetSpawnPoints(); var spawns = map.GetSpawnPoints();
return orderManager.LobbyInfo.Clients return orderManager.LobbyInfo.Clients