From 567487b7970d119c873913e7dd646f00a97cc8e5 Mon Sep 17 00:00:00 2001 From: Wolfolo Date: Sun, 11 Dec 2016 22:51:15 +0100 Subject: [PATCH 1/6] Disallow building of houses along tram tracks only --- src/road.h | 2 ++ src/table/roadtypes.h | 2 +- src/town_cmd.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/road.h b/src/road.h index 0defe7474..d7bc58538 100644 --- a/src/road.h +++ b/src/road.h @@ -25,9 +25,11 @@ /** Roadtype flags. Starts with RO instead of R because R is used for rails */ enum RoadTypeFlags { ROTF_CATENARY = 0, ///< Bit number for adding catenary + ROTF_DISALLOW_HOUSES_ALONG, ///< Bit number for disallowing houses along the road ROTFB_NONE = 0, ///< All flags cleared. ROTFB_CATENARY = 1 << ROTF_CATENARY, ///< Value for drawing a catenary. + ROTFB_DISALLOW_HOUSES_ALONG, ///< Value for disallowing houses along the road. }; DECLARE_ENUM_AS_BIT_SET(RoadTypeFlags) diff --git a/src/table/roadtypes.h b/src/table/roadtypes.h index 27ddd8510..7f0ffd8d7 100644 --- a/src/table/roadtypes.h +++ b/src/table/roadtypes.h @@ -157,7 +157,7 @@ static const RoadtypeInfo _original_tramtypes[] = { 0, // TODO /* flags */ - ROTFB_CATENARY, + ROTFB_CATENARY | ROTFB_DISALLOW_HOUSES_ALONG, /* cost multiplier */ 16, diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index d8d13f0c8..30b899ef4 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -1120,6 +1120,42 @@ static bool GrowTownWithBridge(const Town *t, const TileIndex tile, const DiagDi return false; } + +/** + * Checks whether at least one surrounding roads allows to build a house here + * + * @param t the tile where the house will be built + * @return true if at least one surrounding roadtype allows building houses here + */ +static inline bool RoadTypesAllowHouseHere(TileIndex t) +{ + RoadTypeIdentifier rtid; + RoadTypeIdentifiers rtids; + + static const TileIndexDiffC tiles[] = { {-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1} }; + const TileIndexDiffC *ptr; + bool allow = false; + + for (ptr = tiles; ptr != endof(tiles); ++ptr) { + TileIndex cur_tile = t + ToTileIndexDiff(*ptr); + + if (!(IsTileType(cur_tile, MP_ROAD) || IsTileType(cur_tile, MP_STATION))) continue; + allow = true; + + rtids = RoadTypeIdentifiers::FromTile(cur_tile); + FOR_EACH_SET_ROADTYPEIDENTIFIER(rtid, rtids) + { + /* Found one road which allows the type, it is enough to allow building the house here */ + if (!HasBit(GetRoadTypeInfo(rtid)->flags, ROTF_DISALLOW_HOUSES_ALONG)) return true; + } + } + + /* If no road was found surrounding the tile we can allow building the house since there is + * nothing which forbids it, if a road was found but the execution reached this point, then + * all the found roads don't allow houses to be built */ + return !allow; +} + /** * Grows the given town. * There are at the moment 3 possible way's for @@ -1267,6 +1303,8 @@ static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection t } } + allow_house &= RoadTypesAllowHouseHere(house_tile); + if (allow_house) { /* Build a house, but not if there already is a house there. */ if (!IsTileType(house_tile, MP_HOUSE)) { @@ -2072,6 +2110,9 @@ static inline bool CanBuildHouseHere(TileIndex tile, TownID town, bool noslope) Slope slope = GetTileSlope(tile); if ((noslope && slope != SLOPE_FLAT) || IsSteepSlope(slope)) return false; + /* at least one RoadTypes allow building the house here? */ + if (!RoadTypesAllowHouseHere(tile)) return false; + /* building under a bridge? */ if (IsBridgeAbove(tile)) return false; From 66fc852a38897e6230b26f6ccd58b31780003d61 Mon Sep 17 00:00:00 2001 From: Wolfolo Date: Sun, 11 Dec 2016 23:27:20 +0100 Subject: [PATCH 2/6] Fix: building roadstops without road triggered an assert --- src/station_cmd.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 440fa3909..bd0fb894a 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1819,7 +1819,12 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin if (flags & DC_EXEC) { /* Check every tile in the area. */ TILE_AREA_LOOP(cur_tile, roadstop_area) { - RoadTypeIdentifiers rtids = RoadTypeIdentifiers::FromTile(cur_tile); + RoadTypeIdentifiers rtids; + + if (IsTileType(cur_tile, MP_ROAD) || IsTileType(cur_tile, MP_STATION)) { + rtids = RoadTypeIdentifiers::FromTile(cur_tile); + } + Owner road_owner = rtids.HasRoad() ? GetRoadOwner(cur_tile, ROADTYPE_ROAD) : _current_company; Owner tram_owner = rtids.HasTram() ? GetRoadOwner(cur_tile, ROADTYPE_TRAM) : _current_company; From a1c229c52402ddca9d88628a8086c84ac272d4b5 Mon Sep 17 00:00:00 2001 From: Wolfolo Date: Mon, 12 Dec 2016 19:35:39 +0100 Subject: [PATCH 3/6] Fix: missing 1 << part on the ROTFB_DISALLOW_HOUSES_ALONG flag --- src/road.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/road.h b/src/road.h index d7bc58538..b27f14cd9 100644 --- a/src/road.h +++ b/src/road.h @@ -29,7 +29,7 @@ enum RoadTypeFlags { ROTFB_NONE = 0, ///< All flags cleared. ROTFB_CATENARY = 1 << ROTF_CATENARY, ///< Value for drawing a catenary. - ROTFB_DISALLOW_HOUSES_ALONG, ///< Value for disallowing houses along the road. + ROTFB_DISALLOW_HOUSES_ALONG = 1 << ROTF_DISALLOW_HOUSES_ALONG, ///< Value for disallowing houses along the road. }; DECLARE_ENUM_AS_BIT_SET(RoadTypeFlags) From 2578e645a44cf54ff086d92a6f5d33dfd7925663 Mon Sep 17 00:00:00 2001 From: Wolfolo Date: Mon, 12 Dec 2016 20:51:30 +0100 Subject: [PATCH 4/6] Changed the name of the flag to disallow houses and it's description --- src/road.h | 10 +++++----- src/table/roadtypes.h | 2 +- src/town_cmd.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/road.h b/src/road.h index b27f14cd9..73fa4fa46 100644 --- a/src/road.h +++ b/src/road.h @@ -24,12 +24,12 @@ /** Roadtype flags. Starts with RO instead of R because R is used for rails */ enum RoadTypeFlags { - ROTF_CATENARY = 0, ///< Bit number for adding catenary - ROTF_DISALLOW_HOUSES_ALONG, ///< Bit number for disallowing houses along the road + ROTF_CATENARY = 0, ///< Bit number for adding catenary + ROTF_NO_HOUSES, ///< Bit number for setting this roadtype as not house friendly - ROTFB_NONE = 0, ///< All flags cleared. - ROTFB_CATENARY = 1 << ROTF_CATENARY, ///< Value for drawing a catenary. - ROTFB_DISALLOW_HOUSES_ALONG = 1 << ROTF_DISALLOW_HOUSES_ALONG, ///< Value for disallowing houses along the road. + ROTFB_NONE = 0, ///< All flags cleared. + ROTFB_CATENARY = 1 << ROTF_CATENARY, ///< Value for drawing a catenary. + ROTFB_NO_HOUSES = 1 << ROTF_NO_HOUSES, ///< Value for for setting this roadtype as not house friendly. }; DECLARE_ENUM_AS_BIT_SET(RoadTypeFlags) diff --git a/src/table/roadtypes.h b/src/table/roadtypes.h index 7f0ffd8d7..697cc4f94 100644 --- a/src/table/roadtypes.h +++ b/src/table/roadtypes.h @@ -157,7 +157,7 @@ static const RoadtypeInfo _original_tramtypes[] = { 0, // TODO /* flags */ - ROTFB_CATENARY | ROTFB_DISALLOW_HOUSES_ALONG, + ROTFB_CATENARY | ROTFB_NO_HOUSES, /* cost multiplier */ 16, diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 30b899ef4..798774d13 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -1146,7 +1146,7 @@ static inline bool RoadTypesAllowHouseHere(TileIndex t) FOR_EACH_SET_ROADTYPEIDENTIFIER(rtid, rtids) { /* Found one road which allows the type, it is enough to allow building the house here */ - if (!HasBit(GetRoadTypeInfo(rtid)->flags, ROTF_DISALLOW_HOUSES_ALONG)) return true; + if (!HasBit(GetRoadTypeInfo(rtid)->flags, ROTF_NO_HOUSES)) return true; } } From 1e7d17037776a4fef0c9c9411db15c4aff1015d8 Mon Sep 17 00:00:00 2001 From: Wolfolo Date: Fri, 6 Jan 2017 18:10:49 +0100 Subject: [PATCH 5/6] Change: moved 2 variables in the correct scope --- src/town_cmd.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index bfcfa62e5..9ad85ec3a 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -1129,9 +1129,6 @@ static bool GrowTownWithBridge(const Town *t, const TileIndex tile, const DiagDi */ static inline bool RoadTypesAllowHouseHere(TileIndex t) { - RoadTypeIdentifier rtid; - RoadTypeIdentifiers rtids; - static const TileIndexDiffC tiles[] = { {-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1} }; const TileIndexDiffC *ptr; bool allow = false; @@ -1142,7 +1139,8 @@ static inline bool RoadTypesAllowHouseHere(TileIndex t) if (!(IsTileType(cur_tile, MP_ROAD) || IsTileType(cur_tile, MP_STATION))) continue; allow = true; - rtids = RoadTypeIdentifiers::FromTile(cur_tile); + RoadTypeIdentifier rtid; + RoadTypeIdentifiers rtids = RoadTypeIdentifiers::FromTile(cur_tile); FOR_EACH_SET_ROADTYPEIDENTIFIER(rtid, rtids) { /* Found one road which allows the type, it is enough to allow building the house here */ From ca1fdd514d6949892ffd1a86361ca0add476117f Mon Sep 17 00:00:00 2001 From: Wolfolo Date: Fri, 6 Jan 2017 18:11:40 +0100 Subject: [PATCH 6/6] Change: enabled the no houses flag also for RAIL RoadType --- src/table/roadtypes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/table/roadtypes.h b/src/table/roadtypes.h index cdc0c46db..fbbc3e194 100644 --- a/src/table/roadtypes.h +++ b/src/table/roadtypes.h @@ -224,7 +224,7 @@ static const RoadtypeInfo _original_tramtypes[] = { ROADSUBTYPES_NORMAL | ROADSUBTYPES_ELECTRIC, /* flags */ - ROTFB_NONE, + ROTFB_NO_HOUSES, /* cost multiplier */ 8,