* Try to grow a town at a given road tile. * @param t The town to grow. * @param tile The road tile to try growing from. * @return true if we successfully expanded the town. */
| 1791 | * @return true if we successfully expanded the town. |
| 1792 | */ |
| 1793 | static bool GrowTownAtRoad(Town *t, TileIndex tile, TownExpandModes modes) |
| 1794 | { |
| 1795 | /* Special case. |
| 1796 | * @see GrowTownInTile Check the else if |
| 1797 | */ |
| 1798 | DiagDirection target_dir = DIAGDIR_END; // The direction in which we want to extend the town |
| 1799 | |
| 1800 | assert(tile < Map::Size()); |
| 1801 | |
| 1802 | /* Number of times to search. |
| 1803 | * Better roads, 2X2 and 3X3 grid grow quite fast so we give |
| 1804 | * them a little handicap. */ |
| 1805 | int iterations; |
| 1806 | switch (t->layout) { |
| 1807 | case TL_BETTER_ROADS: |
| 1808 | iterations = 10 + t->cache.num_houses * 2 / 9; |
| 1809 | break; |
| 1810 | |
| 1811 | case TL_3X3_GRID: |
| 1812 | case TL_2X2_GRID: |
| 1813 | iterations = 10 + t->cache.num_houses * 1 / 9; |
| 1814 | break; |
| 1815 | |
| 1816 | default: |
| 1817 | iterations = 10 + t->cache.num_houses * 4 / 9; |
| 1818 | break; |
| 1819 | } |
| 1820 | |
| 1821 | do { |
| 1822 | RoadBits cur_rb = GetTownRoadBits(tile); // The RoadBits of the current tile |
| 1823 | |
| 1824 | /* Try to grow the town from this point */ |
| 1825 | switch (GrowTownInTile(&tile, cur_rb, target_dir, t, modes)) { |
| 1826 | case TownGrowthResult::Succeed: |
| 1827 | return true; |
| 1828 | case TownGrowthResult::SearchStopped: |
| 1829 | iterations = 0; |
| 1830 | break; |
| 1831 | default: |
| 1832 | break; |
| 1833 | }; |
| 1834 | |
| 1835 | /* Exclude the source position from the bitmask |
| 1836 | * and return if no more road blocks available */ |
| 1837 | if (IsValidDiagDirection(target_dir)) cur_rb &= ~DiagDirToRoadBits(ReverseDiagDir(target_dir)); |
| 1838 | if (cur_rb == ROAD_NONE) return false; |
| 1839 | |
| 1840 | if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
| 1841 | /* Only build in the direction away from the tunnel or bridge. */ |
| 1842 | target_dir = ReverseDiagDir(GetTunnelBridgeDirection(tile)); |
| 1843 | } else { |
| 1844 | /* Select a random bit from the blockmask, walk a step |
| 1845 | * and continue the search from there. */ |
| 1846 | do { |
| 1847 | if (cur_rb == ROAD_NONE) return false; |
| 1848 | RoadBits target_bits; |
| 1849 | do { |
| 1850 | target_dir = RandomDiagDir(); |
no test coverage detected