(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
authortron
Mon, 03 Jan 2005 18:59:58 +0000
changeset 863 6a1444534f62
parent 862 9baf2b0cdb18
child 864 a3cf03daee32
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
clear_cmd.c
disaster_cmd.c
economy.c
landscape.c
map.c
map.h
misc.c
network.c
station_cmd.c
town_cmd.c
ttd.c
unmovable_cmd.c
viewport.c
water_cmd.c
--- a/clear_cmd.c	Mon Jan 03 18:49:45 2005 +0000
+++ b/clear_cmd.c	Mon Jan 03 18:59:58 2005 +0000
@@ -86,7 +86,7 @@
 	int r;
 	int32 ret;
 
-	assert(tile < TILES_X * TILES_Y);
+	assert(tile < MapSize());
 
 	if ((r=TerraformAllowTileProcess(ts, tile)) <= 0)
 		return r;
@@ -135,7 +135,7 @@
 	TerraformerHeightMod *mod;
 	int count;
 
-	assert(tile < TILES_X * TILES_Y);
+	assert(tile < MapSize());
 
 	if (height < 0) {
 		_error_message = STR_1003_ALREADY_AT_SEA_LEVEL;
--- a/disaster_cmd.c	Mon Jan 03 18:49:45 2005 +0000
+++ b/disaster_cmd.c	Mon Jan 03 18:59:58 2005 +0000
@@ -178,7 +178,7 @@
 					0);
 			}
 		}
-		if (v->y_pos >= (TILES_Y+9) * 16 - 1)
+		if (v->y_pos >= (MapSizeY() + 9) * 16 - 1)
 			DeleteDisasterVeh(v);
 		return;
 	}
@@ -325,7 +325,7 @@
 	uint tile;
 	byte index = i - _industries;
 
