diff options
-rw-r--r-- | landscape.c | 15 | ||||
-rw-r--r-- | map.h | 14 | ||||
-rw-r--r-- | misc.c | 14 | ||||
-rw-r--r-- | oldloader.c | 20 |
4 files changed, 34 insertions, 29 deletions
diff --git a/landscape.c b/landscape.c index 78da7197f..28fca9648 100644 --- a/landscape.c +++ b/landscape.c @@ -480,19 +480,20 @@ void RunTileLoop() void InitializeLandscape() { + uint map_size = MapSize(); int i; - memset(_map_owner, OWNER_NONE, sizeof(_map_owner)); - memset(_map2, 0, sizeof(_map2)); - memset(_map3_lo, 0, sizeof(_map3_lo)); - memset(_map3_hi, 0, sizeof(_map3_hi)); - memset(_map_extra_bits, 0, sizeof(_map_extra_bits)); - memset(_map_type_and_height, MP_WATER << 4, sizeof(_map_type_and_height)); + memset(_map_owner, OWNER_NONE, map_size); + memset(_map2, 0, map_size); + memset(_map3_lo, 0, map_size); + memset(_map3_hi, 0, map_size); + memset(_map_extra_bits, 0, map_size / 4); + memset(_map_type_and_height, MP_WATER << 4, map_size); for(i=0; i!=TILES_Y-1; i++) memset(_map_type_and_height + i*TILES_X, 0, TILES_X-1); - memset(_map5, 3, sizeof(_map5)); + memset(_map5, 3, map_size); } void ConvertGroundTilesIntoWaterTiles() @@ -10,13 +10,13 @@ #define TILE_X_MAX (TILES_X - 1) #define TILE_Y_MAX (TILES_Y - 1) -extern byte _map_type_and_height[TILES_X * TILES_Y]; -extern byte _map5[TILES_X * TILES_Y]; -extern byte _map3_lo[TILES_X * TILES_Y]; -extern byte _map3_hi[TILES_X * TILES_Y]; -extern byte _map_owner[TILES_X * TILES_Y]; -extern byte _map2[TILES_X * TILES_Y]; -extern byte _map_extra_bits[TILES_X * TILES_Y / 4]; +extern byte _map_type_and_height[]; +extern byte _map5[]; +extern byte _map3_lo[]; +extern byte _map3_hi[]; +extern byte _map_owner[]; +extern byte _map2[]; +extern byte _map_extra_bits[]; // binary logarithm of the map size, try to avoid using this one static inline uint MapLogX(void) { extern uint _map_log_x; return _map_log_x; } @@ -826,31 +826,31 @@ static void SaveLoad_VIEW() } static void SaveLoad_MAPT() { - SlArray(_map_type_and_height, lengthof(_map_type_and_height), SLE_UINT8); + SlArray(_map_type_and_height, MapSize(), SLE_UINT8); } static void SaveLoad_MAP2() { - SlArray(_map2, lengthof(_map2), SLE_UINT8); + SlArray(_map2, MapSize(), SLE_UINT8); } static void SaveLoad_M3LO() { - SlArray(_map3_lo, lengthof(_map3_lo), SLE_UINT8); + SlArray(_map3_lo, MapSize(), SLE_UINT8); } static void SaveLoad_M3HI() { - SlArray(_map3_hi, lengthof(_map3_hi), SLE_UINT8); + SlArray(_map3_hi, MapSize(), SLE_UINT8); } static void SaveLoad_MAPO() { - SlArray(_map_owner, lengthof(_map_owner), SLE_UINT8); + SlArray(_map_owner, MapSize(), SLE_UINT8); } static void SaveLoad_MAP5() { - SlArray(_map5, lengthof(_map5), SLE_UINT8); + SlArray(_map5, MapSize(), SLE_UINT8); } static void SaveLoad_MAPE() { - SlArray(_map_extra_bits, lengthof(_map_extra_bits), SLE_UINT8); + SlArray(_map_extra_bits, MapSize() / 4, SLE_UINT8); } diff --git a/oldloader.c b/oldloader.c index d09ddf20a..9267caf9e 100644 --- a/oldloader.c +++ b/oldloader.c @@ -1356,6 +1356,7 @@ bool LoadOldSaveGame(const char *file) { LoadSavegameState lss; OldMain *m; + uint map_size; int i; _cur_state = &lss; @@ -1380,18 +1381,20 @@ bool LoadOldSaveGame(const char *file) #endif // copy sections of it to our datastructures. - memcpy(_map_owner, m->map_owner, sizeof(_map_owner)); - memcpy(_map2, m->map2, sizeof(_map2)); - memcpy(_map_type_and_height, m->map_type_and_height, sizeof(_map_type_and_height)); - memcpy(_map5, m->map5, sizeof(_map5)); - for(i=0; i!=256*256; i++) { + fprintf(stderr, "moo\n"); + map_size = MapSize(); + memcpy(_map_owner, m->map_owner, map_size); + memcpy(_map2, m->map2, map_size); + memcpy(_map_type_and_height, m->map_type_and_height, map_size); + memcpy(_map5, m->map5, map_size); + for (i = 0; i != map_size; i++) { _map3_lo[i] = m->map3[i] & 0xFF; _map3_hi[i] = m->map3[i] >> 8; } - memcpy(_map_extra_bits, m->map_extra, sizeof(_map_extra_bits)); + memcpy(_map_extra_bits, m->map_extra, map_size / 4); // go through the tables and see if we can find any ttdpatch presignals. Then convert those to our format. - for(i=0; i!=256*256; i++) { + for (i = 0; i != map_size; i++) { if (IS_TILETYPE(i, MP_RAILWAY) && (_map5[i] & 0xC0) == 0x40) { // this byte is always zero in real ttd. if (_map3_hi[i]) { @@ -1456,7 +1459,8 @@ bool LoadOldSaveGame(const char *file) _economy.infl_amount = m->inflation_amount; _economy.infl_amount_pr = m->inflation_amount_payment_rates; - memcpy(_animated_tile_list, m->animated_tile_list, sizeof(m->animated_tile_list)); + for (i = 0; i != lengthof(m->animated_tile_list); ++i) + _animated_tile_list[i] = m->animated_tile_list[i]; memcpy(_engine_name_strings, m->engine_name_strings, sizeof(m->engine_name_strings)); for(i=0; i!=lengthof(m->prices); i++) { |