summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/house.h11
-rw-r--r--src/table/town_land.h2
-rw-r--r--src/town_cmd.cpp12
-rw-r--r--src/town_map.h16
4 files changed, 29 insertions, 12 deletions
diff --git a/src/house.h b/src/house.h
index e6eae34c7..ed73cc806 100644
--- a/src/house.h
+++ b/src/house.h
@@ -137,4 +137,15 @@ struct HouseSpec {
}
};
+/**
+ * Do HouseID translation for NewGRFs.
+ * @param hid the HouseID to get the override for.
+ * @return the HouseID to actually work with.
+ */
+static inline HouseID GetTranslatedHouseID(HouseID hid)
+{
+ const HouseSpec *hs = HouseSpec::Get(hid);
+ return hs->override == INVALID_HOUSE_ID ? hid : hs->override;
+}
+
#endif /* HOUSE_H */
diff --git a/src/table/town_land.h b/src/table/town_land.h
index e4a810d74..7f678da63 100644
--- a/src/table/town_land.h
+++ b/src/table/town_land.h
@@ -1810,7 +1810,7 @@ assert_compile(lengthof(_town_draw_tile_data) == (NEW_HOUSE_OFFSET) * 4 * 4);
*/
#define MS(mnd, mxd, p, rc, bn, rr, mg, ca1, ca2, ca3, bf, ba, cg1, cg2, cg3) \
{mnd, mxd, p, rc, bn, rr, mg, {ca1, ca2, ca3}, {cg1, cg2, cg3}, bf, ba, true, \
- 0, NULL, 0, 0, {0, 0, 0, 0}, 16, NO_EXTRA_FLAG, HOUSE_NO_CLASS, 0, 2, 0, 0, 0, NULL}
+ 0, NULL, INVALID_HOUSE_ID, 0, {0, 0, 0, 0}, 16, NO_EXTRA_FLAG, HOUSE_NO_CLASS, 0, 2, 0, 0, 0, NULL}
/** House specifications from original data */
static const HouseSpec _original_house_specs[] = {
/**
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 59745237d..c96c2d239 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -2094,7 +2094,7 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
const HouseSpec *hs = HouseSpec::Get(i);
/* Verify that the candidate house spec matches the current tile status */
- if ((~hs->building_availability & bitmask) != 0 || !hs->enabled) continue;
+ if ((~hs->building_availability & bitmask) != 0 || !hs->enabled || hs->override != INVALID_HOUSE_ID) continue;
/* Don't let these counters overflow. Global counters are 32bit, there will never be that many houses. */
if (hs->class_id != HOUSE_NO_CLASS) {
@@ -2132,13 +2132,9 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
const HouseSpec *hs = HouseSpec::Get(house);
- if (_loaded_newgrf_features.has_newhouses) {
- if (hs->override != 0) {
- house = hs->override;
- hs = HouseSpec::Get(house);
- }
-
- if ((hs->extra_flags & BUILDING_IS_HISTORICAL) && !_generating_world && _game_mode != GM_EDITOR) continue;
+ if (_loaded_newgrf_features.has_newhouses && !_generating_world &&
+ _game_mode != GM_EDITOR && (hs->extra_flags & BUILDING_IS_HISTORICAL) != 0) {
+ continue;
}
if (_cur_year < hs->min_year || _cur_year > hs->max_year) continue;
diff --git a/src/town_map.h b/src/town_map.h
index 2fd38b210..148fb2891 100644
--- a/src/town_map.h
+++ b/src/town_map.h
@@ -42,19 +42,29 @@ static inline void SetTownIndex(TileIndex t, TownID index)
/**
* Get the type of this house, which is an index into the house spec array
- * Since m4 is only a byte and we want to support 512 houses, we use the bit 6
- * of m3 as an additional bit to house type.
+ * without doing any NewGRF related translations.
* @param t the tile
* @pre IsTileType(t, MP_HOUSE)
* @return house type
*/
-static inline HouseID GetHouseType(TileIndex t)
+static inline HouseID GetCleanHouseType(TileIndex t)
{
assert(IsTileType(t, MP_HOUSE));
return _m[t].m4 | (GB(_m[t].m3, 6, 1) << 8);
}
/**
+ * Get the type of this house, which is an index into the house spec array
+ * @param t the tile
+ * @pre IsTileType(t, MP_HOUSE)
+ * @return house type
+ */
+static inline HouseID GetHouseType(TileIndex t)
+{
+ return GetTranslatedHouseID(GetCleanHouseType(t));
+}
+
+/**
* Set the house type.
* @param t the tile
* @param house_id the new house type