(svn r1144) Don't rely on sizeof() to determine the map size, use MapSize() instead
authortron
Fri, 17 Dec 2004 09:01:24 +0000
changeset 695 5f5be150296f
parent 694 f73bc36814b9
child 696 07448fc0e1a2
(svn r1144) Don't rely on sizeof() to determine the map size, use MapSize() instead
landscape.c
map.h
misc.c
oldloader.c
--- a/landscape.c	Fri Dec 17 04:42:55 2004 +0000
+++ b/landscape.c	Fri Dec 17 09:01:24 2004 +0000
@@ -480,19 +480,20 @@
 
 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()
--- a/map.h	Fri Dec 17 04:42:55 2004 +0000
+++ b/map.h	Fri Dec 17 09:01:24 2004 +0000
@@ -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; }
--- a/misc.c	Fri Dec 17 04:42:55 2004 +0000
+++ b/misc.c	Fri Dec 17 09:01:24 2004 +0000
@@ -826,31 +826,31 @@
 }
 
 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);
 }
 
 
--- a/oldloader.c	Fri Dec 17 04:42:55 2004 +0000
+++ b/oldloader.c	Fri Dec 17 09:01:24 2004 +0000
@@ -1356,6 +1356,7 @@
 {
 	LoadSavegameState lss;
 	OldMain *m;
+	uint map_size;
 	int i;
 
 	_cur_state = &lss;
@@ -1380,18 +1381,20 @@
 	#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 @@
 	_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++) {