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

@@ -308,9 +308,10 @@ namespace OpenRA.Mods.Common.AI
attackForceTicks = Random.Next(0, Info.AttackForceInterval);
minAttackForceDelayTicks = Random.Next(0, Info.MinimumAttackForceDelay);
resourceTypeIndices = new BitArray(World.TileSet.TerrainInfo.Length); // Big enough
var tileset = World.Map.Rules.TileSet;
resourceTypeIndices = new BitArray(tileset.TerrainInfo.Length); // Big enough
foreach (var t in Map.Rules.Actors["world"].TraitInfos<ResourceTypeInfo>())
resourceTypeIndices.Set(World.TileSet.GetTerrainIndex(t.TerrainType), true);
resourceTypeIndices.Set(tileset.GetTerrainIndex(t.TerrainType), true);
}
// TODO: Possibly give this a more generic name when terrain type is unhardcoded
@@ -672,7 +673,7 @@ namespace OpenRA.Mods.Common.AI
{
var harvInfo = harvester.Info.TraitInfo<HarvesterInfo>();
var mobileInfo = harvester.Info.TraitInfo<MobileInfo>();
var passable = (uint)mobileInfo.GetMovementClass(World.TileSet);
var passable = (uint)mobileInfo.GetMovementClass(World.Map.Rules.TileSet);
var path = pathfinder.FindPath(
PathSearch.Search(World, mobileInfo, harvester, true,

View File

@@ -117,7 +117,7 @@ namespace OpenRA.Mods.Common.Activities
var searchRadiusSquared = searchRadius * searchRadius;
// Find any harvestable resources:
var passable = (uint)mobileInfo.GetMovementClass(self.World.TileSet);
var passable = (uint)mobileInfo.GetMovementClass(self.World.Map.Rules.TileSet);
List<CPos> path;
using (var search = PathSearch.Search(self.World, mobileInfo, self, true,
loc => domainIndex.IsPassable(self.Location, loc, passable) && self.CanHarvestAt(loc, resLayer, harvInfo, territory))

View File

@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Activities
mobile = self.Trait<Mobile>();
pathFinder = self.World.WorldActor.Trait<IPathFinder>();
domainIndex = self.World.WorldActor.Trait<DomainIndex>();
movementClass = (uint)mobile.Info.GetMovementClass(self.World.TileSet);
movementClass = (uint)mobile.Info.GetMovementClass(self.World.Map.Rules.TileSet);
if (target.IsValidFor(self))
targetPosition = self.World.Map.CellContaining(target.CenterPosition);

View File

@@ -37,8 +37,7 @@ namespace OpenRA.Mods.Common.Widgets
preview.IsVisible = () => editorWidget.CurrentBrush == this;
var variant = resource.Variants.FirstOrDefault();
var sequenceProvider = wr.World.Map.Rules.Sequences;
var sequence = sequenceProvider.GetSequence("resources", variant);
var sequence = wr.World.Map.Rules.Sequences.GetSequence("resources", variant);
var sprite = sequence.GetSprite(resource.MaxDensity - 1);
preview.GetSprite = () => sprite;
@@ -83,11 +82,11 @@ namespace OpenRA.Mods.Common.Widgets
return false;
var tile = world.Map.MapTiles.Value[cell];
var tileInfo = world.TileSet.GetTileInfo(tile);
var tileInfo = world.Map.Rules.TileSet.GetTileInfo(tile);
if (tileInfo == null)
return false;
var terrainType = world.TileSet.TerrainInfo[tileInfo.TerrainType];
var terrainType = world.Map.Rules.TileSet.TerrainInfo[tileInfo.TerrainType];
if (mapResources[cell].Type == ResourceType.ResourceType)
return false;

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Widgets
preview.GetScale = () => worldRenderer.Viewport.Zoom;
preview.IsVisible = () => editorWidget.CurrentBrush == this;
preview.Template = world.TileSet.Templates.First(t => t.Value.Id == template).Value;
preview.Template = world.Map.Rules.TileSet.Templates.First(t => t.Value.Id == template).Value;
var grid = world.Map.Grid;
bounds = worldRenderer.Theater.TemplateBounds(preview.Template, grid.TileSize, grid.Type);

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Orders
world.Selection.Clear();
var map = world.Map;
var tileset = world.TileSet.Id.ToLowerInvariant();
var tileset = world.Map.Tileset.ToLowerInvariant();
var info = map.Rules.Actors[building];
buildingInfo = info.TraitInfo<BuildingInfo>();

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)

View File

@@ -97,9 +97,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var filter = actor.TraitInfoOrDefault<EditorTilesetFilterInfo>();
if (filter != null)
{
if (filter.ExcludeTilesets != null && filter.ExcludeTilesets.Contains(world.TileSet.Id))
if (filter.ExcludeTilesets != null && filter.ExcludeTilesets.Contains(world.Map.Rules.TileSet.Id))
continue;
if (filter.RequireTilesets != null && !filter.RequireTilesets.Contains(world.TileSet.Id))
if (filter.RequireTilesets != null && !filter.RequireTilesets.Contains(world.Map.Rules.TileSet.Id))
continue;
}
@@ -140,7 +140,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
catch
{
Log.Write("debug", "Map editor ignoring actor {0}, because of missing sprites for tileset {1}.",
actor.Name, world.TileSet.Id);
actor.Name, world.Map.Rules.TileSet.Id);
continue;
}
}

View File

@@ -57,8 +57,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
layerPreview.GetPalette = () => resource.Palette;
var variant = resource.Variants.FirstOrDefault();
var sequenceProvider = rules.Sequences;
var sequence = sequenceProvider.GetSequence("resources", variant);
var sequence = rules.Sequences.GetSequence("resources", variant);
var frame = sequence.Frames != null ? sequence.Frames.Last() : resource.MaxDensity - 1;
layerPreview.GetSprite = () => sequence.GetSprite(frame);

View File

@@ -140,12 +140,12 @@ namespace OpenRA.Mods.Common.Widgets
int leftColor, rightColor;
if (custom == byte.MaxValue)
{
var type = world.TileSet.GetTileInfo(world.Map.MapTiles.Value[uv]);
var type = world.Map.Rules.TileSet.GetTileInfo(world.Map.MapTiles.Value[uv]);
leftColor = type != null ? type.LeftColor.ToArgb() : Color.Black.ToArgb();
rightColor = type != null ? type.RightColor.ToArgb() : Color.Black.ToArgb();
}
else
leftColor = rightColor = world.TileSet[custom].Color.ToArgb();
leftColor = rightColor = world.Map.Rules.TileSet[custom].Color.ToArgb();
var stride = radarSheet.Size.Width;