fix some extraneous refs to Game.world

This commit is contained in:
Bob
2010-04-13 20:25:16 +12:00
parent 2a4460213c
commit e38d978849
9 changed files with 42 additions and 41 deletions

View File

@@ -62,7 +62,7 @@ namespace OpenRA
public void AddLine(Session.Client p, string text) 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) public void AddLine(Color c, string from, string text)

View File

@@ -325,7 +325,7 @@ namespace OpenRA
new int2(mapContainer.Left + mapContainer.Width / 2, y), Color.White); new int2(mapContainer.Left + mapContainer.Width / 2, y), Color.White);
y += 20; y += 20;
var theaterInfo = Game.world.WorldActor.Info.Traits.WithInterface<TheaterInfo>().FirstOrDefault(t => t.Theater == currentMap.Tileset); var theaterInfo = Rules.Info["world"].Traits.WithInterface<TheaterInfo>().FirstOrDefault(t => t.Theater == currentMap.Tileset);
DrawCentered("Theater: {0}".F(theaterInfo.Name), DrawCentered("Theater: {0}".F(theaterInfo.Name),
new int2(mapContainer.Left + mapContainer.Width / 2, y), Color.White); new int2(mapContainer.Left + mapContainer.Width / 2, y), Color.White);
y += 20; y += 20;
@@ -339,12 +339,12 @@ namespace OpenRA
void CyclePalette(bool left) 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) while (!PaletteAvailable(newIndex) && newIndex != (int)Game.LocalClient.PaletteIndex)
newIndex = (newIndex + d) % Player.PlayerColors.Count(); newIndex = (newIndex + d) % Player.PlayerColors(Game.world).Count();
Game.IssueOrder( Game.IssueOrder(
Order.Chat("/pal " + newIndex)); Order.Chat("/pal " + newIndex));
@@ -521,7 +521,7 @@ namespace OpenRA
paletteRect.Top + Game.viewport.Location.Y + 5, paletteRect.Top + Game.viewport.Location.Y + 5,
paletteRect.Right + Game.viewport.Location.X - 5, paletteRect.Right + Game.viewport.Location.X - 5,
paletteRect.Bottom+Game.viewport.Location.Y - 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(); lineRenderer.Flush();
f.DrawText(client.Country, new int2(r.Left + 220, y), Color.White); 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); f.DrawText(client.State.ToString(), new int2(r.Left + 290, y), Color.White);
@@ -558,7 +558,7 @@ namespace OpenRA
if (radarAnimationFrame <= radarSlideAnimationLength) if (radarAnimationFrame <= radarSlideAnimationLength)
radarOrigin = float2.Lerp(radarClosedOrigin, radarOpenOrigin, radarAnimationFrame * 1.0f / radarSlideAnimationLength); radarOrigin = float2.Lerp(radarClosedOrigin, radarOpenOrigin, radarAnimationFrame * 1.0f / radarSlideAnimationLength);
var eva = Game.world.WorldActor.Info.Traits.Get<EvaAlertsInfo>(); var eva = Rules.Info["world"].Traits.Get<EvaAlertsInfo>();
// Play radar-on sound at the start of the activate anim (open) // Play radar-on sound at the start of the activate anim (open)
if (radarAnimationFrame == radarSlideAnimationLength && hasRadar) if (radarAnimationFrame == radarSlideAnimationLength && hasRadar)
@@ -642,7 +642,7 @@ namespace OpenRA
void HandleTabClick(string button) void HandleTabClick(string button)
{ {
var eva = Game.world.WorldActor.Info.Traits.Get<EvaAlertsInfo>(); var eva = Rules.Info["world"].Traits.Get<EvaAlertsInfo>();
Sound.Play(eva.TabClick); Sound.Play(eva.TabClick);
var wasOpen = paletteOpen; var wasOpen = paletteOpen;
paletteOpen = (currentTab == button && wasOpen) ? false : true; paletteOpen = (currentTab == button && wasOpen) ? false : true;
@@ -829,7 +829,7 @@ namespace OpenRA
if (paletteAnimationFrame <= paletteAnimationLength) if (paletteAnimationFrame <= paletteAnimationLength)
paletteOrigin = float2.Lerp(paletteClosedOrigin, paletteOpenOrigin, paletteAnimationFrame * 1.0f / paletteAnimationLength); paletteOrigin = float2.Lerp(paletteClosedOrigin, paletteOpenOrigin, paletteAnimationFrame * 1.0f / paletteAnimationLength);
var eva = Game.world.WorldActor.Info.Traits.Get<EvaAlertsInfo>(); var eva = Rules.Info["world"].Traits.Get<EvaAlertsInfo>();
// Play palette-open sound at the start of the activate anim (open) // Play palette-open sound at the start of the activate anim (open)
if (paletteAnimationFrame == 1 && paletteOpen) if (paletteAnimationFrame == 1 && paletteOpen)

View File

@@ -79,7 +79,7 @@ namespace OpenRA.Graphics
static Cache<string, TerrainColorSet> terrainTypeColors = new Cache<string, TerrainColorSet>( static Cache<string, TerrainColorSet> terrainTypeColors = new Cache<string, TerrainColorSet>(
theater => theater =>
{ {
return new TerrainColorSet(Game.world.WorldActor.Info.Traits.WithInterface<TheaterInfo>().FirstOrDefault(t => t.Theater == theater).MapColors); return new TerrainColorSet(Rules.Info["world"].Traits.WithInterface<TheaterInfo>().FirstOrDefault(t => t.Theater == theater).MapColors);
}); });
static Color shroudColor; static Color shroudColor;
@@ -194,7 +194,7 @@ namespace OpenRA.Graphics
lineRenderer.FillRect(new RectangleF( lineRenderer.FillRect(new RectangleF(
Game.viewport.Location.X + pos.X + 2, Game.viewport.Location.X + pos.X + 2,
Game.viewport.Location.Y + pos.Y + 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"); rgbaRenderer.DrawSprite(ownedSpawnPoint, pos, "chrome");
} }

View File

@@ -31,11 +31,13 @@ namespace OpenRA.Graphics
IIndexBuffer indexBuffer; IIndexBuffer indexBuffer;
Sheet terrainSheet; Sheet terrainSheet;
World world;
Renderer renderer; Renderer renderer;
Map map; Map map;
public TerrainRenderer(World world, Renderer renderer, WorldRenderer wr) public TerrainRenderer(World world, Renderer renderer, WorldRenderer wr)
{ {
this.world = world;
this.renderer = renderer; this.renderer = renderer;
this.map = world.Map; this.map = world.Map;
@@ -88,9 +90,9 @@ namespace OpenRA.Graphics
if (firstRow < 0) firstRow = 0; if (firstRow < 0) firstRow = 0;
if (lastRow > map.Height) lastRow = map.Height; 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) if (firstRow < r.Top - map.YOffset)
firstRow = r.Top - map.YOffset; firstRow = r.Top - map.YOffset;
@@ -107,7 +109,7 @@ namespace OpenRA.Graphics
new Range<int>(indicesPerRow * firstRow, indicesPerRow * lastRow), new Range<int>(indicesPerRow * firstRow, indicesPerRow * lastRow),
PrimitiveType.TriangleList, renderer.SpriteShader)); PrimitiveType.TriangleList, renderer.SpriteShader));
foreach (var r in Game.world.WorldActor.traits.WithInterface<IRenderOverlay>()) foreach (var r in world.WorldActor.traits.WithInterface<IRenderOverlay>())
r.Render(); r.Render();
} }
} }

