summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-09-12 19:40:47 +0000
committerfrosch <frosch@openttd.org>2010-09-12 19:40:47 +0000
commitf0783d7e72b9c8845735df9f21a608883a14aebe (patch)
tree80de445d7ad4c4b22b5f9968ff95a92b1bcee7ff
parentb24904636469dfaed22f6aebd12c1cf4d040a6ef (diff)
downloadopenttd-f0783d7e72b9c8845735df9f21a608883a14aebe.tar.xz
(svn r20791) -Fix (r12161): Building 2x2 houses did not work for 2x2 road layouts on all map sizes.
-rw-r--r--src/town_cmd.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 91dbb9d68..df0813ff2 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -1984,18 +1984,19 @@ static inline bool TownLayoutAllows2x2HouseHere(Town *t, TileIndex tile)
/* Allow towns everywhere when we don't build roads */
if (!_settings_game.economy.allow_town_roads && !_generating_world) return true;
- /* MapSize() is sure dividable by both MapSizeX() and MapSizeY(),
- * so to do only one memory access, use MapSize() */
- uint dx = MapSize() + TileX(t->xy) - TileX(tile);
- uint dy = MapSize() + TileY(t->xy) - TileY(tile);
+ /* Compute relative position of tile. (Positive offsets are towards north) */
+ TileIndexDiffC grid_pos = TileIndexToTileIndexDiffC(t->xy, tile);
switch (t->layout) {
case TL_2X2_GRID:
- if ((dx % 3) != 0 || (dy % 3) != 0) return false;
+ grid_pos.x %= 3;
+ grid_pos.y %= 3;
+ if ((grid_pos.x != 2 && grid_pos.x != -1) ||
+ (grid_pos.y != 2 && grid_pos.y != -1)) return false;
break;
case TL_3X3_GRID:
- if ((dx % 4) < 2 || (dy % 4) < 2) return false;
+ if ((grid_pos.x & 3) < 2 || (grid_pos.y & 3) < 2) return false;
break;
default: