Changeset - r24587:6296750ffdbd
[Not reviewed]
master
0 1 0
Patric Stout - 3 years ago 2021-01-07 07:01:23
truebrain@openttd.org
Fix #7604: prevent houses to wander too far from town center when rebuilding (#8507)

When a multi-tile house is rebuild, it always used the most northern
tile to build the new house. This can very easily lead to houses
wandering off in the north-ish direction (either NW or NE).

To prevent this, pick the tile closest to town center when rebuilding
on a multi-tile house. This still means a house can be build away
from a road, but it is no longer wandering around finding another
town to call home.
1 file changed with 22 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/town_cmd.cpp
Show inline comments
 
@@ -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();
0 comments (0 inline, 0 general)