Remove World.TileSet.

This commit is contained in:
Paul Chote
2016-02-18 18:54:30 +00:00
parent 7993068c8f
commit 602acabe47
34 changed files with 59 additions and 65 deletions

View File

@@ -130,8 +130,9 @@ namespace OpenRA.Mods.Common.Traits
byte GetTerrainType(CPos cell)
{
var dx = cell - self.Location;
var index = dx.X + self.World.TileSet.Templates[template].Size.X * dx.Y;
return self.World.TileSet.GetTerrainIndex(new TerrainTile(template, (byte)index));
var tileSet = self.World.Map.Rules.TileSet;
var index = dx.X + tileSet.Templates[template].Size.X * dx.Y;
return tileSet.GetTerrainIndex(new TerrainTile(template, (byte)index));
}
public void LinkNeighbouringBridges(World world, BridgeLayer bridges)

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
return false;
var tile = world.Map.MapTiles.Value[cell];
var tileInfo = world.TileSet.GetTileInfo(tile);
var tileInfo = world.Map.Rules.TileSet.GetTileInfo(tile);
// TODO: This is bandaiding over bogus tilesets.
if (tileInfo != null && tileInfo.RampType > 0)

View File

@@ -48,11 +48,10 @@ namespace OpenRA.Mods.Common.Traits
var world = self.World;
var map = world.Map;
var tileSet = world.TileSet;
var tiles = map.MapTiles.Value;
var pos = map.CellContaining(self.CenterPosition);
var terrainType = tileSet[tileSet.GetTerrainIndex(tiles[pos])].Type;
var terrainType = map.GetTerrainInfo(pos).Type;
if (!Info.TerrainModifier.ContainsKey(terrainType))
return FullDamage;

View File

@@ -136,7 +136,7 @@ namespace OpenRA.Mods.Common.Traits
// PERF: This struct allows us to cache the terrain info for the tileset used by the world.
// This allows us to speed up some performance-sensitive pathfinding calculations.
World = world;
TerrainInfos = info.TilesetTerrainInfo[world.TileSet];
TerrainInfos = info.TilesetTerrainInfo[world.Map.Rules.TileSet];
}
}
@@ -151,7 +151,7 @@ namespace OpenRA.Mods.Common.Traits
public int MovementCostForCell(World world, CPos cell)
{
return MovementCostForCell(world.Map, TilesetTerrainInfo[world.TileSet], cell);
return MovementCostForCell(world.Map, TilesetTerrainInfo[world.Map.Rules.TileSet], cell);
}
int MovementCostForCell(Map map, TerrainInfo[] terrainInfos, CPos cell)
@@ -630,7 +630,7 @@ namespace OpenRA.Mods.Common.Traits
if (index == byte.MaxValue)
return 0;
var terrainSpeed = Info.TilesetTerrainInfo[self.World.TileSet][index].Speed;
var terrainSpeed = Info.TilesetTerrainInfo[self.World.Map.Rules.TileSet][index].Speed;
if (terrainSpeed == 0)
return 0;

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Traits
{
this.info = info;
rotationBuffer = new uint[info.RotationRange];
tilesetId = world.TileSet.Id;
tilesetId = world.Map.Rules.TileSet.Id;
validTileset = IsValidTileset();
}

View File

@@ -26,7 +26,8 @@ namespace OpenRA.Mods.Common.Traits
public RadarColorFromTerrain(Actor self, string terrain)
{
c = self.World.TileSet[self.World.TileSet.GetTerrainIndex(terrain)].Color;
var tileSet = self.World.Map.Rules.TileSet;
c = tileSet[tileSet.GetTerrainIndex(terrain)].Color;
}
public bool VisibleOnRadar(Actor self) { return true; }

View File

@@ -158,9 +158,8 @@ namespace OpenRA.Mods.Common.Traits
if (!checkTerrainType)
return true;
var tileSet = self.World.TileSet;
var tiles = self.World.Map.MapTiles.Value;
var terrainType = tileSet[tileSet.GetTerrainIndex(tiles[self.Location])].Type;
var terrainType = self.World.Map.GetTerrainInfo(self.Location).Type;
return info.AllowedTerrainTypes.Contains(terrainType);
}
@@ -174,7 +173,7 @@ namespace OpenRA.Mods.Common.Traits
if (self.World.Map.Contains(self.Location))
{
var tile = self.World.Map.MapTiles.Value[self.Location];
var ti = self.World.TileSet.GetTileInfo(tile);
var ti = self.World.Map.Rules.TileSet.GetTileInfo(tile);
if (ti != null)
ramp = ti.RampType;
}

View File

@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Traits
// Correlate the tile "image" aka subtile with its position to find the template origin
var tile = w.Map.MapTiles.Value[cell].Type;
var index = w.Map.MapTiles.Value[cell].Index;
var template = w.TileSet.Templates[tile];
var template = w.Map.Rules.TileSet.Templates[tile];
var ni = cell.X - index % template.Size.X;
var nj = cell.Y - index / template.Size.X;

