diff options
author | rubidium <rubidium@openttd.org> | 2007-10-20 16:50:48 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-10-20 16:50:48 +0000 |
commit | 5289aa2010b5fb249ba316f6e4b67ad5f7159120 (patch) | |
tree | 30e50cebc542be694f72726e770ef47ea943f6d0 /src/viewport.cpp | |
parent | 8212088c03c0a0af451f734391699e5dab8d8608 (diff) | |
download | openttd-5289aa2010b5fb249ba316f6e4b67ad5f7159120.tar.xz |
(svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
Diffstat (limited to 'src/viewport.cpp')
-rw-r--r-- | src/viewport.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/viewport.cpp b/src/viewport.cpp index 4d54bc96b..fc2ca6ab6 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -362,11 +362,17 @@ static Point TranslateXYToTileCoord(const ViewPort *vp, int x, int y) a = clamp(a, 0, (int)(MapMaxX() * TILE_SIZE) - 1); b = clamp(b, 0, (int)(MapMaxY() * TILE_SIZE) - 1); - z = GetSlopeZ(a, b ) / 2; - z = GetSlopeZ(a + z, b + z) / 2; - z = GetSlopeZ(a + z, b + z) / 2; - z = GetSlopeZ(a + z, b + z) / 2; - z = GetSlopeZ(a + z, b + z) / 2; + /* (a, b) is the X/Y-world coordinate that belongs to (x,y) if the landscape would be completely flat on height 0. + * Now find the Z-world coordinate by fix point iteration. + * This is a bit tricky because the tile height is non-continuous at foundations. + * The clicked point should be approached from the back, otherwise there are regions that are not clickable. + * (FOUNDATION_HALFTILE_LOWER on SLOPE_STEEP_S hides north halftile completely) + * So give it a z-malus of 4 in the first iterations. + */ + z = 0; + for (int i = 0; i < 5; i++) z = GetSlopeZ(a + max(z, 4u) - 4, b + max(z, 4u) - 4) / 2; + for (uint malus = 3; malus > 0; malus--) z = GetSlopeZ(a + max(z, malus) - malus, b + max(z, malus) - malus) / 2; + for (int i = 0; i < 5; i++) z = GetSlopeZ(a + z, b + z) / 2; pt.x = a + z; pt.y = b + z; |