Fix #6507: Don't try to load invalid depots from older savegames

(cherry picked from commit d9f9a64389)
This commit is contained in:
Charles Pigott
2019-04-27 09:59:45 +01:00
committed by Jonathan G Rennison
parent 44911ec254
commit e334f7db30

View File

@@ -2530,6 +2530,14 @@ bool AfterLoadGame()
if (IsSavegameVersionBefore(SLV_128)) { if (IsSavegameVersionBefore(SLV_128)) {
const Depot *d; const Depot *d;
FOR_ALL_DEPOTS(d) { FOR_ALL_DEPOTS(d) {
/* At some point, invalid depots were saved into the game (possibly those removed in the past?)
* Remove them here, so they don't cause issues further down the line */
if (!IsDepotTile(d->xy)) {
DEBUG(sl, 0, "Removing invalid depot %d at %d, %d", d->index, TileX(d->xy), TileY(d->xy));
delete d;
d = nullptr;
continue;
}
_m[d->xy].m2 = d->index; _m[d->xy].m2 = d->index;
if (IsTileType(d->xy, MP_WATER)) _m[GetOtherShipDepotTile(d->xy)].m2 = d->index; if (IsTileType(d->xy, MP_WATER)) _m[GetOtherShipDepotTile(d->xy)].m2 = d->index;
} }