summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--misc.c2
-rw-r--r--openttd.c51
-rw-r--r--order_cmd.c8
-rw-r--r--saveload.c30
-rw-r--r--saveload.h22
-rw-r--r--station_cmd.c7
-rw-r--r--texteff.c3
-rw-r--r--vehicle.c8
8 files changed, 79 insertions, 52 deletions
diff --git a/misc.c b/misc.c
index 25db8cc63..36c9deae3 100644
--- a/misc.c
+++ b/misc.c
@@ -811,7 +811,7 @@ static void Load_MAP2(void)
SlArray(buf, lengthof(buf),
/* In those versions the m2 was 8 bits */
- _sl_version < 5 ? SLE_FILE_U8 | SLE_VAR_U16 : SLE_UINT16
+ CheckSavegameVersion(5) ? SLE_FILE_U8 | SLE_VAR_U16 : SLE_UINT16
);
for (j = 0; j != lengthof(buf); j++) _m[i++].m2 = buf[j];
}
diff --git a/openttd.c b/openttd.c
index e26bb7e0f..98ab0206b 100644
--- a/openttd.c
+++ b/openttd.c
@@ -1130,22 +1130,22 @@ bool AfterLoadGame(uint version)
Player *p;
// in version 2.1 of the savegame, town owner was unified.
- if (version <= 0x200) ConvertTownOwner();
+ if (CheckSavegameVersionOldStyle(2, 1)) ConvertTownOwner();
// from version 4.1 of the savegame, exclusive rights are stored at towns
- if (version <= 0x400) UpdateExclusiveRights();
+ if (CheckSavegameVersionOldStyle(4, 1)) UpdateExclusiveRights();
// from version 4.2 of the savegame, currencies are in a different order
- if (version <= 0x401) UpdateCurrencies();
+ if (CheckSavegameVersionOldStyle(4, 2)) UpdateCurrencies();
- // from version 6.0 of the savegame, signs have an "owner"
- if (version <= 0x600) UpdateSignOwner();
+ // from version 6.1 of the savegame, signs have an "owner"
+ if (CheckSavegameVersionOldStyle(6, 1)) UpdateSignOwner();
/* In old version there seems to be a problem that water is owned by
OWNER_NONE, not OWNER_WATER.. I can't replicate it for the current
- (0x402) version, so I just check when versions are older, and then
+ (4.3) version, so I just check when versions are older, and then
walk through the whole map.. */
- if (version <= 0x402) {
+ if (CheckSavegameVersionOldStyle(4, 3)) {
TileIndex tile = TileXY(0, 0);
uint w = MapSizeX();
uint h = MapSizeY();
@@ -1172,12 +1172,12 @@ bool AfterLoadGame(uint version)
AfterLoadVehicles();
// Update all waypoints
- if (version < 0x0C00) FixOldWaypoints();
+ if (CheckSavegameVersion(12)) FixOldWaypoints();
UpdateAllWaypointSigns();
// in version 2.2 of the savegame, we have new airports
- if (version <= 0x201) UpdateOldAircraft();
+ if (CheckSavegameVersionOldStyle(2, 2)) UpdateOldAircraft();
UpdateAllStationVirtCoord();
@@ -1205,12 +1205,12 @@ bool AfterLoadGame(uint version)
vp->virtual_width = vp->width << vp->zoom;
vp->virtual_height = vp->height << vp->zoom;
- // in version 4.0 of the savegame, is_active was introduced to determine
+ // in version 4.1 of the savegame, is_active was introduced to determine
// if a player does exist, rather then checking name_1
- if (version <= 0x400) CheckIsPlayerActive();
+ if (CheckSavegameVersionOldStyle(4, 1)) CheckIsPlayerActive();
- // the void tiles on the southern border used to belong to a wrong class.
- if (version <= 0x402) UpdateVoidTiles();
+ // the void tiles on the southern border used to belong to a wrong class (pre 4.3).
+ if (CheckSavegameVersionOldStyle(4, 3)) UpdateVoidTiles();
// If Load Scenario / New (Scenario) Game is used,
// a player does not exist yet. So create one here.
@@ -1222,10 +1222,13 @@ bool AfterLoadGame(uint version)
DoZoomInOutWindow(ZOOM_NONE, w); // update button status
MarkWholeScreenDirty();
- //In 5.1, Oilrigs have been moved (again)
- if (version <= 0x500) UpdateOilRig();
+ // In 5.1, Oilrigs have been moved (again)
+ if (CheckSavegameVersionOldStyle(5, 1)) UpdateOilRig();
- if (version <= 0x600) {
+ /* In version 6.1 we put the town index in the map-array. To do this, we need
+ * to use m2 (16bit big), so we need to clean m2, and that is where this is
+ * all about ;) */
+ if (CheckSavegameVersionOldStyle(6, 1)) {
BEGIN_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0) {
if (IsTileType(tile, MP_HOUSE)) {
_m[tile].m4 = _m[tile].m2;
@@ -1247,12 +1250,16 @@ bool AfterLoadGame(uint version)
} END_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0);
}
- if (version < 0x900) {
+ /* From version 9.0, we update the max passengers of a town (was sometimes negative
+ * before that. */
+ if (CheckSavegameVersion(9)) {
Town *t;
FOR_ALL_TOWNS(t) UpdateTownMaxPass(t);
}
- if (version < 0xF00) {
+ /* From version 15.0, we moved a semaphore bit from bit 2 to bit 3 in m4, making
+ * room for PBS. While doing that, clean some blocks that should be empty, for PBS. */
+ if (CheckSavegameVersion(15)) {
BEGIN_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0) {
if (IsTileType(tile, MP_RAILWAY) && HasSignals(tile) && HASBIT(_m[tile].m4, 2)) {
CLRBIT(_m[tile].m4, 2);
@@ -1264,7 +1271,9 @@ bool AfterLoadGame(uint version)
} END_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0);
}
- if (version < 0x1000) {
+ /* From version 16.0, we included autorenew on engines, which are now saved, but
+ * of course, we do need to initialize them for older savegames. */
+ if (CheckSavegameVersion(16)) {
FOR_ALL_PLAYERS(p) {
EngineID i;
@@ -1288,7 +1297,7 @@ bool AfterLoadGame(uint version)
/* In version 16.1 of the savegame, trains became aware of station lengths
need to initialized to the invalid state
players needs to set renew_keep_length too */
- if (version < 0x1001) {
+ if (CheckSavegameVersionOldStyle(16, 1)) {
Vehicle *v;
FOR_ALL_PLAYERS(p) {
p->renew_keep_length = false;
@@ -1306,7 +1315,7 @@ bool AfterLoadGame(uint version)
* waypoints to make way for storing the index in m2. The custom graphics
* id which was stored in m4 is now saved as a grf/id reference in the
* waypoint struct. */
- if (version < 0x1100) {
+ if (CheckSavegameVersion(17)) {
Waypoint *wp;
FOR_ALL_WAYPOINTS(wp) {
diff --git a/order_cmd.c b/order_cmd.c
index 6e8f176ca..64c7878e0 100644
--- a/order_cmd.c
+++ b/order_cmd.c
@@ -1129,13 +1129,13 @@ static void Save_ORDR(void)
static void Load_ORDR(void)
{
- if (_sl_full_version <= 0x501) {
- /* Version older than 0x502 did not have a ->next pointer. Convert them
+ if (CheckSavegameVersionOldStyle(5, 2)) {
+ /* Version older than 5.2 did not have a ->next pointer. Convert them
(in the old days, the orderlist was 5000 items big) */
uint len = SlGetFieldLength();
uint i;
- if (_sl_version < 5) {
+ if (CheckSavegameVersion(5)) {
/* Pre-version 5 had an other layout for orders
(uint16 instead of uint32) */
uint16 orders[5000];
@@ -1151,7 +1151,7 @@ static void Load_ORDR(void)
AssignOrder(GetOrder(i), UnpackVersion4Order(orders[i]));
}
- } else if (_sl_full_version <= 0x501) {
+ } else if (CheckSavegameVersionOldStyle(5, 2)) {
uint32 orders[5000];
len /= sizeof(uint32);
diff --git a/saveload.c b/saveload.c
index dfd0d6709..dc7485eac 100644
--- a/saveload.c
+++ b/saveload.c
@@ -29,14 +29,12 @@
#include <setjmp.h>
enum {
- SAVEGAME_MAJOR_VERSION = 17,
- SAVEGAME_MINOR_VERSION = 1,
+ SAVEGAME_VERSION = 18,
- SAVEGAME_LOADABLE_VERSION = (SAVEGAME_MAJOR_VERSION << 8) + SAVEGAME_MINOR_VERSION
};
-byte _sl_version; /// the major savegame version identifier
-uint16 _sl_full_version; /// the full version of the savegame
+uint16 _sl_version; /// the major savegame version identifier
+byte _sl_minor_version; /// the minor savegame version, DO NOT USE!
typedef void WriterProc(uint len);
typedef uint ReaderProc(void);
@@ -1136,7 +1134,7 @@ static void *IntToReference(uint index, SLRefType rt)
{
/* After version 4.3 REF_VEHICLE_OLD is saved as REF_VEHICLE,
* and should be loaded like that */
- if (rt == REF_VEHICLE_OLD && _sl_full_version >= ((4 << 8) | 4))
+ if (rt == REF_VEHICLE_OLD && !CheckSavegameVersionOldStyle(4, 4))
rt = REF_VEHICLE;
/* No need to look up NULL pointers, just return immediately */
@@ -1312,7 +1310,7 @@ static void* SaveFileToDisk(void *arg)
/* We have written our stuff to memory, now write it to file! */
hdr[0] = fmt->tag;
- hdr[1] = TO_BE32((SAVEGAME_MAJOR_VERSION << 16) + (SAVEGAME_MINOR_VERSION << 8));
+ hdr[1] = TO_BE32(SAVEGAME_VERSION << 16);
if (fwrite(hdr, sizeof(hdr), 1, _sl.fh) != 1) SlError("file write failed");
if (!fmt->init_write()) SlError("cannot initialize compressor");
@@ -1426,7 +1424,7 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode)
return AbortSaveLoad();
}
- _sl_version = SAVEGAME_MAJOR_VERSION;
+ _sl_version = SAVEGAME_VERSION;
BeforeSaveGame();
SlSaveChunks();
@@ -1453,23 +1451,27 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode)
DEBUG(misc, 0) ("Unknown savegame type, trying to load it as the buggy format.");
rewind(_sl.fh);
_sl_version = version = 0;
- _sl_full_version = 0;
+ _sl_minor_version = 0;
fmt = _saveload_formats + 1; // LZO
break;
}
if (fmt->tag == hdr[0]) {
// check version number
- version = TO_BE32(hdr[1]) >> 8;
+ _sl_version = version = TO_BE32(hdr[1]) >> 16;
+ /* Minor is not used anymore from version 18.0, but it is still needed
+ * in versions before that (4 cases) which can't be removed easy.
+ * Therefor it is loaded, but never saved (or, it saves a 0 in any scenario).
+ * So never EVER use this minor version again. -- TrueLight -- 22-11-2005 */
+ _sl_minor_version = (TO_BE32(hdr[1]) >> 8) & 0xFF;
+
+ DEBUG(misc, 1)("[Savegame] Loading savegame version %d\n", _sl_version);
/* Is the version higher than the current? */
- if (version > SAVEGAME_LOADABLE_VERSION) {
+ if (_sl_version > SAVEGAME_VERSION) {
DEBUG(misc, 0) ("Savegame version invalid.");
return AbortSaveLoad();
}
-
- _sl_version = (version >> 8);
- _sl_full_version = version;
break;
}
}
diff --git a/saveload.h b/saveload.h
index eb869f4e8..6a3d2e5e4 100644
--- a/saveload.h
+++ b/saveload.h
@@ -26,8 +26,8 @@ typedef void AutolengthProc(void *arg);
typedef struct SaveLoadGlobVarList {
void *address;
byte conv;
- byte from_version;
- byte to_version;
+ uint16 from_version;
+ uint16 to_version;
} SaveLoadGlobVarList;
typedef struct {
@@ -51,8 +51,8 @@ typedef enum SLRefType {
} SLRefType;
-extern byte _sl_version; /// the major savegame version identifier
-extern uint16 _sl_full_version; /// the full version of the savegame
+extern uint16 _sl_version; /// the major savegame version identifier
+extern byte _sl_minor_version; /// the minor savegame version, DO NOT USE!
enum {
@@ -161,6 +161,20 @@ typedef struct SaveLoad {
/* End marker */
#define SLE_END() {SL_END, 0, 0, 0, 0, 0}
+/** Checks if the savegame is below major.minor.
+ */
+static inline bool CheckSavegameVersionOldStyle(uint16 major, byte minor)
+{
+ return (_sl_version < major) || (_sl_version == major && _sl_minor_version < minor);
+}
+
+/** Checks if the savegame is below version.
+ */
+static inline bool CheckSavegameVersion(uint16 version)
+{
+ return _sl_version < version;
+}
+
void SlSetArrayIndex(uint index);
int SlIterateArray(void);
void SlArray(void *array, uint length, VarType conv);
diff --git a/station_cmd.c b/station_cmd.c
index 8b3fe0e21..31391d077 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -2982,7 +2982,7 @@ static void SaveLoad_STNS(Station *st)
SlObject(&st->goods[i], _goods_desc);
/* In older versions, enroute_from had 0xFF as INVALID_STATION, is now 0xFFFF */
- if (_sl_full_version < 0x700 && st->goods[i].enroute_from == 0xFF) {
+ if (CheckSavegameVersion(7) && st->goods[i].enroute_from == 0xFF) {
st->goods[i].enroute_from = INVALID_STATION;
}
}
@@ -3022,8 +3022,9 @@ static void Load_STNS(void)
st->trainst_h = h;
}
- if (_sl_full_version < 0x600) {
- /* Convert old bus and truck tile to new-ones */
+ /* In older versions, we had just 1 tile for a bus/lorry, now we have more..
+ * convert, if needed */
+ if (CheckSavegameVersion(6)) {
if (st->bus_tile_obsolete != 0) {
st->bus_stops = AllocateRoadStop();
if (st->bus_stops == NULL)
diff --git a/texteff.c b/texteff.c
index fb59ff634..34c1d4641 100644
--- a/texteff.c
+++ b/texteff.c
@@ -364,7 +364,8 @@ void InitializeAnimatedTiles(void)
static void SaveLoad_ANIT(void)
{
- if (_sl_version < 6) {
+ // In pre version 6, we has 16bit per tile, now we have 32bit per tile, convert it ;)
+ if (CheckSavegameVersion(6)) {
SlArray(_animated_tile_list, lengthof(_animated_tile_list), SLE_FILE_U16 | SLE_VAR_U32);
} else {
SlArray(_animated_tile_list, lengthof(_animated_tile_list), SLE_UINT32);
diff --git a/vehicle.c b/vehicle.c
index f1aaacc8f..99576a2a2 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -2354,10 +2354,10 @@ static void Load_VEHS(void)
SlObject(v, _veh_descs[SlReadByte()]);
/* Old savegames used 'last_station_visited = 0xFF' */
- if (_sl_version < 5 && v->last_station_visited == 0xFF)
+ if (CheckSavegameVersion(5) && v->last_station_visited == 0xFF)
v->last_station_visited = INVALID_STATION;
- if (_sl_version < 5) {
+ if (CheckSavegameVersion(5)) {
/* Convert the current_order.type (which is a mix of type and flags, because
in those versions, they both were 4 bits big) to type and flags */
v->current_order.flags = (v->current_order.type & 0xF0) >> 4;
@@ -2366,7 +2366,7 @@ static void Load_VEHS(void)
}
/* Check for shared order-lists (we now use pointers for that) */
- if (_sl_full_version < 0x502) {
+ if (CheckSavegameVersionOldStyle(5, 2)) {
FOR_ALL_VEHICLES(v) {
Vehicle *u;
@@ -2389,7 +2389,7 @@ static void Load_VEHS(void)
}
/* Connect front and rear engines of multiheaded trains and converts subtype to the new format */
- if (_sl_full_version < 0x1101) {
+ if (CheckSavegameVersionOldStyle(17, 1)) {
ConvertOldMultiheadToNew();
}
}