From abc235253752a5c182ef0bcc28df7d1d6369d149 Mon Sep 17 00:00:00 2001 From: yexo Date: Sat, 30 Apr 2011 19:44:20 +0000 Subject: [PATCH] (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 --- src/newgrf.cpp | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 93f194b92c..2005054749 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -7602,6 +7602,33 @@ static bool IsHouseSpecValid(HouseSpec *hs, const HouseSpec *next1, const HouseS return true; } +/** + * 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 @@ -7639,8 +7666,6 @@ static void FinaliseHouseArray() } } - 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 @@ static void FinaliseHouseArray() * 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); + 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 (hs->enabled && hs->min_year == min_year) hs->min_year = 0; - } + 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); } }