changeset 14025:ec50d4cd06b5 draft

(svn r18567) -Fix [FS#2613]: [NewGRF] House property 15 did not work
author rubidium <rubidium@openttd.org>
date Sun, 20 Dec 2009 14:53:32 +0000
parents 7b24b1bfb31b
children a9016ea549f9
files src/house.h src/table/town_land.h src/town_cmd.cpp src/town_map.h
diffstat 4 files changed, 30 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/house.h
+++ b/src/house.h
@@ -137,4 +137,15 @@
 	}
 };
 
+/**
+ * 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 */
--- a/src/table/town_land.h
+++ b/src/table/town_land.h
@@ -1810,7 +1810,7 @@
  */
 #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[] = {
 	/**
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -2094,7 +2094,7 @@
 		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 @@
 
 		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;
--- a/src/town_map.h
+++ b/src/town_map.h
@@ -42,16 +42,26 @@
 
 /**
  * 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 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)
 {
-	assert(IsTileType(t, MP_HOUSE));
-	return _m[t].m4 | (GB(_m[t].m3, 6, 1) << 8);
+	return GetTranslatedHouseID(GetCleanHouseType(t));
 }
 
 /**