Skirmish mode starts with a bot selected.

This commit is contained in:
Paul Chote
2011-06-18 00:39:50 +12:00
parent c6182f6039
commit bcbd18bb52
5 changed files with 30 additions and 16 deletions

View File

@@ -31,6 +31,12 @@ namespace OpenRA.Network
return Clients.SingleOrDefault(c => c.Slot == slot.Index);
}
public int FirstEmptySlot()
{
return Slots.First(s => !s.Closed && ClientInSlot(s) == null
&& s.Bot == null).Index;
}
public enum ClientState
{
NotReady,

View File

@@ -216,7 +216,7 @@ namespace OpenRA.Server
// Enforce correct PlayerIndex and Slot
client.Index = newConn.PlayerIndex;
client.Slot = ChooseFreeSlot();
client.Slot = lobbyInfo.FirstEmptySlot();
var slotData = lobbyInfo.Slots.FirstOrDefault( x => x.Index == client.Slot );
if (slotData != null && slotData.MapPlayer != null)
@@ -236,13 +236,6 @@ namespace OpenRA.Server
catch (Exception) { DropClient(newConn); }
}
int ChooseFreeSlot()
{
return lobbyInfo.Slots.First(s => !s.Closed && s.Bot == null
&& !lobbyInfo.Clients.Any( c => c.Slot == s.Index )).Index;
}
public static void SyncClientToPlayerReference(Session.Client c, PlayerReference pr)
{
if (pr == null)

View File

@@ -199,6 +199,8 @@ namespace OpenRA.Widgets
}
return text;
}
public static Action Once( Action a ) { return () => { if (a != null) { a(); a = null; } }; }
}
[Flags]

View File

@@ -50,7 +50,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
Game.OpenWindow("SERVER_LOBBY", new WidgetArgs()
{
{ "onExit", onExit },
{ "onStart", OnGameStart }
{ "onStart", OnGameStart },
{ "addBots", false }
});
};
@@ -86,7 +87,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
[ObjectCreator.Param] World world, // Shellmap world
[ObjectCreator.Param] OrderManager orderManager,
[ObjectCreator.Param] Action onExit,
[ObjectCreator.Param] Action onStart)
[ObjectCreator.Param] Action onStart,
[ObjectCreator.Param] bool addBots)
{
this.orderManager = orderManager;
this.OnGameStart = () => { CloseWindow(); onStart(); };
@@ -222,6 +224,16 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
{ "onExit", () => {} },
});
};
// Add a bot on the first lobbyinfo update
if (addBots)
Game.LobbyInfoChanged += WidgetUtils.Once(() =>
{
var slot = orderManager.LobbyInfo.FirstEmptySlot();
var bot = Rules.Info["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name).FirstOrDefault();
if (bot != null)
orderManager.IssueOrder(Order.Command("slot_bot {0} {1}".F(slot, bot)));
});
}
public void AddChatLine(Color c, string from, string text)

View File

@@ -68,7 +68,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
Widget.OpenWindow("SERVERBROWSER_PANEL", new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Multiplayer },
{ "openLobby", () => OpenLobbyPanel(MenuType.Multiplayer) }
{ "openLobby", () => OpenLobbyPanel(MenuType.Multiplayer, false) }
});
};
@@ -78,7 +78,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
Widget.OpenWindow("CREATESERVER_PANEL", new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Multiplayer },
{ "openLobby", () => OpenLobbyPanel(MenuType.Multiplayer) }
{ "openLobby", () => OpenLobbyPanel(MenuType.Multiplayer, false) }
});
};
@@ -88,7 +88,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
Widget.OpenWindow("DIRECTCONNECT_PANEL", new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Multiplayer },
{ "openLobby", () => OpenLobbyPanel(MenuType.Multiplayer) }
{ "openLobby", () => OpenLobbyPanel(MenuType.Multiplayer, false) }
});
};
@@ -140,13 +140,14 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
rootMenu.Parent.RemoveChild(rootMenu);
}
void OpenLobbyPanel(MenuType menu)
void OpenLobbyPanel(MenuType menu, bool addBots)
{
Menu = MenuType.None;
Game.OpenWindow("SERVER_LOBBY", new WidgetArgs()
{
{ "onExit", () => { Game.Disconnect(); Menu = menu; } },
{ "onStart", RemoveShellmapUI }
{ "onStart", RemoveShellmapUI },
{ "addBots", addBots }
});
}
@@ -156,7 +157,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
var port = Game.CreateLocalServer(map);
CncConnectingLogic.Connect(IPAddress.Loopback.ToString(),
port,
() => OpenLobbyPanel(MenuType.Main),
() => OpenLobbyPanel(MenuType.Main, true),
() => { Game.CloseServer(); Menu = MenuType.Main; });
}
}