Add ITerrainInfo interface.
This commit is contained in:
@@ -88,8 +88,8 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
return false;
|
||||
|
||||
var tile = world.Map.Tiles[cell];
|
||||
var tileInfo = world.Map.Rules.TileSet.GetTileInfo(tile);
|
||||
var terrainType = world.Map.Rules.TileSet.TerrainInfo[tileInfo.TerrainType];
|
||||
var tileInfo = world.Map.Rules.TerrainInfo.GetTerrainInfo(tile);
|
||||
var terrainType = world.Map.Rules.TerrainInfo.TerrainTypes[tileInfo.TerrainType];
|
||||
|
||||
if (mapResources[cell].Type == ResourceType.ResourceType)
|
||||
return false;
|
||||
|
||||
@@ -386,8 +386,7 @@ namespace OpenRA.Mods.Common.Server
|
||||
|
||||
// Pick a random color for the bot
|
||||
var validator = server.ModData.Manifest.Get<ColorValidator>();
|
||||
var tileset = server.Map.Rules.TileSet;
|
||||
var terrainColors = tileset.TerrainInfo.Where(ti => ti.RestrictPlayerColor).Select(ti => ti.Color);
|
||||
var terrainColors = server.Map.Rules.TerrainInfo.RestrictedPlayerColors;
|
||||
var playerColors = server.LobbyInfo.Clients.Select(c => c.Color)
|
||||
.Concat(server.Map.Players.Players.Values.Select(p => p.Color));
|
||||
bot.Color = bot.PreferredColor = validator.RandomPresetColor(server.Random, terrainColors, playerColors);
|
||||
@@ -1105,8 +1104,7 @@ namespace OpenRA.Mods.Common.Server
|
||||
server.SendOrderTo(connectionToEcho, "Message", message);
|
||||
};
|
||||
|
||||
var tileset = server.Map.Rules.TileSet;
|
||||
var terrainColors = tileset.TerrainInfo.Where(ti => ti.RestrictPlayerColor).Select(ti => ti.Color).ToList();
|
||||
var terrainColors = server.Map.Rules.TerrainInfo.RestrictedPlayerColors;
|
||||
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();
|
||||
|
||||
|
||||
@@ -28,14 +28,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
void IMapPreviewSignatureInfo.PopulateMapPreviewSignatureCells(Map map, ActorInfo ai, ActorReference s, List<(MPos, Color)> destinationBuffer)
|
||||
{
|
||||
var tileSet = map.Rules.TileSet;
|
||||
|
||||
Color color;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -173,10 +173,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
protected override void TraitEnabled(Actor self)
|
||||
{
|
||||
var tileset = world.Map.Rules.TileSet;
|
||||
resourceTypeIndices = new BitArray(tileset.TerrainInfo.Length); // Big enough
|
||||
var terrainInfo = world.Map.Rules.TerrainInfo;
|
||||
resourceTypeIndices = new BitArray(terrainInfo.TerrainTypes.Length); // Big enough
|
||||
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)
|
||||
builders.Add(new BaseBuilderQueueManager(this, building, player, playerPower, playerResources, resourceTypeIndices));
|
||||
|
||||
@@ -77,8 +77,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
bridgeLayer.Add(self);
|
||||
|
||||
var tileSet = self.World.Map.Rules.TileSet;
|
||||
var terrainIndex = tileSet.GetTerrainIndex(Info.TerrainType);
|
||||
var terrainIndex = self.World.Map.Rules.TerrainInfo.GetTerrainIndex(Info.TerrainType);
|
||||
UpdateTerrain(self, terrainIndex);
|
||||
KillInvalidActorsInFootprint(self);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var cell = self.Location;
|
||||
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];
|
||||
map.CustomTerrain[cell] = terrain;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public class GrantConditionOnTerrain : ITick
|
||||
{
|
||||
readonly GrantConditionOnTerrainInfo info;
|
||||
readonly TileSet tileSet;
|
||||
readonly TerrainTypeInfo[] terrainTypes;
|
||||
|
||||
int conditionToken = Actor.InvalidConditionToken;
|
||||
string cachedTerrain;
|
||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public GrantConditionOnTerrain(ActorInitializer init, GrantConditionOnTerrainInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
tileSet = init.World.Map.Rules.TileSet;
|
||||
terrainTypes = init.World.Map.Rules.TerrainInfo.TerrainTypes;
|
||||
}
|
||||
|
||||
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
|
||||
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);
|
||||
if (currentTerrain != cachedTerrain)
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
this.info = info;
|
||||
rotationBuffer = new uint[info.RotationRange];
|
||||
tilesetId = world.Map.Rules.TileSet.Id;
|
||||
tilesetId = world.Map.Rules.TerrainInfo.Id;
|
||||
|
||||
validTileset = IsValidTileset();
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var custom = map.CustomTerrain[uv];
|
||||
if (custom != byte.MaxValue)
|
||||
{
|
||||
var c = map.Rules.TileSet[custom].Color.ToArgb();
|
||||
var c = map.Rules.TerrainInfo.TerrainTypes[custom].Color.ToArgb();
|
||||
return (c, c);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ namespace OpenRA.Mods.Common.Traits.Radar
|
||||
|
||||
public Color GetColorFromTerrain(World world)
|
||||
{
|
||||
var tileSet = world.Map.Rules.TileSet;
|
||||
return tileSet[tileSet.GetTerrainIndex(Terrain)].Color;
|
||||
var terrainInfo = world.Map.Rules.TerrainInfo;
|
||||
return terrainInfo.TerrainTypes[terrainInfo.GetTerrainIndex(Terrain)].Color;
|
||||
}
|
||||
|
||||
public override object Create(ActorInitializer init) { return new RadarColorFromTerrain(init.Self, this); }
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
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
|
||||
var tunnelPortals = w.WorldActor.Info.TraitInfos<TerrainTunnelInfo>()
|
||||
|
||||
@@ -23,13 +23,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public class DomainIndex : IWorldLoaded
|
||||
{
|
||||
TileSet tileSet;
|
||||
Dictionary<uint, MovementClassDomainIndex> domainIndexes;
|
||||
|
||||
public void WorldLoaded(World world, WorldRenderer wr)
|
||||
{
|
||||
domainIndexes = new Dictionary<uint, MovementClassDomainIndex>();
|
||||
tileSet = world.Map.Rules.TileSet;
|
||||
var locomotors = world.WorldActor.TraitsImplementing<Locomotor>().Where(l => !string.IsNullOrEmpty(l.Info.Name));
|
||||
var movementClasses = locomotors.Select(t => t.MovementClass).Distinct();
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
for (var x = 0; x < TerrainTemplate.Size.X; x++)
|
||||
{
|
||||
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;
|
||||
|
||||
var sprite = terrainRenderer.TileSprite(tile, 0);
|
||||
|
||||
@@ -26,7 +26,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public class EditorResourceLayer : IResourceLayer, IWorldLoaded, INotifyActorDisposing
|
||||
{
|
||||
protected readonly Map Map;
|
||||
protected readonly TileSet Tileset;
|
||||
protected readonly Dictionary<int, ResourceType> Resources;
|
||||
protected readonly CellLayer<ResourceLayerContents> Tiles;
|
||||
|
||||
@@ -45,8 +44,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return;
|
||||
|
||||
Map = self.World.Map;
|
||||
Tileset = self.World.Map.Rules.TileSet;
|
||||
|
||||
Tiles = new CellLayer<ResourceLayerContents>(Map);
|
||||
Resources = self.TraitsImplementing<ResourceType>()
|
||||
.ToDictionary(r => r.Info.ResourceType, r => r);
|
||||
@@ -82,7 +79,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Density = CalculateCellDensity(type, cell)
|
||||
};
|
||||
|
||||
newTerrain = Tileset.GetTerrainIndex(type.Info.TerrainType);
|
||||
newTerrain = Map.Rules.TerrainInfo.GetTerrainIndex(type.Info.TerrainType);
|
||||
}
|
||||
|
||||
// Nothing has changed
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
map = self.World.Map;
|
||||
cellCenters = new CellLayer<WPos>(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)
|
||||
@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
enabled = true;
|
||||
|
||||
var terrain = map.Rules.TileSet.GetTerrainIndex(tti.TerrainType);
|
||||
var terrain = map.Rules.TerrainInfo.GetTerrainIndex(tti.TerrainType);
|
||||
foreach (var c in tti.BridgeCells())
|
||||
{
|
||||
var uv = c.ToMPos(map);
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public JumpjetActorLayer(Actor self, JumpjetActorLayerInfo info)
|
||||
{
|
||||
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);
|
||||
var cellHeight = self.World.Map.CellHeightStep.Length;
|
||||
foreach (var c in map.AllCells)
|
||||
|
||||
@@ -161,10 +161,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
sharesCell = info.SharesCell;
|
||||
world = self.World;
|
||||
|
||||
var tileSet = world.Map.Rules.TileSet;
|
||||
terrainInfos = new LocomotorInfo.TerrainInfo[tileSet.TerrainInfo.Length];
|
||||
var terrainInfo = world.Map.Rules.TerrainInfo;
|
||||
terrainInfos = new LocomotorInfo.TerrainInfo[terrainInfo.TerrainTypes.Length];
|
||||
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;
|
||||
|
||||
MovementClass = (uint)terrainInfos.Select(ti => ti.Cost < short.MaxValue).ToBits();
|
||||
|
||||
@@ -70,7 +70,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.Map.Rules.TileSet.Id)
|
||||
if (info.Tileset == null || info.Tileset == world.Map.Rules.TerrainInfo.Id)
|
||||
yield return info.Name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,8 +130,8 @@ 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.Tilesets.Count == 0 || info.Tilesets.Contains(world.Map.Rules.TileSet.Id))
|
||||
&& !info.ExcludeTilesets.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.TerrainInfo.Id))
|
||||
yield return info.Name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,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.Map.Rules.TileSet.Id)
|
||||
if (info.Tileset == null || info.Tileset == world.Map.Rules.TerrainInfo.Id)
|
||||
yield return info.Name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
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;
|
||||
|
||||
return new ResourceLayerContents
|
||||
|
||||
@@ -65,8 +65,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
void IMapPreviewSignatureInfo.PopulateMapPreviewSignatureCells(Map map, ActorInfo ai, ActorReference s, List<(MPos, Color)> destinationBuffer)
|
||||
{
|
||||
var tileSet = map.Rules.TileSet;
|
||||
var color = tileSet[tileSet.GetTerrainIndex(TerrainType)].Color;
|
||||
var terrainInfo = map.Rules.TerrainInfo;
|
||||
var color = terrainInfo.TerrainTypes[terrainInfo.GetTerrainIndex(TerrainType)].Color;
|
||||
|
||||
for (var i = 0; i < map.MapSize.X; i++)
|
||||
{
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public SubterraneanActorLayer(Actor self, SubterraneanActorLayerInfo info)
|
||||
{
|
||||
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);
|
||||
foreach (var c in map.AllCells)
|
||||
{
|
||||
|
||||
@@ -52,8 +52,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
yield break;
|
||||
|
||||
var map = wr.World.Map;
|
||||
var tileSet = wr.World.Map.Rules.TileSet;
|
||||
var colors = tileSet.HeightDebugColors;
|
||||
var colors = wr.World.Map.Rules.TerrainInfo.HeightDebugColors;
|
||||
var mouseCell = wr.Viewport.ViewToWorld(Viewport.LastMousePos).ToMPos(wr.World.Map);
|
||||
|
||||
foreach (var uv in wr.Viewport.AllVisibleCells.CandidateMapCoords)
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
map = self.World.Map;
|
||||
cellCenters = new CellLayer<WPos>(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)
|
||||
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
enabled = true;
|
||||
|
||||
var terrain = map.Rules.TileSet.GetTerrainIndex(tti.TerrainType);
|
||||
var terrain = map.Rules.TerrainInfo.GetTerrainIndex(tti.TerrainType);
|
||||
foreach (var c in tti.TunnelCells())
|
||||
{
|
||||
var uv = c.ToMPos(map);
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
ownersDropDown.Text = selectedOwner.Name;
|
||||
ownersDropDown.TextColor = selectedOwner.Color;
|
||||
|
||||
var tileSetId = world.Map.Rules.TileSet.Id;
|
||||
var tileSetId = world.Map.Rules.TerrainInfo.Id;
|
||||
var allActorsTemp = new List<ActorSelectorActor>();
|
||||
foreach (var a in mapRules.Actors.Values)
|
||||
{
|
||||
@@ -209,7 +209,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.Map.Rules.TileSet.Id);
|
||||
actor.Name, World.Map.Rules.TerrainInfo.Id);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user