(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
This commit is contained in:
@@ -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();
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user