Fix IsSinglePlayer
This commit is contained in:
@@ -90,9 +90,14 @@ namespace OpenRA.Network
|
|||||||
return Slots.FirstOrDefault(s => !s.Value.Closed && ClientInSlot(s.Key) == null && s.Value.AllowBots).Key;
|
return Slots.FirstOrDefault(s => !s.Value.Closed && ClientInSlot(s.Key) == null && s.Value.AllowBots).Key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsSinglePlayer
|
public IEnumerable<Client> NonBotClients
|
||||||
{
|
{
|
||||||
get { return Clients.Count(c => c.Bot == null) == 1; }
|
get { return Clients.Where(c => c.Bot == null); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Client> NonBotPlayers
|
||||||
|
{
|
||||||
|
get { return Clients.Where(c => c.Bot == null && c.Slot != null); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ClientState { NotReady, Invalid, Ready, Disconnected = 1000 }
|
public enum ClientState { NotReady, Invalid, Ready, Disconnected = 1000 }
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ namespace OpenRA.Network
|
|||||||
if (client != null)
|
if (client != null)
|
||||||
{
|
{
|
||||||
var pause = order.TargetString == "Pause";
|
var pause = order.TargetString == "Pause";
|
||||||
if (orderManager.World.Paused != pause && world != null && !world.LobbyInfo.IsSinglePlayer)
|
if (orderManager.World.Paused != pause && world != null && world.LobbyInfo.NonBotClients.Count() > 1)
|
||||||
{
|
{
|
||||||
var pausetext = "The game is {0} by {1}".F(pause ? "paused" : "un-paused", client.Name);
|
var pausetext = "The game is {0} by {1}".F(pause ? "paused" : "un-paused", client.Name);
|
||||||
Game.AddChatLine(Color.White, ServerChatName, pausetext);
|
Game.AddChatLine(Color.White, ServerChatName, pausetext);
|
||||||
|
|||||||
@@ -375,7 +375,7 @@ namespace OpenRA.Server
|
|||||||
Log.Write("server", "{0} ({1}) has joined the game.",
|
Log.Write("server", "{0} ({1}) has joined the game.",
|
||||||
client.Name, newConn.Socket.RemoteEndPoint);
|
client.Name, newConn.Socket.RemoteEndPoint);
|
||||||
|
|
||||||
if (Dedicated || !LobbyInfo.IsSinglePlayer)
|
if (LobbyInfo.NonBotClients.Count() > 1)
|
||||||
SendMessage("{0} has joined the game.".F(client.Name));
|
SendMessage("{0} has joined the game.".F(client.Name));
|
||||||
|
|
||||||
// Send initial ping
|
// Send initial ping
|
||||||
@@ -392,7 +392,7 @@ namespace OpenRA.Server
|
|||||||
SendOrderTo(newConn, "Message", motd);
|
SendOrderTo(newConn, "Message", motd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!LobbyInfo.IsSinglePlayer && Map.DefinesUnsafeCustomRules)
|
if (Map.DefinesUnsafeCustomRules)
|
||||||
SendOrderTo(newConn, "Message", "This map contains custom rules. Game experience may change.");
|
SendOrderTo(newConn, "Message", "This map contains custom rules. Game experience may change.");
|
||||||
|
|
||||||
if (!LobbyInfo.GlobalSettings.EnableSingleplayer)
|
if (!LobbyInfo.GlobalSettings.EnableSingleplayer)
|
||||||
@@ -679,7 +679,7 @@ namespace OpenRA.Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HACK: Turn down the latency if there is only one real player
|
// HACK: Turn down the latency if there is only one real player
|
||||||
if (LobbyInfo.IsSinglePlayer)
|
if (LobbyInfo.NonBotClients.Count() == 1)
|
||||||
LobbyInfo.GlobalSettings.OrderLatency = 1;
|
LobbyInfo.GlobalSettings.OrderLatency = 1;
|
||||||
|
|
||||||
SyncLobbyInfo();
|
SyncLobbyInfo();
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace OpenRA.Traits
|
namespace OpenRA.Traits
|
||||||
{
|
{
|
||||||
@@ -113,7 +114,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
void INotifyCreated.Created(Actor self)
|
void INotifyCreated.Created(Actor self)
|
||||||
{
|
{
|
||||||
Enabled = self.World.LobbyInfo.IsSinglePlayer || self.World.LobbyInfo.GlobalSettings
|
Enabled = self.World.LobbyInfo.NonBotPlayers.Count() == 1 || self.World.LobbyInfo.GlobalSettings
|
||||||
.OptionOrDefault("cheats", info.Enabled);
|
.OptionOrDefault("cheats", info.Enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Desc("Returns true if there is only one human player.")]
|
[Desc("Returns true if there is only one human player.")]
|
||||||
public bool IsSinglePlayer { get { return Context.World.LobbyInfo.IsSinglePlayer; } }
|
public bool IsSinglePlayer { get { return Context.World.LobbyInfo.NonBotPlayers.Count() == 1; } }
|
||||||
|
|
||||||
[Desc("Returns the difficulty selected by the player before starting the mission.")]
|
[Desc("Returns the difficulty selected by the player before starting the mission.")]
|
||||||
public string Difficulty
|
public string Difficulty
|
||||||
|
|||||||
@@ -58,21 +58,21 @@ namespace OpenRA.Mods.Common.Server
|
|||||||
|
|
||||||
static void CheckAutoStart(S server)
|
static void CheckAutoStart(S server)
|
||||||
{
|
{
|
||||||
// A spectating admin is included for checking these rules
|
var nonBotPlayers = server.LobbyInfo.NonBotPlayers;
|
||||||
var playerClients = server.LobbyInfo.Clients.Where(c => (c.Bot == null && c.Slot != null) || c.IsAdmin);
|
|
||||||
|
|
||||||
// Are all players ready?
|
// Are all players and admin (could be spectating) ready?
|
||||||
if (!playerClients.Any() || playerClients.Any(c => c.State != Session.ClientState.Ready))
|
if (nonBotPlayers.Any(c => c.State != Session.ClientState.Ready) ||
|
||||||
|
server.LobbyInfo.Clients.First(c => c.IsAdmin).State != Session.ClientState.Ready)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Does server have at least 2 human players?
|
||||||
|
if (!server.LobbyInfo.GlobalSettings.EnableSingleplayer && nonBotPlayers.Count() < 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Are the map conditions satisfied?
|
// Are the map conditions satisfied?
|
||||||
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;
|
||||||
|
|
||||||
// Does server have only one player?
|
|
||||||
if (!server.LobbyInfo.GlobalSettings.EnableSingleplayer && playerClients.Count() == 1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
server.StartGame();
|
server.StartGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,8 +121,7 @@ namespace OpenRA.Mods.Common.Server
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!server.LobbyInfo.GlobalSettings.EnableSingleplayer &&
|
if (!server.LobbyInfo.GlobalSettings.EnableSingleplayer && server.LobbyInfo.NonBotPlayers.Count() < 2)
|
||||||
server.LobbyInfo.Clients.Where(c => c.Bot == null && c.Slot != null).Count() == 1)
|
|
||||||
{
|
{
|
||||||
server.SendOrderTo(conn, "Message", server.TwoHumansRequiredText);
|
server.SendOrderTo(conn, "Message", server.TwoHumansRequiredText);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Server
|
|||||||
lastPing = Game.RunTime;
|
lastPing = Game.RunTime;
|
||||||
|
|
||||||
// Ignore client timeout in singleplayer games to make debugging easier
|
// Ignore client timeout in singleplayer games to make debugging easier
|
||||||
if (server.LobbyInfo.IsSinglePlayer && !server.Dedicated)
|
if (server.LobbyInfo.NonBotClients.Count() < 2 && !server.Dedicated)
|
||||||
foreach (var c in server.Conns.ToList())
|
foreach (var c in server.Conns.ToList())
|
||||||
server.SendOrderTo(c, "Ping", Game.RunTime.ToString());
|
server.SendOrderTo(c, "Ping", Game.RunTime.ToString());
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
chatTraits = world.WorldActor.TraitsImplementing<INotifyChat>().ToArray();
|
chatTraits = world.WorldActor.TraitsImplementing<INotifyChat>().ToArray();
|
||||||
|
|
||||||
var players = world.Players.Where(p => p != world.LocalPlayer && !p.NonCombatant && !p.IsBot);
|
var players = world.Players.Where(p => p != world.LocalPlayer && !p.NonCombatant && !p.IsBot);
|
||||||
disableTeamChat = world.IsReplay || world.LobbyInfo.IsSinglePlayer || (world.LocalPlayer != null && !players.Any(p => p.IsAlliedWith(world.LocalPlayer)));
|
disableTeamChat = world.IsReplay || world.LobbyInfo.NonBotClients.Count() == 1 || (world.LocalPlayer != null && !players.Any(p => p.IsAlliedWith(world.LocalPlayer)));
|
||||||
teamChat = !disableTeamChat;
|
teamChat = !disableTeamChat;
|
||||||
|
|
||||||
tabCompletion.Commands = chatTraits.OfType<ChatCommands>().SelectMany(x => x.Commands.Keys).ToList();
|
tabCompletion.Commands = chatTraits.OfType<ChatCommands>().SelectMany(x => x.Commands.Keys).ToList();
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
|
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
|
||||||
var exitDelay = iop != null ? iop.ExitDelay : 0;
|
var exitDelay = iop != null ? iop.ExitDelay : 0;
|
||||||
|
|
||||||
if (world.LobbyInfo.IsSinglePlayer)
|
if (world.LobbyInfo.NonBotClients.Count() == 1)
|
||||||
{
|
{
|
||||||
restartAction = () =>
|
restartAction = () =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
worldRoot.IsVisible = () => false;
|
worldRoot.IsVisible = () => false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (button.Pause && world.LobbyInfo.IsSinglePlayer)
|
if (button.Pause && world.LobbyInfo.NonBotClients.Count() == 1)
|
||||||
world.SetPauseState(true);
|
world.SetPauseState(true);
|
||||||
|
|
||||||
var cachedDisableWorldSounds = Game.Sound.DisableWorldSounds;
|
var cachedDisableWorldSounds = Game.Sound.DisableWorldSounds;
|
||||||
@@ -118,7 +118,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
if (button.DisableWorldSounds)
|
if (button.DisableWorldSounds)
|
||||||
Game.Sound.DisableWorldSounds = cachedDisableWorldSounds;
|
Game.Sound.DisableWorldSounds = cachedDisableWorldSounds;
|
||||||
|
|
||||||
if (button.Pause && world.LobbyInfo.IsSinglePlayer)
|
if (button.Pause && world.LobbyInfo.NonBotClients.Count() == 1)
|
||||||
world.SetPauseState(cachedPause);
|
world.SetPauseState(cachedPause);
|
||||||
|
|
||||||
menuRoot.RemoveChild(currentWidget);
|
menuRoot.RemoveChild(currentWidget);
|
||||||
|
|||||||
@@ -322,7 +322,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
{
|
{
|
||||||
startGameButton.IsDisabled = () => configurationDisabled() || map.Status != MapStatus.Available ||
|
startGameButton.IsDisabled = () => configurationDisabled() || map.Status != MapStatus.Available ||
|
||||||
orderManager.LobbyInfo.Slots.Any(sl => sl.Value.Required && orderManager.LobbyInfo.ClientInSlot(sl.Key) == null) ||
|
orderManager.LobbyInfo.Slots.Any(sl => sl.Value.Required && orderManager.LobbyInfo.ClientInSlot(sl.Key) == null) ||
|
||||||
(!orderManager.LobbyInfo.GlobalSettings.EnableSingleplayer && orderManager.LobbyInfo.IsSinglePlayer);
|
(!orderManager.LobbyInfo.GlobalSettings.EnableSingleplayer && orderManager.LobbyInfo.NonBotPlayers.Count() < 2);
|
||||||
|
|
||||||
startGameButton.OnClick = () =>
|
startGameButton.OnClick = () =>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user