diff options
author | rubidium <rubidium@openttd.org> | 2014-09-21 11:14:58 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2014-09-21 11:14:58 +0000 |
commit | 04e2324b8f9083627354131cbe45a2164283b952 (patch) | |
tree | 8d7c4a274217ac7cd3d805cc95e8004c56496d24 /src | |
parent | 51a1c712f2f95439fe52679565cc3c3e9a6d23cf (diff) | |
download | openttd-04e2324b8f9083627354131cbe45a2164283b952.tar.xz |
(svn r26873) -Change: split type_height into a type and height array (ic111)
Diffstat (limited to 'src')
-rw-r--r-- | src/map_type.h | 3 | ||||
-rw-r--r-- | src/misc_gui.cpp | 17 | ||||
-rw-r--r-- | src/saveload/afterload.cpp | 7 | ||||
-rw-r--r-- | src/saveload/map_sl.cpp | 28 | ||||
-rw-r--r-- | src/saveload/oldloader_sl.cpp | 2 | ||||
-rw-r--r-- | src/tile_map.h | 8 |
6 files changed, 49 insertions, 16 deletions
diff --git a/src/map_type.h b/src/map_type.h index 3add9e64a..fbfc88308 100644 --- a/src/map_type.h +++ b/src/map_type.h @@ -17,7 +17,8 @@ * Look at docs/landscape.html for the exact meaning of the members. */ struct Tile { - byte type_height; ///< The type (bits 4..7) and height of the northern corner + byte type; ///< The type (bits 4..7) + byte height; ///< The height of the northern corner. byte m1; ///< Primarily used for ownership information uint16 m2; ///< Primarily used for indices to towns, industries and stations byte m3; ///< General purpose diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 0dddb0f5e..1f0a0107e 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -122,14 +122,15 @@ public: # define LANDINFOD_LEVEL 1 #endif DEBUG(misc, LANDINFOD_LEVEL, "TILE: %#x (%i,%i)", tile, TileX(tile), TileY(tile)); - DEBUG(misc, LANDINFOD_LEVEL, "type_height = %#x", _m[tile].type_height); - DEBUG(misc, LANDINFOD_LEVEL, "m1 = %#x", _m[tile].m1); - DEBUG(misc, LANDINFOD_LEVEL, "m2 = %#x", _m[tile].m2); - DEBUG(misc, LANDINFOD_LEVEL, "m3 = %#x", _m[tile].m3); - DEBUG(misc, LANDINFOD_LEVEL, "m4 = %#x", _m[tile].m4); - DEBUG(misc, LANDINFOD_LEVEL, "m5 = %#x", _m[tile].m5); - DEBUG(misc, LANDINFOD_LEVEL, "m6 = %#x", _m[tile].m6); - DEBUG(misc, LANDINFOD_LEVEL, "m7 = %#x", _me[tile].m7); + DEBUG(misc, LANDINFOD_LEVEL, "type = %#x", _m[tile].type); + DEBUG(misc, LANDINFOD_LEVEL, "height = %#x", _m[tile].height); + DEBUG(misc, LANDINFOD_LEVEL, "m1 = %#x", _m[tile].m1); + DEBUG(misc, LANDINFOD_LEVEL, "m2 = %#x", _m[tile].m2); + DEBUG(misc, LANDINFOD_LEVEL, "m3 = %#x", _m[tile].m3); + DEBUG(misc, LANDINFOD_LEVEL, "m4 = %#x", _m[tile].m4); + DEBUG(misc, LANDINFOD_LEVEL, "m5 = %#x", _m[tile].m5); + DEBUG(misc, LANDINFOD_LEVEL, "m6 = %#x", _m[tile].m6); + DEBUG(misc, LANDINFOD_LEVEL, "m7 = %#x", _me[tile].m7); #undef LANDINFOD_LEVEL } 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); diff --git a/src/tile_map.h b/src/tile_map.h index af1cc32dc..345dc1d1e 100644 --- a/src/tile_map.h +++ b/src/tile_map.h @@ -31,7 +31,7 @@ static inline uint TileHeight(TileIndex tile) { assert(tile < MapSize()); - return GB(_m[tile].type_height, 0, 4); + return _m[tile].height; } uint TileHeightOutsideMap(int x, int y); @@ -50,7 +50,7 @@ static inline void SetTileHeight(TileIndex tile, uint height) { assert(tile < MapSize()); assert(height <= MAX_TILE_HEIGHT); - SB(_m[tile].type_height, 0, 4, height); + _m[tile].height = height; } /** @@ -76,7 +76,7 @@ static inline uint TilePixelHeight(TileIndex tile) static inline TileType GetTileType(TileIndex tile) { assert(tile < MapSize()); - return (TileType)GB(_m[tile].type_height, 4, 4); + return (TileType)GB(_m[tile].type, 4, 4); } /** @@ -115,7 +115,7 @@ static inline void SetTileType(TileIndex tile, TileType type) * edges of the map. If _settings_game.construction.freeform_edges is true, * the upper edges of the map are also VOID tiles. */ assert(IsInnerTile(tile) == (type != MP_VOID)); - SB(_m[tile].type_height, 4, 4, type); + SB(_m[tile].type, 4, 4, type); } /** |