Add ITerrainInfo interface.

This commit is contained in:
Paul Chote
2020-10-10 23:52:00 +01:00
committed by reaperrr
parent 0a374e2264
commit 87790069e9
30 changed files with 97 additions and 83 deletions

View File

@@ -27,6 +27,7 @@ namespace OpenRA
public readonly IReadOnlyDictionary<string, SoundInfo> Voices; public readonly IReadOnlyDictionary<string, SoundInfo> Voices;
public readonly IReadOnlyDictionary<string, SoundInfo> Notifications; public readonly IReadOnlyDictionary<string, SoundInfo> Notifications;
public readonly IReadOnlyDictionary<string, MusicInfo> Music; public readonly IReadOnlyDictionary<string, MusicInfo> Music;
public readonly ITerrainInfo TerrainInfo;
public readonly TileSet TileSet; public readonly TileSet TileSet;
public readonly SequenceProvider Sequences; public readonly SequenceProvider Sequences;
public readonly IReadOnlyDictionary<string, MiniYamlNode> ModelSequences; public readonly IReadOnlyDictionary<string, MiniYamlNode> ModelSequences;
@@ -46,6 +47,7 @@ namespace OpenRA
Voices = voices; Voices = voices;
Notifications = notifications; Notifications = notifications;
Music = music; Music = music;
TerrainInfo = tileSet;
TileSet = tileSet; TileSet = tileSet;
Sequences = sequences; Sequences = sequences;
ModelSequences = modelSequences; ModelSequences = modelSequences;

View File

