summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-01-03 12:56:22 +0000
committertron <tron@openttd.org>2005-01-03 12:56:22 +0000
commit32bfe0dddde81d016cb8de15e6a41bca3506d7be (patch)
tree04b3f2dd580a9cd8387358c91a0cfcf95a525153
parent4c14afba4eae4bbfe3d448eeaa072e11b326c78a (diff)
downloadopenttd-32bfe0dddde81d016cb8de15e6a41bca3506d7be.tar.xz
(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()
-rw-r--r--ai.h2
-rw-r--r--ai_pathfinder.c4
-rw-r--r--clear_cmd.c2
-rw-r--r--industry_cmd.c2
-rw-r--r--landscape.c27
-rw-r--r--map.h3
-rw-r--r--misc.c4
-rw-r--r--smallmap_gui.c12
-rw-r--r--station_cmd.c8
-rw-r--r--ttd.c2
-rw-r--r--tunnelbridge_cmd.c2
-rw-r--r--unmovable_cmd.c6
-rw-r--r--viewport.c6
-rw-r--r--water_cmd.c4
-rw-r--r--window.c4
15 files changed, 42 insertions, 46 deletions
diff --git a/ai.h b/ai.h
index d1777d622..2554c1cfc 100644
--- a/ai.h
+++ b/ai.h
@@ -227,7 +227,7 @@ enum {
#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
diff --git a/ai_pathfinder.c b/ai_pathfinder.c
index abde1e772..2fd8f574b 100644
--- a/ai_pathfinder.c
+++ b/ai_pathfinder.c
@@ -175,8 +175,8 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
// 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!
diff --git a/clear_cmd.c b/clear_cmd.c
index a6d062839..c97d6d9a3 100644
--- a/clear_cmd.c
+++ b/clear_cmd.c
@@ -30,7 +30,7 @@ static int TerraformAllowTileProcess(TerraformerState *ts, TileIndex tile)
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;
diff --git a/industry_cmd.c b/industry_cmd.c
index 236a34744..707f7c66b 100644
--- a/industry_cmd.c
+++ b/industry_cmd.c
@@ -1215,7 +1215,7 @@ static bool CheckSuitableIndustryPos(uint tile)
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;
}
diff --git a/landscape.c b/landscape.c
index 67806fad8..b99ff6066 100644
--- a/landscape.c
+++ b/landscape.c
@@ -45,13 +45,13 @@ uint GetTileSlope(uint tile, int *h)
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 @@ int GetTileZ(uint tile)
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 @@ void FindLandscapeHeight(TileInfo *ti, uint x, uint y)
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 @@ void ConvertGroundTilesIntoWaterTiles()
_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 @@ static void GenerateTerrain(int type, int flag)
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 @@ static void GenerateTerrain(int type, int flag)
}
}
- 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 @@ uint TileAddWrap(TileIndex tile, int addx, int addy)
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 @@ uint TileAddWrap(TileIndex tile, int addx, int addy)
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());
}
diff --git a/map.h b/map.h
index 4d2e66413..f18aa11c3 100644
--- a/map.h
+++ b/map.h
@@ -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[];
diff --git a/misc.c b/misc.c
index 4a9789ede..b9f8e0dcf 100644
--- a/misc.c
+++ b/misc.c
@@ -565,8 +565,8 @@ uint GetTileDistAdv(TileIndex xy1, TileIndex xy2)
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);
diff --git a/smallmap_gui.c b/smallmap_gui.c
index 880ff40d4..3e0e8f44c 100644
--- a/smallmap_gui.c
+++ b/smallmap_gui.c
@@ -356,7 +356,7 @@ static inline uint32 GetSmallMapCountoursPixels(uint tile)
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 inline uint32 GetSmallMapVehiclesPixels(uint tile)
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 inline uint32 GetSmallMapIndustriesPixels(uint tile)
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 inline uint32 GetSmallMapRoutesPixels(uint tile)
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 inline uint32 GetSmallMapVegetationPixels(uint tile)
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 inline uint32 GetSmallMapOwnerPixels(uint tile)
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);
}
diff --git a/station_cmd.c b/station_cmd.c
index c1f543814..88d4e47f0 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -414,10 +414,10 @@ void GetProductionAroundTiles(uint *produced, uint tile, int w, int h, int rad)
// 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 @@ void GetAcceptanceAroundTiles(uint *accepts, uint tile, int w, int h, int rad)
// 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);
diff --git a/ttd.c b/ttd.c
index 4352d1d43..5aa13aff0 100644
--- a/ttd.c
+++ b/ttd.c
@@ -1082,7 +1082,7 @@ void GameLoop()
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;
}
}
diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c
index f301d7be7..53dc96c9f 100644
--- a/tunnelbridge_cmd.c
+++ b/tunnelbridge_cmd.c
@@ -431,7 +431,7 @@ static int32 DoBuildTunnel(int x, int y, int x2, int y2, uint32 flags, uint exc_
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) */
diff --git a/unmovable_cmd.c b/unmovable_cmd.c
index 277086a9c..137f66461 100644
--- a/unmovable_cmd.c
+++ b/unmovable_cmd.c
@@ -285,12 +285,12 @@ void GenerateUnmovables()
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)
diff --git a/viewport.c b/viewport.c
index b6bb6ba03..5b1712b2c 100644
--- a/viewport.c
+++ b/viewport.c
@@ -295,7 +295,7 @@ Point TranslateXYToTileCoord(ViewPort *vp, int x, int y) {
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 @@ void UpdateViewportPosition(Window *w)
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;
diff --git a/water_cmd.c b/water_cmd.c
index 9201a374f..9815e3a6f 100644
--- a/water_cmd.c
+++ b/water_cmd.c
@@ -265,8 +265,8 @@ static int32 ClearTile_Water(uint tile, byte flags) {
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) {
diff --git a/window.c b/window.c
index 4474b8604..7e98e8470 100644
--- a/window.c
+++ b/window.c
@@ -1042,9 +1042,9 @@ stop_capt:;
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;