From 23d9d611c17d6550be0a932d1c0d3d3519739ac6 Mon Sep 17 00:00:00 2001 From: Andy Perkins Date: Wed, 5 Jun 2013 21:42:37 +1000 Subject: [PATCH] Lobby, Add Bots button --- AUTHORS | 1 + OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs | 5 ++++- OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs | 19 +++++++++++++++++-- mods/cnc/chrome/lobby.yaml | 9 ++++++++- mods/d2k/chrome/lobby.yaml | 9 ++++++++- mods/ra/chrome/lobby.yaml | 9 ++++++++- 6 files changed, 46 insertions(+), 6 deletions(-) diff --git a/AUTHORS b/AUTHORS index 5a1909815d..de363158b7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -18,6 +18,7 @@ Previous developers included: Also thanks to: * Akseli Virtanen (RAGEQUIT) + * Andrew Perkins * Andrew Riedi * Andreas Beck (baxtor) * Barnaby Smith (mvi) diff --git a/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs b/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs index d9bfcaac4d..8d1d79b352 100644 --- a/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs +++ b/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs @@ -335,7 +335,7 @@ namespace OpenRA.Mods.RA.Server server.SendOrderTo(conn, "Message", "Number of teams could not be parsed: {0}".F(s)); return true; } - teams = teams.Clamp(2, 8); + teams = teams.Clamp(1, 8); var players = server.lobbyInfo.Slots .Select(slot => server.lobbyInfo.Clients.SingleOrDefault(c => c.Slot == slot.Key)) @@ -366,6 +366,9 @@ namespace OpenRA.Mods.RA.Server cl.Team = team; } } + // All vs Host + if (teams == 1) + client.Team = 2; server.SyncLobbyInfo(); return true; }}, diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs index 42056810d9..a98737d2d4 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs @@ -174,9 +174,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic assignTeams.OnMouseDown = _ => { - var options = Enumerable.Range(2, orderManager.LobbyInfo.Clients.Count(c => c.Slot != null).Clamp(2, 8) - 1).Select(d => new DropDownOption + var options = Enumerable.Range(1, orderManager.LobbyInfo.Clients.Count(c => c.Slot != null).Clamp(1, 8) - 1).Select(d => new DropDownOption { - Title = "{0} Teams".F(d), + Title = (d == 1 ? "All vs Host" : "{0} Teams".F(d)), IsSelected = () => false, OnClick = () => orderManager.IssueOrder(Order.Command("assignteams {0}".F(d.ToString()))) }); @@ -193,6 +193,21 @@ namespace OpenRA.Mods.RA.Widgets.Logic var disconnectButton = lobby.Get("DISCONNECT_BUTTON"); disconnectButton.OnClick = () => { CloseWindow(); onExit(); }; + var addBotsButton = lobby.Get("ADD_BOTS"); + addBotsButton.IsVisible = () => Game.IsHost; + addBotsButton.IsDisabled = () => !Game.IsHost || gameStarting || orderManager.LocalClient == null + || orderManager.LocalClient.IsReady || !orderManager.LobbyInfo.Slots.Values.Any(s => s.AllowBots); + addBotsButton.OnClick = () => { + var aiModes = Rules.Info["player"].Traits.WithInterface().Select(t => t.Name); + foreach (var slot in orderManager.LobbyInfo.Slots) + { + var bot = aiModes.Random(Game.CosmeticRandom); + var c = orderManager.LobbyInfo.ClientInSlot(slot.Key); + if (slot.Value.AllowBots == true && (c == null || c.Bot != null)) + orderManager.IssueOrder(Order.Command("slot_bot {0} {1} {2}".F(slot.Key,0,bot))); + } + }; + var allowCheats = lobby.Get("ALLOWCHEATS_CHECKBOX"); allowCheats.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllowCheats; allowCheats.IsDisabled = () => !Game.IsHost || gameStarting || orderManager.LocalClient == null diff --git a/mods/cnc/chrome/lobby.yaml b/mods/cnc/chrome/lobby.yaml index 9b5ecadfaf..c15a57c511 100644 --- a/mods/cnc/chrome/lobby.yaml +++ b/mods/cnc/chrome/lobby.yaml @@ -448,6 +448,13 @@ Container@SERVER_LOBBY: Width:80 Height:20 Text: Crates + Button@ADD_BOTS: + X:398-120-10 + Y:255 + Width:120 + Height:25 + Text:Add Bots + Font:Bold DropDownButton@ASSIGNTEAMS_DROPDOWNBUTTON: X:398 Y:255 @@ -522,4 +529,4 @@ Container@SERVER_LOBBY: Width:140 Height:35 Text:Start Game - TooltipContainer@TOOLTIP_CONTAINER: \ No newline at end of file + TooltipContainer@TOOLTIP_CONTAINER: diff --git a/mods/d2k/chrome/lobby.yaml b/mods/d2k/chrome/lobby.yaml index 35e619db9f..6e84285366 100644 --- a/mods/d2k/chrome/lobby.yaml +++ b/mods/d2k/chrome/lobby.yaml @@ -474,6 +474,13 @@ Background@SERVER_LOBBY: Height:25 Text:Change Map Font:Bold + Button@ADD_BOTS: + X:PARENT_RIGHT-154 + Y:PARENT_BOTTOM-(289-25-5) + Width:120 + Height:25 + Text:Add Bots + Font:Bold DropDownButton@ASSIGNTEAMS_DROPDOWNBUTTON: X:PARENT_RIGHT-154 Y:PARENT_BOTTOM-229 @@ -515,4 +522,4 @@ Background@SERVER_LOBBY: Height:25 Text:Start Game Font:Bold - TooltipContainer@TOOLTIP_CONTAINER: \ No newline at end of file + TooltipContainer@TOOLTIP_CONTAINER: diff --git a/mods/ra/chrome/lobby.yaml b/mods/ra/chrome/lobby.yaml index 523442f36a..84729ad0d4 100644 --- a/mods/ra/chrome/lobby.yaml +++ b/mods/ra/chrome/lobby.yaml @@ -474,6 +474,13 @@ Background@SERVER_LOBBY: Height:25 Text:Change Map Font:Bold + Button@ADD_BOTS: + X:PARENT_RIGHT-154 + Y:PARENT_BOTTOM-(289-25-5) + Width:120 + Height:25 + Text:Add Bots + Font:Bold DropDownButton@ASSIGNTEAMS_DROPDOWNBUTTON: X:PARENT_RIGHT-154 Y:PARENT_BOTTOM-229 @@ -521,4 +528,4 @@ Background@SERVER_LOBBY: Height:25 Text:Start Game Font:Bold - TooltipContainer@TOOLTIP_CONTAINER: \ No newline at end of file + TooltipContainer@TOOLTIP_CONTAINER: