changeset 17625:5ccd436f4590 draft

(svn r22389) -Fix [FS#4600]: try to make sure there is an early house available in the current climate for every townzone, not just a single available house for all climates/townzones
author yexo <yexo@openttd.org>
date Sat, 30 Apr 2011 19:44:20 +0000
parents f1feece6fa62
children bbb42cf4c36c
files src/newgrf.cpp
diffstat 1 files changed, 43 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -7603,6 +7603,33 @@
 }
 
 /**
+ * Make sure there is at least one house available in the year 0 for the given
+ * climate / housezone combination.
+ * @param bitmask The climate and housezone to check for. Exactly one climate
+ *   bit and one housezone bit should be set.
+ */
+static void EnsureEarlyHouse(HouseZones bitmask)
+{
+	Year min_year = MAX_YEAR;
+
+	for (int i = 0; i < HOUSE_MAX; i++) {
+		HouseSpec *hs = HouseSpec::Get(i);
+		if (hs == NULL || !hs->enabled) continue;
+		if ((hs->building_availability & bitmask) != bitmask) continue;
+		if (hs->min_year < min_year) min_year = hs->min_year;
+	}
+
+	if (min_year == 0) return;
+
+	for (int i = 0; i < HOUSE_MAX; i++) {
+		HouseSpec *hs = HouseSpec::Get(i);
+		if (hs == NULL || !hs->enabled) continue;
+		if ((hs->building_availability & bitmask) != bitmask) continue;
+		if (hs->min_year == min_year) hs->min_year = 0;
+	}
+}
+
+/**
  * Add all new houses to the house array. House properties can be set at any
  * time in the GRF file, so we can only add a house spec to the house array
  * after the file has finished loading. We also need to check the dates, due to
@@ -7639,8 +7666,6 @@
 		}
 	}
 
-	Year min_year = MAX_YEAR;
-
 	for (int i = 0; i < HOUSE_MAX; i++) {
 		HouseSpec *hs = HouseSpec::Get(i);
 		const HouseSpec *next1 = (i + 1 < HOUSE_MAX ? HouseSpec::Get(i + 1) : NULL);
@@ -7658,17 +7683,22 @@
 			 * building_flags to zero here to make sure any house following
 			 * this one in the pool is properly handled as 1x1 house. */
 			hs->building_flags = TILE_NO_FLAG;
-		} else {
-			if (hs->min_year < min_year) min_year = hs->min_year;
-		}
-	}
-
-	if (min_year != 0) {
-		for (int i = 0; i < HOUSE_MAX; i++) {
-			HouseSpec *hs = HouseSpec::Get(i);
-
-			if (hs->enabled && hs->min_year == min_year) hs->min_year = 0;
-		}
+		}
+	}
+
+	HouseZones climate_mask = (HouseZones)(1 << (_settings_game.game_creation.landscape + 12));
+	EnsureEarlyHouse(HZ_ZON1 | climate_mask);
+	EnsureEarlyHouse(HZ_ZON2 | climate_mask);
+	EnsureEarlyHouse(HZ_ZON3 | climate_mask);
+	EnsureEarlyHouse(HZ_ZON4 | climate_mask);
+	EnsureEarlyHouse(HZ_ZON5 | climate_mask);
+
+	if (_settings_game.game_creation.landscape == LT_ARCTIC) {
+		EnsureEarlyHouse(HZ_ZON1 | HZ_SUBARTC_ABOVE);
+		EnsureEarlyHouse(HZ_ZON2 | HZ_SUBARTC_ABOVE);
+		EnsureEarlyHouse(HZ_ZON3 | HZ_SUBARTC_ABOVE);
+		EnsureEarlyHouse(HZ_ZON4 | HZ_SUBARTC_ABOVE);
+		EnsureEarlyHouse(HZ_ZON5 | HZ_SUBARTC_ABOVE);
 	}
 }