View File

@@ -28,9 +28,10 @@ namespace OpenRA.Mods.Common.Traits
public void WorldLoaded(World world, WorldRenderer wr)
{
domainIndexes = new Dictionary<uint, MovementClassDomainIndex>();
var tileSet = world.Map.Rules.TileSet;
var movementClasses =
world.Map.Rules.Actors.Where(ai => ai.Value.HasTraitInfo<MobileInfo>())
.Select(ai => (uint)ai.Value.TraitInfo<MobileInfo>().GetMovementClass(world.TileSet)).Distinct();
.Select(ai => (uint)ai.Value.TraitInfo<MobileInfo>().GetMovementClass(tileSet)).Distinct();
foreach (var mc in movementClasses)
domainIndexes[mc] = new MovementClassDomainIndex(world, mc);

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Traits
return;
Map = self.World.Map;
Tileset = self.World.TileSet;
Tileset = self.World.Map.Rules.TileSet;
Tiles = new CellLayer<CellContents>(Map);
Resources = self.TraitsImplementing<ResourceType>()

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits
public void LoadPalettes(WorldRenderer wr)
{
wr.AddPalette(info.Name, new ImmutablePalette(wr.World.Map.Open(world.TileSet.Palette), info.ShadowIndex), info.AllowModifiers);
wr.AddPalette(info.Name, new ImmutablePalette(wr.World.Map.Open(world.Map.Rules.TileSet.Palette), info.ShadowIndex), info.AllowModifiers);
}
public IEnumerable<string> PaletteNames { get { yield return info.Name; } }

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Traits
get
{
// Only expose the palette if it is available for the shellmap's tileset (which is a requirement for its use).
if (info.Tileset == null || info.Tileset == world.TileSet.Id)
if (info.Tileset == null || info.Tileset == world.Map.Rules.TileSet.Id)
yield return info.Name;
}
}

View File

@@ -68,7 +68,7 @@ namespace OpenRA.Mods.Common.Traits
var domainIndex = world.WorldActor.TraitOrDefault<DomainIndex>();
if (domainIndex != null)
{
var passable = mi.GetMovementClass(world.TileSet);
var passable = mi.GetMovementClass(world.Map.Rules.TileSet);
if (!domainIndex.IsPassable(source, target, (uint)passable))
return EmptyPath;
}
@@ -102,7 +102,7 @@ namespace OpenRA.Mods.Common.Traits
var domainIndex = world.WorldActor.TraitOrDefault<DomainIndex>();
if (domainIndex != null)
{
var passable = mi.GetMovementClass(world.TileSet);
var passable = mi.GetMovementClass(world.Map.Rules.TileSet);
tilesInRange = new List<CPos>(tilesInRange.Where(t => domainIndex.IsPassable(source, t, (uint)passable)));
if (!tilesInRange.Any())
return EmptyPath;

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits
public void LoadPalettes(WorldRenderer wr)
{
var filename = world.TileSet.PlayerPalette ?? world.TileSet.Palette;
var filename = world.Map.Rules.TileSet.PlayerPalette ?? world.Map.Rules.TileSet.Palette;
wr.AddPalette(info.Name, new ImmutablePalette(wr.World.Map.Open(filename), info.ShadowIndex), info.AllowModifiers);
}
}

View File

@@ -194,7 +194,7 @@ namespace OpenRA.Mods.Common.Traits
if (!rt.Info.AllowOnRamps)
{
var tile = world.Map.MapTiles.Value[cell];
var tileInfo = world.TileSet.GetTileInfo(tile);
var tileInfo = world.Map.Rules.TileSet.GetTileInfo(tile);
if (tileInfo != null && tileInfo.RampType > 0)
return false;
}
@@ -214,7 +214,7 @@ namespace OpenRA.Mods.Common.Traits
CellContents CreateResourceCell(ResourceType t, CPos cell)
{
world.Map.CustomTerrain[cell] = world.TileSet.GetTerrainIndex(t.Info.TerrainType);
world.Map.CustomTerrain[cell] = world.Map.Rules.TileSet.GetTerrainIndex(t.Info.TerrainType);
return new CellContents
{

View File

@@ -50,9 +50,9 @@ namespace OpenRA.Mods.Common.Traits
return;
var map = wr.World.Map;
var tileSet = wr.World.TileSet;
var tileSet = wr.World.Map.Rules.TileSet;
var wcr = Game.Renderer.WorldRgbaColorRenderer;
var colors = wr.World.TileSet.HeightDebugColors;
var colors = tileSet.HeightDebugColors;
var mouseCell = wr.Viewport.ViewToWorld(Viewport.LastMousePos).ToMPos(wr.World.Map);
foreach (var uv in wr.Viewport.AllVisibleCells.CandidateMapCoords)