diff --git a/OpenRA.Game/GameRules/WeaponInfo.cs b/OpenRA.Game/GameRules/WeaponInfo.cs index f62abf5771..39bde429a0 100644 --- a/OpenRA.Game/GameRules/WeaponInfo.cs +++ b/OpenRA.Game/GameRules/WeaponInfo.cs @@ -182,7 +182,7 @@ namespace OpenRA.GameRules if (!world.Map.IsInMap(cell)) return false; - var cellInfo = world.GetTerrainInfo(cell); + var cellInfo = world.Map.GetTerrainInfo(cell); if (!ValidTargets.Intersect(cellInfo.TargetTypes).Any() || InvalidTargets.Intersect(cellInfo.TargetTypes).Any()) return false; diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 1d99ab4512..f8f315cc19 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -537,5 +537,18 @@ namespace OpenRA } } } + + public int GetTerrainIndex(CPos cell) + { + var custom = CustomTerrain[cell.X, cell.Y]; + var tileSet = Rules.TileSets[Tileset]; + return custom != -1 ? custom : tileSet.GetTerrainIndex(MapTiles.Value[cell.X, cell.Y]); + } + + public TerrainTypeInfo GetTerrainInfo(CPos cell) + { + var tileSet = Rules.TileSets[Tileset]; + return tileSet[GetTerrainIndex(cell)]; + } } } diff --git a/OpenRA.Game/Traits/World/ResourceLayer.cs b/OpenRA.Game/Traits/World/ResourceLayer.cs index e9f60a31bb..6cb45b801e 100644 --- a/OpenRA.Game/Traits/World/ResourceLayer.cs +++ b/OpenRA.Game/Traits/World/ResourceLayer.cs @@ -145,7 +145,7 @@ namespace OpenRA.Traits if (!world.Map.IsInMap(a.X, a.Y)) return false; - if (!rt.Info.AllowedTerrainTypes.Contains(world.GetTerrainInfo(a).Type)) + if (!rt.Info.AllowedTerrainTypes.Contains(world.Map.GetTerrainInfo(a).Type)) return false; if (!rt.Info.AllowUnderActors && world.ActorMap.AnyUnitsAt(a)) diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index 968dd636dc..756f55477c 100644 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -88,17 +88,6 @@ namespace OpenRA public const int MaxRange = 50; static List[] TilesByDistance = InitTilesByDistance(MaxRange); - public static int GetTerrainIndex(this World world, CPos cell) - { - var custom = world.Map.CustomTerrain[cell.X, cell.Y]; - return custom != -1 ? custom : world.TileSet.GetTerrainIndex(world.Map.MapTiles.Value[cell.X, cell.Y]); - } - - public static TerrainTypeInfo GetTerrainInfo(this World world, CPos cell) - { - return world.TileSet[world.GetTerrainIndex(cell)]; - } - public static CPos ClampToWorld(this World world, CPos xy) { var r = world.Map.Bounds; diff --git a/OpenRA.Mods.D2k/DamagedWithoutFoundation.cs b/OpenRA.Mods.D2k/DamagedWithoutFoundation.cs index 6cbf576513..28a6ee9754 100644 --- a/OpenRA.Mods.D2k/DamagedWithoutFoundation.cs +++ b/OpenRA.Mods.D2k/DamagedWithoutFoundation.cs @@ -49,7 +49,7 @@ namespace OpenRA.Mods.Cnc foreach (var kv in self.OccupiesSpace.OccupiedCells()) { totalTiles++; - if (info.SafeTerrain.Contains(self.World.GetTerrainInfo(kv.First).Type)) + if (info.SafeTerrain.Contains(self.World.Map.GetTerrainInfo(kv.First).Type)) safeTiles++; } diff --git a/OpenRA.Mods.RA/AI/HackyAI.cs b/OpenRA.Mods.RA/AI/HackyAI.cs index 9e4a1a555c..e5367bea06 100644 --- a/OpenRA.Mods.RA/AI/HackyAI.cs +++ b/OpenRA.Mods.RA/AI/HackyAI.cs @@ -366,7 +366,7 @@ namespace OpenRA.Mods.RA.AI case BuildingType.Refinery: var tilesPos = world.FindTilesInCircle(baseCenter, MaxBaseDistance) - .Where(a => resourceTypeIndices.Contains(world.GetTerrainIndex(new CPos(a.X, a.Y)))); + .Where(a => resourceTypeIndices.Contains(Map.GetTerrainIndex(new CPos(a.X, a.Y)))); if (tilesPos.Any()) { var pos = tilesPos.MinBy(a => (a.CenterPosition - baseCenter.CenterPosition).LengthSquared); diff --git a/OpenRA.Mods.RA/Air/Aircraft.cs b/OpenRA.Mods.RA/Air/Aircraft.cs index b633bdb6f7..5400e021c9 100755 --- a/OpenRA.Mods.RA/Air/Aircraft.cs +++ b/OpenRA.Mods.RA/Air/Aircraft.cs @@ -171,7 +171,7 @@ namespace OpenRA.Mods.RA.Air if (self.World.ActorMap.AnyUnitsAt(cell)) return false; - var type = self.World.GetTerrainInfo(cell).Type; + var type = self.World.Map.GetTerrainInfo(cell).Type; return info.LandableTerrainTypes.Contains(type); } diff --git a/OpenRA.Mods.RA/Buildings/Bib.cs b/OpenRA.Mods.RA/Buildings/Bib.cs index ec5aeec250..894fd715ec 100755 --- a/OpenRA.Mods.RA/Buildings/Bib.cs +++ b/OpenRA.Mods.RA/Buildings/Bib.cs @@ -44,6 +44,7 @@ namespace OpenRA.Mods.RA.Buildings var centerOffset = FootprintUtils.CenterOffset(bi); var location = self.Location; var rows = info.HasMinibib ? 1 : 2; + var map = self.World.Map; for (var i = 0; i < rows * width; i++) { @@ -52,7 +53,7 @@ namespace OpenRA.Mods.RA.Buildings var cellOffset = new CVec(i % width, i / width + bibOffset); // Some mods may define terrain-specific bibs - var terrain = self.World.GetTerrainInfo(location + cellOffset).Type; + var terrain = map.GetTerrainInfo(location + cellOffset).Type; var testSequence = info.Sequence + "-" + terrain; var sequence = anim.HasSequence(testSequence) ? testSequence : info.Sequence; anim.PlayFetchIndex(sequence, () => index); diff --git a/OpenRA.Mods.RA/Buildings/LaysTerrain.cs b/OpenRA.Mods.RA/Buildings/LaysTerrain.cs index 3dbe0b51f6..a44cdc2381 100755 --- a/OpenRA.Mods.RA/Buildings/LaysTerrain.cs +++ b/OpenRA.Mods.RA/Buildings/LaysTerrain.cs @@ -48,17 +48,19 @@ namespace OpenRA.Mods.RA.Buildings public void AddedToWorld(Actor self) { + var map = self.World.Map; + if (template.PickAny) { // Fill the footprint with random variants foreach (var c in FootprintUtils.Tiles(self)) { // Only place on allowed terrain types - if (!info.TerrainTypes.Contains(self.World.GetTerrainInfo(c).Type)) + if (!info.TerrainTypes.Contains(map.GetTerrainInfo(c).Type)) continue; // Don't place under other buildings or custom terrain - if (bi.GetBuildingAt(c) != self || self.World.Map.CustomTerrain[c.X, c.Y] != -1) + if (bi.GetBuildingAt(c) != self || map.CustomTerrain[c.X, c.Y] != -1) continue; var index = Game.CosmeticRandom.Next(template.TilesCount); @@ -74,11 +76,11 @@ namespace OpenRA.Mods.RA.Buildings var c = origin + new CVec(i % template.Size.X, i / template.Size.X); // Only place on allowed terrain types - if (!info.TerrainTypes.Contains(self.World.GetTerrainInfo(c).Type)) + if (!info.TerrainTypes.Contains(map.GetTerrainInfo(c).Type)) continue; // Don't place under other buildings or custom terrain - if (bi.GetBuildingAt(c) != self || self.World.Map.CustomTerrain[c.X, c.Y] != -1) + if (bi.GetBuildingAt(c) != self || map.CustomTerrain[c.X, c.Y] != -1) continue; layer.AddTile(c, new TileReference(template.Id, (byte)i)); diff --git a/OpenRA.Mods.RA/Buildings/Util.cs b/OpenRA.Mods.RA/Buildings/Util.cs index 34dc19d896..a3264c4dba 100644 --- a/OpenRA.Mods.RA/Buildings/Util.cs +++ b/OpenRA.Mods.RA/Buildings/Util.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Buildings if (world.WorldActor.Trait().GetBuildingAt(a) != null) return false; if (world.ActorMap.GetUnitsAt(a).Any(b => b != toIgnore)) return false; - return world.Map.IsInMap(a) && bi.TerrainTypes.Contains(world.GetTerrainInfo(a).Type); + return world.Map.IsInMap(a) && bi.TerrainTypes.Contains(world.Map.GetTerrainInfo(a).Type); } public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, CPos topLeft, Actor toIgnore) diff --git a/OpenRA.Mods.RA/Combat.cs b/OpenRA.Mods.RA/Combat.cs index fc6c371da5..32463be224 100755 --- a/OpenRA.Mods.RA/Combat.cs +++ b/OpenRA.Mods.RA/Combat.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA if (!world.Map.IsInMap(targetTile)) return; - var isWater = pos.Z <= 0 && world.GetTerrainInfo(targetTile).IsWater; + var isWater = pos.Z <= 0 && world.Map.GetTerrainInfo(targetTile).IsWater; var explosionType = isWater ? warhead.WaterExplosion : warhead.Explosion; var explosionTypePalette = isWater ? warhead.WaterExplosionPalette : warhead.ExplosionPalette; @@ -63,7 +63,7 @@ namespace OpenRA.Mods.RA // Draw the smudges: foreach (var sc in smudgeCells) { - var smudgeType = world.GetTerrainInfo(sc).AcceptsSmudgeType.FirstOrDefault(t => warhead.SmudgeType.Contains(t)); + var smudgeType = world.Map.GetTerrainInfo(sc).AcceptsSmudgeType.FirstOrDefault(t => warhead.SmudgeType.Contains(t)); if (smudgeType == null) continue; SmudgeLayer smudgeLayer; @@ -84,7 +84,7 @@ namespace OpenRA.Mods.RA } else { - var smudgeType = world.GetTerrainInfo(targetTile).AcceptsSmudgeType.FirstOrDefault(t => warhead.SmudgeType.Contains(t)); + var smudgeType = world.Map.GetTerrainInfo(targetTile).AcceptsSmudgeType.FirstOrDefault(t => warhead.SmudgeType.Contains(t)); if (smudgeType != null) { SmudgeLayer smudgeLayer; diff --git a/OpenRA.Mods.RA/Crate.cs b/OpenRA.Mods.RA/Crate.cs index dbb798ce48..0c0bb85728 100644 --- a/OpenRA.Mods.RA/Crate.cs +++ b/OpenRA.Mods.RA/Crate.cs @@ -93,7 +93,7 @@ namespace OpenRA.Mods.RA { if (!self.World.Map.IsInMap(cell.X, cell.Y)) return false; - var type = self.World.GetTerrainInfo(cell).Type; + var type = self.World.Map.GetTerrainInfo(cell).Type; if (!info.TerrainTypes.Contains(type)) return false; diff --git a/OpenRA.Mods.RA/CrateSpawner.cs b/OpenRA.Mods.RA/CrateSpawner.cs index 6956863acd..f397a1e934 100644 --- a/OpenRA.Mods.RA/CrateSpawner.cs +++ b/OpenRA.Mods.RA/CrateSpawner.cs @@ -117,7 +117,7 @@ namespace OpenRA.Mods.RA var p = self.World.ChooseRandomCell(self.World.SharedRandom); // Is this valid terrain? - var terrainType = self.World.GetTerrainInfo(p).Type; + var terrainType = self.World.Map.GetTerrainInfo(p).Type; if (!(inWater ? info.ValidWater : info.ValidGround).Contains(terrainType)) continue; diff --git a/OpenRA.Mods.RA/Effects/Missile.cs b/OpenRA.Mods.RA/Effects/Missile.cs index 994dd98cf0..17aa2e5c5d 100755 --- a/OpenRA.Mods.RA/Effects/Missile.cs +++ b/OpenRA.Mods.RA/Effects/Missile.cs @@ -160,9 +160,8 @@ namespace OpenRA.Mods.RA.Effects var shouldExplode = (pos.Z < 0) // Hit the ground || (dist.LengthSquared < MissileCloseEnough.Range * MissileCloseEnough.Range) // Within range || (info.RangeLimit != 0 && ticks > info.RangeLimit) // Ran out of fuel - || (!info.High && world.ActorMap.GetUnitsAt(cell) - .Any(a => a.HasTrait())) // Hit a wall - || (!string.IsNullOrEmpty(info.BoundToTerrainType) && world.GetTerrainInfo(cell).Type != info.BoundToTerrainType); // Hit incompatible terrain + || (!info.High && world.ActorMap.GetUnitsAt(cell).Any(a => a.HasTrait())) // Hit a wall + || (!string.IsNullOrEmpty(info.BoundToTerrainType) && world.Map.GetTerrainInfo(cell).Type != info.BoundToTerrainType); // Hit incompatible terrain if (shouldExplode) Explode(world); diff --git a/OpenRA.Mods.RA/Husk.cs b/OpenRA.Mods.RA/Husk.cs index 3d2144ed03..810ee851ae 100644 --- a/OpenRA.Mods.RA/Husk.cs +++ b/OpenRA.Mods.RA/Husk.cs @@ -58,7 +58,7 @@ namespace OpenRA.Mods.RA if (!self.World.Map.IsInMap(cell.X, cell.Y)) return false; - if (!info.AllowedTerrain.Contains(self.World.GetTerrainInfo(cell).Type)) + if (!info.AllowedTerrain.Contains(self.World.Map.GetTerrainInfo(cell).Type)) return false; if (!checkTransientActors) diff --git a/OpenRA.Mods.RA/Move/Mobile.cs b/OpenRA.Mods.RA/Move/Mobile.cs index f6b4117381..56c8587514 100755 --- a/OpenRA.Mods.RA/Move/Mobile.cs +++ b/OpenRA.Mods.RA/Move/Mobile.cs @@ -104,7 +104,7 @@ namespace OpenRA.Mods.RA.Move if (!world.Map.IsInMap(cell.X, cell.Y)) return int.MaxValue; - var index = world.GetTerrainIndex(cell); + var index = world.Map.GetTerrainIndex(cell); if (index == -1) return int.MaxValue; @@ -481,7 +481,7 @@ namespace OpenRA.Mods.RA.Move public int MovementSpeedForCell(Actor self, CPos cell) { - var index = self.World.GetTerrainIndex(cell); + var index = self.World.Map.GetTerrainIndex(cell); if (index == -1) return 0; @@ -574,7 +574,7 @@ namespace OpenRA.Mods.RA.Move cursor = "move"; if (self.Owner.Shroud.IsExplored(location)) - cursor = self.World.GetTerrainInfo(location).CustomCursor ?? cursor; + cursor = self.World.Map.GetTerrainInfo(location).CustomCursor ?? cursor; if (!self.World.Map.IsInMap(location) || (self.Owner.Shroud.IsExplored(location) && unitType.MovementCostForCell(self.World, location) == int.MaxValue)) diff --git a/OpenRA.Mods.RA/Render/RenderLandingCraft.cs b/OpenRA.Mods.RA/Render/RenderLandingCraft.cs index eb210b6c44..e0b8fd96c7 100644 --- a/OpenRA.Mods.RA/Render/RenderLandingCraft.cs +++ b/OpenRA.Mods.RA/Render/RenderLandingCraft.cs @@ -45,8 +45,8 @@ namespace OpenRA.Mods.RA.Render if (self.CenterPosition.Z > 0 || move.IsMoving) return false; - return cargo.CurrentAdjacentCells - .Any(c => self.World.Map.IsInMap(c) && info.OpenTerrainTypes.Contains(self.World.GetTerrainInfo(c).Type)); + return cargo.CurrentAdjacentCells.Any(c => self.World.Map.IsInMap(c) + && info.OpenTerrainTypes.Contains(self.World.Map.GetTerrainInfo(c).Type)); } void Open() diff --git a/OpenRA.Mods.RA/Render/WithCrateBody.cs b/OpenRA.Mods.RA/Render/WithCrateBody.cs index d16004de80..e6523b6e6a 100755 --- a/OpenRA.Mods.RA/Render/WithCrateBody.cs +++ b/OpenRA.Mods.RA/Render/WithCrateBody.cs @@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA.Render public void OnLanded() { - var seq = self.World.GetTerrainInfo(self.Location).IsWater ? "water" : "land"; + var seq = self.World.Map.GetTerrainInfo(self.Location).IsWater ? "water" : "land"; anim.PlayRepeating(seq); } } diff --git a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs index 92cf55cba5..30d78eb16c 100644 --- a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs @@ -82,7 +82,7 @@ namespace OpenRA.Mods.RA if (!self.Owner.Shroud.IsExplored(a) || !self.Owner.Shroud.IsExplored(b)) return false; - if (self.World.GetTerrainIndex(a) != self.World.GetTerrainIndex(b)) + if (self.World.Map.GetTerrainIndex(a) != self.World.Map.GetTerrainIndex(b)) return false; } diff --git a/OpenRA.Mods.RA/World/DomainIndex.cs b/OpenRA.Mods.RA/World/DomainIndex.cs index 994505913b..569d49620c 100644 --- a/OpenRA.Mods.RA/World/DomainIndex.cs +++ b/OpenRA.Mods.RA/World/DomainIndex.cs @@ -169,7 +169,7 @@ namespace OpenRA.Mods.RA bool CanTraverseTile(World world, CPos p) { - var terrainOffset = world.GetTerrainIndex(p); + var terrainOffset = world.Map.GetTerrainIndex(p); return (movementClass & (1 << terrainOffset)) > 0; }