diff --git a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs index afdda0b8f2..7abbe924c3 100644 --- a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs +++ b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs @@ -13,6 +13,7 @@ using System; using System.Collections.Generic; using System.Linq; using OpenRA.Mods.Common.Traits; +using OpenRA.Mods.Common.Widgets.Logic; using OpenRA.Network; using OpenRA.Primitives; using OpenRA.Server; @@ -124,9 +125,7 @@ namespace OpenRA.Mods.Common.Server if (server.LobbyInfo.Slots.Any(sl => sl.Value.Required && server.LobbyInfo.ClientInSlot(sl.Key) == null)) return; - // Can't have insufficient spawns - var availableSpawnPointCount = server.Map.SpawnPoints.Length - server.LobbyInfo.DisabledSpawnPoints.Count; - if (availableSpawnPointCount < server.LobbyInfo.Clients.Count(c => !c.IsObserver)) + if (LobbyUtils.InsufficientEnabledSpawnPoints(server.Map, server.LobbyInfo)) return; server.StartGame(); @@ -176,8 +175,7 @@ namespace OpenRA.Mods.Common.Server return true; } - var availableSpawnPointCount = server.Map.SpawnPoints.Length - server.LobbyInfo.DisabledSpawnPoints.Count; - if (availableSpawnPointCount < server.LobbyInfo.Clients.Count(c => !c.IsObserver)) + if (LobbyUtils.InsufficientEnabledSpawnPoints(server.Map, server.LobbyInfo)) { server.SendOrderTo(conn, "Message", "Unable to start the game until more spawn points are enabled."); return true; diff --git a/OpenRA.Mods.Common/Traits/World/MPStartLocations.cs b/OpenRA.Mods.Common/Traits/World/MPStartLocations.cs index 7044ee3aed..0308605b65 100644 --- a/OpenRA.Mods.Common/Traits/World/MPStartLocations.cs +++ b/OpenRA.Mods.Common/Traits/World/MPStartLocations.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; +using OpenRA.Mods.Common.Widgets.Logic; using OpenRA.Network; using OpenRA.Support; using OpenRA.Traits; @@ -70,7 +71,7 @@ namespace OpenRA.Mods.Common.Traits // Initialize the list of unoccupied spawn points for AssignSpawnLocations to pick from state.SpawnLocations = map.SpawnPoints; - state.AvailableSpawnPoints = Enumerable.Range(1, map.SpawnPoints.Length).Except(lobbyInfo.DisabledSpawnPoints).ToList(); + state.AvailableSpawnPoints = LobbyUtils.AvailableSpawnPoints(map.SpawnPoints.Length, lobbyInfo); foreach (var kv in lobbyInfo.Slots) { var client = lobbyInfo.ClientInSlot(kv.Key); @@ -130,7 +131,7 @@ namespace OpenRA.Mods.Common.Traits spawnLocations = spawns.ToArray(); // Initialize the list of unoccupied spawn points for AssignSpawnLocations to pick from - availableSpawnPoints = Enumerable.Range(1, spawnLocations.Length).Except(self.World.LobbyInfo.DisabledSpawnPoints).ToList(); + availableSpawnPoints = LobbyUtils.AvailableSpawnPoints(spawnLocations.Length, self.World.LobbyInfo); foreach (var kv in self.World.LobbyInfo.Slots) { var client = self.World.LobbyInfo.ClientInSlot(kv.Key); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index 1c137bc4e6..46d05d2373 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -573,8 +573,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic c.Bot == null && c.Team == orderManager.LocalClient.Team); - var availableSpawnPointCount = map.SpawnPoints.Length - orderManager.LobbyInfo.DisabledSpawnPoints.Count; - insufficientPlayerSpawns = availableSpawnPointCount < orderManager.LobbyInfo.Clients.Count(c => !c.IsObserver); + insufficientPlayerSpawns = LobbyUtils.InsufficientEnabledSpawnPoints(map, orderManager.LobbyInfo); if (disableTeamChat) teamChat = false; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs index 4bba88bc68..685166426e 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs @@ -273,6 +273,21 @@ namespace OpenRA.Mods.Common.Widgets.Logic orderManager.IssueOrder(Order.Command("spawn {0} {1}".F((playerToMove ?? orderManager.LocalClient).Index, selectedSpawnPoint))); } + public static List AvailableSpawnPoints(int spawnPoints, Session lobbyInfo) + { + return Enumerable.Range(1, spawnPoints).Except(lobbyInfo.DisabledSpawnPoints).ToList(); + } + + public static bool InsufficientEnabledSpawnPoints(MapPreview map, Session lobbyInfo) + { + // If a map doesn't define spawn points we always have enough space + var spawnPoints = map.SpawnPoints.Length; + if (spawnPoints == 0) + return false; + + return AvailableSpawnPoints(spawnPoints, lobbyInfo).Count < lobbyInfo.Clients.Count(c => !c.IsObserver); + } + public static Color LatencyColor(Session.ClientPing ping) { if (ping == null)