Add setting to limit length of continuous inclined roads built by towns

Default to max 4 tiles
This commit is contained in:
Jonathan G Rennison
2022-10-10 18:14:09 +01:00
parent 1e4912cf78
commit 846cd7e228
6 changed files with 52 additions and 2 deletions

View File

@@ -1592,6 +1592,35 @@ static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection t
break;
}
if (_settings_game.economy.town_max_road_slope > 0 && ((rcmd == ROAD_X) || (rcmd == ROAD_Y))) {
/* Limit consecutive sloped road tiles */
auto get_road_slope = [rcmd](TileIndex t) -> Slope {
Slope slope = GetTileSlope(t);
extern Foundation GetRoadFoundation(Slope tileh, RoadBits bits);
ApplyFoundationToSlope(GetRoadFoundation(slope, rcmd), &slope);
return slope;
};
const Slope slope = get_road_slope(tile);
if (slope != SLOPE_FLAT) {
const int delta = TileOffsByDiagDir(ReverseDiagDir(target_dir));
bool ok = false;
TileIndex t = tile;
for (uint i = 0; i < _settings_game.economy.town_max_road_slope; i++) {
t += delta;
if (!IsValidTile(t) || !IsNormalRoadTile(t) || GetRoadBits(t, RTT_ROAD) != rcmd || get_road_slope(t) != slope) {
ok = true;
break;
}
}
if (!ok) {
/* All tested tiles had the same incline, disallow road */
return;
}
}
}
} else if (target_dir < DIAGDIR_END && !(cur_rb & DiagDirToRoadBits(ReverseDiagDir(target_dir)))) {
/* Continue building on a partial road.
* Should be always OK, so we only generate