move LobbyInfo onto OrderManager

This commit is contained in:
Bob
2010-10-11 16:00:02 +13:00
parent beecb8aeb1
commit 17990ab8b7
17 changed files with 98 additions and 88 deletions

View File

@@ -18,7 +18,7 @@ namespace OpenRA.FileFormats
public class Manifest public class Manifest
{ {
public readonly string[] public readonly string[]
Folders, Packages, Rules, Mods, Folders, Packages, Rules,
Sequences, Cursors, Chrome, Assemblies, ChromeLayout, Sequences, Cursors, Chrome, Assemblies, ChromeLayout,
Weapons, Voices, Music, Movies, TileSets; Weapons, Voices, Music, Movies, TileSets;
@@ -27,6 +27,7 @@ namespace OpenRA.FileFormats
public Manifest(string[] mods) public Manifest(string[] mods)
{ {
Mods = mods;
var yaml = mods var yaml = mods
.Select(m => MiniYaml.FromFile("mods/" + m + "/mod.yaml")) .Select(m => MiniYaml.FromFile("mods/" + m + "/mod.yaml"))
.Aggregate(MiniYaml.Merge); .Aggregate(MiniYaml.Merge);

View File

@@ -40,7 +40,6 @@ namespace OpenRA
public static XRandom CosmeticRandom = new XRandom(); // not synced public static XRandom CosmeticRandom = new XRandom(); // not synced
public static Renderer Renderer; public static Renderer Renderer;
public static Session LobbyInfo = new Session();
public static bool HasInputFocus = false; public static bool HasInputFocus = false;
static void LoadMap(string uid) static void LoadMap(string uid)
@@ -48,7 +47,7 @@ namespace OpenRA
var map = modData.PrepareMap(uid); var map = modData.PrepareMap(uid);
viewport = new Viewport(new float2(Renderer.Resolution), map.TopLeft, map.BottomRight, Renderer); 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) public static void MoveViewport(int2 loc)
@@ -164,29 +163,13 @@ namespace OpenRA
internal static event Action LobbyInfoChanged = () => { }; 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(); LobbyInfoChanged();
} }
public static void IssueOrder( Order o ) { orderManager.IssueOrder( o ); } /* avoid exposing the OM to mod code */ public static void IssueOrder( Order o ) { orderManager.IssueOrder( o ); } /* avoid exposing the OM to mod code */
public static event Action<World> AfterGameStart = _ => {}; public static event Action<World> AfterGameStart = _ => {};
public static event Action BeforeGameStart = () => {}; public static event Action BeforeGameStart = () => {};
internal static void StartGame(string map) internal static void StartGame(string map)
@@ -227,11 +210,6 @@ namespace OpenRA
get { return orderManager.Connection.LocalClientId == 0; } 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) public static void HandleKeyEvent(KeyInput e)
{ {
var world = Game.world; var world = Game.world;
@@ -278,10 +256,10 @@ namespace OpenRA
Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version); Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version);
// Discard any invalid mods // Discard any invalid mods
LobbyInfo.GlobalSettings.Mods = Settings.Game.Mods.Where(m => ModData.AllMods.ContainsKey(m)).ToArray(); var mods = Settings.Game.Mods.Where( m => ModData.AllMods.ContainsKey( m ) ).ToArray();
Console.WriteLine("Loading mods: {0}",string.Join(",",LobbyInfo.GlobalSettings.Mods)); Console.WriteLine("Loading mods: {0}",string.Join(",",mods));
modData = new ModData( LobbyInfo.GlobalSettings.Mods ); modData = new ModData( mods );
Sound.Initialize(); Sound.Initialize();
PerfHistory.items["render"].hasNormalTick = false; PerfHistory.items["render"].hasNormalTick = false;
@@ -309,7 +287,7 @@ namespace OpenRA
case ConnectionState.NotConnected: case ConnectionState.NotConnected:
Widget.OpenWindow("CONNECTION_FAILED_BG"); Widget.OpenWindow("CONNECTION_FAILED_BG");
break; break;
case ConnectionState.Connected: case ConnectionState.Connected:
var lobby = Widget.OpenWindow( "SERVER_LOBBY", new Dictionary<string, object> { { "orderManager", orderManager } } ); var lobby = Widget.OpenWindow( "SERVER_LOBBY", new Dictionary<string, object> { { "orderManager", orderManager } } );
lobby.GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").ClearChat(); lobby.GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").ClearChat();
lobby.GetWidget("CHANGEMAP_BUTTON").Visible = true; lobby.GetWidget("CHANGEMAP_BUTTON").Visible = true;
@@ -348,8 +326,6 @@ namespace OpenRA
public static void Disconnect() public static void Disconnect()
{ {
orderManager.Dispose(); orderManager.Dispose();
var shellmap = modData.Manifest.ShellmapUid;
LobbyInfo = new Session();
var shellmap = modData.Manifest.ShellmapUid; var shellmap = modData.Manifest.ShellmapUid;
JoinLocal(); JoinLocal();
StartGame(shellmap); StartGame(shellmap);

View File

@@ -21,8 +21,10 @@ namespace OpenRA.Network
readonly SyncReport syncReport = new SyncReport(); readonly SyncReport syncReport = new SyncReport();
readonly FrameData frameData = new FrameData(); 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 int FramesAhead = 0;
public bool GameStarted { get { return FrameNumber != 0; } } public bool GameStarted { get { return FrameNumber != 0; } }
@@ -82,7 +84,7 @@ namespace OpenRA.Network
foreach( var p in immediatePackets ) foreach( var p in immediatePackets )
foreach( var o in p.Second.ToOrderList( world ) ) foreach( var o in p.Second.ToOrderList( world ) )
UnitOrders.ProcessOrder( world, p.First, o ); UnitOrders.ProcessOrder( this, world, p.First, o );
} }
Dictionary<int, byte[]> syncForFrame = new Dictionary<int, byte[]>(); Dictionary<int, byte[]> syncForFrame = new Dictionary<int, byte[]>();
@@ -152,7 +154,7 @@ namespace OpenRA.Network
foreach( var order in frameData.OrdersForFrame( world, FrameNumber) ) 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() ); sync.Add( world.SyncHash() );
} }

