Created
December 12, 2016 18:28
-
-
Save Wolfolo/e32645b91f41878a77c96628c8032313 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/road.h b/src/road.h | |
index 0defe74..d7bc585 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 27ddd85..7f0ffd8 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 d8d13f0..30b899e 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; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment