summaryrefslogtreecommitdiff
path: root/src/saveload/town_sl.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2012-04-25 21:06:31 +0000
committerrubidium <rubidium@openttd.org>2012-04-25 21:06:31 +0000
commitb926277caf0ab423dd4b6cdfa38bce3eb8a58d2c (patch)
tree7ddd714e183d8103efdc3abde574c84914639b2c /src/saveload/town_sl.cpp
parent41e5c839e08bfc811b1e8d7272996567776b788f (diff)
downloadopenttd-b926277caf0ab423dd4b6cdfa38bce3eb8a58d2c.tar.xz
(svn r24180) -Codechange/feature-ish: add cache checker for the town's cache
Diffstat (limited to 'src/saveload/town_sl.cpp')
-rw-r--r--src/saveload/town_sl.cpp61
1 files changed, 36 insertions, 25 deletions
diff --git a/src/saveload/town_sl.cpp b/src/saveload/town_sl.cpp
index 07043bc0a..6edd6ddd3 100644
--- a/src/saveload/town_sl.cpp
+++ b/src/saveload/town_sl.cpp
@@ -13,19 +13,15 @@
#include "../newgrf_house.h"
#include "../town.h"
#include "../landscape.h"
+#include "../subsidy_func.h"
#include "saveload.h"
#include "newgrf_sl.h"
/**
- * 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.
+ * Rebuild all the cached variables of towns.
*/
-void UpdateHousesAndTowns()
+void RebuildTownCaches()
{
Town *town;
InitializeBuildingCounts();
@@ -40,6 +36,38 @@ void UpdateHousesAndTowns()
if (!IsTileType(t, MP_HOUSE)) continue;
HouseID house_id = GetCleanHouseType(t);
+ town = Town::GetByTile(t);
+ IncreaseBuildingCount(town, house_id);
+ if (IsHouseCompleted(t)) town->cache.population += HouseSpec::Get(house_id)->population;
+
+ /* Increase the number of houses for every house, but only once. */
+ if (GetHouseNorthPart(house_id) == 0) town->cache.num_houses++;
+ }
+
+ /* Update the population and num_house dependant values */
+ FOR_ALL_TOWNS(town) {
+ UpdateTownRadius(town);
+ UpdateTownCargoes(town);
+ }
+ UpdateTownCargoBitmap();
+
+ RebuildSubsidisedSourceAndDestinationCache();
+}
+
+/**
+ * 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()
+{
+ for (TileIndex t = 0; t < MapSize(); t++) {
+ if (!IsTileType(t, MP_HOUSE)) continue;
+
+ HouseID house_id = GetCleanHouseType(t);
if (!HouseSpec::Get(house_id)->enabled && house_id >= NEW_HOUSE_OFFSET) {
/* The specs for this type of house are not available any more, so
* replace it with the substitute original house type. */
@@ -82,24 +110,7 @@ void UpdateHousesAndTowns()
}
}
- for (TileIndex t = 0; t < MapSize(); t++) {
- if (!IsTileType(t, MP_HOUSE)) continue;
-
- HouseID house_id = GetCleanHouseType(t);
- town = Town::GetByTile(t);
- IncreaseBuildingCount(town, house_id);
- if (IsHouseCompleted(t)) town->cache.population += HouseSpec::Get(house_id)->population;
-
- /* Increase the number of houses for every house, but only once. */
- if (GetHouseNorthPart(house_id) == 0) town->cache.num_houses++;
- }
-
- /* Update the population and num_house dependant values */
- FOR_ALL_TOWNS(town) {
- UpdateTownRadius(town);
- UpdateTownCargoes(town);
- }
- UpdateTownCargoBitmap();
+ RebuildTownCaches();
}
/** Save and load of towns. */