@@ -283,7 +283,7 @@ namespace OpenRA
/// Initializes a new map created by the editor or importer. /// Initializes a new map created by the editor or importer.
/// The map will not receive a valid UID until after it has been saved and reloaded. /// The map will not receive a valid UID until after it has been saved and reloaded.
/// </summary> /// </summary>
public Map(ModData modData, TileSet tileset, int width, int height) public Map(ModData modData, ITerrainInfo terrainInfo, int width, int height)
{ {
this.modData = modData; this.modData = modData;
var size = new Size(width, height); var size = new Size(width, height);
@@ -293,7 +293,7 @@ namespace OpenRA
Author = "Your name here"; Author = "Your name here";
MapSize = new int2(size); MapSize = new int2(size);
Tileset = tileset.Id; Tileset = terrainInfo.Id;
// Empty rules that can be added to by the importers. // Empty rules that can be added to by the importers.
// Will be dropped on save if nothing is added to it // Will be dropped on save if nothing is added to it
@@ -310,7 +310,7 @@ namespace OpenRA
Tiles.CellEntryChanged += UpdateRamp; Tiles.CellEntryChanged += UpdateRamp;
} }
Tiles.Clear(tileset.DefaultTerrainTile); Tiles.Clear(terrainInfo.DefaultTerrainTile);
PostInit(); PostInit();
} }
@@ -431,14 +431,14 @@ namespace OpenRA
CustomTerrain[uv] = byte.MaxValue; CustomTerrain[uv] = byte.MaxValue;
// Replace invalid tiles and cache ramp state // Replace invalid tiles and cache ramp state
var tileset = Rules.TileSet; var terrainInfo = Rules.TerrainInfo;
foreach (var uv in AllCells.MapCoords) foreach (var uv in AllCells.MapCoords)
{ {
if (!tileset.TryGetTileInfo(Tiles[uv], out var info)) if (!terrainInfo.TryGetTerrainInfo(Tiles[uv], out var info))
{ {
ReplacedInvalidTerrainTiles[uv.ToCPos(this)] = Tiles[uv]; ReplacedInvalidTerrainTiles[uv.ToCPos(this)] = Tiles[uv];
Tiles[uv] = tileset.DefaultTerrainTile; Tiles[uv] = terrainInfo.DefaultTerrainTile;
info = tileset.GetTileInfo(tileset.DefaultTerrainTile); info = terrainInfo.GetTerrainInfo(terrainInfo.DefaultTerrainTile);
} }
Ramp[uv] = info.RampType; Ramp[uv] = info.RampType;
@@ -449,7 +449,7 @@ namespace OpenRA
void UpdateRamp(CPos cell) void UpdateRamp(CPos cell)
{ {
Ramp[cell] = Rules.TileSet.GetTileInfo(Tiles[cell]).RampType; Ramp[cell] = Rules.TerrainInfo.GetTerrainInfo(Tiles[cell]).RampType;
} }
void InitializeCellProjection() void InitializeCellProjection()
@@ -536,8 +536,7 @@ namespace OpenRA
// The original games treat the top of cliffs the same way as the bottom // The original games treat the top of cliffs the same way as the bottom
// This information isn't stored in the map data, so query the offset from the tileset // This information isn't stored in the map data, so query the offset from the tileset
var temp = inverse.MaxBy(uv => uv.V); var temp = inverse.MaxBy(uv => uv.V);
var terrain = Tiles[temp]; return (byte)(Height[temp] - Rules.TerrainInfo.GetTerrainInfo(Tiles[temp]).Height);
return (byte)(Height[temp] - Rules.TileSet.Templates[terrain.Type][terrain.Index].Height);
} }
// Try the next cell down if this is a cliff face // Try the next cell down if this is a cliff face
@@ -673,8 +672,8 @@ namespace OpenRA
public (Color Left, Color Right) GetTerrainColorPair(MPos uv) public (Color Left, Color Right) GetTerrainColorPair(MPos uv)
{ {
Color left, right; Color left, right;
var tileset = Rules.TileSet; var terrainInfo = Rules.TerrainInfo;
var type = tileset.GetTileInfo(Tiles[uv]); var type = terrainInfo.GetTerrainInfo(Tiles[uv]);
if (type.MinColor != type.MaxColor) if (type.MinColor != type.MaxColor)
{ {
left = Exts.ColorLerp(Game.CosmeticRandom.NextFloat(), type.MinColor, type.MaxColor); left = Exts.ColorLerp(Game.CosmeticRandom.NextFloat(), type.MinColor, type.MaxColor);
@@ -683,9 +682,9 @@ namespace OpenRA
else else
left = right = type.MinColor; left = right = type.MinColor;
if (tileset.MinHeightColorBrightness != 1.0f || tileset.MaxHeightColorBrightness != 1.0f) if (terrainInfo.MinHeightColorBrightness != 1.0f || terrainInfo.MaxHeightColorBrightness != 1.0f)
{ {
var scale = float2.Lerp(tileset.MinHeightColorBrightness, tileset.MaxHeightColorBrightness, Height[uv] * 1f / Grid.MaximumTerrainHeight); var scale = float2.Lerp(terrainInfo.MinHeightColorBrightness, terrainInfo.MaxHeightColorBrightness, Height[uv] * 1f / Grid.MaximumTerrainHeight);
left = Color.FromArgb((int)(scale * left.R).Clamp(0, 255), (int)(scale * left.G).Clamp(0, 255), (int)(scale * left.B).Clamp(0, 255)); left = Color.FromArgb((int)(scale * left.R).Clamp(0, 255), (int)(scale * left.G).Clamp(0, 255), (int)(scale * left.B).Clamp(0, 255));
right = Color.FromArgb((int)(scale * right.R).Clamp(0, 255), (int)(scale * right.G).Clamp(0, 255), (int)(scale * right.B).Clamp(0, 255)); right = Color.FromArgb((int)(scale * right.R).Clamp(0, 255), (int)(scale * right.G).Clamp(0, 255), (int)(scale * right.B).Clamp(0, 255));
} }
@@ -1071,8 +1070,7 @@ namespace OpenRA
if (terrainIndex == InvalidCachedTerrainIndex) if (terrainIndex == InvalidCachedTerrainIndex)
{ {
var custom = CustomTerrain[uv]; var custom = CustomTerrain[uv];
terrainIndex = cachedTerrainIndexes[uv] = terrainIndex = cachedTerrainIndexes[uv] = custom != byte.MaxValue ? custom : Rules.TerrainInfo.GetTerrainInfo(Tiles[uv]).TerrainType;
custom != byte.MaxValue ? custom : Rules.TileSet.GetTerrainIndex(Tiles[uv]);
} }
return (byte)terrainIndex; return (byte)terrainIndex;
@@ -1080,7 +1078,7 @@ namespace OpenRA
public TerrainTypeInfo GetTerrainInfo(CPos cell) public TerrainTypeInfo GetTerrainInfo(CPos cell)
{ {
return Rules.TileSet[GetTerrainIndex(cell)]; return Rules.TerrainInfo.TerrainTypes[GetTerrainIndex(cell)];
} }
public CPos Clamp(CPos cell) public CPos Clamp(CPos cell)

View File

@@ -18,6 +18,22 @@ using OpenRA.Traits;
namespace OpenRA namespace OpenRA
{ {
public interface ITerrainInfo
{
string Id { get; }
TerrainTypeInfo[] TerrainTypes { get; }
TerrainTileInfo GetTerrainInfo(TerrainTile r);
bool TryGetTerrainInfo(TerrainTile r, out TerrainTileInfo info);
byte GetTerrainIndex(string type);
byte GetTerrainIndex(TerrainTile r);
TerrainTile DefaultTerrainTile { get; }
Color[] HeightDebugColors { get; }
IEnumerable<Color> RestrictedPlayerColors { get; }
float MinHeightColorBrightness { get; }
float MaxHeightColorBrightness { get; }
}
public class TerrainTileInfo public class TerrainTileInfo
{ {
[FieldLoader.Ignore] [FieldLoader.Ignore]
@@ -54,7 +70,7 @@ namespace OpenRA
readonly TerrainTileInfo[] tileInfo; readonly TerrainTileInfo[] tileInfo;
public TerrainTemplateInfo(TileSet tileSet, MiniYaml my) public TerrainTemplateInfo(ITerrainInfo terrainInfo, MiniYaml my)
{ {
FieldLoader.Load(this, my); FieldLoader.Load(this, my);
@@ -66,12 +82,12 @@ namespace OpenRA
foreach (var node in nodes) foreach (var node in nodes)
{ {
if (!int.TryParse(node.Key, out var key)) if (!int.TryParse(node.Key, out var key))
throw new YamlException("Tileset `{0}` template `{1}` defines a frame `{2}` that is not a valid integer.".F(tileSet.Id, Id, node.Key)); throw new YamlException("Tileset `{0}` template `{1}` defines a frame `{2}` that is not a valid integer.".F(terrainInfo.Id, Id, node.Key));
if (key < 0 || key >= tileInfo.Length) if (key < 0 || key >= tileInfo.Length)
throw new YamlException("Tileset `{0}` template `{1}` references frame {2}, but only [0..{3}] are valid for a {4}x{5} Size template.".F(tileSet.Id, Id, key, tileInfo.Length - 1, Size.X, Size.Y)); throw new YamlException("Tileset `{0}` template `{1}` references frame {2}, but only [0..{3}] are valid for a {4}x{5} Size template.".F(terrainInfo.Id, Id, key, tileInfo.Length - 1, Size.X, Size.Y));
tileInfo[key] = LoadTileInfo(tileSet, node.Value); tileInfo[key] = LoadTileInfo(terrainInfo, node.Value);
} }
} }
else else
@@ -82,30 +98,30 @@ namespace OpenRA
foreach (var node in nodes) foreach (var node in nodes)
{ {
if (!int.TryParse(node.Key, out var key)) if (!int.TryParse(node.Key, out var key))
throw new YamlException("Tileset `{0}` template `{1}` defines a frame `{2}` that is not a valid integer.".F(tileSet.Id, Id, node.Key)); throw new YamlException("Tileset `{0}` template `{1}` defines a frame `{2}` that is not a valid integer.".F(terrainInfo.Id, Id, node.Key));
if (key != i++) if (key != i++)
throw new YamlException("Tileset `{0}` template `{1}` is missing a definition for frame {2}.".F(tileSet.Id, Id, i - 1)); throw new YamlException("Tileset `{0}` template `{1}` is missing a definition for frame {2}.".F(terrainInfo.Id, Id, i - 1));
tileInfo[key] = LoadTileInfo(tileSet, node.Value); tileInfo[key] = LoadTileInfo(terrainInfo, node.Value);
} }
} }
} }
static TerrainTileInfo LoadTileInfo(TileSet tileSet, MiniYaml my) static TerrainTileInfo LoadTileInfo(ITerrainInfo terrainInfo, MiniYaml my)
{ {
var tile = new TerrainTileInfo(); var tile = new TerrainTileInfo();
FieldLoader.Load(tile, my); FieldLoader.Load(tile, my);
// Terrain type must be converted from a string to an index // Terrain type must be converted from a string to an index
tile.GetType().GetField("TerrainType").SetValue(tile, tileSet.GetTerrainIndex(my.Value)); tile.GetType().GetField("TerrainType").SetValue(tile, terrainInfo.GetTerrainIndex(my.Value));
// Fall back to the terrain-type color if necessary // Fall back to the terrain-type color if necessary
var overrideColor = tileSet.TerrainInfo[tile.TerrainType].Color; var overrideColor = terrainInfo.TerrainTypes[tile.TerrainType].Color;
if (tile.MinColor == default(Color)) if (tile.MinColor == default)
tile.GetType().GetField("MinColor").SetValue(tile, overrideColor); tile.GetType().GetField("MinColor").SetValue(tile, overrideColor);
if (tile.MaxColor == default(Color)) if (tile.MaxColor == default)
tile.GetType().GetField("MaxColor").SetValue(tile, overrideColor); tile.GetType().GetField("MaxColor").SetValue(tile, overrideColor);
return tile; return tile;
@@ -124,7 +140,7 @@ namespace OpenRA
} }
} }
public class TileSet public class TileSet : ITerrainInfo
{ {
public const string TerrainPaletteInternalName = "terrain"; public const string TerrainPaletteInternalName = "terrain";
@@ -245,6 +261,14 @@ namespace OpenRA
return info != null; return info != null;
} }
public TerrainTile DefaultTerrainTile { get { return new TerrainTile(Templates.First().Key, 0); } } string ITerrainInfo.Id { get { return Id; } }
TerrainTypeInfo[] ITerrainInfo.TerrainTypes { get { return TerrainInfo; } }
TerrainTileInfo ITerrainInfo.GetTerrainInfo(TerrainTile r) { return GetTileInfo(r); }
bool ITerrainInfo.TryGetTerrainInfo(TerrainTile r, out TerrainTileInfo info) { return TryGetTileInfo(r, out info); }
Color[] ITerrainInfo.HeightDebugColors { get { return HeightDebugColors; } }
IEnumerable<Color> ITerrainInfo.RestrictedPlayerColors { get { return TerrainInfo.Where(ti => ti.RestrictPlayerColor).Select(ti => ti.Color); } }
float ITerrainInfo.MinHeightColorBrightness { get { return MinHeightColorBrightness; } }
float ITerrainInfo.MaxHeightColorBrightness { get { return MaxHeightColorBrightness; } }
TerrainTile ITerrainInfo.DefaultTerrainTile { get { return new TerrainTile(Templates.First().Key, 0); } }
} }
} }

