From 8b1b3fd0f91fd30d09d3acaa65bd9a7d23d966cc Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Thu, 14 Feb 2019 21:07:15 +0000 Subject: Feature: Non-rectangular sparse station catchment area. --- src/town_cmd.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/town_cmd.cpp') diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index d7cb45bb9..4aad76f44 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -446,6 +446,22 @@ uint32 GetWorldPopulation() return pop; } +/** + * Remove stations from nearby station list if a town is no longer in the catchment area of each. + * @param t Town to work on + */ +static void RemoveNearbyStations(Town *t) +{ + for (StationList::iterator it = t->stations_near.begin(); it != t->stations_near.end(); /* incremented inside loop */) { + const Station *st = *it; + if (!st->CatchmentCoversTown(t->index)) { + it = t->stations_near.erase(it); + } else { + ++it; + } + } +} + /** * Helper function for house completion stages progression * @param tile TileIndex of the house (or parts of it) to "grow" @@ -599,7 +615,11 @@ 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 || !BuildTownHouse(t, tile)) + { + /* House wasn't replaced, so remove it */ + if (!_generating_world) RemoveNearbyStations(t); + } } cur_company.Restore(); @@ -628,6 +648,7 @@ static CommandCost ClearTile_Town(TileIndex tile, DoCommandFlag flags) ChangeTownRating(t, -rating, RATING_HOUSE_MINIMUM, flags); if (flags & DC_EXEC) { ClearTownHouse(t, tile); + RemoveNearbyStations(t); } return cost; @@ -2151,6 +2172,8 @@ static void MakeTownHouse(TileIndex t, Town *town, byte counter, byte stage, Hou if (size & BUILDING_2_TILES_Y) ClearMakeHouseTile(t + TileDiffXY(0, 1), town, counter, stage, ++type, random_bits); if (size & BUILDING_2_TILES_X) ClearMakeHouseTile(t + TileDiffXY(1, 0), town, counter, stage, ++type, random_bits); if (size & BUILDING_HAS_4_TILES) ClearMakeHouseTile(t + TileDiffXY(1, 1), town, counter, stage, ++type, random_bits); + + if (!_generating_world) FindStationsAroundTiles(TileArea(t, (size & BUILDING_2_TILES_X) ? 2 : 1, (size & BUILDING_2_TILES_Y) ? 2 : 1), &town->stations_near, false); } -- cgit v1.2.3-54-g00ecf