View File

@@ -166,11 +166,11 @@ namespace OpenRA.Graphics
if (world.LocalPlayer != null) if (world.LocalPlayer != null)
DrawBox(world.LocalPlayer.Shroud.bounds.Value, Color.Blue); DrawBox(world.LocalPlayer.Shroud.bounds.Value, Color.Blue);
for (var j = 0; j < Game.world.Map.MapSize.Y; for (var j = 0; j < world.Map.MapSize.Y;
j += Game.world.WorldActor.Info.Traits.Get<SpatialBinsInfo>().BinSize) j += world.WorldActor.Info.Traits.Get<SpatialBinsInfo>().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(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, Game.world.Map.MapSize.Y * 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);
} }
} }

View File

@@ -29,6 +29,7 @@ namespace OpenRA
{ {
public class PathSearch public class PathSearch
{ {
World world;
public CellInfo[ , ] cellInfo; public CellInfo[ , ] cellInfo;
public PriorityQueue<PathDistance> queue; public PriorityQueue<PathDistance> queue;
public Func<int2, float> heuristic; public Func<int2, float> heuristic;
@@ -42,6 +43,7 @@ namespace OpenRA
public PathSearch(World world) public PathSearch(World world)
{ {
this.world = world;
cellInfo = InitCellInfo(); cellInfo = InitCellInfo();
queue = new PriorityQueue<PathDistance>(); queue = new PriorityQueue<PathDistance>();
@@ -171,11 +173,11 @@ namespace OpenRA
return search; return search;
} }
static CellInfo[ , ] InitCellInfo() CellInfo[ , ] InitCellInfo()
{ {
var cellInfo = new CellInfo[ Game.world.Map.MapSize.X, Game.world.Map.MapSize.Y ]; var cellInfo = new CellInfo[ world.Map.MapSize.X, world.Map.MapSize.Y ];
for( int x = 0 ; x < Game.world.Map.MapSize.X ; x++ ) for( int x = 0 ; x < world.Map.MapSize.X ; x++ )
for( int y = 0 ; y < Game.world.Map.MapSize.Y ; y++ ) for( int y = 0 ; y < world.Map.MapSize.Y ; y++ )
cellInfo[ x, y ] = new CellInfo( float.PositiveInfinity, new int2( x, y ), false ); cellInfo[ x, y ] = new CellInfo( float.PositiveInfinity, new int2( x, y ), false );
return cellInfo; return cellInfo;
} }

View File

@@ -52,15 +52,12 @@ namespace OpenRA
public ShroudRenderer Shroud; public ShroudRenderer Shroud;
public World World { get; private set; } public World World { get; private set; }
public static List<Tuple<string, string, Color>> PlayerColors public static List<Tuple<string, string, Color>> PlayerColors( World world )
{ {
get return world.WorldActor.Info.Traits.WithInterface<PlayerColorPaletteInfo>()
{ .Where(p => p.Playable)
return Game.world.WorldActor.Info.Traits.WithInterface<PlayerColorPaletteInfo>() .Select(p => Tuple.New(p.Name, p.DisplayName, p.Color))
.Where(p => p.Playable) .ToList();
.Select(p => Tuple.New(p.Name, p.DisplayName, p.Color))
.ToList();
}
} }
public Player( World world, Session.Client client ) public Player( World world, Session.Client client )
@@ -73,8 +70,8 @@ namespace OpenRA
if (client != null) if (client != null)
{ {
Index = client.Index; Index = client.Index;
Palette = PlayerColors[client.PaletteIndex % PlayerColors.Count()].a; Palette = PlayerColors(world)[client.PaletteIndex % PlayerColors(world).Count()].a;
Color = PlayerColors[client.PaletteIndex % PlayerColors.Count()].c; Color = PlayerColors(world)[client.PaletteIndex % PlayerColors(world).Count()].c;
PlayerName = client.Name; PlayerName = client.Name;
InternalName = "Multi{0}".F(client.Index); InternalName = "Multi{0}".F(client.Index);
} }

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Traits
public class ResourceLayer: IRenderOverlay, ILoadWorldHook public class ResourceLayer: IRenderOverlay, ILoadWorldHook
{ {
SpriteRenderer sr; SpriteRenderer sr;
World w; World world;
public ResourceTypeInfo[] resourceTypes; public ResourceTypeInfo[] resourceTypes;
CellContents[,] content; CellContents[,] content;
@@ -44,12 +44,12 @@ namespace OpenRA.Traits
public void Render() 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 y = map.YOffset; y < map.YOffset + map.Height; y++)
for (int x = map.XOffset; x < map.XOffset + map.Width; x++) 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]; var c = content[x, y];
if (c.image != null) if (c.image != null)
@@ -63,7 +63,7 @@ namespace OpenRA.Traits
public void WorldLoaded(World w) public void WorldLoaded(World w)
{ {
this.w = w; this.world = w;
content = new CellContents[w.Map.MapSize.X, w.Map.MapSize.Y]; content = new CellContents[w.Map.MapSize.X, w.Map.MapSize.Y];
resourceTypes = w.WorldActor.Info.Traits.WithInterface<ResourceTypeInfo>().ToArray(); resourceTypes = w.WorldActor.Info.Traits.WithInterface<ResourceTypeInfo>().ToArray();
@@ -89,7 +89,7 @@ namespace OpenRA.Traits
public Sprite[] ChooseContent(ResourceTypeInfo info) 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) public int GetAdjacentCellsWith(ResourceTypeInfo info, int i, int j)
@@ -147,7 +147,7 @@ namespace OpenRA.Traits
public void Grow(ResourceTypeInfo info) public void Grow(ResourceTypeInfo info)
{ {
var map = w.Map; var map = world.Map;
var newDensity = new byte[map.MapSize.X, map.MapSize.Y]; var newDensity = new byte[map.MapSize.X, map.MapSize.Y];
for (int i = map.TopLeft.X; i < map.BottomRight.X; i++) for (int i = map.TopLeft.X; i < map.BottomRight.X; i++)
for (int j = map.TopLeft.Y; j < map.BottomRight.Y; j++) for (int j = map.TopLeft.Y; j < map.BottomRight.Y; j++)
@@ -162,13 +162,13 @@ namespace OpenRA.Traits
public void Spread(ResourceTypeInfo info) public void Spread(ResourceTypeInfo info)
{ {
var map = w.Map; var map = world.Map;
var growMask = new bool[map.MapSize.X, map.MapSize.Y]; var growMask = new bool[map.MapSize.X, map.MapSize.Y];
for (int i = map.TopLeft.X; i < map.BottomRight.X; i++) for (int i = map.TopLeft.X; i < map.BottomRight.X; i++)
for (int j = map.TopLeft.Y; j < map.BottomRight.Y; j++) for (int j = map.TopLeft.Y; j < map.BottomRight.Y; j++)
if (content[i,j].type == null if (content[i,j].type == null
&& GetAdjacentCellsWith(info, i,j ) > 0 && GetAdjacentCellsWith(info, i,j ) > 0
&& w.IsCellBuildable(new int2(i, j), false)) && world.IsCellBuildable(new int2(i, j), false))
growMask[i, j] = true; growMask[i, j] = true;
for (int i = map.TopLeft.X; i < map.BottomRight.X; i++) for (int i = map.TopLeft.X; i < map.BottomRight.X; i++)

View File

@@ -113,7 +113,7 @@ namespace OpenRA
continue; // Cell is empty; continue search continue; // Cell is empty; continue search
// Cell contains an actor. Is it the type we want? // Cell contains an actor. Is it the type we want?
if (Game.world.Queries.WithTrait<LineBuild>().Any(a => (a.Actor.Info.Name == name && a.Actor.Location.X == cell.X && a.Actor.Location.Y == cell.Y))) if (world.Queries.WithTrait<LineBuild>().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 dirs[d] = i; // Cell contains actor of correct type
else else
dirs[d] = -1; // Cell is blocked by another actor type dirs[d] = -1; // Cell is blocked by another actor type