(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()
This commit is contained in:
tron 2005-01-03 12:56:22 +00:00
parent 4c14afba4e
commit 32bfe0dddd
15 changed files with 42 additions and 46 deletions

2
ai.h
View File

@ -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

View File

@ -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!

View File

@ -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;

View File

@ -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;
}

View File

@ -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());
}

3
map.h
View File

@ -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[];

4
misc.c
View File

@ -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);

View File

@ -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);
}

View File

@ -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);

2
ttd.c
View File

@ -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;
}
}

View File

@ -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) */

View File

@ -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)

View File

@ -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;

View File

@ -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) {

View File

@ -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;