-	for(tile=0; tile != TILES_X*TILES_Y; tile++) {
+	for(tile=0; tile != MapSize(); tile++) {
 		if (IS_TILETYPE(tile, MP_INDUSTRY) &&	_map2[tile] == index) {
 			_map_owner[tile] = 0;
 			MarkTileDirtyByTile(tile);
@@ -388,7 +388,7 @@
 		x = v->x_pos - 15*16;
 		y = v->y_pos;
 
-		if ( (uint)x > (TILES_X-1) * 16-1)
+		if ( (uint)x > MapMaxX() * 16-1)
 			return;
 
 		tile = TILE_FROM_XY(x,y);
@@ -416,7 +416,7 @@
 	GetNewVehiclePos(v, &gp);
 	SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
 
-	if (gp.x > TILES_X * 16 + 9*16 - 1) {
+	if (gp.x > MapSizeX() * 16 + 9*16 - 1) {
 		DeleteDisasterVeh(v);
 		return;
 	}
@@ -459,7 +459,7 @@
 		x = v->x_pos - 15*16;
 		y = v->y_pos;
 
-		if ( (uint)x > (TILES_X-1) * 16-1)
+		if ( (uint)x > MapMaxX() * 16-1)
 			return;
 
 		tile = TILE_FROM_XY(x,y);
@@ -594,7 +594,7 @@
 	GetNewVehiclePos(v, &gp);
 	SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
 
-	if (gp.x > TILES_X * 16 + 9*16 - 1) {
+	if (gp.x > MapSizeX() * 16 + 9*16 - 1) {
 		DeleteDisasterVeh(v);
 		return;
 	}
@@ -737,7 +737,7 @@
 	x = (GET_TILE_X(Random())) * 16 + 8;
 
 	InitializeDisasterVehicle(v, x, 0, 135, 3, 2);
-	v->dest_tile = TILE_XY(TILES_X/2,TILES_Y/2);
+	v->dest_tile = TILE_XY(MapSizeX() / 2, MapSizeY() / 2);
 	v->age = 0;
 
 	// Allocate shadow too?
@@ -772,7 +772,7 @@
 	if (v == NULL)
 		return;
 
-	x = (TILES_X+9) * 16 - 1;
+	x = (MapSizeX() + 9) * 16 - 1;
 	y = GET_TILE_Y(found->xy)*16 + 37;
 
 	InitializeDisasterVehicle(v,x,y, 135,1,4);
@@ -837,9 +837,9 @@
 
 	x = (GET_TILE_X(Random())) * 16 + 8;
 
-	y = (TILES_X-1)*16-1;
+	y = MapMaxX() * 16 - 1;
 	InitializeDisasterVehicle(v, x, y, 135, 7, 9);
-	v->dest_tile = TILE_XY(TILES_X/2,TILES_Y/2);
+	v->dest_tile = TILE_XY(MapSizeX() / 2, MapSizeY() / 2);
 	v->age = 0;
 
 	// Allocate shadow too?
@@ -867,7 +867,7 @@
 
 	y = 8;
 	dir = 3;
-	if (r & 0x80000000) { y = (TILES_X-1) * 16 - 8 - 1; dir = 7; }
+	if (r & 0x80000000) { y = MapMaxX() * 16 - 8 - 1; dir = 7; }
 	InitializeDisasterVehicle(v, x, y, 0, dir,13);
 	v->age = 0;
 }
@@ -888,7 +888,7 @@
 
 	y = 8;
 	dir = 3;
-	if (r & 0x80000000) { y = (TILES_X-1) * 16 - 8 - 1;	dir = 7; }
+	if (r & 0x80000000) { y = MapMaxX() * 16 - 8 - 1; dir = 7; }
 	InitializeDisasterVehicle(v, x, y, 0, dir,14);
 	v->age = 0;
 }
--- a/economy.c	Mon Jan 03 18:49:45 2005 +0000
+++ b/economy.c	Mon Jan 03 18:59:58 2005 +0000
@@ -349,7 +349,7 @@
 		uint tile = 0;
 		do {
 			ChangeTileOwner(tile, old_player, new_player);
-		} while (++tile != TILES_X * TILES_Y);
+		} while (++tile != MapSize());
 	}
 
 	// Change color of existing windows
--- a/landscape.c	Mon Jan 03 18:49:45 2005 +0000
+++ b/landscape.c	Mon Jan 03 18:59:58 2005 +0000
@@ -51,7 +51,7 @@
 		return 0;
 	}
 
-	assert(tile < TILES_X * TILES_Y && GET_TILE_X(tile) != MapMaxX() && GET_TILE_Y(tile) != MapMaxY());
+	assert(tile < MapSize() && GET_TILE_X(tile) != MapMaxX() && GET_TILE_Y(tile) != MapMaxY());
 
 	min = a = _map_type_and_height[tile] & 0xF;
 	b = _map_type_and_height[tile+TILE_XY(1,0)] & 0xF;
@@ -463,21 +463,21 @@
 	tile = _cur_tileloop_tile;
 
 	assert( (tile & ~TILELOOP_ASSERTMASK) == 0);
-	count = (TILES_X/TILELOOP_SIZE) * (TILES_Y/TILELOOP_SIZE);
+	count = (MapSizeX() / TILELOOP_SIZE) * (MapSizeY() / TILELOOP_SIZE);
 	do {
 		_tile_type_procs[GET_TILETYPE(tile)]->tile_loop_proc(tile);
 
-		if ( GET_TILE_X(tile) < TILES_X - TILELOOP_SIZE) {
+		if ( GET_TILE_X(tile) < MapSizeX() - TILELOOP_SIZE) {
 			tile += TILELOOP_SIZE; /* no overflow */
 		} else {
-			tile = TILE_MASK(tile - TILELOOP_SIZE * (TILES_X/TILELOOP_SIZE-1) + TILE_XY(0, TILELOOP_SIZE)); /* x would overflow, also increase y */
+			tile = TILE_MASK(tile - TILELOOP_SIZE * (MapSizeX() / TILELOOP_SIZE-1) + TILE_XY(0, TILELOOP_SIZE)); /* x would overflow, also increase y */
 		}
 	} while (--count);
 	assert( (tile & ~TILELOOP_ASSERTMASK) == 0);
 
 	tile += 9;
 	if (tile & TILELOOP_CHKMASK)
-		tile = (tile + TILES_X) & TILELOOP_ASSERTMASK;
+		tile = (tile + MapSizeX()) & TILELOOP_ASSERTMASK;
 	_cur_tileloop_tile = tile;
 }
 
