diff --git a/OpenRA.Game/Chat.cs b/OpenRA.Game/Chat.cs index 11b7118d08..910f5fdcc5 100644 --- a/OpenRA.Game/Chat.cs +++ b/OpenRA.Game/Chat.cs @@ -62,7 +62,7 @@ namespace OpenRA public void AddLine(Session.Client p, string text) { - AddLine(Player.PlayerColors[p.PaletteIndex].c, p.Name, text); + AddLine(Player.PlayerColors( Game.world )[p.PaletteIndex].c, p.Name, text); } public void AddLine(Color c, string from, string text) diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs index 45616104dc..3815d52f55 100644 --- a/OpenRA.Game/Chrome.cs +++ b/OpenRA.Game/Chrome.cs @@ -325,7 +325,7 @@ namespace OpenRA new int2(mapContainer.Left + mapContainer.Width / 2, y), Color.White); y += 20; - var theaterInfo = Game.world.WorldActor.Info.Traits.WithInterface().FirstOrDefault(t => t.Theater == currentMap.Tileset); + var theaterInfo = Rules.Info["world"].Traits.WithInterface().FirstOrDefault(t => t.Theater == currentMap.Tileset); DrawCentered("Theater: {0}".F(theaterInfo.Name), new int2(mapContainer.Left + mapContainer.Width / 2, y), Color.White); y += 20; @@ -339,12 +339,12 @@ namespace OpenRA void CyclePalette(bool left) { - var d = left ? +1 : Player.PlayerColors.Count() - 1; + var d = left ? +1 : Player.PlayerColors(Game.world).Count() - 1; - var newIndex = ((int)Game.LocalClient.PaletteIndex + d) % Player.PlayerColors.Count(); + var newIndex = ((int)Game.LocalClient.PaletteIndex + d) % Player.PlayerColors(Game.world).Count(); while (!PaletteAvailable(newIndex) && newIndex != (int)Game.LocalClient.PaletteIndex) - newIndex = (newIndex + d) % Player.PlayerColors.Count(); + newIndex = (newIndex + d) % Player.PlayerColors(Game.world).Count(); Game.IssueOrder( Order.Chat("/pal " + newIndex)); @@ -521,7 +521,7 @@ namespace OpenRA paletteRect.Top + Game.viewport.Location.Y + 5, paletteRect.Right + Game.viewport.Location.X - 5, paletteRect.Bottom+Game.viewport.Location.Y - 5), - Player.PlayerColors[client.PaletteIndex % Player.PlayerColors.Count()].c); + Player.PlayerColors(Game.world)[client.PaletteIndex % Player.PlayerColors(Game.world).Count()].c); lineRenderer.Flush(); f.DrawText(client.Country, new int2(r.Left + 220, y), Color.White); f.DrawText(client.State.ToString(), new int2(r.Left + 290, y), Color.White); @@ -558,7 +558,7 @@ namespace OpenRA if (radarAnimationFrame <= radarSlideAnimationLength) radarOrigin = float2.Lerp(radarClosedOrigin, radarOpenOrigin, radarAnimationFrame * 1.0f / radarSlideAnimationLength); - var eva = Game.world.WorldActor.Info.Traits.Get(); + var eva = Rules.Info["world"].Traits.Get(); // Play radar-on sound at the start of the activate anim (open) if (radarAnimationFrame == radarSlideAnimationLength && hasRadar) @@ -642,7 +642,7 @@ namespace OpenRA void HandleTabClick(string button) { - var eva = Game.world.WorldActor.Info.Traits.Get(); + var eva = Rules.Info["world"].Traits.Get(); Sound.Play(eva.TabClick); var wasOpen = paletteOpen; paletteOpen = (currentTab == button && wasOpen) ? false : true; @@ -829,7 +829,7 @@ namespace OpenRA if (paletteAnimationFrame <= paletteAnimationLength) paletteOrigin = float2.Lerp(paletteClosedOrigin, paletteOpenOrigin, paletteAnimationFrame * 1.0f / paletteAnimationLength); - var eva = Game.world.WorldActor.Info.Traits.Get(); + var eva = Rules.Info["world"].Traits.Get(); // Play palette-open sound at the start of the activate anim (open) if (paletteAnimationFrame == 1 && paletteOpen) diff --git a/OpenRA.Game/Graphics/Minimap.cs b/OpenRA.Game/Graphics/Minimap.cs index c8553d6a80..42ead5228b 100644 --- a/OpenRA.Game/Graphics/Minimap.cs +++ b/OpenRA.Game/Graphics/Minimap.cs @@ -79,7 +79,7 @@ namespace OpenRA.Graphics static Cache terrainTypeColors = new Cache( theater => { - return new TerrainColorSet(Game.world.WorldActor.Info.Traits.WithInterface().FirstOrDefault(t => t.Theater == theater).MapColors); + return new TerrainColorSet(Rules.Info["world"].Traits.WithInterface().FirstOrDefault(t => t.Theater == theater).MapColors); }); static Color shroudColor; @@ -194,7 +194,7 @@ namespace OpenRA.Graphics lineRenderer.FillRect(new RectangleF( Game.viewport.Location.X + pos.X + 2, Game.viewport.Location.Y + pos.Y + 2, - 12, 12), Player.PlayerColors[ p.Second.PaletteIndex % Player.PlayerColors.Count() ].c); + 12, 12), Player.PlayerColors(world)[ p.Second.PaletteIndex % Player.PlayerColors(world).Count() ].c); rgbaRenderer.DrawSprite(ownedSpawnPoint, pos, "chrome"); } diff --git a/OpenRA.Game/Graphics/TerrainRenderer.cs b/OpenRA.Game/Graphics/TerrainRenderer.cs index 0be5fe1b21..bbb9c2de0d 100644 --- a/OpenRA.Game/Graphics/TerrainRenderer.cs +++ b/OpenRA.Game/Graphics/TerrainRenderer.cs @@ -31,11 +31,13 @@ namespace OpenRA.Graphics IIndexBuffer indexBuffer; Sheet terrainSheet; + World world; Renderer renderer; Map map; public TerrainRenderer(World world, Renderer renderer, WorldRenderer wr) { + this.world = world; this.renderer = renderer; this.map = world.Map; @@ -88,9 +90,9 @@ namespace OpenRA.Graphics if (firstRow < 0) firstRow = 0; if (lastRow > map.Height) lastRow = map.Height; - if (Game.world.LocalPlayer != null && !Game.world.LocalPlayer.Shroud.Disabled && Game.world.LocalPlayer.Shroud.bounds.HasValue) + if (world.LocalPlayer != null && !world.LocalPlayer.Shroud.Disabled && world.LocalPlayer.Shroud.bounds.HasValue) { - var r = Game.world.LocalPlayer.Shroud.bounds.Value; + var r = world.LocalPlayer.Shroud.bounds.Value; if (firstRow < r.Top - map.YOffset) firstRow = r.Top - map.YOffset; @@ -107,7 +109,7 @@ namespace OpenRA.Graphics new Range(indicesPerRow * firstRow, indicesPerRow * lastRow), PrimitiveType.TriangleList, renderer.SpriteShader)); - foreach (var r in Game.world.WorldActor.traits.WithInterface()) + foreach (var r in world.WorldActor.traits.WithInterface()) r.Render(); } } diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 1eeee1aa3e..3477562d66 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -166,11 +166,11 @@ namespace OpenRA.Graphics if (world.LocalPlayer != null) DrawBox(world.LocalPlayer.Shroud.bounds.Value, Color.Blue); - for (var j = 0; j < Game.world.Map.MapSize.Y; - j += Game.world.WorldActor.Info.Traits.Get().BinSize) + for (var j = 0; j < world.Map.MapSize.Y; + j += world.WorldActor.Info.Traits.Get().BinSize) { - lineRenderer.DrawLine(new float2(0, j * 24), new float2(Game.world.Map.MapSize.X * 24, j * 24), Color.Black, Color.Black); - lineRenderer.DrawLine(new float2(j * 24, 0), new float2(j * 24, Game.world.Map.MapSize.Y * 24), Color.Black, Color.Black); + lineRenderer.DrawLine(new float2(0, j * 24), new float2(world.Map.MapSize.X * 24, j * 24), Color.Black, Color.Black); + lineRenderer.DrawLine(new float2(j * 24, 0), new float2(j * 24, world.Map.MapSize.Y * 24), Color.Black, Color.Black); } } diff --git a/OpenRA.Game/PathSearch.cs b/OpenRA.Game/PathSearch.cs index e465facfeb..b36e71bd9b 100755 --- a/OpenRA.Game/PathSearch.cs +++ b/OpenRA.Game/PathSearch.cs @@ -29,6 +29,7 @@ namespace OpenRA { public class PathSearch { + World world; public CellInfo[ , ] cellInfo; public PriorityQueue queue; public Func heuristic; @@ -42,6 +43,7 @@ namespace OpenRA public PathSearch(World world) { + this.world = world; cellInfo = InitCellInfo(); queue = new PriorityQueue(); @@ -171,11 +173,11 @@ namespace OpenRA return search; } - static CellInfo[ , ] InitCellInfo() + CellInfo[ , ] InitCellInfo() { - var cellInfo = new CellInfo[ Game.world.Map.MapSize.X, Game.world.Map.MapSize.Y ]; - for( int x = 0 ; x < Game.world.Map.MapSize.X ; x++ ) - for( int y = 0 ; y < Game.world.Map.MapSize.Y ; y++ ) + var cellInfo = new CellInfo[ world.Map.MapSize.X, world.Map.MapSize.Y ]; + for( int x = 0 ; x < world.Map.MapSize.X ; x++ ) + for( int y = 0 ; y < world.Map.MapSize.Y ; y++ ) cellInfo[ x, y ] = new CellInfo( float.PositiveInfinity, new int2( x, y ), false ); return cellInfo; } diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index c01cf28fb4..b30ab049b3 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -52,15 +52,12 @@ namespace OpenRA public ShroudRenderer Shroud; public World World { get; private set; } - public static List> PlayerColors + public static List> PlayerColors( World world ) { - get - { - return Game.world.WorldActor.Info.Traits.WithInterface() - .Where(p => p.Playable) - .Select(p => Tuple.New(p.Name, p.DisplayName, p.Color)) - .ToList(); - } + return world.WorldActor.Info.Traits.WithInterface() + .Where(p => p.Playable) + .Select(p => Tuple.New(p.Name, p.DisplayName, p.Color)) + .ToList(); } public Player( World world, Session.Client client ) @@ -73,8 +70,8 @@ namespace OpenRA if (client != null) { Index = client.Index; - Palette = PlayerColors[client.PaletteIndex % PlayerColors.Count()].a; - Color = PlayerColors[client.PaletteIndex % PlayerColors.Count()].c; + Palette = PlayerColors(world)[client.PaletteIndex % PlayerColors(world).Count()].a; + Color = PlayerColors(world)[client.PaletteIndex % PlayerColors(world).Count()].c; PlayerName = client.Name; InternalName = "Multi{0}".F(client.Index); } diff --git a/OpenRA.Game/Traits/World/ResourceLayer.cs b/OpenRA.Game/Traits/World/ResourceLayer.cs index d413890d4e..ce333cf7a2 100644 --- a/OpenRA.Game/Traits/World/ResourceLayer.cs +++ b/OpenRA.Game/Traits/World/ResourceLayer.cs @@ -32,7 +32,7 @@ namespace OpenRA.Traits public class ResourceLayer: IRenderOverlay, ILoadWorldHook { SpriteRenderer sr; - World w; + World world; public ResourceTypeInfo[] resourceTypes; CellContents[,] content; @@ -44,12 +44,12 @@ namespace OpenRA.Traits public void Render() { - var map = Game.world.Map; + var map = world.Map; for (int y = map.YOffset; y < map.YOffset + map.Height; y++) for (int x = map.XOffset; x < map.XOffset + map.Width; x++) { - if (Game.world.LocalPlayer != null && !Game.world.LocalPlayer.Shroud.IsExplored(new int2(x, y))) continue; + if (world.LocalPlayer != null && !world.LocalPlayer.Shroud.IsExplored(new int2(x, y))) continue; var c = content[x, y]; if (c.image != null) @@ -63,7 +63,7 @@ namespace OpenRA.Traits public void WorldLoaded(World w) { - this.w = w; + this.world = w; content = new CellContents[w.Map.MapSize.X, w.Map.MapSize.Y]; resourceTypes = w.WorldActor.Info.Traits.WithInterface().ToArray(); @@ -89,7 +89,7 @@ namespace OpenRA.Traits public Sprite[] ChooseContent(ResourceTypeInfo info) { - return info.Sprites[w.SharedRandom.Next(info.Sprites.Length)]; + return info.Sprites[world.SharedRandom.Next(info.Sprites.Length)]; } public int GetAdjacentCellsWith(ResourceTypeInfo info, int i, int j) @@ -147,7 +147,7 @@ namespace OpenRA.Traits public void Grow(ResourceTypeInfo info) { - var map = w.Map; + var map = world.Map; var newDensity = new byte[map.MapSize.X, map.MapSize.Y]; for (int i = map.TopLeft.X; i < map.BottomRight.X; i++) for (int j = map.TopLeft.Y; j < map.BottomRight.Y; j++) @@ -162,13 +162,13 @@ namespace OpenRA.Traits public void Spread(ResourceTypeInfo info) { - var map = w.Map; + var map = world.Map; var growMask = new bool[map.MapSize.X, map.MapSize.Y]; for (int i = map.TopLeft.X; i < map.BottomRight.X; i++) for (int j = map.TopLeft.Y; j < map.BottomRight.Y; j++) if (content[i,j].type == null && GetAdjacentCellsWith(info, i,j ) > 0 - && w.IsCellBuildable(new int2(i, j), false)) + && world.IsCellBuildable(new int2(i, j), false)) growMask[i, j] = true; for (int i = map.TopLeft.X; i < map.BottomRight.X; i++) diff --git a/OpenRA.Game/UiOverlay.cs b/OpenRA.Game/UiOverlay.cs index 793fe428db..a420b2b407 100644 --- a/OpenRA.Game/UiOverlay.cs +++ b/OpenRA.Game/UiOverlay.cs @@ -113,7 +113,7 @@ namespace OpenRA continue; // Cell is empty; continue search // Cell contains an actor. Is it the type we want? - if (Game.world.Queries.WithTrait().Any(a => (a.Actor.Info.Name == name && a.Actor.Location.X == cell.X && a.Actor.Location.Y == cell.Y))) + if (world.Queries.WithTrait().Any(a => (a.Actor.Info.Name == name && a.Actor.Location.X == cell.X && a.Actor.Location.Y == cell.Y))) dirs[d] = i; // Cell contains actor of correct type else dirs[d] = -1; // Cell is blocked by another actor type