Index: src/town_cmd.cpp =================================================================== --- src/town_cmd.cpp (Revision 11005) +++ src/town_cmd.cpp (Arbeitskopie) @@ -577,15 +577,6 @@ { 0, 1} }; -/** - * Distance multiplyer - * Defines the possible distances between 2 road tiles - */ -enum RoadBlockTitleDistance { - RB_TILE_DIST1 = 1, ///< 1 tile between - RB_TILE_DIST2, ///< 2 tiles between -}; - static bool GrowTown(Town *t); static void TownTickHandler(Town *t) @@ -645,14 +636,28 @@ * @param dir target direction * @param dist_multi distance multiplyer * @return true if one of the neighboring tiles at the - * given distance is a road tile else + * given distance is a road tile else false */ -static bool IsNeighborRoadTile(TileIndex tile, int dir, RoadBlockTitleDistance dist_multi) +static bool IsNeighborRoadTile(TileIndex tile, int dir, int dist_multi) { - return (HASBIT(GetTownRoadMask(TILE_ADD(tile, dist_multi * ToTileIndexDiff(_roadblock_tileadd[dir + 1]))), dir ^ 2) || - HASBIT(GetTownRoadMask(TILE_ADD(tile, dist_multi * ToTileIndexDiff(_roadblock_tileadd[dir + 3]))), dir ^ 2) || - HASBIT(GetTownRoadMask(TILE_ADD(tile, dist_multi * (ToTileIndexDiff(_roadblock_tileadd[dir + 1]) + ToTileIndexDiff(_roadblock_tileadd[dir + 2])))), dir) || - HASBIT(GetTownRoadMask(TILE_ADD(tile, dist_multi * (ToTileIndexDiff(_roadblock_tileadd[dir + 3]) + ToTileIndexDiff(_roadblock_tileadd[dir + 2])))), dir)); + static TileIndexDiff tid_lt[3]; ///< lookup table for the used diff values + tid_lt[0] = ToTileIndexDiff(_roadblock_tileadd[dir + 1]); + tid_lt[1] = ToTileIndexDiff(_roadblock_tileadd[dir + 3]); + tid_lt[2] = ToTileIndexDiff(_roadblock_tileadd[dir + 2]); + + for (uint pos = (dist_multi * 4) - 1; pos != 0; pos--) { + TileIndexDiff cur = 0; + /* For each even value of pos add the left TileIndexDiff + * for each uneven value the right TileIndexDiff + * for each with 2nd bit set (2,3,6,7,..) add the reversed TileIndexDiff + */ + cur += tid_lt[(pos & 1) ? 0 : 1]; + if (pos & 2) cur += tid_lt[2]; + + cur = ((uint)(pos / 4) + 1) * cur; ///< Multiply for the fitting distance + if (HASBIT(GetTownRoadMask(TILE_ADD(tile, cur)), (pos & 2) ? dir ^ 2 : dir)) return true; + } + return false; } static bool IsRoadAllowedHere(TileIndex tile, int dir) @@ -685,11 +690,10 @@ default: NOT_REACHED(); case TL_ORIGINAL: /* Disallow the road if any neighboring tile has a road (distance: 1) */ - return !IsNeighborRoadTile(tile, dir, RB_TILE_DIST1); + return !IsNeighborRoadTile(tile, dir, 1); case TL_BETTER_ROADS: /* Disallow the road if any neighboring tile has a road (distance: 1 and 2). */ - return !(IsNeighborRoadTile(tile, dir, RB_TILE_DIST1) || - IsNeighborRoadTile(tile, dir, RB_TILE_DIST2)); + return !IsNeighborRoadTile(tile, dir, 2); } }