* Grows the given town. * There are at the moment 3 possible way's for * the town expansion: * @li Generate a random tile and check if there is a road allowed * @li TL_ORIGINAL * @li TL_BETTER_ROADS * @li Check if the town geometry allows a road and which one * @li TL_2X2_GRID * @li TL_3X3_GRID * @li Forbid roads, only build houses * * @param tile_ptr The current tile * @param c
| 1533 | * @return Result so far. |
| 1534 | */ |
| 1535 | static TownGrowthResult GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection target_dir, Town *t1, TownExpandModes modes) |
| 1536 | { |
| 1537 | RoadBits rcmd = ROAD_NONE; // RoadBits for the road construction command |
| 1538 | TileIndex tile = *tile_ptr; // The main tile on which we base our growth |
| 1539 | |
| 1540 | assert(tile < Map::Size()); |
| 1541 | |
| 1542 | if (cur_rb == ROAD_NONE) { |
| 1543 | /* Tile has no road. |
| 1544 | * We will return TownGrowthResult::SearchStopped to say that this is the last iteration. */ |
| 1545 | |
| 1546 | if (!TownAllowedToBuildRoads(modes)) return TownGrowthResult::SearchStopped; |
| 1547 | if (!_settings_game.economy.allow_town_level_crossings && IsTileType(tile, MP_RAILWAY)) return TownGrowthResult::SearchStopped; |
| 1548 | |
| 1549 | /* Remove hills etc */ |
| 1550 | if (!_settings_game.construction.build_on_slopes || Chance16(1, 6)) LevelTownLand(tile); |
| 1551 | |
| 1552 | /* Is a road allowed here? */ |
| 1553 | switch (t1->layout) { |
| 1554 | default: NOT_REACHED(); |
| 1555 | |
| 1556 | case TL_3X3_GRID: |
| 1557 | case TL_2X2_GRID: |
| 1558 | rcmd = GetTownRoadGridElement(t1, tile, target_dir); |
| 1559 | if (rcmd == ROAD_NONE) return TownGrowthResult::SearchStopped; |
| 1560 | break; |
| 1561 | |
| 1562 | case TL_BETTER_ROADS: |
| 1563 | case TL_ORIGINAL: |
| 1564 | if (!IsRoadAllowedHere(t1, tile, target_dir)) return TownGrowthResult::SearchStopped; |
| 1565 | |
| 1566 | DiagDirection source_dir = ReverseDiagDir(target_dir); |
| 1567 | |
| 1568 | if (Chance16(1, 4)) { |
| 1569 | /* Randomize a new target dir */ |
| 1570 | do target_dir = RandomDiagDir(); while (target_dir == source_dir); |
| 1571 | } |
| 1572 | |
| 1573 | if (!IsRoadAllowedHere(t1, TileAddByDiagDir(tile, target_dir), target_dir)) { |
| 1574 | /* A road is not allowed to continue the randomized road, |
| 1575 | * return if the road we're trying to build is curved. */ |
| 1576 | if (target_dir != ReverseDiagDir(source_dir)) return TownGrowthResult::SearchStopped; |
| 1577 | |
| 1578 | /* Return if neither side of the new road is a house */ |
| 1579 | if (!IsTileType(TileAddByDiagDir(tile, ChangeDiagDir(target_dir, DIAGDIRDIFF_90RIGHT)), MP_HOUSE) && |
| 1580 | !IsTileType(TileAddByDiagDir(tile, ChangeDiagDir(target_dir, DIAGDIRDIFF_90LEFT)), MP_HOUSE)) { |
| 1581 | return TownGrowthResult::SearchStopped; |
| 1582 | } |
| 1583 | |
| 1584 | /* That means that the road is only allowed if there is a house |
| 1585 | * at any side of the new road. */ |
| 1586 | } |
| 1587 | |
| 1588 | rcmd = DiagDirToRoadBits(target_dir) | DiagDirToRoadBits(source_dir); |
| 1589 | break; |
| 1590 | } |
| 1591 | |
| 1592 | } else if (target_dir < DIAGDIR_END && !(cur_rb & DiagDirToRoadBits(ReverseDiagDir(target_dir)))) { |
no test coverage detected