(svn r26873) -Change: split type_height into a type and height array (ic111)

This commit is contained in:
rubidium 2014-09-21 11:14:58 +00:00
parent 51a1c712f2
commit 04e2324b8f
6 changed files with 49 additions and 16 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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();

View File

@ -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 },

View File

@ -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);

View File

@ -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);
}
/**