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)
{
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)

View File

@@ -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<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),
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<EvaAlertsInfo>();
var eva = Rules.Info["world"].Traits.Get<EvaAlertsInfo>();
// 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<EvaAlertsInfo>();
var eva = Rules.Info["world"].Traits.Get<EvaAlertsInfo>();
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<EvaAlertsInfo>();
var eva = Rules.Info["world"].Traits.Get<EvaAlertsInfo>();
// Play palette-open sound at the start of the activate anim (open)
if (paletteAnimationFrame == 1 && paletteOpen)

View File

@@ -79,7 +79,7 @@ namespace OpenRA.Graphics
static Cache<string, TerrainColorSet> terrainTypeColors = new Cache<string, TerrainColorSet>(
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;
@@ -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");
}

View File

@@ -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<int>(indicesPerRow * firstRow, indicesPerRow * lastRow),
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();
}
}

View File

@@ -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<SpatialBinsInfo>().BinSize)
for (var j = 0; j < world.Map.MapSize.Y;
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(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);
}
}

View File

@@ -29,6 +29,7 @@ namespace OpenRA
{
public class PathSearch
{
World world;
public CellInfo[ , ] cellInfo;
public PriorityQueue<PathDistance> queue;
public Func<int2, float> heuristic;
@@ -42,6 +43,7 @@ namespace OpenRA
public PathSearch(World world)
{
this.world = world;
cellInfo = InitCellInfo();
queue = new PriorityQueue<PathDistance>();
@@ -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;
}

View File

@@ -52,16 +52,13 @@ namespace OpenRA
public ShroudRenderer Shroud;
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 Game.world.WorldActor.Info.Traits.WithInterface<PlayerColorPaletteInfo>()
return world.WorldActor.Info.Traits.WithInterface<PlayerColorPaletteInfo>()
.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);
}

View File

@@ -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<ResourceTypeInfo>().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++)

View File

@@ -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<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
else
dirs[d] = -1; // Cell is blocked by another actor type