View File

@@ -88,8 +88,8 @@ namespace OpenRA.Mods.Common.Widgets
return false; return false;
var tile = world.Map.Tiles[cell]; var tile = world.Map.Tiles[cell];
var tileInfo = world.Map.Rules.TileSet.GetTileInfo(tile); var tileInfo = world.Map.Rules.TerrainInfo.GetTerrainInfo(tile);
var terrainType = world.Map.Rules.TileSet.TerrainInfo[tileInfo.TerrainType]; var terrainType = world.Map.Rules.TerrainInfo.TerrainTypes[tileInfo.TerrainType];
if (mapResources[cell].Type == ResourceType.ResourceType) if (mapResources[cell].Type == ResourceType.ResourceType)
return false; return false;

View File

@@ -386,8 +386,7 @@ namespace OpenRA.Mods.Common.Server
// Pick a random color for the bot // Pick a random color for the bot
var validator = server.ModData.Manifest.Get<ColorValidator>(); var validator = server.ModData.Manifest.Get<ColorValidator>();
var tileset = server.Map.Rules.TileSet; var terrainColors = server.Map.Rules.TerrainInfo.RestrictedPlayerColors;
var terrainColors = tileset.TerrainInfo.Where(ti => ti.RestrictPlayerColor).Select(ti => ti.Color);
var playerColors = server.LobbyInfo.Clients.Select(c => c.Color) var playerColors = server.LobbyInfo.Clients.Select(c => c.Color)
.Concat(server.Map.Players.Players.Values.Select(p => p.Color)); .Concat(server.Map.Players.Players.Values.Select(p => p.Color));
bot.Color = bot.PreferredColor = validator.RandomPresetColor(server.Random, terrainColors, playerColors); bot.Color = bot.PreferredColor = validator.RandomPresetColor(server.Random, terrainColors, playerColors);
@@ -1105,8 +1104,7 @@ namespace OpenRA.Mods.Common.Server
server.SendOrderTo(connectionToEcho, "Message", message); server.SendOrderTo(connectionToEcho, "Message", message);
}; };
var tileset = server.Map.Rules.TileSet; var terrainColors = server.Map.Rules.TerrainInfo.RestrictedPlayerColors;
var terrainColors = tileset.TerrainInfo.Where(ti => ti.RestrictPlayerColor).Select(ti => ti.Color).ToList();
var playerColors = server.LobbyInfo.Clients.Where(c => c.Index != playerIndex).Select(c => c.Color) var playerColors = server.LobbyInfo.Clients.Where(c => c.Index != playerIndex).Select(c => c.Color)
.Concat(server.Map.Players.Players.Values.Select(p => p.Color)).ToList(); .Concat(server.Map.Players.Players.Values.Select(p => p.Color)).ToList();

