From f4c2b36778153591b4da24cb9267f66972392e12 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 17 Sep 2017 08:47:26 +0000 Subject: [PATCH] Fix height calculations in custom terrain layers. --- OpenRA.Game/Map/Map.cs | 13 +++++++++++++ .../Traits/World/ElevatedBridgeLayer.cs | 3 ++- .../Traits/World/JumpjetActorLayer.cs | 3 ++- .../Traits/World/TerrainTunnelLayer.cs | 3 ++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 993c6de8e8..82c1407d6e 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -784,6 +784,19 @@ namespace OpenRA return new WDist(delta.Z); } + /// + /// The size of the map Height step in world units + /// + public WDist CellHeightStep + { + get + { + // RectangularIsometric defines 1024 units along the diagonal axis, + // giving a half-tile height step of sqrt(2) * 512 + return new WDist(Grid.Type == MapGridType.RectangularIsometric ? 724 : 512); + } + } + public CPos CellContaining(WPos pos) { if (Grid.Type == MapGridType.Rectangular) diff --git a/OpenRA.Mods.Common/Traits/World/ElevatedBridgeLayer.cs b/OpenRA.Mods.Common/Traits/World/ElevatedBridgeLayer.cs index 1683a36bce..d15b1bddd7 100644 --- a/OpenRA.Mods.Common/Traits/World/ElevatedBridgeLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/ElevatedBridgeLayer.cs @@ -43,6 +43,7 @@ namespace OpenRA.Mods.Common.Traits public void WorldLoaded(World world, WorldRenderer wr) { var domainIndex = world.WorldActor.Trait(); + var cellHeight = world.Map.CellHeightStep.Length; foreach (var tti in world.WorldActor.Info.TraitInfos()) { enabled = true; @@ -54,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits terrainIndices[uv] = terrain; var pos = map.CenterOfCell(c); - cellCenters[uv] = pos - new WVec(0, 0, pos.Z - 512 * tti.Height); + cellCenters[uv] = pos - new WVec(0, 0, pos.Z - cellHeight * tti.Height); } var end = tti.EndCells(); diff --git a/OpenRA.Mods.Common/Traits/World/JumpjetActorLayer.cs b/OpenRA.Mods.Common/Traits/World/JumpjetActorLayer.cs index ccfc0e5268..ba7ec6fd02 100644 --- a/OpenRA.Mods.Common/Traits/World/JumpjetActorLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/JumpjetActorLayer.cs @@ -40,6 +40,7 @@ namespace OpenRA.Mods.Common.Traits map = self.World.Map; terrainIndex = self.World.Map.Rules.TileSet.GetTerrainIndex(info.TerrainType); height = new CellLayer(map); + var cellHeight = self.World.Map.CellHeightStep.Length; foreach (var c in map.AllCells) { var neighbourCount = 0; @@ -57,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits } } - height[c] = info.HeightOffset.Length + neighbourHeight * 512 / neighbourCount; + height[c] = info.HeightOffset.Length + neighbourHeight * cellHeight / neighbourCount; } } diff --git a/OpenRA.Mods.Common/Traits/World/TerrainTunnelLayer.cs b/OpenRA.Mods.Common/Traits/World/TerrainTunnelLayer.cs index 6355c4b60c..6fda51abf5 100644 --- a/OpenRA.Mods.Common/Traits/World/TerrainTunnelLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/TerrainTunnelLayer.cs @@ -42,6 +42,7 @@ namespace OpenRA.Mods.Common.Traits public void WorldLoaded(World world, WorldRenderer wr) { var domainIndex = world.WorldActor.Trait(); + var cellHeight = world.Map.CellHeightStep.Length; foreach (var tti in world.WorldActor.Info.TraitInfos()) { enabled = true; @@ -53,7 +54,7 @@ namespace OpenRA.Mods.Common.Traits terrainIndices[uv] = terrain; var pos = map.CenterOfCell(c); - cellCenters[uv] = pos - new WVec(0, 0, pos.Z - 512 * tti.Height); + cellCenters[uv] = pos - new WVec(0, 0, pos.Z - cellHeight * tti.Height); } var portal = tti.PortalCells();