(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
authortron
Mon, 03 Jan 2005 12:56:22 +0000
changeset 856 918759cedca8
parent 855 77d7ff319a94
child 857 cd1fdb44121d
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
While here replace one erroneous TILE_MAX_X with MapMaxY()
ai.h
ai_pathfinder.c
clear_cmd.c
industry_cmd.c
landscape.c
map.h
misc.c
smallmap_gui.c
station_cmd.c
ttd.c
tunnelbridge_cmd.c
unmovable_cmd.c
viewport.c
water_cmd.c
window.c
--- a/ai.h	Mon Jan 03 12:15:55 2005 +0000
+++ b/ai.h	Mon Jan 03 12:56:22 2005 +0000
@@ -227,7 +227,7 @@
 
 #define AI_NO_CARGO 0xFF // Means that there is no cargo defined yet (used for industry)
 #define AI_NEED_CARGO 0xFE // Used when the AI needs to find out a cargo for the route
-#define AI_STATION_RANGE TILE_XY(TILE_X_MAX, TILE_Y_MAX)
+#define AI_STATION_RANGE TILE_XY(MapMaxX(), MapMaxY())
 
 #define AI_PATHFINDER_NO_DIRECTION (byte)-1
 
--- a/ai_pathfinder.c	Mon Jan 03 12:15:55 2005 +0000
+++ b/ai_pathfinder.c	Mon Jan 03 12:56:22 2005 +0000
@@ -175,8 +175,8 @@
 
   	// Go through all surrounding tiles and check if they are within the limits
    	for (i=0;i<4;i++) {
-   		if (GET_TILE_X(_tiles_around[i] + current->path.node.tile) > 1 && GET_TILE_X(_tiles_around[i] + current->path.node.tile) < TILE_X_MAX - 1 &&
-       		GET_TILE_Y(_tiles_around[i] + current->path.node.tile) > 1 && GET_TILE_Y(_tiles_around[i] + current->path.node.tile) < TILE_Y_MAX - 1) {
+   		if (GET_TILE_X(_tiles_around[i] + current->path.node.tile) > 1 && GET_TILE_X(_tiles_around[i] + current->path.node.tile) < MapMaxX() - 1 &&
+       		GET_TILE_Y(_tiles_around[i] + current->path.node.tile) > 1 && GET_TILE_Y(_tiles_around[i] + current->path.node.tile) < MapMaxY() - 1) {
        		// We also directly test if the current tile can connect to this tile..
        		//  We do this simply by just building the tile!
 
--- a/clear_cmd.c	Mon Jan 03 12:15:55 2005 +0000
+++ b/clear_cmd.c	Mon Jan 03 12:56:22 2005 +0000
@@ -30,7 +30,7 @@
 	TileIndex *t;
 	int count;
 
-	if ((GET_TILE_X(tile) == TILE_X_MAX) || (GET_TILE_Y(tile) == TILE_Y_MAX))
+	if (GET_TILE_X(tile) == MapMaxX() || GET_TILE_Y(tile) == MapMaxY())
 		return -1;
 
 	t = ts->tile_table;
--- a/industry_cmd.c	Mon Jan 03 12:15:55 2005 +0000
+++ b/industry_cmd.c	Mon Jan 03 12:56:22 2005 +0000
@@ -1215,7 +1215,7 @@
 	int x = GET_TILE_X(tile);
 	int y = GET_TILE_Y(tile);
 
-	if ( x < 2 || y < 2 || x > TILE_X_MAX - 3 || y > TILE_Y_MAX - 3) {
+	if ( x < 2 || y < 2 || x > MapMaxX() - 3 || y > MapMaxY() - 3) {
 		_error_message = STR_0239_SITE_UNSUITABLE;
 		return false;
 	}
--- a/landscape.c	Mon Jan 03 12:15:55 2005 +0000
+++ b/landscape.c	Mon Jan 03 12:56:22 2005 +0000
@@ -45,13 +45,13 @@
 	uint a,b,c,d,min;
 	int r;
 
-	if (GET_TILE_X(tile) == TILE_X_MAX || GET_TILE_Y(tile) == TILE_Y_MAX) {
+	if (GET_TILE_X(tile) == MapMaxX() || GET_TILE_Y(tile) == MapMaxY()) {
 		if (h)
 			*h = 0;
 		return 0;
 	}
 
-	assert(tile < TILES_X * TILES_Y && GET_TILE_X(tile) != TILE_X_MAX && GET_TILE_Y(tile) != TILE_Y_MAX);
+	assert(tile < TILES_X * TILES_Y && 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;
@@ -82,8 +82,7 @@
 
 void FindLandscapeHeightByTile(TileInfo *ti, uint tile)
 {
-	if (GET_TILE_X(tile) == TILE_X_MAX ||
-			GET_TILE_Y(tile) == TILE_Y_MAX) {
+	if (GET_TILE_X(tile) == MapMaxX() || GET_TILE_Y(tile) == MapMaxY()) {
 		ti->tileh = 0;
 		ti->type = MP_STRANGE;
 		ti->tile = 0;
@@ -107,7 +106,7 @@
 	ti->x = x;
 	ti->y = y;
 
-	if (x >= TILE_X_MAX*16-1 || y >= TILE_Y_MAX*16-1) {
+	if (x >= MapMaxX() * 16 - 1 || y >= MapMaxY() * 16 - 1) {
 		ti->tileh = 0;
 		ti->type = MP_STRANGE;
 		ti->tile = 0;
@@ -512,9 +511,9 @@
 			_map_owner[tile] = OWNER_WATER;
 		}
 		tile++;
-		if (GET_TILE_X(tile) == TILE_X_MAX) {
-			tile += TILE_XY(-TILE_X_MAX, 1);
-			if (GET_TILE_Y(tile) == TILE_Y_MAX)
+		if (GET_TILE_X(tile) == MapMaxX()) {
+			tile += TILE_XY(-MapMaxX(), 1);
+			if (GET_TILE_Y(tile) == MapMaxY())
 				break;
 		}
 	}
@@ -534,8 +533,8 @@
 	r = Random();
 	p = GetSpritePtr((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + 4845);
 
-	x = r & TILE_X_MAX;
-	y = (r >> TILE_X_BITS) & TILE_Y_MAX;
+	x = r & MapMaxX();
+	y = (r >> TILE_X_BITS) & MapMaxY();
 
 
 	if (x < 2 || y < 2)
@@ -567,10 +566,10 @@
 		}
 	}
 
-	if (x + w >= TILE_X_MAX-1)
+	if (x + w >= MapMaxX() - 1)
 		return;
 
-	if (y + h >= TILE_Y_MAX-1)
+	if (y + h >= MapMaxY() - 1)
 		return;
 
 	tile = &_map_type_and_height[TILE_XY(x,y)];
@@ -753,7 +752,7 @@
 	y = GET_TILE_Y(tile) + addy;
 
 	// Are we about to wrap?
-	if (x > 0 && x < TILE_X_MAX && y > 0 && y < TILE_Y_MAX)
+	if (x > 0 && x < MapMaxX() && y > 0 && y < MapMaxY())
 		return tile + TILE_XY(addx, addy);
 
 	return TILE_WRAPPED;
@@ -761,5 +760,5 @@
 
 bool IsValidTile(uint tile)
 {
-	return (tile < TILES_X * TILE_Y_MAX && GET_TILE_X(tile) != TILE_X_MAX);
+	return (tile < TILES_X * MapMaxY() && GET_TILE_X(tile) != MapMaxX());
 }
--- a/map.h	Mon Jan 03 12:15:55 2005 +0000
+++ b/map.h	Mon Jan 03 12:56:22 2005 +0000
@@ -7,9 +7,6 @@
 #define TILES_X (1 << TILE_X_BITS)
 #define TILES_Y (1 << TILE_Y_BITS)
 
-#define TILE_X_MAX (TILES_X - 1)
-#define TILE_Y_MAX (TILES_Y - 1)
-
 extern byte   _map_type_and_height[];
 extern byte   _map5[];
 extern byte   _map3_lo[];
--- a/misc.c	Mon Jan 03 12:15:55 2005 +0000
+++ b/misc.c	Mon Jan 03 12:56:22 2005 +0000
@@ -565,8 +565,8 @@
 
 bool CheckDistanceFromEdge(TileIndex tile, uint distance)
 {
-	return IS_INT_INSIDE(GET_TILE_X(tile), distance, TILE_X_MAX + 1 - distance) &&
-			IS_INT_INSIDE(GET_TILE_Y(tile), distance, TILE_Y_MAX + 1 - distance);
+	return IS_INT_INSIDE(GET_TILE_X(tile), distance, MapSizeX() - distance) &&
+			IS_INT_INSIDE(GET_TILE_Y(tile), distance, MapSizeY() - distance);
 }
 
 void OnNewDay_Train(Vehicle *v);
--- a/smallmap_gui.c	Mon Jan 03 12:15:55 2005 +0000
+++ b/smallmap_gui.c	Mon Jan 03 12:56:22 2005 +0000
@@ -356,7 +356,7 @@
 static void DrawSmallMapContours(byte *dst, uint xc, uint yc, int pitch, int reps, uint32 mask)
 {
 	do {
-		if (xc < TILE_X_MAX && yc < TILE_Y_MAX)
+		if (xc < MapMaxX() && yc < MapMaxY())
 		    if (dst > _screen.dst_ptr && dst < (_screen.dst_ptr + _screen.width * _screen.height - _screen.width) )
 		        WRITE_PIXELS_OR( dst, GetSmallMapCountoursPixels(TILE_XY(xc,yc)) & mask );
 	} while (xc++,yc++,dst+=pitch,--reps != 0);
@@ -386,7 +386,7 @@
 static void DrawSmallMapVehicles(byte *dst, uint xc, uint yc, int pitch, int reps, uint32 mask)
 {
 	do {
-		if (xc < TILE_X_MAX && yc < TILE_Y_MAX)
+		if (xc < MapMaxX() && yc < MapMaxY())
 			WRITE_PIXELS_OR( dst, GetSmallMapVehiclesPixels(TILE_XY(xc,yc)) & mask );
 	} while (xc++,yc++,dst+=pitch,--reps != 0);
 }
@@ -443,7 +443,7 @@
 static void DrawSmallMapIndustries(byte *dst, uint xc, uint yc, int pitch, int reps, uint32 mask)
 {
 	do {
-		if (xc < TILE_X_MAX && yc < TILE_Y_MAX)
+		if (xc < MapMaxX() && yc < MapMaxY())
 			WRITE_PIXELS_OR(dst, GetSmallMapIndustriesPixels(TILE_XY(xc,yc)) & mask);
 	} while (xc++,yc++,dst+=pitch,--reps != 0);
 }
@@ -484,7 +484,7 @@
 static void DrawSmallMapRoutes(byte *dst, uint xc, uint yc, int pitch, int reps, uint32 mask)
 {
 	do {
-		if (xc < TILE_X_MAX && yc < TILE_Y_MAX)
+		if (xc < MapMaxX() && yc < MapMaxY())
 			WRITE_PIXELS_OR(dst, GetSmallMapRoutesPixels(TILE_XY(xc,yc)) & mask);
 	} while (xc++,yc++,dst+=pitch,--reps != 0);
 }
@@ -542,7 +542,7 @@
 static void DrawSmallMapVegetation(byte *dst, uint xc, uint yc, int pitch, int reps, uint32 mask)
 {
 	do {
-		if (xc < TILE_X_MAX && yc < TILE_Y_MAX)
+		if (xc < MapMaxX() && yc < MapMaxY())
 			WRITE_PIXELS_OR(dst, GetSmallMapVegetationPixels(TILE_XY(xc,yc)) & mask);
 	} while (xc++,yc++,dst+=pitch,--reps != 0);
 }
@@ -570,7 +570,7 @@
 static void DrawSmallMapOwners(byte *dst, uint xc, uint yc, int pitch, int reps, uint32 mask)
 {
 	do {
-		if (xc < TILE_X_MAX && yc < TILE_Y_MAX)
+		if (xc < MapMaxX() && yc < MapMaxY())
 			WRITE_PIXELS_OR(dst, GetSmallMapOwnerPixels(TILE_XY(xc,yc)) & mask);
 	} while (xc++,yc++,dst+=pitch,--reps != 0);
 }
--- a/station_cmd.c	Mon Jan 03 12:15:55 2005 +0000
+++ b/station_cmd.c	Mon Jan 03 12:56:22 2005 +0000
@@ -414,10 +414,10 @@
 
 	// expand the region by 4 tiles on each side
 	// while making sure that we remain inside the board.
-	x2 = min(x + w + rad, TILE_X_MAX+1);
+	x2 = min(x + w + rad, MapSizeX());
 	x1 = max(x-rad, 0);
 
-	y2 = min(y + h + rad, TILE_Y_MAX+1);
+	y2 = min(y + h + rad, MapSizeY());
 	y1 = max(y-rad, 0);
 
 	assert(x1 < x2);
@@ -462,8 +462,8 @@
 
 	// expand the region by 4 tiles on each side
 	// while making sure that we remain inside the board.
-	x2 = min(x + w + rad, TILE_X_MAX+1);
-	y2 = min(y + h + rad, TILE_Y_MAX+1);
+	x2 = min(x + w + rad, MapSizeX());
+	y2 = min(y + h + rad, MapSizeY());
 	x1 = max(x-rad, 0);
 	y1 = max(y-rad, 0);
 
--- a/ttd.c	Mon Jan 03 12:15:55 2005 +0000
+++ b/ttd.c	Mon Jan 03 12:56:22 2005 +0000
@@ -1082,7 +1082,7 @@
 			ShowScreenshotResult(MakeScreenshot());
 			break;
 		case 2: // make large screenshot
-			ShowScreenshotResult(MakeWorldScreenshot(-(TILE_X_MAX)*32, 0, TILE_X_MAX*32 + (TILE_X_MAX)*32, TILES_Y * 32, 0));
+			ShowScreenshotResult(MakeWorldScreenshot(-MapMaxX() * 32, 0, MapMaxX() * 64, TILES_Y * 32, 0));
 			break;
 		}
 	}
--- a/tunnelbridge_cmd.c	Mon Jan 03 12:15:55 2005 +0000
+++ b/tunnelbridge_cmd.c	Mon Jan 03 12:56:22 2005 +0000
@@ -431,7 +431,7 @@
 	TileInfo ti;
 	uint z;
 
-	if ( (uint) x > TILE_X_MAX * 16 - 1 ||  (uint) y > TILE_X_MAX * 16 - 1)
+	if ((uint)x > MapMaxX() * 16 - 1 || (uint)y > MapMaxY() * 16 - 1)
 		return CMD_ERROR;
 
 	/* check if valid, and make sure that (x,y) is smaller than (x2,y2) */
--- a/unmovable_cmd.c	Mon Jan 03 12:15:55 2005 +0000
+++ b/unmovable_cmd.c	Mon Jan 03 12:56:22 2005 +0000
@@ -285,12 +285,12 @@
 restart:
 		r = Random();
 		dir = r >> 30;
-		r = r%((dir==0 || dir== 2)?TILE_Y_MAX:TILE_X_MAX);
+		r %= (dir == 0 || dir == 2) ? MapMaxY() : MapMaxX();
 		tile =
           (dir==0)?TILE_XY(0,r):0 +             // left
           (dir==1)?TILE_XY(r,0):0 +             // top
-          (dir==2)?TILE_XY(TILE_X_MAX,r):0 +    // right
-          (dir==3)?TILE_XY(r,TILE_Y_MAX):0;     // bottom
+			(dir == 2) ? TILE_XY(MapMaxX(), r) : 0 + // right
+			(dir == 3) ? TILE_XY(r, MapMaxY()) : 0;  // bottom
 		j = 20;
 		do {
 			if (--j == 0)
--- a/viewport.c	Mon Jan 03 12:15:55 2005 +0000
+++ b/viewport.c	Mon Jan 03 12:56:22 2005 +0000
@@ -295,7 +295,7 @@
 	pt.x = a+z;
 	pt.y = b+z;
 
-	if ((uint)pt.x >= TILE_X_MAX*16 || (uint)pt.y >= TILE_Y_MAX*16) {
+	if ((uint)pt.x >= MapMaxX() * 16 || (uint)pt.y >= MapMaxY() * 16) {
 		pt.x = pt.y = -1;
 	}
 
@@ -1289,8 +1289,8 @@
 		vx = -x + y * 2;
 		vy =  x + y * 2;
 		// clamp to size of map
-		vx = clamp(vx, 0 * 4, TILE_X_MAX * 16 * 4);
-		vy = clamp(vy, 0 * 4, TILE_Y_MAX * 16 * 4);
+		vx = clamp(vx, 0 * 4, MapMaxX() * 16 * 4);
+		vy = clamp(vy, 0 * 4, MapMaxY() * 16 * 4);
 		// Convert map coordinates to viewport coordinates
 		x = (-vx + vy) / 2;
 		y = ( vx + vy) / 4;
--- a/water_cmd.c	Mon Jan 03 12:15:55 2005 +0000
+++ b/water_cmd.c	Mon Jan 03 12:56:22 2005 +0000
@@ -265,8 +265,8 @@
 			return CMD_ERROR;
 
 		// Make sure it's not an edge tile.
-		if (!(IS_INT_INSIDE(GET_TILE_X(tile),1,TILE_X_MAX-1) &&
-				IS_INT_INSIDE(GET_TILE_Y(tile),1,TILE_Y_MAX-1)))
+		if (!(IS_INT_INSIDE(GET_TILE_X(tile), 1, MapMaxX() - 1) &&
+				IS_INT_INSIDE(GET_TILE_Y(tile), 1, MapMaxY() - 1)))
 			return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP);
 
 		if (m5 == 0) {
--- a/window.c	Mon Jan 03 12:15:55 2005 +0000
+++ b/window.c	Mon Jan 03 12:56:22 2005 +0000
@@ -1042,9 +1042,9 @@
 		hvx = hx * -4 + hy * 8;
 		hvy = hx *  4 + hy * 8;
 		if (x < -hvx) { x = -hvx; sub = 0; }
-		if (x > TILE_X_MAX * 16 - hvx)  { x = TILE_X_MAX * 16 - hvx; sub = 0; }
+		if (x > MapMaxX() * 16 - hvx) { x = MapMaxX() * 16 - hvx; sub = 0; }
 		if (y < -hvy) { y = -hvy; sub = 0; }
-		if (y > TILE_Y_MAX * 16 - hvy)  { y = TILE_Y_MAX * 16 - hvy; sub = 0; }
+		if (y > MapMaxY() * 16 - hvy) { y = MapMaxY() * 16 - hvy; sub = 0; }
 
 		WP(w,smallmap_d).scroll_x = x;
 		WP(w,smallmap_d).scroll_y = y;