@@ -493,8 +493,8 @@
 	memset(_map_extra_bits, 0, map_size / 4);
 	memset(_map_type_and_height, MP_CLEAR << 4, map_size);
 
-	for(i=0; i!=TILES_Y-1; i++)
-		memset(_map_type_and_height + i*TILES_X, 0, TILES_X-1);
+	for (i = 0; i != MapMaxY(); i++)
+		memset(_map_type_and_height + i * MapSizeX(), 0,  MapSizeX() - 1);
 
 	memset(_map5, 3, map_size);
 }
@@ -643,7 +643,7 @@
 			}
 			mt = _map_type_and_height[TILE_MASK(tile + i)];
 		} while ((mt & 0xC) == 0 && (mt >> 4) != MP_WATER);
-	} while (++tile != TILES_X*TILES_Y);
+	} while (++tile != MapSize());
 
 	for(i=0; i!=256; i++)
 		RunTileLoop();
@@ -657,7 +657,7 @@
 				break;
 			}
 		} while ( !IS_TILETYPE(TILE_MASK(tile+i), MP_CLEAR) || (_map5[TILE_MASK(tile + i)]&0x1C) != 0x14);
-	} while (++tile != TILES_X*TILES_Y);
+	} while (++tile != MapSize());
 }
 
 void GenerateLandscape()
@@ -760,5 +760,5 @@
 
 bool IsValidTile(uint tile)
 {
-	return (tile < TILES_X * MapMaxY() && GET_TILE_X(tile) != MapMaxX());
+	return (tile < MapSizeX() * MapMaxY() && GET_TILE_X(tile) != MapMaxX());
 }
--- a/map.c	Mon Jan 03 18:49:45 2005 +0000
+++ b/map.c	Mon Jan 03 18:59:58 2005 +0000
@@ -5,10 +5,12 @@
 uint _map_log_x = TILE_X_BITS;
 uint _map_log_y = TILE_Y_BITS;
 
-byte   _map_type_and_height [TILES_X * TILES_Y];
-byte   _map5                [TILES_X * TILES_Y];
-byte   _map3_lo             [TILES_X * TILES_Y];
-byte   _map3_hi             [TILES_X * TILES_Y];
-byte   _map_owner           [TILES_X * TILES_Y];
-uint16 _map2                [TILES_X * TILES_Y];
-byte   _map_extra_bits      [TILES_X * TILES_Y / 4];
+#define MAP_SIZE ((1 << TILE_X_BITS) * (1 << TILE_Y_BITS))
+
+byte   _map_type_and_height [MAP_SIZE];
+byte   _map5                [MAP_SIZE];
+byte   _map3_lo             [MAP_SIZE];
+byte   _map3_hi             [MAP_SIZE];
+byte   _map_owner           [MAP_SIZE];
+uint16 _map2                [MAP_SIZE];
+byte   _map_extra_bits      [MAP_SIZE / 4];
--- a/map.h	Mon Jan 03 18:49:45 2005 +0000
+++ b/map.h	Mon Jan 03 18:59:58 2005 +0000
@@ -4,9 +4,6 @@
 #define TILE_X_BITS 8
 #define TILE_Y_BITS 8
 
-#define TILES_X (1 << TILE_X_BITS)
-#define TILES_Y (1 << TILE_Y_BITS)
-
 extern byte   _map_type_and_height[];
 extern byte   _map5[];
 extern byte   _map3_lo[];
