Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #7604: prevent houses to wander too far from town center when rebuilding #8507

Merged
merged 1 commit into from Jan 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/town_cmd.cpp
Expand Up @@ -626,7 +626,28 @@ static void TileLoop_Town(TileIndex tile)
ClearTownHouse(t, tile);

/* Rebuild with another house? */
if (GB(r, 24, 8) >= 12) BuildTownHouse(t, tile);
if (GB(r, 24, 8) >= 12) {
/* If we are multi-tile houses, make sure to replace the house
* closest to city center. If we do not do this, houses tend to
* wander away from roads and other houses. */
if (hs->building_flags & BUILDING_HAS_2_TILES) {
/* House tiles are always the most north tile. Move the new
* house to the south if we are north of the city center. */
TileIndexDiffC grid_pos = TileIndexToTileIndexDiffC(t->xy, tile);
int x = Clamp(grid_pos.x, 0, 1);
int y = Clamp(grid_pos.y, 0, 1);

if (hs->building_flags & TILE_SIZE_2x2) {
tile = TILE_ADDXY(tile, x, y);
} else if (hs->building_flags & TILE_SIZE_1x2) {
tile = TILE_ADDXY(tile, 0, y);
} else if (hs->building_flags & TILE_SIZE_2x1) {
tile = TILE_ADDXY(tile, x, 0);
}
}

BuildTownHouse(t, tile);
}
}

cur_company.Restore();
Expand Down