Skip to content

Commit

Permalink
Merge no-houses into RATT
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfolo committed Feb 3, 2018
2 parents a2196a7 + 841c4d6 commit b13a79c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/road.h
Expand Up @@ -26,10 +26,12 @@
enum RoadTypeFlags {
ROTF_CATENARY = 0, ///< Bit number for adding catenary
ROTF_NO_LEVEL_CROSSING, ///< Bit number for disabling level crossing
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_NO_LEVEL_CROSSING = 1 << ROTF_NO_LEVEL_CROSSING, ///< Value for disabling a level crossing.
ROTFB_NO_HOUSES = 1 << ROTF_NO_HOUSES, ///< Value for for setting this roadtype as not house friendly.
};
DECLARE_ENUM_AS_BIT_SET(RoadTypeFlags)

Expand Down
4 changes: 2 additions & 2 deletions src/table/roadtypes.h
Expand Up @@ -224,7 +224,7 @@ static const RoadtypeInfo _original_tramtypes[] = {
ROADSUBTYPES_NORMAL | ROADSUBTYPES_ELECTRIC,

/* flags */
ROTFB_NONE,
ROTFB_NO_HOUSES,

/* cost multiplier */
8,
Expand Down Expand Up @@ -303,7 +303,7 @@ static const RoadtypeInfo _original_tramtypes[] = {
ROADSUBTYPES_ELECTRIC,

/* flags */
ROTFB_CATENARY,
ROTFB_CATENARY | ROTFB_NO_HOUSES,

/* cost multiplier */
16,
Expand Down
39 changes: 39 additions & 0 deletions src/town_cmd.cpp
Expand Up @@ -1120,6 +1120,40 @@ 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)
{
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;

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 */
if (!HasBit(GetRoadTypeInfo(rtid)->flags, ROTF_NO_HOUSES)) 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
Expand Down Expand Up @@ -1267,6 +1301,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)) {
Expand Down Expand Up @@ -2071,6 +2107,9 @@ static inline bool CanBuildHouseHere(TileIndex tile, 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;

Expand Down

0 comments on commit b13a79c

Please sign in to comment.