Ignore spectators when counting clients for the assignteams command

This commit is contained in:
Scott_NZ
2013-03-11 01:20:08 +13:00
parent 7af91f1747
commit bd292b56cf
2 changed files with 15 additions and 10 deletions

View File

@@ -335,25 +335,30 @@ namespace OpenRA.Mods.RA.Server
} }
teams = teams.Clamp(2, 8); teams = teams.Clamp(2, 8);
var clients = server.lobbyInfo.Slots var players = server.lobbyInfo.Slots
.Select(slot => server.lobbyInfo.Clients.SingleOrDefault(c => c.Slot == slot.Key)) .Select(slot => server.lobbyInfo.Clients.SingleOrDefault(c => c.Slot == slot.Key))
.Where(c => c != null && !server.lobbyInfo.Slots[c.Slot].LockTeam).ToArray(); .Where(c => c != null && !server.lobbyInfo.Slots[c.Slot].LockTeam).ToArray();
if (clients.Length < 2) if (players.Length < 2)
{ {
server.SendChatTo(conn, "Not enough clients to assign teams"); server.SendChatTo(conn, "Not enough players to assign teams");
return true;
}
if (teams > players.Length)
{
server.SendChatTo(conn, "Too many teams for the number of players");
return true; return true;
} }
var teamSizes = new int[clients.Length]; var teamSizes = new int[players.Length];
for (var i = 0; i < clients.Length; i++) for (var i = 0; i < players.Length; i++)
teamSizes[i % teams]++; teamSizes[i % teams]++;
var clientIndex = 0; var playerIndex = 0;
for (var team = 1; team <= teams; team++) for (var team = 1; team <= teams; team++)
{ {
for (var teamClientIndex = 0; teamClientIndex < teamSizes[team - 1]; clientIndex++, teamClientIndex++) for (var teamPlayerIndex = 0; teamPlayerIndex < teamSizes[team - 1]; playerIndex++, teamPlayerIndex++)
{ {
var cl = clients[clientIndex]; var cl = players[playerIndex];
if (cl.Bot == null) if (cl.Bot == null)
cl.State = Session.ClientState.NotReady; cl.State = Session.ClientState.NotReady;
cl.Team = team; cl.Team = team;

View File

@@ -163,12 +163,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic
if (assignTeams != null) if (assignTeams != null)
{ {
assignTeams.IsVisible = () => Game.IsHost; assignTeams.IsVisible = () => Game.IsHost;
assignTeams.IsDisabled = () => gameStarting || orderManager.LobbyInfo.Clients.Count < 2 assignTeams.IsDisabled = () => gameStarting || orderManager.LobbyInfo.Clients.Count(c => c.Slot != null) < 2
|| orderManager.LocalClient == null || orderManager.LocalClient.IsReady; || orderManager.LocalClient == null || orderManager.LocalClient.IsReady;
assignTeams.OnMouseDown = _ => assignTeams.OnMouseDown = _ =>
{ {
var options = Enumerable.Range(2, orderManager.LobbyInfo.Clients.Count.Clamp(2, 8) - 1).Select(d => new DropDownOption var options = Enumerable.Range(2, orderManager.LobbyInfo.Clients.Count(c => c.Slot != null).Clamp(2, 8) - 1).Select(d => new DropDownOption
{ {
Title = "{0} Teams".F(d), Title = "{0} Teams".F(d),
IsSelected = () => false, IsSelected = () => false,