diff -r 1963f2a972d9 src/map_func.h --- a/src/map_func.h Thu Jun 15 02:22:53 2017 +0300 +++ b/src/map_func.h Fri Aug 18 12:36:56 2017 +0300 @@ -363,6 +363,18 @@ } /** + * Adds a Direction to a tile. + * + * @param tile The current tile + * @param dir The direction in which we want to step + * @return the moved tile + */ +static inline TileIndex TileAddByDir(TileIndex tile, Direction dir) +{ + return TILE_ADD(tile, TileOffsByDir(dir)); +} + +/** * Adds a DiagDir to a tile. * * @param tile The current tile diff -r 1963f2a972d9 src/town_cmd.cpp --- a/src/town_cmd.cpp Thu Jun 15 02:22:53 2017 +0300 +++ b/src/town_cmd.cpp Fri Aug 18 12:36:56 2017 +0300 @@ -1228,17 +1228,44 @@ /* Possibly extend the road in a direction. * Randomize a direction and if it has a road, bail out. */ target_dir = RandomDiagDir(); - if (cur_rb & DiagDirToRoadBits(target_dir)) return; - - /* This is the tile we will reach if we extend to this direction. */ - TileIndex house_tile = TileAddByDiagDir(tile, target_dir); // position of a possible house + RoadBits target_rb = DiagDirToRoadBits(target_dir); + TileIndex house_tile; // position of a possible house + + if (cur_rb & target_rb) { + /* If it's a road turn possibly build a house in a corner. + * Use intersection of turn with straight road (always 1 bit) + * as an indicator that we randomed corner house position */ + if ((cur_rb & ROAD_X) != target_rb) return; + + /* Check whether it is a turn and if so determine + * position of the corner tile */ + switch (cur_rb) { + case ROAD_N: + house_tile = TileAddByDir(tile, DIR_S); + break; + case ROAD_S: + house_tile = TileAddByDir(tile, DIR_N); + break; + case ROAD_E: + house_tile = TileAddByDir(tile, DIR_W); + break; + case ROAD_W: + house_tile = TileAddByDir(tile, DIR_E); + break; + default: + return; // not a turn + } + target_dir = DIAGDIR_END; + } else { + house_tile = TileAddByDiagDir(tile, target_dir); + } /* Don't walk into water. */ if (HasTileWaterGround(house_tile)) return; if (!IsValidTile(house_tile)) return; - if (_settings_game.economy.allow_town_roads || _generating_world) { + if (target_dir != DIAGDIR_END && (_settings_game.economy.allow_town_roads || _generating_world)) { switch (t1->layout) { default: NOT_REACHED(); @@ -1248,7 +1275,7 @@ case TL_2X2_GRID: rcmd = GetTownRoadGridElement(t1, tile, target_dir); - allow_house = (rcmd & DiagDirToRoadBits(target_dir)) == ROAD_NONE; + allow_house = (rcmd & target_rb) == ROAD_NONE; break; case TL_BETTER_ROADS: // Use original afterwards! @@ -1258,7 +1285,7 @@ case TL_ORIGINAL: /* Allow a house at the edge. 60% chance or * always ok if no road allowed. */ - rcmd = DiagDirToRoadBits(target_dir); + rcmd = target_rb; allow_house = (!IsRoadAllowedHere(t1, house_tile, target_dir) || Chance16(6, 10)); break; }