From 8c138523731f38af4143fc3a447ed5ee29cf5035 Mon Sep 17 00:00:00 2001 From: glx Date: Tue, 15 Jan 2008 00:03:48 +0000 Subject: (svn r11855) -Fix [FS#1335]: recompute town population when removing a 'newhouses' grf, or when loading a game with missing 'newhouses' grfs --- src/newgrf_house.cpp | 24 +++++++----------------- src/newgrf_house.h | 1 - src/openttd.cpp | 4 ++-- src/town_cmd.cpp | 5 ++--- 4 files changed, 11 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp index 5f7adedf8..31aa4e972 100644 --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -33,8 +33,12 @@ HouseOverrideManager _house_mngr(NEW_HOUSE_OFFSET, HOUSE_MAX, INVALID_HOUSE_ID); void CheckHouseIDs() { + Town *town; InitializeBuildingCounts(); + /* Reset town population */ + FOR_ALL_TOWNS(town) town->population = 0; + for (TileIndex t = 0; t < MapSize(); t++) { HouseID house_id; @@ -47,7 +51,9 @@ void CheckHouseIDs() house_id = _house_mngr.GetSubstituteID(house_id); SetHouseType(t, house_id); } - IncreaseBuildingCount(GetTownByTile(t), house_id); + town = GetTownByTile(t); + IncreaseBuildingCount(town, house_id); + if (IsHouseCompleted(t)) town->population += GetHouseSpecs(house_id)->population; } } @@ -122,22 +128,6 @@ void DecreaseBuildingCount(Town *t, HouseID house_id) if (_building_counts.class_count[class_id] > 0) _building_counts.class_count[class_id]--; } -/** - * AfterLoadCountBuildings() - * - * After a savegame has been loaded, count the number of buildings on the map. - */ -void AfterLoadCountBuildings() -{ - if (!_loaded_newgrf_features.has_newhouses) return; - - for (TileIndex t = 0; t < MapSize(); t++) { - if (!IsTileType(t, MP_HOUSE)) continue; - IncreaseBuildingCount(GetTownByTile(t), GetHouseType(t)); - } -} - - static uint32 HouseGetRandomBits(const ResolverObject *object) { const TileIndex tile = object->u.house.tile; diff --git a/src/newgrf_house.h b/src/newgrf_house.h index ffee181d5..5c70a2cb8 100644 --- a/src/newgrf_house.h +++ b/src/newgrf_house.h @@ -33,7 +33,6 @@ HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid); void InitializeBuildingCounts(); void IncreaseBuildingCount(Town *t, HouseID house_id); void DecreaseBuildingCount(Town *t, HouseID house_id); -void AfterLoadCountBuildings(); void DrawNewHouseTile(TileInfo *ti, HouseID house_id); void AnimateNewHouseTile(TileIndex tile); diff --git a/src/openttd.cpp b/src/openttd.cpp index f53b4a621..2ec5db868 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -2018,8 +2018,8 @@ bool AfterLoadGame() } } - /* Count the buildings after updating the map array. */ - AfterLoadCountBuildings(); + /* Check that house ids are still valid. */ + CheckHouseIDs(); if (CheckSavegameVersion(43)) { for (TileIndex t = 0; t < map_size; t++) { diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index e6ee6c208..3bb6b7d9c 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -2411,9 +2411,8 @@ static const SaveLoad _town_desc[] = { SLE_CONDVAR(Town, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), SLE_CONDVAR(Town, xy, SLE_UINT32, 6, SL_MAX_VERSION), - SLE_CONDVAR(Town, population, SLE_FILE_U16 | SLE_VAR_U32, 0, 2), - SLE_CONDVAR(Town, population, SLE_UINT32, 3, SL_MAX_VERSION), - + SLE_CONDNULL(2, 0, 2), + SLE_CONDNULL(4, 3, 84), SLE_VAR(Town, num_houses, SLE_UINT16), SLE_CONDVAR(Town, townnamegrfid, SLE_UINT32, 66, SL_MAX_VERSION), -- cgit v1.2.3-70-g09d2