diff options
-rw-r--r-- | src/newgrf.cpp | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 93f194b92..200505474 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -7603,6 +7603,33 @@ static bool IsHouseSpecValid(HouseSpec *hs, const HouseSpec *next1, const HouseS } /** + * 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 @@ 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); } } |