summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-01-09 14:55:22 +0000
committerrubidium <rubidium@openttd.org>2011-01-09 14:55:22 +0000
commitade2f29f5d4bd48bf94dd875fe212f884e336c4c (patch)
treecea2f99ff3efd69b4e155b3a63c063b26145342e /src
parent35be634974abbd5a78429ef114cff16c78eb555a (diff)
downloadopenttd-ade2f29f5d4bd48bf94dd875fe212f884e336c4c.tar.xz
(svn r21747) -Fix [FS#4395]: the diagonal iterator would iterate twice over some tiles (fonsinchen)
Diffstat (limited to 'src')
-rw-r--r--src/tilearea.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/tilearea.cpp b/src/tilearea.cpp
index 74f701315..c518fe8f1 100644
--- a/src/tilearea.cpp
+++ b/src/tilearea.cpp
@@ -139,15 +139,22 @@ TileIterator &DiagonalTileIterator::operator++()
{
assert(this->tile != INVALID_TILE);
+ bool new_line = false;
do {
/* Iterate using the rotated coordinates. */
if (this->a_max > 0) {
- ++this->a_cur;
+ this->a_cur += 2;
+ new_line = this->a_cur >= this->a_max;
} else {
- --this->a_cur;
+ this->a_cur -= 2;
+ new_line = this->a_cur <= this->a_max;
}
- if (this->a_cur == this->a_max) {
- this->a_cur = 0;
+ if (new_line) {
+ /* offset of initial a_cur: one tile in the same direction as a_max
+ * every second line.
+ */
+ this->a_cur = abs(this->a_cur) % 2 ? 0 : (this->a_max > 0 ? 1 : -1);
+
if (this->b_max > 0) {
++this->b_cur;
} else {