From 17990ab8b7b2d758f6c5dac5c6c652b6e80119cd Mon Sep 17 00:00:00 2001 From: Bob Date: Mon, 11 Oct 2010 16:00:02 +1300 Subject: [PATCH] move LobbyInfo onto OrderManager --- OpenRA.FileFormats/Manifest.cs | 3 +- OpenRA.Game/Game.cs | 36 +++----------- OpenRA.Game/Network/OrderManager.cs | 8 ++-- OpenRA.Game/Network/Session.cs | 19 +++++++- OpenRA.Game/Network/UnitOrders.cs | 32 ++++++++----- OpenRA.Game/ObjectCreator.cs | 2 +- OpenRA.Game/Server/Server.cs | 3 +- OpenRA.Game/Traits/Player/DeveloperMode.cs | 2 +- .../Delegates/DeveloperModeDelegate.cs | 2 +- .../Widgets/Delegates/DiplomacyDelegate.cs | 2 +- .../Widgets/Delegates/LobbyDelegate.cs | 48 ++++++++++--------- .../Delegates/ServerBrowserDelegate.cs | 2 +- OpenRA.Game/World.cs | 7 ++- OpenRA.Mods.RA/CreateMPPlayers.cs | 6 +-- OpenRA.Mods.RA/MPStartLocations.cs | 6 +-- OpenRA.Mods.RA/Player/ProductionQueue.cs | 6 +-- OpenRA.Mods.RA/SupportPowers/SupportPower.cs | 2 +- 17 files changed, 98 insertions(+), 88 deletions(-) diff --git a/OpenRA.FileFormats/Manifest.cs b/OpenRA.FileFormats/Manifest.cs index 842baf135b..7103737467 100644 --- a/OpenRA.FileFormats/Manifest.cs +++ b/OpenRA.FileFormats/Manifest.cs @@ -18,7 +18,7 @@ namespace OpenRA.FileFormats public class Manifest { public readonly string[] - Folders, Packages, Rules, + Mods, Folders, Packages, Rules, Sequences, Cursors, Chrome, Assemblies, ChromeLayout, Weapons, Voices, Music, Movies, TileSets; @@ -27,6 +27,7 @@ namespace OpenRA.FileFormats public Manifest(string[] mods) { + Mods = mods; var yaml = mods .Select(m => MiniYaml.FromFile("mods/" + m + "/mod.yaml")) .Aggregate(MiniYaml.Merge); diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 5bc6034f5c..9326aacfa2 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -40,7 +40,6 @@ namespace OpenRA public static XRandom CosmeticRandom = new XRandom(); // not synced public static Renderer Renderer; - public static Session LobbyInfo = new Session(); public static bool HasInputFocus = false; static void LoadMap(string uid) @@ -48,7 +47,7 @@ namespace OpenRA var map = modData.PrepareMap(uid); viewport = new Viewport(new float2(Renderer.Resolution), map.TopLeft, map.BottomRight, Renderer); - world = new World(modData.Manifest, map); + world = new World(modData.Manifest, map, orderManager); } public static void MoveViewport(int2 loc) @@ -164,29 +163,13 @@ namespace OpenRA internal static event Action LobbyInfoChanged = () => { }; - internal static void SyncLobbyInfo( string data) + internal static void SyncLobbyInfo() { - LobbyInfo = Session.Deserialize(data); - - //if( !world.GameHasStarted ) - // world.SharedRandom = new XRandom( LobbyInfo.GlobalSettings.RandomSeed ); - - //if (orderManager.Connection.ConnectionState == ConnectionState.Connected) - // world.SetLocalPlayer(orderManager.Connection.LocalClientId); - - if (orderManager.FramesAhead != LobbyInfo.GlobalSettings.OrderLatency - && !orderManager.GameStarted) - { - orderManager.FramesAhead = LobbyInfo.GlobalSettings.OrderLatency; - Debug("Order lag is now {0} frames.".F(LobbyInfo.GlobalSettings.OrderLatency)); - } - LobbyInfoChanged(); } public static void IssueOrder( Order o ) { orderManager.IssueOrder( o ); } /* avoid exposing the OM to mod code */ - public static event Action AfterGameStart = _ => {}; public static event Action BeforeGameStart = () => {}; internal static void StartGame(string map) @@ -227,11 +210,6 @@ namespace OpenRA get { return orderManager.Connection.LocalClientId == 0; } } - internal static Session.Client LocalClient - { - get { return LobbyInfo.Clients.FirstOrDefault(c => c.Index == orderManager.Connection.LocalClientId); } - } - public static void HandleKeyEvent(KeyInput e) { var world = Game.world; @@ -278,10 +256,10 @@ namespace OpenRA Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version); // Discard any invalid mods - LobbyInfo.GlobalSettings.Mods = Settings.Game.Mods.Where(m => ModData.AllMods.ContainsKey(m)).ToArray(); - Console.WriteLine("Loading mods: {0}",string.Join(",",LobbyInfo.GlobalSettings.Mods)); + var mods = Settings.Game.Mods.Where( m => ModData.AllMods.ContainsKey( m ) ).ToArray(); + Console.WriteLine("Loading mods: {0}",string.Join(",",mods)); - modData = new ModData( LobbyInfo.GlobalSettings.Mods ); + modData = new ModData( mods ); Sound.Initialize(); PerfHistory.items["render"].hasNormalTick = false; @@ -309,7 +287,7 @@ namespace OpenRA Widget.OpenWindow("CONNECTION_FAILED_BG"); break; case ConnectionState.Connected: - var lobby = Widget.OpenWindow("SERVER_LOBBY"); + var lobby = Widget.OpenWindow( "SERVER_LOBBY", new Dictionary { { "orderManager", orderManager } } ); lobby.GetWidget("CHAT_DISPLAY").ClearChat(); lobby.GetWidget("CHANGEMAP_BUTTON").Visible = true; lobby.GetWidget("LOCKTEAMS_CHECKBOX").Visible = true; @@ -348,8 +326,6 @@ namespace OpenRA { orderManager.Dispose(); var shellmap = modData.Manifest.ShellmapUid; - LobbyInfo = new Session(); - LobbyInfo.GlobalSettings.Mods = Settings.Game.Mods; JoinLocal(); StartGame(shellmap); diff --git a/OpenRA.Game/Network/OrderManager.cs b/OpenRA.Game/Network/OrderManager.cs index 714f63242f..b375848919 100755 --- a/OpenRA.Game/Network/OrderManager.cs +++ b/OpenRA.Game/Network/OrderManager.cs @@ -21,8 +21,10 @@ namespace OpenRA.Network readonly SyncReport syncReport = new SyncReport(); readonly FrameData frameData = new FrameData(); - public int FrameNumber { get; private set; } + public Session LobbyInfo = new Session( Game.Settings.Game.Mods ); + public Session.Client LocalClient { get { return LobbyInfo.ClientWithIndex( Connection.LocalClientId ); } } + public int FrameNumber { get; private set; } public int FramesAhead = 0; public bool GameStarted { get { return FrameNumber != 0; } } @@ -82,7 +84,7 @@ namespace OpenRA.Network foreach( var p in immediatePackets ) foreach( var o in p.Second.ToOrderList( world ) ) - UnitOrders.ProcessOrder( world, p.First, o ); + UnitOrders.ProcessOrder( this, world, p.First, o ); } Dictionary syncForFrame = new Dictionary(); @@ -152,7 +154,7 @@ namespace OpenRA.Network foreach( var order in frameData.OrdersForFrame( world, FrameNumber) ) { - UnitOrders.ProcessOrder( world, order.Client, order.Order ); + UnitOrders.ProcessOrder( this, world, order.Client, order.Order ); sync.Add( world.SyncHash() ); } diff --git a/OpenRA.Game/Network/Session.cs b/OpenRA.Game/Network/Session.cs index 9056b57885..9072c6537e 100644 --- a/OpenRA.Game/Network/Session.cs +++ b/OpenRA.Game/Network/Session.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Drawing; +using System.Linq; using OpenRA.FileFormats; namespace OpenRA.Network @@ -20,6 +21,16 @@ namespace OpenRA.Network public List Slots = new List(); public Global GlobalSettings = new Global(); + public Client ClientWithIndex( int clientID ) + { + return Clients.Single( c => c.Index == clientID ); + } + + public Client ClientInSlot( Slot slot ) + { + return Clients.SingleOrDefault( c => c.Slot == slot.Index ); + } + public enum ClientState { NotReady, @@ -59,6 +70,11 @@ namespace OpenRA.Network public bool AllowCheats = false; } + public Session( string[] mods ) + { + this.GlobalSettings.Mods = mods.ToArray(); + } + public string Serialize() { var clientData = new List(); @@ -76,8 +92,7 @@ namespace OpenRA.Network public static Session Deserialize(string data) { - var session = new Session(); - session.GlobalSettings.Mods = Game.Settings.Game.Mods; + var session = new Session( Game.Settings.Game.Mods ); var ys = MiniYaml.FromString(data); foreach (var y in ys) diff --git a/OpenRA.Game/Network/UnitOrders.cs b/OpenRA.Game/Network/UnitOrders.cs index d504bf70ef..3e8c63ffa4 100755 --- a/OpenRA.Game/Network/UnitOrders.cs +++ b/OpenRA.Game/Network/UnitOrders.cs @@ -16,18 +16,13 @@ namespace OpenRA.Network { static class UnitOrders { - static Session.Client FindClientById(int id) - { - return Game.LobbyInfo.Clients.FirstOrDefault(c => c.Index == id); - } - static Player FindPlayerByClientId( this World world, int id) { /* todo: find the interactive player. */ return world.players.Values.FirstOrDefault(p => p.ClientIndex == id); } - public static void ProcessOrder( World world, int clientId, Order order ) + public static void ProcessOrder( OrderManager orderManager, World world, int clientId, Order order ) { // Drop exploiting orders if (order.Subject != null && order.Subject.Owner.ClientIndex != clientId) @@ -40,7 +35,7 @@ namespace OpenRA.Network { case "Chat": { - var client = FindClientById(clientId); + var client = orderManager.LobbyInfo.ClientWithIndex( clientId ); if (client != null) { var player = world.FindPlayerByClientId(clientId); @@ -53,14 +48,14 @@ namespace OpenRA.Network } case "TeamChat": { - var client = FindClientById(clientId); + var client = orderManager.LobbyInfo.ClientWithIndex(clientId); if (client != null) { var player = world.FindPlayerByClientId(clientId); var display = (world.GameHasStarted) ? player != null && (world.LocalPlayer != null && player.Stances[world.LocalPlayer] == Stance.Ally || player.WinState == WinState.Lost) : - client == Game.LocalClient || (client.Team == Game.LocalClient.Team && client.Team != 0); + client == orderManager.LocalClient || (client.Team == orderManager.LocalClient.Team && client.Team != 0); if (display) { @@ -73,12 +68,27 @@ namespace OpenRA.Network case "StartGame": { Game.AddChatLine(Color.White, "Server", "The game has started."); - Game.StartGame(Game.LobbyInfo.GlobalSettings.Map); + Game.StartGame(orderManager.LobbyInfo.GlobalSettings.Map); break; } case "SyncInfo": { - Game.SyncLobbyInfo( order.TargetString); + orderManager.LobbyInfo = Session.Deserialize( order.TargetString ); + + //if( !world.GameHasStarted ) + // world.SharedRandom = new XRandom( LobbyInfo.GlobalSettings.RandomSeed ); + + //if (orderManager.Connection.ConnectionState == ConnectionState.Connected) + // world.SetLocalPlayer(orderManager.Connection.LocalClientId); + + if( orderManager.FramesAhead != orderManager.LobbyInfo.GlobalSettings.OrderLatency + && !orderManager.GameStarted ) + { + orderManager.FramesAhead = orderManager.LobbyInfo.GlobalSettings.OrderLatency; + Game.Debug( "Order lag is now {0} frames.".F( orderManager.LobbyInfo.GlobalSettings.OrderLatency ) ); + } + + Game.SyncLobbyInfo(); break; } case "SetStance": diff --git a/OpenRA.Game/ObjectCreator.cs b/OpenRA.Game/ObjectCreator.cs index d346f639d4..136bfc062f 100755 --- a/OpenRA.Game/ObjectCreator.cs +++ b/OpenRA.Game/ObjectCreator.cs @@ -42,7 +42,7 @@ namespace OpenRA { var type = mod.First.GetType( mod.Second + "." + className, false ); if( type == null ) continue; - var ctors = type.GetConstructors().Where( x => x.HasAttribute() ).ToList(); + var ctors = type.GetConstructors( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance ).Where( x => x.HasAttribute() ).ToList(); if( ctors.Count == 0 ) return (T)CreateBasic( type ); else if( ctors.Count == 1 ) diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index f06347d293..dd27e63664 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -60,8 +60,7 @@ namespace OpenRA.Server randomSeed = (int)DateTime.Now.ToBinary(); ModData = modData; - lobbyInfo = new Session(); - lobbyInfo.GlobalSettings.Mods = settings.Game.Mods; + lobbyInfo = new Session( settings.Game.Mods ); lobbyInfo.GlobalSettings.RandomSeed = randomSeed; lobbyInfo.GlobalSettings.Map = map; lobbyInfo.GlobalSettings.AllowCheats = settings.Server.AllowCheats; diff --git a/OpenRA.Game/Traits/Player/DeveloperMode.cs b/OpenRA.Game/Traits/Player/DeveloperMode.cs index 3c45552a72..223fa91e1f 100644 --- a/OpenRA.Game/Traits/Player/DeveloperMode.cs +++ b/OpenRA.Game/Traits/Player/DeveloperMode.cs @@ -42,7 +42,7 @@ namespace OpenRA.Traits public void ResolveOrder (Actor self, Order order) { - if (!Game.LobbyInfo.GlobalSettings.AllowCheats) return; + if (!self.World.LobbyInfo.GlobalSettings.AllowCheats) return; switch(order.OrderString) { diff --git a/OpenRA.Game/Widgets/Delegates/DeveloperModeDelegate.cs b/OpenRA.Game/Widgets/Delegates/DeveloperModeDelegate.cs index bb9b550c0c..ad9a695db8 100644 --- a/OpenRA.Game/Widgets/Delegates/DeveloperModeDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/DeveloperModeDelegate.cs @@ -101,7 +101,7 @@ namespace OpenRA.Widgets.Delegates return true; }; - devModeButton.IsVisible = () => { return Game.LobbyInfo.GlobalSettings.AllowCheats; }; + devModeButton.IsVisible = () => { return world.LobbyInfo.GlobalSettings.AllowCheats; }; } } } diff --git a/OpenRA.Game/Widgets/Delegates/DiplomacyDelegate.cs b/OpenRA.Game/Widgets/Delegates/DiplomacyDelegate.cs index 62a00d2c4c..7ab3e71ac4 100644 --- a/OpenRA.Game/Widgets/Delegates/DiplomacyDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/DiplomacyDelegate.cs @@ -133,7 +133,7 @@ namespace OpenRA.Widgets.Delegates void CycleStance(Player p, ButtonWidget bw) { - if (Game.LobbyInfo.GlobalSettings.LockTeams) + if (p.World.LobbyInfo.GlobalSettings.LockTeams) return; // team changes are banned var nextStance = GetNextStance((Stance)Enum.Parse(typeof(Stance), bw.Text)); diff --git a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs index c72a0bb1f3..00939438fc 100755 --- a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs @@ -26,10 +26,12 @@ namespace OpenRA.Widgets.Delegates public static Color CurrentColorPreview1; public static Color CurrentColorPreview2; - + + readonly OrderManager orderManager; [ObjectCreator.UseCtor] - public LobbyDelegate( [ObjectCreator.Param( "widget" )] Widget lobby ) + internal LobbyDelegate( [ObjectCreator.Param( "widget" )] Widget lobby, [ObjectCreator.Param] OrderManager orderManager ) { + this.orderManager = orderManager; Game.LobbyInfoChanged += UpdateCurrentMap; UpdateCurrentMap(); @@ -46,8 +48,8 @@ namespace OpenRA.Widgets.Delegates mapPreview.Map = () => Map; mapPreview.OnSpawnClick = sp => { - if (Game.LocalClient.State == Session.ClientState.Ready) return; - var owned = Game.LobbyInfo.Clients.Any(c => c.SpawnPoint == sp); + if (orderManager.LocalClient.State == Session.ClientState.Ready) return; + var owned = orderManager.LobbyInfo.Clients.Any(c => c.SpawnPoint == sp); if (sp == 0 || !owned) Game.IssueOrder(Order.Command("spawn {0}".F(sp))); }; @@ -59,7 +61,7 @@ namespace OpenRA.Widgets.Delegates for (int i = 1; i <= spawns.Count(); i++) { - var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.SpawnPoint == i); + var client = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.SpawnPoint == i); if (client == null) continue; sc.Add(spawns.ElementAt(i - 1), client.Color1); @@ -88,12 +90,12 @@ namespace OpenRA.Widgets.Delegates var lockTeamsCheckbox = lobby.GetWidget("LOCKTEAMS_CHECKBOX"); lockTeamsCheckbox.IsVisible = () => lockTeamsCheckbox.Visible && true; - lockTeamsCheckbox.Checked = () => Game.LobbyInfo.GlobalSettings.LockTeams; + lockTeamsCheckbox.Checked = () => orderManager.LobbyInfo.GlobalSettings.LockTeams; lockTeamsCheckbox.OnMouseDown = mi => { if (Game.IsHost) Game.IssueOrder(Order.Command( - "lockteams {0}".F(!Game.LobbyInfo.GlobalSettings.LockTeams))); + "lockteams {0}".F(!orderManager.LobbyInfo.GlobalSettings.LockTeams))); return true; }; @@ -175,8 +177,8 @@ namespace OpenRA.Widgets.Delegates void UpdateCurrentMap() { - if (MapUid == Game.LobbyInfo.GlobalSettings.Map) return; - MapUid = Game.LobbyInfo.GlobalSettings.Map; + if (MapUid == orderManager.LobbyInfo.GlobalSettings.Map) return; + MapUid = orderManager.LobbyInfo.GlobalSettings.Map; Map = Game.modData.AvailableMaps[MapUid]; } @@ -188,13 +190,13 @@ namespace OpenRA.Widgets.Delegates return; hasJoined = true; - if (Game.LocalClient.Name != Game.Settings.Player.Name) + if (orderManager.LocalClient.Name != Game.Settings.Player.Name) Game.IssueOrder(Order.Command("name " + Game.Settings.Player.Name)); var c1 = Game.Settings.Player.Color1; var c2 = Game.Settings.Player.Color2; - if (Game.LocalClient.Color1 != c1 || Game.LocalClient.Color2 != c2) + if (orderManager.LocalClient.Color1 != c1 || orderManager.LocalClient.Color2 != c2) Game.IssueOrder(Order.Command("color {0},{1},{2},{3},{4},{5}".F(c1.R,c1.G,c1.B,c2.R,c2.G,c2.B))); } @@ -204,9 +206,9 @@ namespace OpenRA.Widgets.Delegates hasJoined = false; } - static Session.Client GetClientInSlot(Session.Slot slot) + Session.Client GetClientInSlot(Session.Slot slot) { - return Game.LobbyInfo.Clients.FirstOrDefault(c => c.Slot == slot.Index); + return orderManager.LobbyInfo.ClientInSlot( slot ); } void UpdatePlayerList() @@ -216,7 +218,7 @@ namespace OpenRA.Widgets.Delegates Players.Children.Clear(); int offset = 0; - foreach (var slot in Game.LobbyInfo.Slots) + foreach (var slot in orderManager.LobbyInfo.Slots) { var s = slot; var c = GetClientInSlot(s); @@ -260,7 +262,7 @@ namespace OpenRA.Widgets.Delegates join.IsVisible = () => !s.Closed && s.Bot == null; } } - else if (c.Index == Game.LocalClient.Index && c.State != Session.ClientState.Ready) + else if (c.Index == orderManager.LocalClient.Index && c.State != Session.ClientState.Ready) { template = LocalPlayerTemplate.Clone(); var name = template.GetWidget("NAME"); @@ -287,16 +289,16 @@ namespace OpenRA.Widgets.Delegates { var colorChooser = Widget.RootWidget.GetWidget("SERVER_LOBBY").GetWidget("COLOR_CHOOSER"); var hueSlider = colorChooser.GetWidget("HUE_SLIDER"); - hueSlider.SetOffset(Game.LocalClient.Color1.GetHue()/360f); + hueSlider.SetOffset(orderManager.LocalClient.Color1.GetHue()/360f); var satSlider = colorChooser.GetWidget("SAT_SLIDER"); - satSlider.SetOffset(Game.LocalClient.Color1.GetSaturation()); + satSlider.SetOffset(orderManager.LocalClient.Color1.GetSaturation()); var lumSlider = colorChooser.GetWidget("LUM_SLIDER"); - lumSlider.SetOffset(Game.LocalClient.Color1.GetBrightness()); + lumSlider.SetOffset(orderManager.LocalClient.Color1.GetBrightness()); var rangeSlider = colorChooser.GetWidget("RANGE_SLIDER"); - rangeSlider.SetOffset(Game.LocalClient.Color1.GetBrightness() == 0 ? 0 : Game.LocalClient.Color2.GetBrightness()/Game.LocalClient.Color1.GetBrightness()); + rangeSlider.SetOffset(orderManager.LocalClient.Color1.GetBrightness() == 0 ? 0 : orderManager.LocalClient.Color2.GetBrightness()/orderManager.LocalClient.Color1.GetBrightness()); UpdateColorPreview(hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset(), rangeSlider.GetOffset()); colorChooser.IsVisible = () => true; @@ -341,7 +343,7 @@ namespace OpenRA.Widgets.Delegates var status = template.GetWidget("STATUS"); status.Checked = () => c.State == Session.ClientState.Ready; - if (c.Index == Game.LocalClient.Index) status.OnMouseDown = CycleReady; + if (c.Index == orderManager.LocalClient.Index) status.OnMouseDown = CycleReady; } template.Id = "SLOT_{0}".F(s.Index); @@ -355,7 +357,7 @@ namespace OpenRA.Widgets.Delegates } } - bool SpawnPointAvailable(int index) { return (index == 0) || Game.LobbyInfo.Clients.All(c => c.SpawnPoint != index); } + bool SpawnPointAvailable(int index) { return (index == 0) || orderManager.LobbyInfo.Clients.All(c => c.SpawnPoint != index); } bool CycleRace(MouseInput mi) { var countries = CountryNames.Select(a => a.Key); @@ -364,7 +366,7 @@ namespace OpenRA.Widgets.Delegates countries = countries.Reverse(); var nextCountry = countries - .SkipWhile(c => c != Game.LocalClient.Country) + .SkipWhile(c => c != orderManager.LocalClient.Country) .Skip(1) .FirstOrDefault(); @@ -385,7 +387,7 @@ namespace OpenRA.Widgets.Delegates bool CycleTeam(MouseInput mi) { var d = (mi.Button == MouseButton.Left) ? +1 : Map.PlayerCount; - var newIndex = (Game.LocalClient.Team + d) % (Map.PlayerCount + 1); + var newIndex = (orderManager.LocalClient.Team + d) % (Map.PlayerCount + 1); Game.IssueOrder( Order.Command("team " + newIndex)); diff --git a/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs b/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs index 44783bf892..bdc46cb971 100644 --- a/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs @@ -95,7 +95,7 @@ namespace OpenRA.Widgets.Delegates // Or even better, reject them server side and display the error in the connection failed dialog. // Don't bother joining a server with different mods... its only going to crash - if (currentServer.Mods.SymmetricDifference(Game.LobbyInfo.GlobalSettings.Mods).Any()) + if (currentServer.Mods.SymmetricDifference(Game.modData.Manifest.Mods).Any()) { System.Console.WriteLine("Player has different mods to server; not connecting to avoid crash"); System.Console.WriteLine("FIX THIS BUG YOU NOOB!"); diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index 7a57be92df..7ce1d6c322 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -18,6 +18,7 @@ using OpenRA.Orders; using OpenRA.Traits; using XRandom = OpenRA.Thirdparty.Random; +using OpenRA.Network; namespace OpenRA { @@ -28,6 +29,9 @@ namespace OpenRA List effects = new List(); Queue> frameEndActions = new Queue>(); + readonly OrderManager orderManager; + public Session LobbyInfo { get { return orderManager.LobbyInfo; } } + public XRandom SharedRandom = new XRandom(0); public readonly Dictionary players = new Dictionary(); @@ -84,8 +88,9 @@ namespace OpenRA } } - public World(Manifest manifest, Map map) + internal World(Manifest manifest, Map map, OrderManager orderManager) { + this.orderManager = orderManager; orderGenerator_ = new UnitOrderGenerator(); Map = map; diff --git a/OpenRA.Mods.RA/CreateMPPlayers.cs b/OpenRA.Mods.RA/CreateMPPlayers.cs index c8a6320ee4..52b859a98a 100644 --- a/OpenRA.Mods.RA/CreateMPPlayers.cs +++ b/OpenRA.Mods.RA/CreateMPPlayers.cs @@ -34,9 +34,9 @@ namespace OpenRA.Mods.RA } // create the players which are bound through slots. - foreach (var slot in Game.LobbyInfo.Slots) + foreach (var slot in w.LobbyInfo.Slots) { - var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.Slot == slot.Index); + var client = w.LobbyInfo.Clients.FirstOrDefault(c => c.Slot == slot.Index); if (client != null) { /* spawn a real player in this slot. */ @@ -101,7 +101,7 @@ namespace OpenRA.Mods.RA static Session.Client GetClientForPlayer(Player p) { - return Game.LobbyInfo.Clients.Single(c => c.Index == p.ClientIndex); + return p.World.LobbyInfo.ClientWithIndex(p.ClientIndex); } } } diff --git a/OpenRA.Mods.RA/MPStartLocations.cs b/OpenRA.Mods.RA/MPStartLocations.cs index 3308eee92b..713bab2b37 100755 --- a/OpenRA.Mods.RA/MPStartLocations.cs +++ b/OpenRA.Mods.RA/MPStartLocations.cs @@ -28,14 +28,14 @@ namespace OpenRA.Mods.RA public void WorldLoaded(World world) { - var taken = Game.LobbyInfo.Clients.Where(c => c.SpawnPoint != 0) + var taken = world.LobbyInfo.Clients.Where(c => c.SpawnPoint != 0) .Select(c => world.Map.SpawnPoints.ElementAt(c.SpawnPoint - 1)).ToList(); var available = world.Map.SpawnPoints.Except(taken).ToList(); // Set spawn - foreach (var slot in Game.LobbyInfo.Slots) + foreach (var slot in world.LobbyInfo.Slots) { - var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.Slot == slot.Index); + var client = world.LobbyInfo.Clients.FirstOrDefault(c => c.Slot == slot.Index); var player = FindPlayerInSlot(world, slot); if (player == null) continue; diff --git a/OpenRA.Mods.RA/Player/ProductionQueue.cs b/OpenRA.Mods.RA/Player/ProductionQueue.cs index 2a8817d179..5e8e3c770b 100755 --- a/OpenRA.Mods.RA/Player/ProductionQueue.cs +++ b/OpenRA.Mods.RA/Player/ProductionQueue.cs @@ -97,7 +97,7 @@ namespace OpenRA.Mods.RA public virtual IEnumerable AllItems() { - if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait().AllTech) + if (self.World.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait().AllTech) return Produceable.Select(a => a.Key); return Produceable.Where(a => a.Value.Buildable || a.Value.Visible).Select(a => a.Key); @@ -105,7 +105,7 @@ namespace OpenRA.Mods.RA public virtual IEnumerable BuildableItems() { - if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait().AllTech) + if (self.World.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait().AllTech) return Produceable.Select(a => a.Key); return Produceable.Where(a => a.Value.Buildable).Select(a => a.Key); @@ -185,7 +185,7 @@ namespace OpenRA.Mods.RA if (unit == null || ! unit.Traits.Contains()) return 0; - if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait().FastBuild) return 0; + if (self.World.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait().FastBuild) return 0; var cost = unit.Traits.Contains() ? unit.Traits.Get().Cost : 0; var time = cost * Info.BuildSpeed diff --git a/OpenRA.Mods.RA/SupportPowers/SupportPower.cs b/OpenRA.Mods.RA/SupportPowers/SupportPower.cs index ca0fe097fb..545d44555b 100755 --- a/OpenRA.Mods.RA/SupportPowers/SupportPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/SupportPower.cs @@ -74,7 +74,7 @@ namespace OpenRA.Mods.RA if (IsAvailable && (!Info.RequiresPower || PlayerPower.PowerState == PowerState.Normal)) { - if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Trait().FastCharge) RemainingTime = 0; + if (self.World.LobbyInfo.GlobalSettings.AllowCheats && self.Trait().FastCharge) RemainingTime = 0; if (RemainingTime > 0) --RemainingTime; if (!notifiedCharging)