summaryrefslogtreecommitdiff
path: root/src/newgrf_house.cpp
diff options
context:
space:
mode:
authorskidd13 <skidd13@openttd.org>2008-03-18 12:28:21 +0000
committerskidd13 <skidd13@openttd.org>2008-03-18 12:28:21 +0000
commit49cf499cf2be57504e2e1553e17c3bbafd6f2936 (patch)
tree3635265faa97c3ae592a1ad08aee603ada1d45f0 /src/newgrf_house.cpp
parent285a43037b412e4943ffe96407a14c4d9a058dd7 (diff)
downloadopenttd-49cf499cf2be57504e2e1553e17c3bbafd6f2936.tar.xz
(svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
Diffstat (limited to 'src/newgrf_house.cpp')
-rw-r--r--src/newgrf_house.cpp31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp
index 88494b33e..251207c19 100644
--- a/src/newgrf_house.cpp
+++ b/src/newgrf_house.cpp
@@ -31,13 +31,24 @@ static HouseClassMapping _class_mapping[HOUSE_CLASS_MAX];
HouseOverrideManager _house_mngr(NEW_HOUSE_OFFSET, HOUSE_MAX, INVALID_HOUSE_ID);
-void CheckHouseIDs()
+/**
+ * Check and update town and house values.
+ *
+ * Checked are the HouseIDs. Updated are the
+ * town population the number of houses per
+ * town, the town radius and the max passengers
+ * of the town.
+ */
+void UpdateHousesAndTowns()
{
Town *town;
InitializeBuildingCounts();
- /* Reset town population */
- FOR_ALL_TOWNS(town) town->population = 0;
+ /* Reset town population and num_houses */
+ FOR_ALL_TOWNS(town) {
+ town->population = 0;
+ town->num_houses = 0;
+ }
for (TileIndex t = 0; t < MapSize(); t++) {
HouseID house_id;
@@ -51,9 +62,23 @@ void CheckHouseIDs()
house_id = _house_mngr.GetSubstituteID(house_id);
SetHouseType(t, house_id);
}
+
town = GetTownByTile(t);
IncreaseBuildingCount(town, house_id);
if (IsHouseCompleted(t)) town->population += GetHouseSpecs(house_id)->population;
+
+ /* Increase the number of houses for every house tile which
+ * has a size bit set. Multi tile buildings have got only
+ * one tile with such a bit set, so there is no problem. */
+ if (GetHouseSpecs(GetHouseType(t))->building_flags & BUILDING_HAS_1_TILE) {
+ town->num_houses++;
+ }
+ }
+
+ /* Update the population and num_house dependant values */
+ FOR_ALL_TOWNS(town) {
+ UpdateTownRadius(town);
+ UpdateTownMaxPass(town);
}
}