Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix height calculations in custom terrain layers. #14038

Merged
merged 1 commit into from
Sep 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions OpenRA.Game/Map/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,19 @@ public WDist DistanceAboveTerrain(WPos pos)
return new WDist(delta.Z);
}

/// <summary>
/// The size of the map Height step in world units
/// </summary>
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)
Expand Down
3 changes: 2 additions & 1 deletion OpenRA.Mods.Common/Traits/World/ElevatedBridgeLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public ElevatedBridgeLayer(Actor self, ElevatedBridgeLayerInfo info)
public void WorldLoaded(World world, WorldRenderer wr)
{
var domainIndex = world.WorldActor.Trait<DomainIndex>();
var cellHeight = world.Map.CellHeightStep.Length;
foreach (var tti in world.WorldActor.Info.TraitInfos<ElevatedBridgePlaceholderInfo>())
{
enabled = true;
Expand All @@ -54,7 +55,7 @@ public void WorldLoaded(World world, WorldRenderer wr)
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();
Expand Down
3 changes: 2 additions & 1 deletion OpenRA.Mods.Common/Traits/World/JumpjetActorLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public JumpjetActorLayer(Actor self, JumpjetActorLayerInfo info)
map = self.World.Map;
terrainIndex = self.World.Map.Rules.TileSet.GetTerrainIndex(info.TerrainType);
height = new CellLayer<int>(map);
var cellHeight = self.World.Map.CellHeightStep.Length;
foreach (var c in map.AllCells)
{
var neighbourCount = 0;
Expand All @@ -57,7 +58,7 @@ public JumpjetActorLayer(Actor self, JumpjetActorLayerInfo info)
}
}

height[c] = info.HeightOffset.Length + neighbourHeight * 512 / neighbourCount;
height[c] = info.HeightOffset.Length + neighbourHeight * cellHeight / neighbourCount;
}
}

Expand Down
3 changes: 2 additions & 1 deletion OpenRA.Mods.Common/Traits/World/TerrainTunnelLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public TerrainTunnelLayer(Actor self, TerrainTunnelLayerInfo info)
public void WorldLoaded(World world, WorldRenderer wr)
{
var domainIndex = world.WorldActor.Trait<DomainIndex>();
var cellHeight = world.Map.CellHeightStep.Length;
foreach (var tti in world.WorldActor.Info.TraitInfos<TerrainTunnelInfo>())
{
enabled = true;
Expand All @@ -53,7 +54,7 @@ public void WorldLoaded(World world, WorldRenderer wr)
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();
Expand Down