View File

@@ -10,6 +10,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq;
using OpenRA.FileFormats; using OpenRA.FileFormats;
namespace OpenRA.Network namespace OpenRA.Network
@@ -20,6 +21,16 @@ namespace OpenRA.Network
public List<Slot> Slots = new List<Slot>(); public List<Slot> Slots = new List<Slot>();
public Global GlobalSettings = new Global(); 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 public enum ClientState
{ {
NotReady, NotReady,
@@ -59,6 +70,11 @@ namespace OpenRA.Network
public bool AllowCheats = false; public bool AllowCheats = false;
} }
public Session( string[] mods )
{
this.GlobalSettings.Mods = mods.ToArray();
}
public string Serialize() public string Serialize()
{ {
var clientData = new List<MiniYamlNode>(); var clientData = new List<MiniYamlNode>();
@@ -76,8 +92,7 @@ namespace OpenRA.Network
public static Session Deserialize(string data) public static Session Deserialize(string data)
{ {
var session = new Session(); var session = new Session( Game.Settings.Game.Mods );
session.GlobalSettings.Mods = Game.Settings.Game.Mods;
var ys = MiniYaml.FromString(data); var ys = MiniYaml.FromString(data);
foreach (var y in ys) foreach (var y in ys)

View File

@@ -16,18 +16,13 @@ namespace OpenRA.Network
{ {
static class UnitOrders 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) static Player FindPlayerByClientId( this World world, int id)
{ {
/* todo: find the interactive player. */ /* todo: find the interactive player. */
return world.players.Values.FirstOrDefault(p => p.ClientIndex == id); 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 // Drop exploiting orders
if (order.Subject != null && order.Subject.Owner.ClientIndex != clientId) if (order.Subject != null && order.Subject.Owner.ClientIndex != clientId)
@@ -40,7 +35,7 @@ namespace OpenRA.Network
{ {
case "Chat": case "Chat":
{ {
var client = FindClientById(clientId); var client = orderManager.LobbyInfo.ClientWithIndex( clientId );
if (client != null) if (client != null)
{ {
var player = world.FindPlayerByClientId(clientId); var player = world.FindPlayerByClientId(clientId);
@@ -53,14 +48,14 @@ namespace OpenRA.Network
} }
case "TeamChat": case "TeamChat":
{ {
var client = FindClientById(clientId); var client = orderManager.LobbyInfo.ClientWithIndex(clientId);
if (client != null) if (client != null)
{ {
var player = world.FindPlayerByClientId(clientId); var player = world.FindPlayerByClientId(clientId);
var display = (world.GameHasStarted) ? var display = (world.GameHasStarted) ?
player != null && (world.LocalPlayer != null && player.Stances[world.LocalPlayer] == Stance.Ally player != null && (world.LocalPlayer != null && player.Stances[world.LocalPlayer] == Stance.Ally
|| player.WinState == WinState.Lost) : || 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) if (display)
{ {
@@ -73,12 +68,27 @@ namespace OpenRA.Network
case "StartGame": case "StartGame":
{ {
Game.AddChatLine(Color.White, "Server", "The game has started."); Game.AddChatLine(Color.White, "Server", "The game has started.");
Game.StartGame(Game.LobbyInfo.GlobalSettings.Map); Game.StartGame(orderManager.LobbyInfo.GlobalSettings.Map);
break; break;
} }
case "SyncInfo": 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; break;
} }
case "SetStance": case "SetStance":

View File

@@ -42,7 +42,7 @@ namespace OpenRA
{ {
var type = mod.First.GetType( mod.Second + "." + className, false ); var type = mod.First.GetType( mod.Second + "." + className, false );
if( type == null ) continue; if( type == null ) continue;
var ctors = type.GetConstructors().Where( x => x.HasAttribute<UseCtorAttribute>() ).ToList(); var ctors = type.GetConstructors( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance ).Where( x => x.HasAttribute<UseCtorAttribute>() ).ToList();
if( ctors.Count == 0 ) if( ctors.Count == 0 )
return (T)CreateBasic( type ); return (T)CreateBasic( type );
else if( ctors.Count == 1 ) else if( ctors.Count == 1 )

View File

@@ -60,8 +60,7 @@ namespace OpenRA.Server
randomSeed = (int)DateTime.Now.ToBinary(); randomSeed = (int)DateTime.Now.ToBinary();
ModData = modData; ModData = modData;
lobbyInfo = new Session(); lobbyInfo = new Session( settings.Game.Mods );
lobbyInfo.GlobalSettings.Mods = settings.Game.Mods;
lobbyInfo.GlobalSettings.RandomSeed = randomSeed; lobbyInfo.GlobalSettings.RandomSeed = randomSeed;
lobbyInfo.GlobalSettings.Map = map; lobbyInfo.GlobalSettings.Map = map;
lobbyInfo.GlobalSettings.AllowCheats = settings.Server.AllowCheats; lobbyInfo.GlobalSettings.AllowCheats = settings.Server.AllowCheats;

View File

@@ -42,7 +42,7 @@ namespace OpenRA.Traits
public void ResolveOrder (Actor self, Order order) public void ResolveOrder (Actor self, Order order)
{ {
if (!Game.LobbyInfo.GlobalSettings.AllowCheats) return; if (!self.World.LobbyInfo.GlobalSettings.AllowCheats) return;
switch(order.OrderString) switch(order.OrderString)
{ {

View File

@@ -101,7 +101,7 @@ namespace OpenRA.Widgets.Delegates
return true; return true;
}; };
devModeButton.IsVisible = () => { return Game.LobbyInfo.GlobalSettings.AllowCheats; }; devModeButton.IsVisible = () => { return world.LobbyInfo.GlobalSettings.AllowCheats; };
} }
} }
} }

View File

@@ -133,7 +133,7 @@ namespace OpenRA.Widgets.Delegates
void CycleStance(Player p, ButtonWidget bw) void CycleStance(Player p, ButtonWidget bw)
{ {
if (Game.LobbyInfo.GlobalSettings.LockTeams) if (p.World.LobbyInfo.GlobalSettings.LockTeams)
return; // team changes are banned return; // team changes are banned
var nextStance = GetNextStance((Stance)Enum.Parse(typeof(Stance), bw.Text)); var nextStance = GetNextStance((Stance)Enum.Parse(typeof(Stance), bw.Text));

View File

@@ -27,9 +27,11 @@ namespace OpenRA.Widgets.Delegates
public static Color CurrentColorPreview1; public static Color CurrentColorPreview1;
public static Color CurrentColorPreview2; public static Color CurrentColorPreview2;
readonly OrderManager orderManager;
[ObjectCreator.UseCtor] [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; Game.LobbyInfoChanged += UpdateCurrentMap;
UpdateCurrentMap(); UpdateCurrentMap();
@@ -46,8 +48,8 @@ namespace OpenRA.Widgets.Delegates
mapPreview.Map = () => Map; mapPreview.Map = () => Map;
mapPreview.OnSpawnClick = sp => mapPreview.OnSpawnClick = sp =>
{ {
if (Game.LocalClient.State == Session.ClientState.Ready) return; if (orderManager.LocalClient.State == Session.ClientState.Ready) return;
var owned = Game.LobbyInfo.Clients.Any(c => c.SpawnPoint == sp); var owned = orderManager.LobbyInfo.Clients.Any(c => c.SpawnPoint == sp);
if (sp == 0 || !owned) if (sp == 0 || !owned)
Game.IssueOrder(Order.Command("spawn {0}".F(sp))); Game.IssueOrder(Order.Command("spawn {0}".F(sp)));
}; };
@@ -59,7 +61,7 @@ namespace OpenRA.Widgets.Delegates
for (int i = 1; i <= spawns.Count(); i++) 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) if (client == null)
continue; continue;
sc.Add(spawns.ElementAt(i - 1), client.Color1); sc.Add(spawns.ElementAt(i - 1), client.Color1);
@@ -88,12 +90,12 @@ namespace OpenRA.Widgets.Delegates
var lockTeamsCheckbox = lobby.GetWidget<CheckboxWidget>("LOCKTEAMS_CHECKBOX"); var lockTeamsCheckbox = lobby.GetWidget<CheckboxWidget>("LOCKTEAMS_CHECKBOX");
lockTeamsCheckbox.IsVisible = () => lockTeamsCheckbox.Visible && true; lockTeamsCheckbox.IsVisible = () => lockTeamsCheckbox.Visible && true;
lockTeamsCheckbox.Checked = () => Game.LobbyInfo.GlobalSettings.LockTeams; lockTeamsCheckbox.Checked = () => orderManager.LobbyInfo.GlobalSettings.LockTeams;
lockTeamsCheckbox.OnMouseDown = mi => lockTeamsCheckbox.OnMouseDown = mi =>
{ {
if (Game.IsHost) if (Game.IsHost)
Game.IssueOrder(Order.Command( Game.IssueOrder(Order.Command(
"lockteams {0}".F(!Game.LobbyInfo.GlobalSettings.LockTeams))); "lockteams {0}".F(!orderManager.LobbyInfo.GlobalSettings.LockTeams)));
return true; return true;
}; };
@@ -175,8 +177,8 @@ namespace OpenRA.Widgets.Delegates
void UpdateCurrentMap() void UpdateCurrentMap()
{ {
if (MapUid == Game.LobbyInfo.GlobalSettings.Map) return; if (MapUid == orderManager.LobbyInfo.GlobalSettings.Map) return;
MapUid = Game.LobbyInfo.GlobalSettings.Map; MapUid = orderManager.LobbyInfo.GlobalSettings.Map;
Map = Game.modData.AvailableMaps[MapUid]; Map = Game.modData.AvailableMaps[MapUid];
} }
@@ -188,13 +190,13 @@ namespace OpenRA.Widgets.Delegates
return; return;
hasJoined = true; 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)); Game.IssueOrder(Order.Command("name " + Game.Settings.Player.Name));
var c1 = Game.Settings.Player.Color1; var c1 = Game.Settings.Player.Color1;
var c2 = Game.Settings.Player.Color2; 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))); 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; 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() void UpdatePlayerList()
@@ -216,7 +218,7 @@ namespace OpenRA.Widgets.Delegates
Players.Children.Clear(); Players.Children.Clear();
int offset = 0; int offset = 0;
foreach (var slot in Game.LobbyInfo.Slots) foreach (var slot in orderManager.LobbyInfo.Slots)
{ {
var s = slot; var s = slot;
var c = GetClientInSlot(s); var c = GetClientInSlot(s);
@@ -260,7 +262,7 @@ namespace OpenRA.Widgets.Delegates
join.IsVisible = () => !s.Closed && s.Bot == null; 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(); template = LocalPlayerTemplate.Clone();
var name = template.GetWidget<TextFieldWidget>("NAME"); var name = template.GetWidget<TextFieldWidget>("NAME");
@@ -287,16 +289,16 @@ namespace OpenRA.Widgets.Delegates
{ {
var colorChooser = Widget.RootWidget.GetWidget("SERVER_LOBBY").GetWidget("COLOR_CHOOSER"); var colorChooser = Widget.RootWidget.GetWidget("SERVER_LOBBY").GetWidget("COLOR_CHOOSER");
var hueSlider = colorChooser.GetWidget<SliderWidget>("HUE_SLIDER"); var hueSlider = colorChooser.GetWidget<SliderWidget>("HUE_SLIDER");
hueSlider.SetOffset(Game.LocalClient.Color1.GetHue()/360f); hueSlider.SetOffset(orderManager.LocalClient.Color1.GetHue()/360f);
var satSlider = colorChooser.GetWidget<SliderWidget>("SAT_SLIDER"); var satSlider = colorChooser.GetWidget<SliderWidget>("SAT_SLIDER");
satSlider.SetOffset(Game.LocalClient.Color1.GetSaturation()); satSlider.SetOffset(orderManager.LocalClient.Color1.GetSaturation());
var lumSlider = colorChooser.GetWidget<SliderWidget>("LUM_SLIDER"); var lumSlider = colorChooser.GetWidget<SliderWidget>("LUM_SLIDER");
lumSlider.SetOffset(Game.LocalClient.Color1.GetBrightness()); lumSlider.SetOffset(orderManager.LocalClient.Color1.GetBrightness());
var rangeSlider = colorChooser.GetWidget<SliderWidget>("RANGE_SLIDER"); var rangeSlider = colorChooser.GetWidget<SliderWidget>("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()); UpdateColorPreview(hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset(), rangeSlider.GetOffset());
colorChooser.IsVisible = () => true; colorChooser.IsVisible = () => true;
@@ -341,7 +343,7 @@ namespace OpenRA.Widgets.Delegates
var status = template.GetWidget<CheckboxWidget>("STATUS"); var status = template.GetWidget<CheckboxWidget>("STATUS");
status.Checked = () => c.State == Session.ClientState.Ready; 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); 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) bool CycleRace(MouseInput mi)
{ {
var countries = CountryNames.Select(a => a.Key); var countries = CountryNames.Select(a => a.Key);
@@ -364,7 +366,7 @@ namespace OpenRA.Widgets.Delegates
countries = countries.Reverse(); countries = countries.Reverse();
var nextCountry = countries var nextCountry = countries
.SkipWhile(c => c != Game.LocalClient.Country) .SkipWhile(c => c != orderManager.LocalClient.Country)
.Skip(1) .Skip(1)
.FirstOrDefault(); .FirstOrDefault();
@@ -385,7 +387,7 @@ namespace OpenRA.Widgets.Delegates
bool CycleTeam(MouseInput mi) bool CycleTeam(MouseInput mi)
{ {
var d = (mi.Button == MouseButton.Left) ? +1 : Map.PlayerCount; 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( Game.IssueOrder(
Order.Command("team " + newIndex)); Order.Command("team " + newIndex));

View File

@@ -95,7 +95,7 @@ namespace OpenRA.Widgets.Delegates
// Or even better, reject them server side and display the error in the connection failed dialog. // 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 // 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("Player has different mods to server; not connecting to avoid crash");
System.Console.WriteLine("FIX THIS BUG YOU NOOB!"); System.Console.WriteLine("FIX THIS BUG YOU NOOB!");

View File

@@ -18,6 +18,7 @@ using OpenRA.Orders;
using OpenRA.Traits; using OpenRA.Traits;
using XRandom = OpenRA.Thirdparty.Random; using XRandom = OpenRA.Thirdparty.Random;
using OpenRA.Network;
namespace OpenRA namespace OpenRA
{ {
@@ -28,6 +29,9 @@ namespace OpenRA
List<IEffect> effects = new List<IEffect>(); List<IEffect> effects = new List<IEffect>();
Queue<Action<World>> frameEndActions = new Queue<Action<World>>(); Queue<Action<World>> frameEndActions = new Queue<Action<World>>();
readonly OrderManager orderManager;
public Session LobbyInfo { get { return orderManager.LobbyInfo; } }
public XRandom SharedRandom = new XRandom(0); public XRandom SharedRandom = new XRandom(0);
public readonly Dictionary<int, Player> players = new Dictionary<int, Player>(); public readonly Dictionary<int, Player> players = new Dictionary<int, Player>();
@@ -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(); orderGenerator_ = new UnitOrderGenerator();
Map = map; Map = map;

View File

@@ -34,9 +34,9 @@ namespace OpenRA.Mods.RA
} }
// create the players which are bound through slots. // 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) if (client != null)
{ {
/* spawn a real player in this slot. */ /* spawn a real player in this slot. */
@@ -101,7 +101,7 @@ namespace OpenRA.Mods.RA
static Session.Client GetClientForPlayer(Player p) static Session.Client GetClientForPlayer(Player p)
{ {
return Game.LobbyInfo.Clients.Single(c => c.Index == p.ClientIndex); return p.World.LobbyInfo.ClientWithIndex(p.ClientIndex);
} }
} }
} }

View File

@@ -28,14 +28,14 @@ namespace OpenRA.Mods.RA
public void WorldLoaded(World world) 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(); .Select(c => world.Map.SpawnPoints.ElementAt(c.SpawnPoint - 1)).ToList();
var available = world.Map.SpawnPoints.Except(taken).ToList(); var available = world.Map.SpawnPoints.Except(taken).ToList();
// Set spawn // 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); var player = FindPlayerInSlot(world, slot);
if (player == null) continue; if (player == null) continue;

View File

@@ -97,7 +97,7 @@ namespace OpenRA.Mods.RA
public virtual IEnumerable<ActorInfo> AllItems() public virtual IEnumerable<ActorInfo> AllItems()
{ {
if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait<DeveloperMode>().AllTech) if (self.World.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait<DeveloperMode>().AllTech)
return Produceable.Select(a => a.Key); return Produceable.Select(a => a.Key);
return Produceable.Where(a => a.Value.Buildable || a.Value.Visible).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<ActorInfo> BuildableItems() public virtual IEnumerable<ActorInfo> BuildableItems()
{ {
if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait<DeveloperMode>().AllTech) if (self.World.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait<DeveloperMode>().AllTech)
return Produceable.Select(a => a.Key); return Produceable.Select(a => a.Key);
return Produceable.Where(a => a.Value.Buildable).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<BuildableInfo>()) if (unit == null || ! unit.Traits.Contains<BuildableInfo>())
return 0; return 0;
if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild) return 0; if (self.World.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild) return 0;
var cost = unit.Traits.Contains<ValuedInfo>() ? unit.Traits.Get<ValuedInfo>().Cost : 0; var cost = unit.Traits.Contains<ValuedInfo>() ? unit.Traits.Get<ValuedInfo>().Cost : 0;
var time = cost var time = cost
* Info.BuildSpeed * Info.BuildSpeed

View File

@@ -74,7 +74,7 @@ namespace OpenRA.Mods.RA
if (IsAvailable && (!Info.RequiresPower || PlayerPower.PowerState == PowerState.Normal)) if (IsAvailable && (!Info.RequiresPower || PlayerPower.PowerState == PowerState.Normal))
{ {
if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Trait<DeveloperMode>().FastCharge) RemainingTime = 0; if (self.World.LobbyInfo.GlobalSettings.AllowCheats && self.Trait<DeveloperMode>().FastCharge) RemainingTime = 0;
if (RemainingTime > 0) --RemainingTime; if (RemainingTime > 0) --RemainingTime;
if (!notifiedCharging) if (!notifiedCharging)