Fix maps without spawn points no longer working
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<int> 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)
|
||||
|
||||
Reference in New Issue
Block a user