--- a/misc.c	Mon Jan 03 18:49:45 2005 +0000
+++ b/misc.c	Mon Jan 03 18:59:58 2005 +0000
@@ -740,7 +740,7 @@
 	int x = GET_TILE_X(tile) + (signed char)(add & 0xFF);
 	int y = GET_TILE_Y(tile) + ((((0x8080 + add)>>8) & 0xFF) - 0x80);
 
-	if (x < 0 || y < 0 || x >= TILES_X || y >= TILES_Y) {
+	if (x < 0 || y < 0 || x >= MapSizeX() || y >= MapSizeY()) {
 		char buf[512];
 
 		sprintf(buf, "TILE_ADD(%s) when adding 0x%.4X and %d failed", exp, tile, add);
--- a/network.c	Mon Jan 03 18:49:45 2005 +0000
+++ b/network.c	Mon Jan 03 18:59:58 2005 +0000
@@ -936,8 +936,8 @@
 	_network_game_info.spectators_on = 0;
 	_network_game_info.game_date = _date;
 	_network_game_info.start_date = ConvertIntDate(_patches.starting_date);
-	_network_game_info.map_width = TILES_X;
-	_network_game_info.map_height = TILES_Y;
+	_network_game_info.map_width = MapSizeX();
+	_network_game_info.map_height = MapSizeY();
 	_network_game_info.map_set = _opt.landscape;
 
 	if (_network_game_info.server_password[0] == '\0') {
--- a/station_cmd.c	Mon Jan 03 18:49:45 2005 +0000
+++ b/station_cmd.c	Mon Jan 03 18:59:58 2005 +0000
@@ -113,7 +113,7 @@
 	uint y2 = y1 + h - 1;
 	uint t;
 
-	for(i=0; i!=TILES_X*TILES_Y; i++) {
+	for (i = 0; i != MapSize(); i++) {
 		if (IS_TILETYPE(i, MP_STATION) && _map2[i] == station_index) {
 			t = GET_TILE_X(i);
 			if (t < x1) x1 = t;
--- a/town_cmd.c	Mon Jan 03 18:49:45 2005 +0000
+++ b/town_cmd.c	Mon Jan 03 18:59:58 2005 +0000
@@ -1410,7 +1410,7 @@
 				DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 			}
 		}
-	} while (++tile != TILES_X * TILES_Y);
+	} while (++tile != MapSize());
 
 	t->xy = 0;
 	DeleteName(t->townnametype);
--- a/ttd.c	Mon Jan 03 18:49:45 2005 +0000
+++ b/ttd.c	Mon Jan 03 18:59:58 2005 +0000
@@ -1082,7 +1082,7 @@
 			ShowScreenshotResult(MakeScreenshot());
 			break;
 		case 2: // make large screenshot
-			ShowScreenshotResult(MakeWorldScreenshot(-(int)MapMaxX() * 32, 0, MapMaxX() * 64, TILES_Y * 32, 0));
+			ShowScreenshotResult(MakeWorldScreenshot(-(int)MapMaxX() * 32, 0, MapMaxX() * 64, MapSizeY() * 32, 0));
 			break;
 		}
 	}
