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.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
|
using OpenRA.Mods.Common.Widgets.Logic;
|
||||||
using OpenRA.Network;
|
using OpenRA.Network;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Server;
|
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))
|
if (server.LobbyInfo.Slots.Any(sl => sl.Value.Required && server.LobbyInfo.ClientInSlot(sl.Key) == null))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Can't have insufficient spawns
|
if (LobbyUtils.InsufficientEnabledSpawnPoints(server.Map, server.LobbyInfo))
|
||||||
var availableSpawnPointCount = server.Map.SpawnPoints.Length - server.LobbyInfo.DisabledSpawnPoints.Count;
|
|
||||||
if (availableSpawnPointCount < server.LobbyInfo.Clients.Count(c => !c.IsObserver))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
server.StartGame();
|
server.StartGame();
|
||||||
@@ -176,8 +175,7 @@ namespace OpenRA.Mods.Common.Server
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var availableSpawnPointCount = server.Map.SpawnPoints.Length - server.LobbyInfo.DisabledSpawnPoints.Count;
|
if (LobbyUtils.InsufficientEnabledSpawnPoints(server.Map, server.LobbyInfo))
|
||||||
if (availableSpawnPointCount < server.LobbyInfo.Clients.Count(c => !c.IsObserver))
|
|
||||||
{
|
{
|
||||||
server.SendOrderTo(conn, "Message", "Unable to start the game until more spawn points are enabled.");
|
server.SendOrderTo(conn, "Message", "Unable to start the game until more spawn points are enabled.");
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Mods.Common.Widgets.Logic;
|
||||||
using OpenRA.Network;
|
using OpenRA.Network;
|
||||||
using OpenRA.Support;
|
using OpenRA.Support;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
@@ -70,7 +71,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
// Initialize the list of unoccupied spawn points for AssignSpawnLocations to pick from
|
// Initialize the list of unoccupied spawn points for AssignSpawnLocations to pick from
|
||||||
state.SpawnLocations = map.SpawnPoints;
|
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)
|
foreach (var kv in lobbyInfo.Slots)
|
||||||
{
|
{
|
||||||
var client = lobbyInfo.ClientInSlot(kv.Key);
|
var client = lobbyInfo.ClientInSlot(kv.Key);
|
||||||
@@ -130,7 +131,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
spawnLocations = spawns.ToArray();
|
spawnLocations = spawns.ToArray();
|
||||||
|
|
||||||
// Initialize the list of unoccupied spawn points for AssignSpawnLocations to pick from
|
// 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)
|
foreach (var kv in self.World.LobbyInfo.Slots)
|
||||||
{
|
{
|
||||||
var client = self.World.LobbyInfo.ClientInSlot(kv.Key);
|
var client = self.World.LobbyInfo.ClientInSlot(kv.Key);
|
||||||
|
|||||||
@@ -573,8 +573,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
c.Bot == null &&
|
c.Bot == null &&
|
||||||
c.Team == orderManager.LocalClient.Team);
|
c.Team == orderManager.LocalClient.Team);
|
||||||
|
|
||||||
var availableSpawnPointCount = map.SpawnPoints.Length - orderManager.LobbyInfo.DisabledSpawnPoints.Count;
|
insufficientPlayerSpawns = LobbyUtils.InsufficientEnabledSpawnPoints(map, orderManager.LobbyInfo);
|
||||||
insufficientPlayerSpawns = availableSpawnPointCount < orderManager.LobbyInfo.Clients.Count(c => !c.IsObserver);
|
|
||||||
|
|
||||||
if (disableTeamChat)
|
if (disableTeamChat)
|
||||||
teamChat = false;
|
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)));
|
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)
|
public static Color LatencyColor(Session.ClientPing ping)
|
||||||
{
|
{
|
||||||
if (ping == null)
|
if (ping == null)
|
||||||
|
|||||||
Reference in New Issue
Block a user