summaryrefslogtreecommitdiff
path: root/src/saveload
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2014-09-21 11:14:58 +0000
committerrubidium <rubidium@openttd.org>2014-09-21 11:14:58 +0000
commit04e2324b8f9083627354131cbe45a2164283b952 (patch)
tree8d7c4a274217ac7cd3d805cc95e8004c56496d24 /src/saveload
parent51a1c712f2f95439fe52679565cc3c3e9a6d23cf (diff)
downloadopenttd-04e2324b8f9083627354131cbe45a2164283b952.tar.xz
(svn r26873) -Change: split type_height into a type and height array (ic111)
Diffstat (limited to 'src/saveload')
-rw-r--r--src/saveload/afterload.cpp7
-rw-r--r--src/saveload/map_sl.cpp28
-rw-r--r--src/saveload/oldloader_sl.cpp2
3 files changed, 34 insertions, 3 deletions
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index 986803b23..a66f845b6 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -570,6 +570,13 @@ bool AfterLoadGame()
}
}
+ if (IsSavegameVersionBefore(194)) {
+ /* In old savegame versions, the heightlevel was coded in bits 0..3 of the type field */
+ for (TileIndex t = 0; t < map_size; t++) {
+ _m[t].height = GB(_m[t].type, 0, 4);
+ }
+ }
+
/* in version 2.1 of the savegame, town owner was unified. */
if (IsSavegameVersionBefore(2, 1)) ConvertTownOwner();
diff --git a/src/saveload/map_sl.cpp b/src/saveload/map_sl.cpp
index 007af7bc6..1b3977720 100644
--- a/src/saveload/map_sl.cpp
+++ b/src/saveload/map_sl.cpp
@@ -56,7 +56,7 @@ static void Load_MAPT()
for (TileIndex i = 0; i != size;) {
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
- for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].type_height = buf[j];
+ for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].type = buf[j];
}
}
@@ -67,7 +67,30 @@ static void Save_MAPT()
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
- for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].type_height;
+ for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].type;
+ SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
+ }
+}
+
+static void Load_MAPH()
+{
+ SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
+ TileIndex size = MapSize();
+
+ for (TileIndex i = 0; i != size;) {
+ SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
+ for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].height = buf[j];
+ }
+}
+
+static void Save_MAPH()
+{
+ SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
+ TileIndex size = MapSize();
+
+ SlSetLength(size);
+ for (TileIndex i = 0; i != size;) {
+ for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].height;
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
}
}
@@ -252,6 +275,7 @@ static void Save_MAP7()
extern const ChunkHandler _map_chunk_handlers[] = {
{ 'MAPS', Save_MAPS, Load_MAPS, NULL, Check_MAPS, CH_RIFF },
{ 'MAPT', Save_MAPT, Load_MAPT, NULL, NULL, CH_RIFF },
+ { 'MAPH', Save_MAPH, Load_MAPH, NULL, NULL, CH_RIFF },
{ 'MAPO', Save_MAP1, Load_MAP1, NULL, NULL, CH_RIFF },
{ 'MAP2', Save_MAP2, Load_MAP2, NULL, NULL, CH_RIFF },
{ 'M3LO', Save_MAP3, Load_MAP3, NULL, NULL, CH_RIFF },
diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp
index 61fa87a5b..7a2ce4c30 100644
--- a/src/saveload/oldloader_sl.cpp
+++ b/src/saveload/oldloader_sl.cpp
@@ -1510,7 +1510,7 @@ static bool LoadOldMapPart2(LoadgameState *ls, int num)
uint i;
for (i = 0; i < OLD_MAP_SIZE; i++) {
- _m[i].type_height = ReadByte(ls);
+ _m[i].type = ReadByte(ls);
}
for (i = 0; i < OLD_MAP_SIZE; i++) {
_m[i].m5 = ReadByte(ls);