View File

@@ -28,14 +28,13 @@ namespace OpenRA.Mods.Common.Traits
void IMapPreviewSignatureInfo.PopulateMapPreviewSignatureCells(Map map, ActorInfo ai, ActorReference s, List<(MPos, Color)> destinationBuffer) void IMapPreviewSignatureInfo.PopulateMapPreviewSignatureCells(Map map, ActorInfo ai, ActorReference s, List<(MPos, Color)> destinationBuffer)
{ {
var tileSet = map.Rules.TileSet;
Color color; Color color;
if (!string.IsNullOrEmpty(Terrain)) if (!string.IsNullOrEmpty(Terrain))
{ {
color = tileSet[tileSet.GetTerrainIndex(Terrain)].Color; var terrainInfo = map.Rules.TerrainInfo;
color = terrainInfo.TerrainTypes[terrainInfo.GetTerrainIndex(Terrain)].Color;
} }
else if (Color != default(Color)) else if (Color != default)
{ {
color = Color; color = Color;
} }

View File

@@ -173,10 +173,10 @@ namespace OpenRA.Mods.Common.Traits
protected override void TraitEnabled(Actor self) protected override void TraitEnabled(Actor self)
{ {
var tileset = world.Map.Rules.TileSet; var terrainInfo = world.Map.Rules.TerrainInfo;
resourceTypeIndices = new BitArray(tileset.TerrainInfo.Length); // Big enough resourceTypeIndices = new BitArray(terrainInfo.TerrainTypes.Length); // Big enough
foreach (var t in world.Map.Rules.Actors["world"].TraitInfos<ResourceTypeInfo>()) foreach (var t in world.Map.Rules.Actors["world"].TraitInfos<ResourceTypeInfo>())
resourceTypeIndices.Set(tileset.GetTerrainIndex(t.TerrainType), true); resourceTypeIndices.Set(terrainInfo.GetTerrainIndex(t.TerrainType), true);
foreach (var building in Info.BuildingQueues) foreach (var building in Info.BuildingQueues)
builders.Add(new BaseBuilderQueueManager(this, building, player, playerPower, playerResources, resourceTypeIndices)); builders.Add(new BaseBuilderQueueManager(this, building, player, playerPower, playerResources, resourceTypeIndices));

View File

@@ -77,8 +77,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
bridgeLayer.Add(self); bridgeLayer.Add(self);
var tileSet = self.World.Map.Rules.TileSet; var terrainIndex = self.World.Map.Rules.TerrainInfo.GetTerrainIndex(Info.TerrainType);
var terrainIndex = tileSet.GetTerrainIndex(Info.TerrainType);
UpdateTerrain(self, terrainIndex); UpdateTerrain(self, terrainIndex);
KillInvalidActorsInFootprint(self); KillInvalidActorsInFootprint(self);
} }

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
var cell = self.Location; var cell = self.Location;
var map = self.World.Map; var map = self.World.Map;
var terrain = map.Rules.TileSet.GetTerrainIndex(info.TerrainType); var terrain = map.Rules.TerrainInfo.GetTerrainIndex(info.TerrainType);
previousTerrain = map.CustomTerrain[cell]; previousTerrain = map.CustomTerrain[cell];
map.CustomTerrain[cell] = terrain; map.CustomTerrain[cell] = terrain;
} }

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits
public class GrantConditionOnTerrain : ITick public class GrantConditionOnTerrain : ITick
{ {
readonly GrantConditionOnTerrainInfo info; readonly GrantConditionOnTerrainInfo info;
readonly TileSet tileSet; readonly TerrainTypeInfo[] terrainTypes;
int conditionToken = Actor.InvalidConditionToken; int conditionToken = Actor.InvalidConditionToken;
string cachedTerrain; string cachedTerrain;
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
public GrantConditionOnTerrain(ActorInitializer init, GrantConditionOnTerrainInfo info) public GrantConditionOnTerrain(ActorInitializer init, GrantConditionOnTerrainInfo info)
{ {
this.info = info; this.info = info;
tileSet = init.World.Map.Rules.TileSet; terrainTypes = init.World.Map.Rules.TerrainInfo.TerrainTypes;
} }
void ITick.Tick(Actor self) void ITick.Tick(Actor self)
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
// The terrain type may change between ticks without the actor moving // The terrain type may change between ticks without the actor moving
var currentTerrain = cell.Layer == 0 ? self.World.Map.GetTerrainInfo(cell).Type : var currentTerrain = cell.Layer == 0 ? self.World.Map.GetTerrainInfo(cell).Type :
tileSet[self.World.GetCustomMovementLayers()[cell.Layer].GetTerrainIndex(cell)].Type; terrainTypes[self.World.GetCustomMovementLayers()[cell.Layer].GetTerrainIndex(cell)].Type;
var wantsGranted = info.TerrainTypes.Contains(currentTerrain); var wantsGranted = info.TerrainTypes.Contains(currentTerrain);
if (currentTerrain != cachedTerrain) if (currentTerrain != cachedTerrain)

View File

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

View File

@@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Traits
var custom = map.CustomTerrain[uv]; var custom = map.CustomTerrain[uv];
if (custom != byte.MaxValue) if (custom != byte.MaxValue)
{ {
var c = map.Rules.TileSet[custom].Color.ToArgb(); var c = map.Rules.TerrainInfo.TerrainTypes[custom].Color.ToArgb();
return (c, c); return (c, c);
} }

View File

@@ -21,8 +21,8 @@ namespace OpenRA.Mods.Common.Traits.Radar
public Color GetColorFromTerrain(World world) public Color GetColorFromTerrain(World world)
{ {
var tileSet = world.Map.Rules.TileSet; var terrainInfo = world.Map.Rules.TerrainInfo;
return tileSet[tileSet.GetTerrainIndex(Terrain)].Color; return terrainInfo.TerrainTypes[terrainInfo.GetTerrainIndex(Terrain)].Color;
} }
public override object Create(ActorInitializer init) { return new RadarColorFromTerrain(init.Self, this); } public override object Create(ActorInitializer init) { return new RadarColorFromTerrain(init.Self, this); }

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits
public void WorldLoaded(World w, WorldRenderer wr) public void WorldLoaded(World w, WorldRenderer wr)
{ {
var tileType = w.Map.Rules.TileSet.GetTerrainIndex(info.TerrainType); var tileType = w.Map.Rules.TerrainInfo.GetTerrainIndex(info.TerrainType);
// Units are allowed behind cliffs *only* if they are part of a tunnel portal // Units are allowed behind cliffs *only* if they are part of a tunnel portal
var tunnelPortals = w.WorldActor.Info.TraitInfos<TerrainTunnelInfo>() var tunnelPortals = w.WorldActor.Info.TraitInfos<TerrainTunnelInfo>()

View File

@@ -23,13 +23,11 @@ namespace OpenRA.Mods.Common.Traits
public class DomainIndex : IWorldLoaded public class DomainIndex : IWorldLoaded
{ {
TileSet tileSet;
Dictionary<uint, MovementClassDomainIndex> domainIndexes; Dictionary<uint, MovementClassDomainIndex> domainIndexes;
public void WorldLoaded(World world, WorldRenderer wr) public void WorldLoaded(World world, WorldRenderer wr)
{ {
domainIndexes = new Dictionary<uint, MovementClassDomainIndex>(); domainIndexes = new Dictionary<uint, MovementClassDomainIndex>();
tileSet = world.Map.Rules.TileSet;
var locomotors = world.WorldActor.TraitsImplementing<Locomotor>().Where(l => !string.IsNullOrEmpty(l.Info.Name)); var locomotors = world.WorldActor.TraitsImplementing<Locomotor>().Where(l => !string.IsNullOrEmpty(l.Info.Name));
var movementClasses = locomotors.Select(t => t.MovementClass).Distinct(); var movementClasses = locomotors.Select(t => t.MovementClass).Distinct();

View File

@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits
for (var x = 0; x < TerrainTemplate.Size.X; x++) for (var x = 0; x < TerrainTemplate.Size.X; x++)
{ {
var tile = new TerrainTile(TerrainTemplate.Id, (byte)i++); var tile = new TerrainTile(TerrainTemplate.Id, (byte)i++);
if (!world.Map.Rules.TileSet.TryGetTileInfo(tile, out var tileInfo)) if (!world.Map.Rules.TerrainInfo.TryGetTerrainInfo(tile, out var tileInfo))
continue; continue;
var sprite = terrainRenderer.TileSprite(tile, 0); var sprite = terrainRenderer.TileSprite(tile, 0);

View File

@@ -26,7 +26,6 @@ namespace OpenRA.Mods.Common.Traits
public class EditorResourceLayer : IResourceLayer, IWorldLoaded, INotifyActorDisposing public class EditorResourceLayer : IResourceLayer, IWorldLoaded, INotifyActorDisposing
{ {
protected readonly Map Map; protected readonly Map Map;
protected readonly TileSet Tileset;
protected readonly Dictionary<int, ResourceType> Resources; protected readonly Dictionary<int, ResourceType> Resources;
protected readonly CellLayer<ResourceLayerContents> Tiles; protected readonly CellLayer<ResourceLayerContents> Tiles;
@@ -45,8 +44,6 @@ namespace OpenRA.Mods.Common.Traits
return; return;
Map = self.World.Map; Map = self.World.Map;
Tileset = self.World.Map.Rules.TileSet;
Tiles = new CellLayer<ResourceLayerContents>(Map); Tiles = new CellLayer<ResourceLayerContents>(Map);
Resources = self.TraitsImplementing<ResourceType>() Resources = self.TraitsImplementing<ResourceType>()
.ToDictionary(r => r.Info.ResourceType, r => r); .ToDictionary(r => r.Info.ResourceType, r => r);
@@ -82,7 +79,7 @@ namespace OpenRA.Mods.Common.Traits
Density = CalculateCellDensity(type, cell) Density = CalculateCellDensity(type, cell)
}; };
newTerrain = Tileset.GetTerrainIndex(type.Info.TerrainType); newTerrain = Map.Rules.TerrainInfo.GetTerrainIndex(type.Info.TerrainType);
} }
// Nothing has changed // Nothing has changed

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits
map = self.World.Map; map = self.World.Map;
cellCenters = new CellLayer<WPos>(map); cellCenters = new CellLayer<WPos>(map);
terrainIndices = new CellLayer<byte>(map); terrainIndices = new CellLayer<byte>(map);
terrainIndices.Clear(map.Rules.TileSet.GetTerrainIndex(info.ImpassableTerrainType)); terrainIndices.Clear(map.Rules.TerrainInfo.GetTerrainIndex(info.ImpassableTerrainType));
} }
public void WorldLoaded(World world, WorldRenderer wr) public void WorldLoaded(World world, WorldRenderer wr)
@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
enabled = true; enabled = true;
var terrain = map.Rules.TileSet.GetTerrainIndex(tti.TerrainType); var terrain = map.Rules.TerrainInfo.GetTerrainIndex(tti.TerrainType);
foreach (var c in tti.BridgeCells()) foreach (var c in tti.BridgeCells())
{ {
var uv = c.ToMPos(map); var uv = c.ToMPos(map);

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits
public JumpjetActorLayer(Actor self, JumpjetActorLayerInfo info) public JumpjetActorLayer(Actor self, JumpjetActorLayerInfo info)
{ {
map = self.World.Map; map = self.World.Map;
terrainIndex = self.World.Map.Rules.TileSet.GetTerrainIndex(info.TerrainType); terrainIndex = self.World.Map.Rules.TerrainInfo.GetTerrainIndex(info.TerrainType);
height = new CellLayer<int>(map); height = new CellLayer<int>(map);
var cellHeight = self.World.Map.CellHeightStep.Length; var cellHeight = self.World.Map.CellHeightStep.Length;
foreach (var c in map.AllCells) foreach (var c in map.AllCells)

View File

@@ -161,10 +161,10 @@ namespace OpenRA.Mods.Common.Traits
sharesCell = info.SharesCell; sharesCell = info.SharesCell;
world = self.World; world = self.World;
var tileSet = world.Map.Rules.TileSet; var terrainInfo = world.Map.Rules.TerrainInfo;
terrainInfos = new LocomotorInfo.TerrainInfo[tileSet.TerrainInfo.Length]; terrainInfos = new LocomotorInfo.TerrainInfo[terrainInfo.TerrainTypes.Length];
for (var i = 0; i < terrainInfos.Length; i++) for (var i = 0; i < terrainInfos.Length; i++)
if (!info.TerrainSpeeds.TryGetValue(tileSet.TerrainInfo[i].Type, out terrainInfos[i])) if (!info.TerrainSpeeds.TryGetValue(terrainInfo.TerrainTypes[i].Type, out terrainInfos[i]))
terrainInfos[i] = LocomotorInfo.TerrainInfo.Impassable; terrainInfos[i] = LocomotorInfo.TerrainInfo.Impassable;
MovementClass = (uint)terrainInfos.Select(ti => ti.Cost < short.MaxValue).ToBits(); MovementClass = (uint)terrainInfos.Select(ti => ti.Cost < short.MaxValue).ToBits();

View File

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

View File

@@ -130,8 +130,8 @@ namespace OpenRA.Mods.Common.Traits
get get
{ {
// Only expose the palette if it is available for the shellmap's tileset (which is a requirement for its use). // Only expose the palette if it is available for the shellmap's tileset (which is a requirement for its use).
if ((info.Tilesets.Count == 0 || info.Tilesets.Contains(world.Map.Rules.TileSet.Id)) if ((info.Tilesets.Count == 0 || info.Tilesets.Contains(world.Map.Rules.TerrainInfo.Id))
&& !info.ExcludeTilesets.Contains(world.Map.Rules.TileSet.Id)) && !info.ExcludeTilesets.Contains(world.Map.Rules.TerrainInfo.Id))
yield return info.Name; yield return info.Name;
} }
} }

View File

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

View File

@@ -137,7 +137,7 @@ namespace OpenRA.Mods.Common.Traits
ResourceLayerContents CreateResourceCell(ResourceType t, CPos cell) ResourceLayerContents CreateResourceCell(ResourceType t, CPos cell)
{ {
world.Map.CustomTerrain[cell] = world.Map.Rules.TileSet.GetTerrainIndex(t.Info.TerrainType); world.Map.CustomTerrain[cell] = world.Map.Rules.TerrainInfo.GetTerrainIndex(t.Info.TerrainType);
++resCells; ++resCells;
return new ResourceLayerContents return new ResourceLayerContents

View File

@@ -65,8 +65,8 @@ namespace OpenRA.Mods.Common.Traits
void IMapPreviewSignatureInfo.PopulateMapPreviewSignatureCells(Map map, ActorInfo ai, ActorReference s, List<(MPos, Color)> destinationBuffer) void IMapPreviewSignatureInfo.PopulateMapPreviewSignatureCells(Map map, ActorInfo ai, ActorReference s, List<(MPos, Color)> destinationBuffer)
{ {
var tileSet = map.Rules.TileSet; var terrainInfo = map.Rules.TerrainInfo;
var color = tileSet[tileSet.GetTerrainIndex(TerrainType)].Color; var color = terrainInfo.TerrainTypes[terrainInfo.GetTerrainIndex(TerrainType)].Color;
for (var i = 0; i < map.MapSize.X; i++) for (var i = 0; i < map.MapSize.X; i++)
{ {

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits
public SubterraneanActorLayer(Actor self, SubterraneanActorLayerInfo info) public SubterraneanActorLayer(Actor self, SubterraneanActorLayerInfo info)
{ {
map = self.World.Map; map = self.World.Map;
terrainIndex = self.World.Map.Rules.TileSet.GetTerrainIndex(info.TerrainType); terrainIndex = self.World.Map.Rules.TerrainInfo.GetTerrainIndex(info.TerrainType);
height = new CellLayer<int>(map); height = new CellLayer<int>(map);
foreach (var c in map.AllCells) foreach (var c in map.AllCells)
{ {

View File

@@ -52,8 +52,7 @@ namespace OpenRA.Mods.Common.Traits
yield break; yield break;
var map = wr.World.Map; var map = wr.World.Map;
var tileSet = wr.World.Map.Rules.TileSet; var colors = wr.World.Map.Rules.TerrainInfo.HeightDebugColors;
var colors = tileSet.HeightDebugColors;
var mouseCell = wr.Viewport.ViewToWorld(Viewport.LastMousePos).ToMPos(wr.World.Map); var mouseCell = wr.Viewport.ViewToWorld(Viewport.LastMousePos).ToMPos(wr.World.Map);
foreach (var uv in wr.Viewport.AllVisibleCells.CandidateMapCoords) foreach (var uv in wr.Viewport.AllVisibleCells.CandidateMapCoords)

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
map = self.World.Map; map = self.World.Map;
cellCenters = new CellLayer<WPos>(map); cellCenters = new CellLayer<WPos>(map);
terrainIndices = new CellLayer<byte>(map); terrainIndices = new CellLayer<byte>(map);
terrainIndices.Clear(map.Rules.TileSet.GetTerrainIndex(info.ImpassableTerrainType)); terrainIndices.Clear(map.Rules.TerrainInfo.GetTerrainIndex(info.ImpassableTerrainType));
} }
public void WorldLoaded(World world, WorldRenderer wr) public void WorldLoaded(World world, WorldRenderer wr)
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
enabled = true; enabled = true;
var terrain = map.Rules.TileSet.GetTerrainIndex(tti.TerrainType); var terrain = map.Rules.TerrainInfo.GetTerrainIndex(tti.TerrainType);
foreach (var c in tti.TunnelCells()) foreach (var c in tti.TunnelCells())
{ {
var uv = c.ToMPos(map); var uv = c.ToMPos(map);

View File

@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
ownersDropDown.Text = selectedOwner.Name; ownersDropDown.Text = selectedOwner.Name;
ownersDropDown.TextColor = selectedOwner.Color; ownersDropDown.TextColor = selectedOwner.Color;
var tileSetId = world.Map.Rules.TileSet.Id; var tileSetId = world.Map.Rules.TerrainInfo.Id;
var allActorsTemp = new List<ActorSelectorActor>(); var allActorsTemp = new List<ActorSelectorActor>();
foreach (var a in mapRules.Actors.Values) foreach (var a in mapRules.Actors.Values)
{ {
@@ -209,7 +209,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
catch catch
{ {
Log.Write("debug", "Map editor ignoring actor {0}, because of missing sprites for tileset {1}.", Log.Write("debug", "Map editor ignoring actor {0}, because of missing sprites for tileset {1}.",
actor.Name, World.Map.Rules.TileSet.Id); actor.Name, World.Map.Rules.TerrainInfo.Id);
continue; continue;
} }
} }

View File

@@ -58,7 +58,7 @@ namespace OpenRA.Mods.D2k.Traits
if (!strength.Contains(cell)) if (!strength.Contains(cell))
return; return;
world.Map.CustomTerrain[cell] = world.Map.Rules.TileSet.GetTerrainIndex(tile); world.Map.CustomTerrain[cell] = world.Map.Rules.TerrainInfo.GetTerrainIndex(tile);
strength[cell] = info.MaxStrength; strength[cell] = info.MaxStrength;
dirty[cell] = tile; dirty[cell] = tile;
} }