@@ -1150,7 +1150,7 @@
 {
 	uint tile;
 
-	for(tile=0; tile!=TILES_X * TILES_Y; tile++) {
+	for (tile = 0; tile != MapSize(); tile++) {
 		if (IS_TILETYPE(tile, MP_STREET)) {
 			if ((_map5[tile] & 0xF0) == 0x10 && _map3_lo[tile] & 0x80)
 				_map3_lo[tile] = OWNER_TOWN;
--- a/unmovable_cmd.c	Mon Jan 03 18:49:45 2005 +0000
+++ b/unmovable_cmd.c	Mon Jan 03 18:59:58 2005 +0000
@@ -262,7 +262,7 @@
 	j = 40; // limit of 40 radio towers per world.
 	do {
 		r = Random();
-		tile = r % (TILES_X*TILES_Y);
+		tile = r % MapSize();
 //		TILE_MASK seems to be not working correctly. Radio masts accumulate in one area.
 //		tile = TILE_MASK(r);
 		if (IS_TILETYPE(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h >= 32) {
--- a/viewport.c	Mon Jan 03 18:49:45 2005 +0000
+++ b/viewport.c	Mon Jan 03 18:59:58 2005 +0000
@@ -1376,7 +1376,8 @@
 {
 	int z = 0;
 	Point pt;
-	if (IS_INT_INSIDE(x, 0, TILES_X*16) && IS_INT_INSIDE(y, 0, TILES_Y*16))
+	if (IS_INT_INSIDE(x, 0, MapSizeX() * 16) &&
+			IS_INT_INSIDE(y, 0, MapSizeY() * 16))
 		z = GetTileZ(TILE_FROM_XY(x,y));
 	pt = RemapCoords(x, y, z);
 
--- a/water_cmd.c	Mon Jan 03 18:49:45 2005 +0000
+++ b/water_cmd.c	Mon Jan 03 18:59:58 2005 +0000
@@ -579,8 +579,8 @@
 		{TILE_XY(0,-1), TILE_XY(0,0), TILE_XY(1,0), TILE_XY(0,-1), TILE_XY(1,-1)},
 	};
 
-	if ( IS_INT_INSIDE(GET_TILE_X(tile),1,TILES_X-3+1) &&
-	     IS_INT_INSIDE(GET_TILE_Y(tile),1,TILES_Y-3+1)) {
+	if (IS_INT_INSIDE(GET_TILE_X(tile), 1, MapSizeX() - 3 + 1) &&
+			IS_INT_INSIDE(GET_TILE_Y(tile), 1, MapSizeY() - 3 + 1)) {
 		for(i=0; i!=4; i++)
 			TileLoopWaterHelper(tile, _tile_loop_offs_array[i]);
 	}
@@ -589,16 +589,16 @@
 	_current_player = OWNER_NONE;
 
 	// edges
-	if ( GET_TILE_X(tile)==0 && IS_INT_INSIDE(GET_TILE_Y(tile),1,TILES_Y-3+1)) //NE
+	if (GET_TILE_X(tile) == 0 && IS_INT_INSIDE(GET_TILE_Y(tile), 1, MapSizeY() - 3 + 1)) //NE
 		TileLoopWaterHelper(tile, _tile_loop_offs_array[2]);
 
-	if ( GET_TILE_X(tile)==(TILES_X-2) && IS_INT_INSIDE(GET_TILE_Y(tile),1,TILES_Y-3+1)) //SW
+	if (GET_TILE_X(tile) == (MapSizeX() - 2) && IS_INT_INSIDE(GET_TILE_Y(tile), 1, MapSizeY() - 3 + 1)) //SW
 		TileLoopWaterHelper(tile, _tile_loop_offs_array[0]);
 
-	if ( GET_TILE_Y(tile)==0 && IS_INT_INSIDE(GET_TILE_X(tile),1,TILES_X-3+1)) //NW
+	if (GET_TILE_Y(tile) == 0 && IS_INT_INSIDE(GET_TILE_X(tile), 1, MapSizeX() - 3 + 1)) //NW
 		TileLoopWaterHelper(tile, _tile_loop_offs_array[1]);
 
-	if ( GET_TILE_Y(tile)==(TILES_Y-2) && IS_INT_INSIDE(GET_TILE_X(tile),1,TILES_X-3+1)) //SE
+	if (GET_TILE_Y(tile) == (MapSizeY() - 2) && IS_INT_INSIDE(GET_TILE_X(tile), 1, MapSizeX() - 3 + 1)) //SE
 		TileLoopWaterHelper(tile, _tile_loop_offs_array[3]);
 
 }