summaryrefslogtreecommitdiff
path: root/landscape.c
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2004-08-24 12:54:37 +0000
committertruelight <truelight@openttd.org>2004-08-24 12:54:37 +0000
commita0ba5a79394c4a6b8087bf5f2d076bba7ff13135 (patch)
tree897b6585f4866af42f4b45e81f6c517977a93d05 /landscape.c
parentc32166a5c9d6cd969bdc3a6942b62286a685d26f (diff)
downloadopenttd-a0ba5a79394c4a6b8087bf5f2d076bba7ff13135.tar.xz
(svn r132) -Fix: [1014278] TileAddWrap() gave wrong results. Fixed now.
Diffstat (limited to 'landscape.c')
-rw-r--r--landscape.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/landscape.c b/landscape.c
index 45e371bb2..4c13d880b 100644
--- a/landscape.c
+++ b/landscape.c
@@ -742,11 +742,22 @@ TileIndex AdjustTileCoordRandomly(TileIndex a, byte rng)
);
}
-uint TileAddWrap(TileIndex tile, int add)
+// This function checks if we add addx/addy to tile, if we
+// do wrap around the edges. For example, tile = (10,2) and
+// addx = +3 and addy = -4. This function will now return
+// TILE_WRAPPED, because the y is wrapped. This is needed in
+// for example, farmland. When the tile is not wrapped,
+// the result will be tile + TILE_XY(addx, addy)
+uint TileAddWrap(TileIndex tile, int addx, int addy)
{
- uint t = tile + add;
- if (t < TILES_X * TILE_Y_MAX && GET_TILE_X(t) != TILE_X_MAX)
- return t;
+ int x, y;
+ x = GET_TILE_X(tile) + addx;
+ y = GET_TILE_Y(tile) + addy;
+
+ // Are we about to wrap?
+ if (x > 0 && x < TILE_X_MAX && y > 0 && y < TILE_Y_MAX)
+ return tile + TILE_XY(addx, addy);
+
return TILE_WRAPPED;
}