summaryrefslogtreecommitdiff
path: root/src/saveload
diff options
context:
space:
mode:
authorterkhen <terkhen@openttd.org>2011-12-03 22:21:27 +0000
committerterkhen <terkhen@openttd.org>2011-12-03 22:21:27 +0000
commit59d8b0204fbb6c54da18e49a72ced5d83b0141dc (patch)
tree5d471c7a07a55deaae260ae0b2d9091f5b437128 /src/saveload
parente9e62b1629e75f6a908d03ccc02033ba349eb659 (diff)
downloadopenttd-59d8b0204fbb6c54da18e49a72ced5d83b0141dc.tar.xz
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
Diffstat (limited to 'src/saveload')
-rw-r--r--src/saveload/afterload.cpp13
-rw-r--r--src/saveload/town_sl.cpp36
2 files changed, 49 insertions, 0 deletions
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index d231f6912..800f81647 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -2700,6 +2700,19 @@ bool AfterLoadGame()
* which is done by StartupEngines(). */
if (gcf_res != GLC_ALL_GOOD) StartupEngines();
+ if (IsSavegameVersionBefore(166)) {
+ /* Update cargo acceptance map of towns. */
+ for (TileIndex t = 0; t < map_size; t++) {
+ if (!IsTileType(t, MP_HOUSE)) continue;
+ Town::Get(GetTownIndex(t))->cargo_accepted.Add(t);
+ }
+
+ Town *town;
+ FOR_ALL_TOWNS(town) {
+ UpdateTownCargos(town);
+ }
+ }
+
/* Road stops is 'only' updating some caches */
AfterLoadRoadStops();
AfterLoadLabelMaps();
diff --git a/src/saveload/town_sl.cpp b/src/saveload/town_sl.cpp
index c88754ca8..71dc4cd5b 100644
--- a/src/saveload/town_sl.cpp
+++ b/src/saveload/town_sl.cpp
@@ -97,6 +97,7 @@ void UpdateHousesAndTowns()
/* Update the population and num_house dependant values */
FOR_ALL_TOWNS(town) {
UpdateTownRadius(town);
+ UpdateTownCargos(town);
}
}
@@ -176,6 +177,8 @@ static const SaveLoad _town_desc[] = {
SLE_CONDLST(Town, psa_list, REF_STORAGE, 161, SL_MAX_VERSION),
+ SLE_CONDVAR(Town, cargo_produced, SLE_UINT32, 166, SL_MAX_VERSION),
+
/* reserve extra space in savegame here. (currently 30 bytes) */
SLE_CONDNULL(30, 2, SL_MAX_VERSION),
@@ -210,6 +213,19 @@ static void Load_HIDS()
Load_NewGRFMapping(_house_mngr);
}
+const SaveLoad *GetTileMatrixDesc()
+{
+ /* Here due to private member vars. */
+ static const SaveLoad _tilematrix_desc[] = {
+ SLE_VAR(AcceptanceMatrix, area.tile, SLE_UINT32),
+ SLE_VAR(AcceptanceMatrix, area.w, SLE_UINT16),
+ SLE_VAR(AcceptanceMatrix, area.h, SLE_UINT16),
+ SLE_END()
+ };
+
+ return _tilematrix_desc;
+}
+
static void RealSave_Town(Town *t)
{
SlObject(t, _town_desc);
@@ -220,6 +236,14 @@ static void RealSave_Town(Town *t)
for (int i = TE_BEGIN; i < NUM_TE; i++) {
SlObject(&t->received[i], _town_received_desc);
}
+
+ if (IsSavegameVersionBefore(166)) return;
+
+ SlObject(&t->cargo_accepted, GetTileMatrixDesc());
+ if (t->cargo_accepted.area.w != 0) {
+ uint arr_len = t->cargo_accepted.area.w / AcceptanceMatrix::GRID * t->cargo_accepted.area.h / AcceptanceMatrix::GRID;
+ SlArray(t->cargo_accepted.data, arr_len, SLE_UINT32);
+ }
}
static void Save_TOWN()
@@ -250,6 +274,18 @@ static void Load_TOWN()
if (t->townnamegrfid == 0 && !IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST)) {
SlErrorCorrupt("Invalid town name generator");
}
+
+ if (IsSavegameVersionBefore(166)) continue;
+
+ SlObject(&t->cargo_accepted, GetTileMatrixDesc());
+ if (t->cargo_accepted.area.w != 0) {
+ uint arr_len = t->cargo_accepted.area.w / AcceptanceMatrix::GRID * t->cargo_accepted.area.h / AcceptanceMatrix::GRID;
+ t->cargo_accepted.data = MallocT<uint32>(arr_len);
+ SlArray(t->cargo_accepted.data, arr_len, SLE_UINT32);
+
+ /* Rebuild total cargo acceptance. */
+ UpdateTownCargoTotal(t);
+ }
}
}