summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-01-07 17:02:43 +0000
committertron <tron@openttd.org>2005-01-07 17:02:43 +0000
commit7ca6b2b8b0d6f66966fa2ff01e3e9961314dfcc4 (patch)
treee4137b60a824b45ce09f668d58520e36dba10256
parentf5c33e50733c46cee14e84ade6da0c171d96064b (diff)
downloadopenttd-7ca6b2b8b0d6f66966fa2ff01e3e9961314dfcc4.tar.xz
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
-rw-r--r--ai.c10
-rw-r--r--ai_new.c4
-rw-r--r--ai_pathfinder.c18
-rw-r--r--ai_shared.c30
-rw-r--r--aircraft_cmd.c8
-rw-r--r--aystar.c3
-rw-r--r--bridge_gui.c3
-rw-r--r--clear_cmd.c6
-rw-r--r--command.c6
-rw-r--r--disaster_cmd.c36
-rw-r--r--industry_cmd.c16
-rw-r--r--landscape.c30
-rw-r--r--macros.h14
-rw-r--r--main_gui.c7
-rw-r--r--map.h16
-rw-r--r--misc.c24
-rw-r--r--misc_gui.c6
-rw-r--r--pathfind.c6
-rw-r--r--pathfind.h2
-rw-r--r--rail_cmd.c8
-rw-r--r--rail_gui.c8
-rw-r--r--road_cmd.c4
-rw-r--r--roadveh_cmd.c16
-rw-r--r--ship_cmd.c13
-rw-r--r--smallmap_gui.c4
-rw-r--r--sound.c4
-rw-r--r--station_cmd.c38
-rw-r--r--town_cmd.c2
-rw-r--r--train_cmd.c8
-rw-r--r--tree_cmd.c4
-rw-r--r--tunnelbridge_cmd.c12
-rw-r--r--unmovable_cmd.c6
-rw-r--r--vehicle.c12
-rw-r--r--viewport.c26
-rw-r--r--water_cmd.c18
35 files changed, 220 insertions, 208 deletions
diff --git a/ai.c b/ai.c
index 9ca11cc70..ac9172af0 100644
--- a/ai.c
+++ b/ai.c
@@ -622,17 +622,17 @@ static bool AiCheckIfRouteIsGood(Player *p, FoundRoute *fr, byte bitmask)
static byte AiGetDirectionBetweenTiles(TileIndex a, TileIndex b)
{
- byte i = (GET_TILE_X(a) < GET_TILE_X(b)) ? 1 : 0;
- if (GET_TILE_Y(a) >= GET_TILE_Y(b)) i ^= 3;
+ byte i = (TileX(a) < TileX(b)) ? 1 : 0;
+ if (TileY(a) >= TileY(b)) i ^= 3;
return i;
}
static TileIndex AiGetPctTileBetween(TileIndex a, TileIndex b, byte pct)
{
return TILE_XY(
- GET_TILE_X(a) + ((GET_TILE_X(b) - GET_TILE_X(a)) * pct >> 8),
- GET_TILE_Y(a) + ((GET_TILE_Y(b) - GET_TILE_Y(a)) * pct >> 8)
- );
+ TileX(a) + ((TileX(b) - TileX(a)) * pct >> 8),
+ TileY(a) + ((TileY(b) - TileY(a)) * pct >> 8)
+ );
}
static void AiWantLongIndustryRoute(Player *p)
diff --git a/ai_new.c b/ai_new.c
index 8a6dc0dd1..91219642e 100644
--- a/ai_new.c
+++ b/ai_new.c
@@ -606,8 +606,8 @@ static void AiNew_State_FindStation(Player *p) {
// where we get the most cargo and where it is buildable.
// TODO: also check for station of myself and make sure we are not
// taking eachothers passangers away (bad result when it does not)
- for (x = GET_TILE_X(tile) - AI_FINDSTATION_TILE_RANGE; x <= GET_TILE_X(tile) + AI_FINDSTATION_TILE_RANGE; x++) {
- for (y = GET_TILE_Y(tile) - AI_FINDSTATION_TILE_RANGE; y <= GET_TILE_Y(tile) + AI_FINDSTATION_TILE_RANGE; y++) {
+ for (x = TileX(tile) - AI_FINDSTATION_TILE_RANGE; x <= TileX(tile) + AI_FINDSTATION_TILE_RANGE; x++) {
+ for (y = TileY(tile) - AI_FINDSTATION_TILE_RANGE; y <= TileY(tile) + AI_FINDSTATION_TILE_RANGE; y++) {
new_tile = TILE_XY(x,y);
if (IS_TILETYPE(new_tile, MP_CLEAR) || IS_TILETYPE(new_tile, MP_TREES)) {
// This tile we can build on!
diff --git a/ai_pathfinder.c b/ai_pathfinder.c
index df97d1df5..d1bccb17d 100644
--- a/ai_pathfinder.c
+++ b/ai_pathfinder.c
@@ -28,7 +28,7 @@ bool TestCanBuildStationHere(uint tile, byte dir) {
}
// Checks if a tile 'a' is between the tiles 'b' and 'c'
-#define TILES_BETWEEN(a,b,c) (GET_TILE_X(a) >= GET_TILE_X(b) && GET_TILE_X(a) <= GET_TILE_X(c) && GET_TILE_Y(a) >= GET_TILE_Y(b) && GET_TILE_Y(a) <= GET_TILE_Y(c))
+#define TILES_BETWEEN(a, b, c) (TileX(a) >= TileX(b) && TileX(a) <= TileX(c) && TileY(a) >= TileY(b) && TileY(a) <= TileY(c))
// Check if the current tile is in our end-area
int32 AyStar_AiPathFinder_EndNodeCheck(AyStar *aystar, OpenListNode *current) {
@@ -46,7 +46,7 @@ int32 AyStar_AiPathFinder_EndNodeCheck(AyStar *aystar, OpenListNode *current) {
// Calculates the hash
// Currently it is a 10 bit hash, so the hash array has a max depth of 6 bits (so 64)
uint AiPathFinder_Hash(uint key1, uint key2) {
- return (GET_TILE_X(key1) & 0x1F) + ((GET_TILE_Y(key1) & 0x1F) << 5);
+ return (TileX(key1) & 0x1F) + ((TileY(key1) & 0x1F) << 5);
}
// Clear the memory of all the things
@@ -90,8 +90,8 @@ AyStar *new_AyStar_AiPathFinder(int max_tiles_around, Ai_PathFinderInfo *PathFin
start_node.node.user_data[0] = 0;
// Now we add all the starting tiles
- for (x=GET_TILE_X(PathFinderInfo->start_tile_tl);x<=GET_TILE_X(PathFinderInfo->start_tile_br);x++) {
- for (y=GET_TILE_Y(PathFinderInfo->start_tile_tl);y<=GET_TILE_Y(PathFinderInfo->start_tile_br);y++) {
+ for (x = TileX(PathFinderInfo->start_tile_tl); x <= TileX(PathFinderInfo->start_tile_br); x++) {
+ for (y = TileY(PathFinderInfo->start_tile_tl); y <= TileY(PathFinderInfo->start_tile_br); y++) {
start_node.node.tile = TILE_XY(x,y);
result->addstart(result, &start_node.node);
}
@@ -117,8 +117,8 @@ void clean_AyStar_AiPathFinder(AyStar *aystar, Ai_PathFinderInfo *PathFinderInfo
start_node.node.tile = PathFinderInfo->start_tile_tl;
// Now we add all the starting tiles
- for (x=GET_TILE_X(PathFinderInfo->start_tile_tl);x<=GET_TILE_X(PathFinderInfo->start_tile_br);x++) {
- for (y=GET_TILE_Y(PathFinderInfo->start_tile_tl);y<=GET_TILE_Y(PathFinderInfo->start_tile_br);y++) {
+ for (x = TileX(PathFinderInfo->start_tile_tl); x <= TileX(PathFinderInfo->start_tile_br); x++) {
+ for (y = TileY(PathFinderInfo->start_tile_tl); y <= TileY(PathFinderInfo->start_tile_br); y++) {
if (!(IS_TILETYPE(TILE_XY(x,y), MP_CLEAR) || IS_TILETYPE(TILE_XY(x,y), MP_TREES))) continue;
if (!TestCanBuildStationHere(TILE_XY(x,y),TEST_STATION_NO_DIR)) continue;
start_node.node.tile = TILE_XY(x,y);
@@ -175,8 +175,10 @@ 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(TileOffsByDir(i) + current->path.node.tile) > 1 && GET_TILE_X(TileOffsByDir(i) + current->path.node.tile) < MapMaxX() - 1 &&
- GET_TILE_Y(TileOffsByDir(i) + current->path.node.tile) > 1 && GET_TILE_Y(TileOffsByDir(i) + current->path.node.tile) < MapMaxY() - 1) {
+ if (TileX(TileOffsByDir(i) + current->path.node.tile) > 1 &&
+ TileX(TileOffsByDir(i) + current->path.node.tile) < MapMaxX() - 1 &&
+ TileY(TileOffsByDir(i) + current->path.node.tile) > 1 &&
+ TileY(TileOffsByDir(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/ai_shared.c b/ai_shared.c
index 9558c72bd..30dc3adcb 100644
--- a/ai_shared.c
+++ b/ai_shared.c
@@ -15,13 +15,13 @@ int AiNew_GetRailDirection(uint tile_a, uint tile_b, uint tile_c) {
int x1, x2, x3;
int y1, y2, y3;
- x1 = GET_TILE_X(tile_a);
- x2 = GET_TILE_X(tile_b);
- x3 = GET_TILE_X(tile_c);
+ x1 = TileX(tile_a);
+ x2 = TileX(tile_b);
+ x3 = TileX(tile_c);
- y1 = GET_TILE_Y(tile_a);
- y2 = GET_TILE_Y(tile_b);
- y3 = GET_TILE_Y(tile_c);
+ y1 = TileY(tile_a);
+ y2 = TileY(tile_b);
+ y3 = TileY(tile_c);
if (y1 == y2 && y2 == y3) return 0;
if (x1 == x2 && x2 == x3) return 1;
@@ -50,13 +50,13 @@ int AiNew_GetRoadDirection(uint tile_a, uint tile_b, uint tile_c) {
int y1, y2, y3;
int r;
- x1 = GET_TILE_X(tile_a);
- x2 = GET_TILE_X(tile_b);
- x3 = GET_TILE_X(tile_c);
+ x1 = TileX(tile_a);
+ x2 = TileX(tile_b);
+ x3 = TileX(tile_c);
- y1 = GET_TILE_Y(tile_a);
- y2 = GET_TILE_Y(tile_b);
- y3 = GET_TILE_Y(tile_c);
+ y1 = TileY(tile_a);
+ y2 = TileY(tile_b);
+ y3 = TileY(tile_c);
r = 0;
@@ -75,9 +75,9 @@ int AiNew_GetRoadDirection(uint tile_a, uint tile_b, uint tile_c) {
// Get's the direction between 2 tiles seen from tile_a
int AiNew_GetDirection(uint tile_a, uint tile_b) {
- if (GET_TILE_Y(tile_a) < GET_TILE_Y(tile_b)) return 1;
- if (GET_TILE_Y(tile_a) > GET_TILE_Y(tile_b)) return 3;
- if (GET_TILE_X(tile_a) < GET_TILE_X(tile_b)) return 2;
+ if (TileY(tile_a) < TileY(tile_b)) return 1;
+ if (TileY(tile_a) > TileY(tile_b)) return 3;
+ if (TileX(tile_a) < TileX(tile_b)) return 2;
return 0;
}
diff --git a/aircraft_cmd.c b/aircraft_cmd.c
index 7d52329d9..0009078ef 100644
--- a/aircraft_cmd.c
+++ b/aircraft_cmd.c
@@ -146,8 +146,8 @@ int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
v->tile = tile;
// u->tile = 0;
- x = GET_TILE_X(tile)*16 + 5;
- y = GET_TILE_Y(tile)*16 + 3;
+ x = TileX(tile) * 16 + 5;
+ y = TileY(tile) * 16 + 3;
v->x_pos = u->x_pos = x;
v->y_pos = u->y_pos = y;
@@ -739,8 +739,8 @@ static bool Aircraft_5(Vehicle *v)
uint tile = st->airport_tile;
if (tile == 0) tile = st->xy;
// xy of destination
- x = GET_TILE_X(tile)*16;
- y = GET_TILE_Y(tile)*16;
+ x = TileX(tile) * 16;
+ y = TileY(tile) * 16;
}
// get airport moving data
diff --git a/aystar.c b/aystar.c
index bb09656a8..92e79fee3 100644
--- a/aystar.c
+++ b/aystar.c
@@ -246,7 +246,8 @@ int AyStarMain_Main(AyStar *aystar) {
*/
void AyStarMain_AddStartNode(AyStar *aystar, AyStarNode *start_node) {
#ifdef AYSTAR_DEBUG
- printf("[AyStar] Starting A* Algorithm from node (%d, %d, %d)\n", GET_TILE_X(start_node->tile), GET_TILE_Y(start_node->tile), start_node->direction);
+ printf("[AyStar] Starting A* Algorithm from node (%d, %d, %d)\n",
+ TileX(start_node->tile), TileY(start_node->tile), start_node->direction);
#endif
AyStarMain_OpenList_Add(aystar, NULL, start_node, 0, 0, 0);
}
diff --git a/bridge_gui.c b/bridge_gui.c
index 3dda50732..881cb625a 100644
--- a/bridge_gui.c
+++ b/bridge_gui.c
@@ -161,6 +161,7 @@ void ShowBuildBridgeWindow(uint start, uint end, byte bridge_type)
w->vscroll.cap = 4;
w->vscroll.count = (byte)j;
} else {
- ShowErrorMessage(errmsg, STR_5015_CAN_T_BUILD_BRIDGE_HERE, GET_TILE_X(end) * 16, GET_TILE_Y(end) * 16);
+ ShowErrorMessage(errmsg, STR_5015_CAN_T_BUILD_BRIDGE_HERE,
+ TileX(end) * 16, TileY(end) * 16);
}
}
diff --git a/clear_cmd.c b/clear_cmd.c
index fd6b58bfd..40de46dad 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) == MapMaxX() || GET_TILE_Y(tile) == MapMaxY())
+ if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY())
return -1;
t = ts->tile_table;
@@ -343,8 +343,8 @@ int32 CmdLevelLand(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
ex >>= 4; ey >>= 4;
// make sure sx,sy are smaller than ex,ey
- sx = GET_TILE_X(p1);
- sy = GET_TILE_Y(p1);
+ sx = TileX(p1);
+ sy = TileY(p1);
if (ex < sx) intswap(ex, sx);
if (ey < sy) intswap(ey, sy);
tile = TILE_XY(sx,sy);
diff --git a/command.c b/command.c
index cf4ac7944..eff7af906 100644
--- a/command.c
+++ b/command.c
@@ -325,7 +325,7 @@ bool IsValidCommand(int cmd)
int32 DoCommandByTile(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
{
- return DoCommand(GET_TILE_X(tile)*16, GET_TILE_Y(tile)*16, p1, p2, flags, procc);
+ return DoCommand(TileX(tile) * 16, TileY(tile) * 16, p1, p2, flags, procc);
}
@@ -401,8 +401,8 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
uint32 flags;
bool notest;
- int x = GET_TILE_X(tile)*16;
- int y = GET_TILE_Y(tile)*16;
+ int x = TileX(tile) * 16;
+ int y = TileY(tile) * 16;
assert(_docommand_recursive == 0);
diff --git a/disaster_cmd.c b/disaster_cmd.c
index a00bedcf1..cac58ac03 100644
--- a/disaster_cmd.c
+++ b/disaster_cmd.c
@@ -253,8 +253,8 @@ static void DisasterTick_UFO(Vehicle *v)
if (v->current_order.station == 0) {
// fly around randomly
- int x = GET_TILE_X(v->dest_tile)*16;
- int y = GET_TILE_Y(v->dest_tile)*16;
+ int x = TileX(v->dest_tile) * 16;
+ int y = TileY(v->dest_tile) * 16;
if (abs(x - v->x_pos) + abs(y - v->y_pos) >= 16) {
v->direction = GetDirectionTowards(v, x, y);
GetNewVehiclePos(v, &gp);
@@ -352,8 +352,8 @@ static void DisasterTick_2(Vehicle *v)
if (v->current_order.station == 2) {
if (!(v->tick_counter&3)) {
Industry *i = GetIndustry(v->dest_tile);
- int x = GET_TILE_X(i->xy)*16;
- int y = GET_TILE_Y(i->xy)*16;
+ int x = TileX(i->xy) * 16;
+ int y = TileY(i->xy) * 16;
uint32 r = Random();
CreateEffectVehicleAbove(
@@ -423,8 +423,8 @@ static void DisasterTick_3(Vehicle *v)
if (v->current_order.station == 2) {
if (!(v->tick_counter&3)) {
Industry *i = GetIndustry(v->dest_tile);
- int x = GET_TILE_X(i->xy)*16;
- int y = GET_TILE_Y(i->xy)*16;
+ int x = TileX(i->xy) * 16;
+ int y = TileY(i->xy) * 16;
uint32 r = Random();
CreateEffectVehicleAbove(
@@ -501,8 +501,8 @@ static void DisasterTick_4(Vehicle *v)
v->tick_counter++;
if (v->current_order.station == 1) {
- int x = GET_TILE_X(v->dest_tile)*16 + 8;
- int y = GET_TILE_Y(v->dest_tile)*16 + 8;
+ int x = TileX(v->dest_tile) * 16 + 8;
+ int y = TileY(v->dest_tile) * 16 + 8;
if (abs(v->x_pos - x) + abs(v->y_pos - y) >= 8) {
v->direction = GetDirectionTowards(v, x, y);
@@ -553,8 +553,8 @@ static void DisasterTick_4(Vehicle *v)
w->vehstatus |= VS_DISASTER;
} else if (v->current_order.station < 1) {
- int x = GET_TILE_X(v->dest_tile)*16;
- int y = GET_TILE_Y(v->dest_tile)*16;
+ int x = TileX(v->dest_tile) * 16;
+ int y = TileY(v->dest_tile) * 16;
if (abs(x - v->x_pos) + abs(y - v->y_pos) >= 16) {
v->direction = GetDirectionTowards(v, x, y);
GetNewVehiclePos(v, &gp);
@@ -702,13 +702,13 @@ static void Disaster0_Init()
/* Pick a random place, unless we find
a small airport */
- x = (GET_TILE_X(Random())) * 16 + 8;
+ x = TileX(Random()) * 16 + 8;
FOR_ALL_STATIONS(st) {
if (st->xy && st->airport_tile != 0 &&
st->airport_type <= 1 &&
IS_HUMAN_PLAYER(st->owner)) {
- x = (GET_TILE_X(st->xy) + 2) * 16;
+ x = (TileX(st->xy) + 2) * 16;
break;
}
}
@@ -732,7 +732,7 @@ static void Disaster1_Init()
if (v == NULL)
return;
- x = (GET_TILE_X(Random())) * 16 + 8;
+ x = TileX(Random()) * 16 + 8;
InitializeDisasterVehicle(v, x, 0, 135, 3, 2);
v->dest_tile = TILE_XY(MapSizeX() / 2, MapSizeY() / 2);
@@ -771,7 +771,7 @@ static void Disaster2_Init()
return;
x = (MapSizeX() + 9) * 16 - 1;
- y = GET_TILE_Y(found->xy)*16 + 37;
+ y = TileY(found->xy) * 16 + 37;
InitializeDisasterVehicle(v,x,y, 135,1,4);
@@ -807,7 +807,7 @@ static void Disaster3_Init()
return;
x = -16 * 16;
- y = GET_TILE_Y(found->xy)*16 + 37;
+ y = TileY(found->xy) * 16 + 37;
InitializeDisasterVehicle(v,x,y, 135,5,6);
@@ -833,7 +833,7 @@ static void Disaster4_Init()
if (v == NULL)
return;
- x = (GET_TILE_X(Random())) * 16 + 8;
+ x = TileX(Random()) * 16 + 8;
y = MapMaxX() * 16 - 1;
InitializeDisasterVehicle(v, x, y, 135, 7, 9);
@@ -861,7 +861,7 @@ static void Disaster5_Init()
return;
r = Random();
- x = (GET_TILE_X(r)) * 16 + 8;
+ x = TileX(r) * 16 + 8;
y = 8;
dir = 3;
@@ -882,7 +882,7 @@ static void Disaster6_Init()
return;
r = Random();
- x = (GET_TILE_X(r)) * 16 + 8;
+ x = TileX(r) * 16 + 8;
y = 8;
dir = 3;
diff --git a/industry_cmd.c b/industry_cmd.c
index 5014daae5..498958bfc 100644
--- a/industry_cmd.c
+++ b/industry_cmd.c
@@ -628,7 +628,7 @@ static void AnimateTile_Industry(uint tile)
static void MakeIndustryTileBiggerCase8(uint tile)
{
TileInfo ti;
- FindLandscapeHeight(&ti, GET_TILE_X(tile)*16, GET_TILE_Y(tile)*16);
+ FindLandscapeHeight(&ti, TileX(tile) * 16, TileY(tile) * 16);
CreateEffectVehicle(ti.x + 15, ti.y + 14, ti.z + 59 + (ti.tileh != 0 ? 8 : 0), EV_INDUSTRYSMOKE);
}
@@ -692,8 +692,8 @@ static void TileLoopIndustryCase161(uint tile)
dir = Random() & 3;
v = CreateEffectVehicleAbove(
- GET_TILE_X(tile)*16 + _tileloop_ind_case_161[dir + 0],
- GET_TILE_Y(tile)*16 + _tileloop_ind_case_161[dir + 4],
+ TileX(tile) * 16 + _tileloop_ind_case_161[dir + 0],
+ TileY(tile) * 16 + _tileloop_ind_case_161[dir + 4],
_tileloop_ind_case_161[dir + 8],
EV_INDUSTRY_SMOKE
);
@@ -779,7 +779,7 @@ static void TileLoop_Industry(uint tile)
break;
case 49: {
- CreateEffectVehicleAbove(GET_TILE_X(tile)*16 + 6, GET_TILE_Y(tile)*16 + 6, 43, EV_SMOKE_3);
+ CreateEffectVehicleAbove(TileX(tile) * 16 + 6, TileY(tile) * 16 + 6, 43, EV_SMOKE_3);
} break;
@@ -1145,8 +1145,8 @@ static bool CheckNewIndustry_Oilwell(uint tile, int type)
if (type != IT_OIL_RIG && _game_mode == GM_EDITOR)
return true;
- x = GET_TILE_X(tile);
- y = GET_TILE_Y(tile);
+ x = TileX(tile);
+ y = TileY(tile);
if ( x < 15 || y < 15 || x > 238 || y > 238)
return true;
@@ -1217,8 +1217,8 @@ static CheckNewIndustryProc * const _check_new_industry_procs[] = {
static bool CheckSuitableIndustryPos(uint tile)
{
- uint x = GET_TILE_X(tile);
- uint y = GET_TILE_Y(tile);
+ uint x = TileX(tile);
+ uint y = TileY(tile);
if ( x < 2 || y < 2 || x > MapMaxX() - 3 || y > MapMaxY() - 3) {
_error_message = STR_0239_SITE_UNSUITABLE;
diff --git a/landscape.c b/landscape.c
index 0971713e8..016d45854 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) == MapMaxX() || GET_TILE_Y(tile) == MapMaxY()) {
+ if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) {
if (h)
*h = 0;
return 0;
}
- assert(tile < MapSize() && GET_TILE_X(tile) != MapMaxX() && GET_TILE_Y(tile) != MapMaxY());
+ assert(tile < MapSize() && TileX(tile) != MapMaxX() && TileY(tile) != MapMaxY());
min = a = _map_type_and_height[tile] & 0xF;
b = _map_type_and_height[tile+TILE_XY(1,0)] & 0xF;
@@ -82,7 +82,7 @@ int GetTileZ(uint tile)
void FindLandscapeHeightByTile(TileInfo *ti, uint tile)
{
- if (GET_TILE_X(tile) == MapMaxX() || GET_TILE_Y(tile) == MapMaxY()) {
+ if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) {
ti->tileh = 0;
ti->type = MP_VOID;
ti->tile = 0;
@@ -354,8 +354,8 @@ int32 CmdClearArea(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
// make sure sx,sy are smaller than ex,ey
- sx = GET_TILE_X(p1)*16;
- sy = GET_TILE_Y(p1)*16;
+ sx = TileX(p1) * 16;
+ sy = TileY(p1) * 16;
if (ex < sx) intswap(ex, sx);
if (ey < sy) intswap(ey, sy);
@@ -445,8 +445,8 @@ void SetMapExtraBits(uint tile, byte bits)
uint GetMapExtraBits(uint tile)
{
- if (GET_TILE_X(tile) < MapSizeX() && GET_TILE_Y(tile) < MapSizeY() &&
- GET_TILE_X(tile) > 0 && GET_TILE_Y(tile) > 0)
+ if (TileX(tile) < MapSizeX() && TileY(tile) < MapSizeY() &&
+ TileX(tile) > 0 && TileY(tile) > 0)
return (_map_extra_bits[tile >> 2] >> (tile&3)*2)&3;
else
return 0;
@@ -469,7 +469,7 @@ void RunTileLoop()
do {
_tile_type_procs[GET_TILETYPE(tile)]->tile_loop_proc(tile);
- if ( GET_TILE_X(tile) < MapSizeX() - TILELOOP_SIZE) {
+ if (TileX(tile) < MapSizeX() - TILELOOP_SIZE) {
tile += TILELOOP_SIZE; /* no overflow */
} else {
tile = TILE_MASK(tile - TILELOOP_SIZE * (MapSizeX() / TILELOOP_SIZE-1) + TILE_XY(0, TILELOOP_SIZE)); /* x would overflow, also increase y */
@@ -515,9 +515,9 @@ void ConvertGroundTilesIntoWaterTiles()
_map_owner[tile] = OWNER_WATER;
}
tile++;
- if (GET_TILE_X(tile) == MapMaxX()) {
+ if (TileX(tile) == MapMaxX()) {
tile += TILE_XY(-(int)MapMaxX(), 1);
- if (GET_TILE_Y(tile) == MapMaxY())
+ if (TileY(tile) == MapMaxY())
break;
}
}
@@ -735,8 +735,8 @@ TileIndex AdjustTileCoordRandomly(TileIndex a, byte rng)
uint32 r = Random();
return TILE_XY(
- GET_TILE_X(a) + ((byte)r * rn * 2 >> 8) - rn,
- GET_TILE_Y(a) + ((byte)(r>>8) * rn * 2 >> 8) - rn
+ TileX(a) + ((byte)r * rn * 2 >> 8) - rn,
+ TileY(a) + ((byte)(r >> 8) * rn * 2 >> 8) - rn
);
}
@@ -749,8 +749,8 @@ TileIndex AdjustTileCoordRandomly(TileIndex a, byte rng)
uint TileAddWrap(TileIndex tile, int addx, int addy)
{
uint x, y;
- x = GET_TILE_X(tile) + addx;
- y = GET_TILE_Y(tile) + addy;
+ x = TileX(tile) + addx;
+ y = TileY(tile) + addy;
// Are we about to wrap?
if (x < MapMaxX() && y < MapMaxY())
@@ -761,5 +761,5 @@ uint TileAddWrap(TileIndex tile, int addx, int addy)
bool IsValidTile(uint tile)
{
- return (tile < MapSizeX() * MapMaxY() && GET_TILE_X(tile) != MapMaxX());
+ return (tile < MapSizeX() * MapMaxY() && TileX(tile) != MapMaxX());
}
diff --git a/macros.h b/macros.h
index 24be9a911..d9577304d 100644
--- a/macros.h
+++ b/macros.h
@@ -1,6 +1,8 @@
#ifndef MACROS_H
#define MACROS_H
+#include "map.h"
+
#define MAX_INT 0x7FFFFFFF
#ifdef min
@@ -96,16 +98,6 @@ extern uint SafeTileAdd(uint x, int add, const char *exp, const char *file, int
#define TILE_ADDXY(tile, x, y) TILE_ADD(tile, TILE_XY(x,y))
-#if TILE_X_BITS == 8
-#define GET_TILE_X(t) (uint)((byte)(t))
-#define GET_TILE_Y(t) (uint)((t) >> 8)
-#define TILE_MASK(x) ((uint16)(x))
-#else
-#define GET_TILE_X(t) (uint)((t) & ((1 << TILE_X_BITS)-1))
-#define GET_TILE_Y(t) (uint)((t) >> TILE_X_BITS)
-#define TILE_MASK(x) (int)((x) & ((1 << (TILE_X_BITS + TILE_Y_BITS))-1))
-#endif
-
//#define REMADP_COORDS(x,y,z) { int t = x; x = (y-t)*2; y+=t-z; }
#define PACK_POINT(x,y) ((x) | ((y) << 16))
@@ -148,8 +140,6 @@ static inline int FindFirstBit2x64(int value)
}
-typedef uint16 TileIndex;
-
/* [min,max), strictly less than */
#define IS_BYTE_INSIDE(a,min,max) ((byte)((a)-(min)) < (byte)((max)-(min)))
#define IS_INT_INSIDE(a,min,max) ((uint)((a)-(min)) < (uint)((max)-(min)))
diff --git a/main_gui.c b/main_gui.c
index 91c7bcc48..2f21e7aef 100644
--- a/main_gui.c
+++ b/main_gui.c
@@ -381,7 +381,8 @@ void ShowRenameWaypointWindow(Waypoint *cp)
/* Are we allowed to change the name of the waypoint? */
if (!CheckTileOwnership(cp->xy)) {
- ShowErrorMessage(_error_message, STR_CANT_CHANGE_WAYPOINT_NAME, GET_TILE_X(cp->xy) * 16, GET_TILE_Y(cp->xy) * 16);
+ ShowErrorMessage(_error_message, STR_CANT_CHANGE_WAYPOINT_NAME,
+ TileX(cp->xy) * 16, TileY(cp->xy) * 16);
return;
}
@@ -1143,7 +1144,7 @@ static void CommonRaiseLowerBigLand(uint tile, int mode)
_generating_world = true;
-// tile = TILE_FROM_XY(GET_TILE_X(tile)*16+_tile_fract_coords.x + 8,GET_TILE_Y(tile)*16+_tile_fract_coords.y + 8);
+// tile = TILE_FROM_XY(TileX(tile) * 16 + _tile_fract_coords.x + 8, TileY(tile) * 16 + _tile_fract_coords.y + 8);
if (_terraform_size == 1) {
DoCommandP(tile, 8, (uint32)mode, CcTerraform, CMD_TERRAFORM_LAND | CMD_AUTO);
@@ -1190,7 +1191,7 @@ static void PlaceProc_LowerBigLand(uint tile)
//{
// if (success) {
//SndPlayTileFx(0x10, tile);
- //CreateEffectVehicleAbove(GET_TILE_X(tile)*16 + 8,GET_TILE_Y(tile)*16 + 8, 2, EV_DEMOLISH);
+ //CreateEffectVehicleAbove(TileX(tile) * 16 + 8, TileY(tile) * 16 + 8, 2, EV_DEMOLISH);
// }
//}
diff --git a/map.h b/map.h
index c234de5a8..f7bb61b70 100644
--- a/map.h
+++ b/map.h
@@ -4,6 +4,8 @@
#define TILE_X_BITS 8
#define TILE_Y_BITS 8
+#define TILE_MASK(x) (int)((x) & ((1 << (MapLogX() + MapLogY())) - 1))
+
extern byte _map_type_and_height[];
extern byte _map5[];
extern byte _map3_lo[];
@@ -24,6 +26,20 @@ static inline uint MapMaxY(void) { return MapSizeY() - 1; }
/* The number of tiles in the map */
static inline uint MapSize(void) { return MapSizeX() * MapSizeY(); }
+
+typedef uint16 TileIndex;
+
+static inline uint TileX(TileIndex tile)
+{
+ return tile & MapMaxX();
+}
+
+static inline uint TileY(TileIndex tile)
+{
+ return tile >> MapLogX();
+}
+
+
typedef int16 TileIndexDiff;
typedef struct TileIndexDiffC {
diff --git a/misc.c b/misc.c
index 00f8e5739..7a7b41d51 100644
--- a/misc.c
+++ b/misc.c
@@ -527,21 +527,21 @@ void InitializeLandscapeVariables(bool only_constants)
// distance in Manhattan metric
uint GetTileDist(TileIndex xy1, TileIndex xy2)
{
- return myabs(GET_TILE_X(xy1) - GET_TILE_X(xy2)) +
- myabs(GET_TILE_Y(xy1) - GET_TILE_Y(xy2));
+ return myabs(TileX(xy1) - TileX(xy2)) +
+ myabs(TileY(xy1) - TileY(xy2));
}
// maximum distance in x _or_ y
uint GetTileDist1D(TileIndex xy1, TileIndex xy2)
{
- return max(myabs(GET_TILE_X(xy1) - GET_TILE_X(xy2)),
- myabs(GET_TILE_Y(xy1) - GET_TILE_Y(xy2)));
+ return max(myabs(TileX(xy1) - TileX(xy2)),
+ myabs(TileY(xy1) - TileY(xy2)));
}
uint GetTileDist1Db(TileIndex xy1, TileIndex xy2)
{
- int a = myabs(GET_TILE_X(xy1) - GET_TILE_X(xy2));
- int b = myabs(GET_TILE_Y(xy1) - GET_TILE_Y(xy2));
+ int a = myabs(TileX(xy1) - TileX(xy2));
+ int b = myabs(TileY(xy1) - TileY(xy2));
if (a > b)
return a*2+b;
@@ -551,15 +551,15 @@ uint GetTileDist1Db(TileIndex xy1, TileIndex xy2)
uint GetTileDistAdv(TileIndex xy1, TileIndex xy2)
{
- uint a = myabs(GET_TILE_X(xy1) - GET_TILE_X(xy2));
- uint b = myabs(GET_TILE_Y(xy1) - GET_TILE_Y(xy2));
+ uint a = myabs(TileX(xy1) - TileX(xy2));
+ uint b = myabs(TileY(xy1) - TileY(xy2));
return a*a+b*b;
}
bool CheckDistanceFromEdge(TileIndex tile, uint distance)
{
- return IS_INT_INSIDE(GET_TILE_X(tile), distance, MapSizeX() - distance) &&
- IS_INT_INSIDE(GET_TILE_Y(tile), distance, MapSizeY() - distance);
+ return IS_INT_INSIDE(TileX(tile), distance, MapSizeX() - distance) &&
+ IS_INT_INSIDE(TileY(tile), distance, MapSizeY() - distance);
}
void OnNewDay_Train(Vehicle *v);
@@ -732,8 +732,8 @@ int FindFirstBit(uint32 value)
extern uint SafeTileAdd(uint tile, int add, const char *exp, const char *file, int line)
{
- uint x = GET_TILE_X(tile) + (signed char)(add & 0xFF);
- uint y = GET_TILE_Y(tile) + ((((0x8080 + add)>>8) & 0xFF) - 0x80);
+ uint x = TileX(tile) + (signed char)(add & 0xFF);
+ uint y = TileY(tile) + ((((0x8080 + add)>>8) & 0xFF) - 0x80);
if (x >= MapSizeX() || y >= MapSizeY()) {
char buf[512];
diff --git a/misc_gui.c b/misc_gui.c
index 71727ebb7..919a6675c 100644
--- a/misc_gui.c
+++ b/misc_gui.c
@@ -58,8 +58,8 @@ static void LandInfoWndProc(Window *w, WindowEvent *e)
DrawStringCentered(140, 38, str, 0);
snprintf(_userstring, USERSTRING_LEN, "%.4X", lid->tile);
- SetDParam(0, GET_TILE_X(lid->tile));
- SetDParam(1, GET_TILE_Y(lid->tile));
+ SetDParam(0, TileX(lid->tile));
+ SetDParam(1, TileY(lid->tile));
SetDParam(2, STR_SPEC_USERSTRING);
DrawStringCentered(140, 49, STR_LANDINFO_COORDS, 0);
@@ -143,7 +143,7 @@ static void Place_LandInfo(uint tile)
GetTileDesc(tile, &lid.td);
#if defined(_DEBUG)
- DEBUG(misc, 0) ("TILE: %#x (%i,%i)", tile, GET_TILE_X(tile), GET_TILE_Y(tile));
+ DEBUG(misc, 0) ("TILE: %#x (%i,%i)", tile, TileX(tile), TileY(tile));
DEBUG(misc, 0) ("TILE: %d ", tile);
DEBUG(misc, 0) ("_map_type_and_height=%#x", _map_type_and_height[tile]);
DEBUG(misc, 0) ("_map2=%#x", _map2[tile]);
diff --git a/pathfind.c b/pathfind.c
index a6b23a540..befb45f4c 100644
--- a/pathfind.c
+++ b/pathfind.c
@@ -161,7 +161,7 @@ static void TPFMode2(TrackPathFinder *tpf, uint tile, int direction)
if (bits == 0)
return;
- assert(GET_TILE_X(tile) != MapMaxX() && GET_TILE_Y(tile) != MapMaxY());
+ assert(TileX(tile) != MapMaxX() && TileY(tile) != MapMaxY());
if ( (bits & (bits - 1)) == 0 ) {
/* only one direction */
@@ -218,8 +218,8 @@ FindLengthOfTunnelResult FindLengthOfTunnel(uint tile, int direction)
flotr.length = 0;
- x = GET_TILE_X(tile) * 16;
- y = GET_TILE_Y(tile) * 16;
+ x = TileX(tile) * 16;
+ y = TileY(tile) * 16;
z = GetSlopeZ(x+8, y+8);
diff --git a/pathfind.h b/pathfind.h
index 07f42753e..ea9038ea3 100644
--- a/pathfind.h
+++ b/pathfind.h
@@ -14,7 +14,7 @@ typedef void TPFAfterProc(TrackPathFinder *tpf);
* 0 0 y7 y6 y5 y4 y3 y2 y1 y0 x4 x3 x2 x1 x0 0
* 0 0 0 0 y5 y4 y3 y2 y1 y0 x4 x3 x2 x1 x0 0
*/
-#define PATHFIND_HASH_TILE(tile) (GET_TILE_X(tile) & 0x1F) + ((GET_TILE_Y(tile)&0x1F)<<5)
+#define PATHFIND_HASH_TILE(tile) (TileX(tile) & 0x1F) + ((TileY(tile) & 0x1F) << 5)
typedef struct TrackPathFinderLink {
TileIndex tile;
diff --git a/rail_cmd.c b/rail_cmd.c
index 763dd0965..cab96d87e 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -983,8 +983,8 @@ int32 CmdBuildManySignals(int x, int y, uint32 flags, uint32 p1, uint32 p2)
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
/* unpack end tile */
- ex = GET_TILE_X(p1)*16;
- ey = GET_TILE_Y(p1)*16;
+ ex = TileX(p1) * 16;
+ ey = TileY(p1) * 16;
railbit = _railbit.initial[((p2 >> 4)&0xF) + (x > ex ? 4 : 0) + (y > ey ? 8 : 0)];
@@ -1144,8 +1144,8 @@ int32 CmdConvertRail(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
// make sure sx,sy are smaller than ex,ey
- sx = GET_TILE_X(p1)*16;
- sy = GET_TILE_Y(p1)*16;
+ sx = TileX(p1) * 16;
+ sy = TileY(p1) * 16;
if (ex < sx) intswap(ex, sx);
if (ey < sy) intswap(ey, sy);
diff --git a/rail_gui.c b/rail_gui.c
index 5e0ea7a33..7958f9f82 100644
--- a/rail_gui.c
+++ b/rail_gui.c
@@ -819,10 +819,10 @@ void ShowBuildRailToolbar(int index, int button)
static void HandleStationPlacement(uint start, uint end)
{
- uint sx = GET_TILE_X(start);
- uint sy = GET_TILE_Y(start);
- uint ex = GET_TILE_X(end);
- uint ey = GET_TILE_Y(end);
+ uint sx = TileX(start);
+ uint sy = TileY(start);
+ uint ex = TileX(end);
+ uint ey = TileY(end);
uint w,h;
if (sx > ex) intswap(sx,ex);
diff --git a/road_cmd.c b/road_cmd.c
index d42e50f03..c7ea7d08e 100644
--- a/road_cmd.c
+++ b/road_cmd.c
@@ -980,8 +980,8 @@ static void TileLoop_Road(uint tile)
SndPlayTileFx(SND_21_JACKHAMMER, tile);
CreateEffectVehicleAbove(
- GET_TILE_X(tile) * 16 + 7,
- GET_TILE_Y(tile) * 16 + 7,
+ TileX(tile) * 16 + 7,
+ TileY(tile) * 16 + 7,
0,
EV_ROADWORK);
MarkTileDirtyByTile(tile);
diff --git a/roadveh_cmd.c b/roadveh_cmd.c
index e7b42e574..0e8d808c2 100644
--- a/roadveh_cmd.c
+++ b/roadveh_cmd.c
@@ -138,8 +138,8 @@ int32 CmdBuildRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
v->owner = _current_player;
v->tile = tile;
- x = GET_TILE_X(tile)*16 + 8;
- y = GET_TILE_Y(tile)*16 + 8;
+ x = TileX(tile) * 16 + 8;
+ y = TileY(tile) * 16 + 8;
v->x_pos = x;
v->y_pos = y;
v->z_pos = GetSlopeZ(x,y);
@@ -1107,8 +1107,8 @@ static void RoadVehEventHandler(Vehicle *v)
rd2 = _roadveh_data_2[dir];
rdp = _road_drive_data[(_opt.road_side<<4) + rd2];
- x = GET_TILE_X(v->tile)*16 + (rdp[6].x&0xF);
- y = GET_TILE_Y(v->tile)*16 + (rdp[6].y&0xF);
+ x = TileX(v->tile) * 16 + (rdp[6].x & 0xF);
+ y = TileY(v->tile) * 16 + (rdp[6].y & 0xF);
if (RoadVehFindCloseTo(v,x,y,v->direction))
return;
@@ -1192,8 +1192,8 @@ again:
tmp &= ~0x10;
- x = GET_TILE_X(tile)*16 + rdp[0].x;
- y = GET_TILE_Y(tile)*16 + rdp[0].y;
+ x = TileX(tile) * 16 + rdp[0].x;
+ y = TileY(tile) * 16 + rdp[0].y;
if (RoadVehFindCloseTo(v, x, y, newdir=RoadVehGetSlidingDirection(v, x, y)))
return;
@@ -1254,8 +1254,8 @@ again:
tmp = (_opt.road_side<<4) + dir;
rdp = _road_drive_data[tmp];
- x = GET_TILE_X(v->tile)*16 + rdp[1].x;
- y = GET_TILE_Y(v->tile)*16 + rdp[1].y;
+ x = TileX(v->tile) * 16 + rdp[1].x;
+ y = TileY(v->tile) * 16 + rdp[1].y;
if (RoadVehFindCloseTo(v, x, y, newdir=RoadVehGetSlidingDirection(v, x, y)))
return;
diff --git a/ship_cmd.c b/ship_cmd.c
index 7b22502fa..dc6587a30 100644
--- a/ship_cmd.c
+++ b/ship_cmd.c
@@ -569,8 +569,8 @@ static const byte _new_vehicle_direction_table[11] = {
static int ShipGetNewDirectionFromTiles(uint new_tile, uint old_tile)
{
- uint offs = (GET_TILE_Y(new_tile) - GET_TILE_Y(old_tile) + 1) * 4 +
- GET_TILE_X(new_tile) - GET_TILE_X(old_tile) + 1;
+ uint offs = (TileY(new_tile) - TileY(old_tile) + 1) * 4 +
+ TileX(new_tile) - TileX(old_tile) + 1;
assert(offs < 11 && offs != 3 && offs != 7);
return _new_vehicle_direction_table[offs];
}
@@ -711,9 +711,8 @@ static void ShipController(Vehicle *v)
}
} else {
// new tile
- if (GET_TILE_X(gp.new_tile) == 0xFF ||
- (byte)GET_TILE_Y(gp.new_tile) == 0xFF)
- goto reverse_direction;
+ if (TileX(gp.new_tile) == MapMaxX() || TileY(gp.new_tile) == MapMaxY())
+ goto reverse_direction;
dir = ShipGetNewDirectionFromTiles(gp.new_tile, gp.old_tile);
assert(dir == 1 || dir == 3 || dir == 5 || dir == 7);
@@ -828,8 +827,8 @@ int32 CmdBuildShip(int x, int y, uint32 flags, uint32 p1, uint32 p2)
v->owner = _current_player;
v->tile = tile;
- x = GET_TILE_X(tile)*16 + 8;
- y = GET_TILE_Y(tile)*16 + 8;
+ x = TileX(tile) * 16 + 8;
+ y = TileY(tile) * 16 + 8;
v->x_pos = x;
v->y_pos = y;
v->z_pos = GetSlopeZ(x,y);
diff --git a/smallmap_gui.c b/smallmap_gui.c
index a8afa85c8..e7073eede 100644
--- a/smallmap_gui.c
+++ b/smallmap_gui.c
@@ -750,8 +750,8 @@ skip_column:
if (t->xy != 0) {
// Remap the town coordinate
Point pt = RemapCoords(
- (int)(GET_TILE_X(t->xy)*16 - WP(w,smallmap_d).scroll_x) >> 4,
- (int)(GET_TILE_Y(t->xy)*16 - WP(w,smallmap_d).scroll_y) >> 4,
+ (int)(TileX(t->xy) * 16 - WP(w,smallmap_d).scroll_x) >> 4,
+ (int)(TileY(t->xy) * 16 - WP(w,smallmap_d).scroll_y) >> 4,
0);
x = pt.x - WP(w,smallmap_d).subscroll + 3 - (t->sign.width_2 >> 1);
y = pt.y;
diff --git a/sound.c b/sound.c
index 1dd67e834..f8b5de7da 100644
--- a/sound.c
+++ b/sound.c
@@ -331,8 +331,8 @@ static void SndPlayScreenCoordFx(SoundFx sound, int x, int y)
void SndPlayTileFx(SoundFx sound, TileIndex tile)
{
/* emits sound from center (+ 8) of the tile */
- int x = GET_TILE_X(tile) * 16 + 8;
- int y = GET_TILE_Y(tile) * 16 + 8;
+ int x = TileX(tile) * 16 + 8;
+ int y = TileY(tile) * 16 + 8;
Point pt = RemapCoords(x, y, GetSlopeZ(x, y));
SndPlayScreenCoordFx(sound, pt.x, pt.y);
}
diff --git a/station_cmd.c b/station_cmd.c
index 6f3940f4f..f6bac7bfa 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -111,19 +111,19 @@ static bool CheckStationSpreadOut(Station *st, uint tile, int w, int h)
{
uint16 station_index = st->index;
uint i;
- uint x1 = GET_TILE_X(tile);
- uint y1 = GET_TILE_Y(tile);
+ uint x1 = TileX(tile);
+ uint y1 = TileY(tile);
uint x2 = x1 + w - 1;
uint y2 = y1 + h - 1;
uint t;
for (i = 0; i != MapSize(); i++) {
if (IS_TILETYPE(i, MP_STATION) && _map2[i] == station_index) {
- t = GET_TILE_X(i);
+ t = TileX(i);
if (t < x1) x1 = t;
if (t > x2) x2 = t;
- t = GET_TILE_Y(i);
+ t = TileY(i);
if (t < y1) y1 = t;
if (t > y2) y2 = t;
}
@@ -286,8 +286,8 @@ static bool GenerateStationName(Station *st, uint tile, int flag)
};
free_names &= _direction_and_table[
- (GET_TILE_X(tile) < GET_TILE_X(t->xy)) +
- (GET_TILE_Y(tile) < GET_TILE_Y(t->xy))*2];
+ (TileX(tile) < TileX(t->xy)) +
+ (TileY(tile) < TileY(t->xy)) * 2];
}
tmp = free_names & ((1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<6)|(1<<7)|(1<<12)|(1<<26)|(1<<27)|(1<<28)|(1<<29)|(1<<30));
@@ -350,7 +350,7 @@ static void StationInitialize(Station *st, TileIndex tile)
// st = Station to update for.
static void UpdateStationVirtCoord(Station *st)
{
- Point pt = RemapCoords2(GET_TILE_X(st->xy) * 16, GET_TILE_Y(st->xy) * 16);
+ Point pt = RemapCoords2(TileX(st->xy) * 16, TileY(st->xy) * 16);
pt.y -= 32;
if (st->facilities&FACIL_AIRPORT && st->airport_type==AT_OILRIG) pt.y -= 16;
@@ -412,8 +412,8 @@ void GetProductionAroundTiles(uint *produced, uint tile, int w, int h, int rad)
memset(produced, 0, NUM_CARGO * sizeof(uint));
- x = GET_TILE_X(tile);
- y = GET_TILE_Y(tile);
+ x = TileX(tile);
+ y = TileY(tile);
// expand the region by 4 tiles on each side
// while making sure that we remain inside the board.
@@ -460,8 +460,8 @@ void GetAcceptanceAroundTiles(uint *accepts, uint tile, int w, int h, int rad)
memset(accepts, 0, sizeof(AcceptedCargo));
- x = GET_TILE_X(tile);
- y = GET_TILE_Y(tile);
+ x = TileX(tile);
+ y = TileY(tile);
// expand the region by 4 tiles on each side
// while making sure that we remain inside the board.
@@ -531,10 +531,10 @@ static void UpdateStationAcceptance(Station *st, bool show_msg)
for(i=0; i!=7; i++) {
uint tile = span[i];
if (tile) {
- min_x = min(min_x,GET_TILE_X(tile));
- max_x = max(max_x,GET_TILE_X(tile));
- min_y = min(min_y,GET_TILE_Y(tile));
- max_y = max(max_y,GET_TILE_Y(tile));
+ min_x = min(min_x, TileX(tile));
+ max_x = max(max_x, TileX(tile));
+ min_y = min(min_y, TileY(tile));
+ max_y = max(max_y, TileY(tile));
}
}
if (_patches.modified_catchment) {
@@ -677,10 +677,10 @@ static bool CanExpandRailroadStation(Station *st, uint *fin, int direction)
if (_patches.nonuniform_stations) {
// determine new size of train station region..
- int x = min(GET_TILE_X(st->train_tile), GET_TILE_X(tile));
- int y = min(GET_TILE_Y(st->train_tile), GET_TILE_Y(tile));
- curw = max(GET_TILE_X(st->train_tile) + curw, GET_TILE_X(tile) + w) - x;
- curh = max(GET_TILE_Y(st->train_tile) + curh, GET_TILE_Y(tile) + h) - y;
+ int x = min(TileX(st->train_tile), TileX(tile));
+ int y = min(TileY(st->train_tile), TileY(tile));
+ curw = max(TileX(st->train_tile) + curw, TileX(tile) + w) - x;
+ curh = max(TileY(st->train_tile) + curh, TileY(tile) + h) - y;
tile = TILE_XY(x,y);
} else {
// check so the direction is the same
diff --git a/town_cmd.c b/town_cmd.c
index b7a142ad0..eb3f11a68 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -186,7 +186,7 @@ void UpdateTownVirtCoord(Town *t)
Point pt;
MarkTownSignDirty(t);
- pt = RemapCoords2(GET_TILE_X(t->xy)*16, GET_TILE_Y(t->xy)*16);
+ pt = RemapCoords2(TileX(t->xy) * 16, TileY(t->xy) * 16);
SetDParam(0, t->townnametype);
SetDParam(1, t->townnameparts);
SetDParam(2, t->population);
diff --git a/train_cmd.c b/train_cmd.c
index 44813fdef..a1ff5150c 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -266,8 +266,8 @@ static int32 CmdBuildRailWagon(uint engine, uint tile, uint32 flags)
v->direction = (byte)(dir*2+1);
v->tile = (TileIndex)tile;
- x = GET_TILE_X(tile)*16 | _vehicle_initial_x_fract[dir];
- y = GET_TILE_Y(tile)*16 | _vehicle_initial_y_fract[dir];
+ x = TileX(tile) * 16 | _vehicle_initial_x_fract[dir];
+ y = TileY(tile) * 16 | _vehicle_initial_y_fract[dir];
v->x_pos = x;
v->y_pos = y;
@@ -1846,8 +1846,8 @@ static const byte _new_vehicle_direction_table[11] = {
static int GetNewVehicleDirectionByTile(uint new_tile, uint old_tile)
{
- uint offs = (GET_TILE_Y(new_tile) - GET_TILE_Y(old_tile) + 1) * 4 +
- GET_TILE_X(new_tile) - GET_TILE_X(old_tile) + 1;
+ uint offs = (TileY(new_tile) - TileY(old_tile) + 1) * 4 +
+ TileX(new_tile) - TileX(old_tile) + 1;
assert(offs < 11);
return _new_vehicle_direction_table[offs];
}
diff --git a/tree_cmd.c b/tree_cmd.c
index b7316312c..52854c9c6 100644
--- a/tree_cmd.c
+++ b/tree_cmd.c
@@ -155,8 +155,8 @@ int32 CmdPlantTree(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
SET_EXPENSES_TYPE(EXPENSES_OTHER);
// make sure sx,sy are smaller than ex,ey
- sx = GET_TILE_X(p2)*16;
- sy = GET_TILE_Y(p2)*16;
+ sx = TileX(p2) * 16;
+ sy = TileY(p2) * 16;
if (ex < sx) intswap(ex, sx);
if (ey < sy) intswap(ey, sy);
diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c
index 4a373d9ab..06d398ffa 100644
--- a/tunnelbridge_cmd.c
+++ b/tunnelbridge_cmd.c
@@ -134,10 +134,10 @@ static uint32 CheckBridgeSlope(uint direction, uint tileh, bool is_start_tile)
uint32 GetBridgeLength(TileIndex begin, TileIndex end)
{
int x1, y1, x2, y2; // coordinates of starting and end tiles
- x1 = GET_TILE_X(begin);
- y1 = GET_TILE_Y(begin);
- x2 = GET_TILE_X(end);
- y2 = GET_TILE_Y(end);
+ x1 = TileX(begin);
+ y1 = TileY(begin);
+ x2 = TileX(end);
+ y2 = TileY(end);
return abs((x2 + y2 - x1 - y1)) - 1;
}
@@ -190,8 +190,8 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
rail_or_road = 0;
}
- sx = GET_TILE_X(p1) * 16;
- sy = GET_TILE_Y(p1) * 16;
+ sx = TileX(p1) * 16;
+ sy = TileY(p1) * 16;
direction = 0;
diff --git a/unmovable_cmd.c b/unmovable_cmd.c
index adb82bc03..66c8a38f4 100644
--- a/unmovable_cmd.c
+++ b/unmovable_cmd.c
@@ -236,7 +236,7 @@ static bool checkRadioTowerNearby(uint tile)
{
uint tile_s;
- tile_s = TILE_XY( (int) GET_TILE_X(tile)-4, (int) GET_TILE_Y(tile)-4 );
+ tile_s = TILE_XY(TileX(tile) - 4, TileY(tile) - 4);
BEGIN_TILE_LOOP(tile, 9, 9, tile_s)
// already a radio tower here?
@@ -324,7 +324,9 @@ int32 CmdBuildCompanyHQ(int x, int y, uint32 flags, uint32 p1, uint32 p2)
return CMD_ERROR;
if (p1)
- cost = DoCommand(GET_TILE_X(p->location_of_house)*16, GET_TILE_Y(p->location_of_house)*16, p1&0xFF, 0, flags, CMD_DESTROY_COMPANY_HQ);
+ cost = DoCommand(
+ TileX(p->location_of_house) * 16, TileY(p->location_of_house) * 16,
+ p1 & 0xFF, 0, flags, CMD_DESTROY_COMPANY_HQ);
if (flags & DC_EXEC) {
score = UpdateCompanyRatingAndValue(p, false);
diff --git a/vehicle.c b/vehicle.c
index f58d05cfa..f6bb1d39e 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -105,10 +105,10 @@ bool EnsureNoVehicleZ(TileIndex tile, byte z)
Vehicle *FindVehicleBetween(TileIndex from, TileIndex to, byte z)
{
- int x1 = GET_TILE_X(from);
- int y1 = GET_TILE_Y(from);
- int x2 = GET_TILE_X(to);
- int y2 = GET_TILE_Y(to);
+ int x1 = TileX(from);
+ int y1 = TileY(from);
+ int x2 = TileX(to);
+ int y2 = TileY(to);
Vehicle *veh;
/* Make sure x1 < x2 or y1 < y2 */
@@ -148,7 +148,7 @@ void VehiclePositionChanged(Vehicle *v)
void UpdateWaypointSign(Waypoint *cp)
{
- Point pt = RemapCoords2(GET_TILE_X(cp->xy)*16, GET_TILE_Y(cp->xy)*16);
+ Point pt = RemapCoords2(TileX(cp->xy) * 16, TileY(cp->xy) * 16);
SetDParam(0, cp - _waypoints);
UpdateViewportSignPos(&cp->sign, pt.x, pt.y - 0x20, STR_WAYPOINT_VIEWPORT);
}
@@ -263,7 +263,7 @@ void *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
{
int x,y,x2,y2;
VehicleID veh;
- Point pt = RemapCoords(GET_TILE_X(tile) * 16, GET_TILE_Y(tile) * 16, 0);
+ Point pt = RemapCoords(TileX(tile) * 16, TileY(tile) * 16, 0);
x2 = ((pt.x + 104) & 0x1F80) >> 7;
x = ((pt.x - 174) & 0x1F80) >> 7;
diff --git a/viewport.c b/viewport.c
index 3e86cf8d7..b7d338a75 100644
--- a/viewport.c
+++ b/viewport.c
@@ -119,8 +119,8 @@ void AssignWindowViewport(Window *w, int x, int y,
veh = GetVehicle(WP(w,vp_d).follow_vehicle);
pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos);
} else {
- int x = GET_TILE_X(follow_flags) * 16;
- int y = GET_TILE_Y(follow_flags) * 16;
+ int x = TileX(follow_flags) * 16;
+ int y = TileY(follow_flags) * 16;
WP(w,vp_d).follow_vehicle = 0xFFFF;
z = GetSlopeZ(x,y);
pt = MapXYZToViewport(vp, x,y, z);
@@ -1363,7 +1363,7 @@ void MarkAllViewportsDirty(int left, int top, int right, int bottom)
}
void MarkTileDirtyByTile(TileIndex tile) {
- Point pt = RemapCoords(GET_TILE_X(tile) * 16, GET_TILE_Y(tile) * 16, GetTileZ(tile));
+ Point pt = RemapCoords(TileX(tile) * 16, TileY(tile) * 16, GetTileZ(tile));
MarkAllViewportsDirty(
pt.x - 31,
pt.y - 122,
@@ -1747,7 +1747,7 @@ bool ScrollWindowTo(int x , int y, Window * w)
/* scrolls the viewport in a window to a given tile */
bool ScrollWindowToTile(TileIndex tile, Window * w)
{
- return ScrollWindowTo(GET_TILE_X(tile)*16+8, GET_TILE_Y(tile)*16+8, w);
+ return ScrollWindowTo(TileX(tile) * 16 + 8, TileY(tile) * 16 + 8, w);
}
@@ -1772,7 +1772,7 @@ bool ScrollMainWindowTo(int x, int y)
bool ScrollMainWindowToTile(TileIndex tile)
{
- return ScrollMainWindowTo(GET_TILE_X(tile)*16+8, GET_TILE_Y(tile)*16+8);
+ return ScrollMainWindowTo(TileX(tile) * 16 + 8, TileY(tile) * 16 + 8);
}
void SetRedErrorSquare(TileIndex tile)
@@ -1872,10 +1872,10 @@ void VpStartPlaceSizing(uint tile, int user)
thd = _thd_ptr;
thd->userdata = user;
- thd->selend.x = GET_TILE_X(tile)*16;
- thd->selstart.x = GET_TILE_X(tile)*16;
- thd->selend.y = GET_TILE_Y(tile)*16;
- thd->selstart.y = GET_TILE_Y(tile)*16;
+ thd->selend.x = TileX(tile) * 16;
+ thd->selstart.x = TileX(tile) * 16;
+ thd->selend.y = TileY(tile) * 16;
+ thd->selstart.y = TileY(tile) * 16;
if (thd->place_mode == 1) {
thd->place_mode = 3;
thd->next_drawstyle = HT_RECT;
@@ -1894,10 +1894,10 @@ void VpSetPlaceSizingLimit(int limit)
void VpSetPresizeRange(uint from, uint to)
{
TileHighlightData *thd = _thd_ptr;
- thd->selend.x = GET_TILE_X(to)*16;
- thd->selend.y = GET_TILE_Y(to)*16;
- thd->selstart.x = GET_TILE_X(from)*16;
- thd->selstart.y = GET_TILE_Y(from)*16;
+ thd->selend.x = TileX(to) * 16;
+ thd->selend.y = TileY(to) * 16;
+ thd->selstart.x = TileX(from) * 16;
+ thd->selstart.y = TileY(from) * 16;
thd->next_drawstyle = HT_RECT;
}
diff --git a/water_cmd.c b/water_cmd.c
index 16d3e09d3..f29a06391 100644
--- a/water_cmd.c
+++ b/water_cmd.c
@@ -197,7 +197,7 @@ int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
// move in which direction?
- delta = (GET_TILE_X(tile) == GET_TILE_X(endtile)) ? TILE_XY(0,1) : TILE_XY(1,0);
+ delta = (TileX(tile) == TileX(endtile)) ? TILE_XY(0,1) : TILE_XY(1,0);
if (endtile < tile) delta = -delta;
cost = 0;
@@ -267,8 +267,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, MapMaxX() - 1) &&
- IS_INT_INSIDE(GET_TILE_Y(tile), 1, MapMaxY() - 1)))
+ if (!(IS_INT_INSIDE(TileX(tile), 1, MapMaxX() - 1) &&
+ IS_INT_INSIDE(TileY(tile), 1, MapMaxY() - 1)))
return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP);
if (m5 == 0) {
@@ -582,8 +582,8 @@ void TileLoop_Water(uint tile)
{{ 0, -1}, {0, 0}, {1, 0}, { 0, -1}, { 1, -1}}
};
- if (IS_INT_INSIDE(GET_TILE_X(tile), 1, MapSizeX() - 3 + 1) &&
- IS_INT_INSIDE(GET_TILE_Y(tile), 1, MapSizeY() - 3 + 1)) {
+ if (IS_INT_INSIDE(TileX(tile), 1, MapSizeX() - 3 + 1) &&
+ IS_INT_INSIDE(TileY(tile), 1, MapSizeY() - 3 + 1)) {
for(i=0; i!=4; i++)
TileLoopWaterHelper(tile, _tile_loop_offs_array[i]);
}
@@ -592,16 +592,16 @@ void TileLoop_Water(uint tile)
_current_player = OWNER_NONE;
// edges
- if (GET_TILE_X(tile) == 0 && IS_INT_INSIDE(GET_TILE_Y(tile), 1, MapSizeY() - 3 + 1)) //NE
+ if (TileX(tile) == 0 && IS_INT_INSIDE(TileY(tile), 1, MapSizeY() - 3 + 1)) //NE
TileLoopWaterHelper(tile, _tile_loop_offs_array[2]);
- if (GET_TILE_X(tile) == (MapSizeX() - 2) && IS_INT_INSIDE(GET_TILE_Y(tile), 1, MapSizeY() - 3 + 1)) //SW
+ if (TileX(tile) == (MapSizeX() - 2) && IS_INT_INSIDE(TileY(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, MapSizeX() - 3 + 1)) //NW
+ if (TileY(tile) == 0 && IS_INT_INSIDE(TileX(tile), 1, MapSizeX() - 3 + 1)) //NW
TileLoopWaterHelper(tile, _tile_loop_offs_array[1]);
- if (GET_TILE_Y(tile) == (MapSizeY() - 2) && IS_INT_INSIDE(GET_TILE_X(tile), 1, MapSizeX() - 3 + 1)) //SE
+ if (TileY(tile) == (MapSizeY() - 2) && IS_INT_INSIDE(TileX(tile), 1, MapSizeX() - 3 + 1)) //SE
TileLoopWaterHelper(tile, _tile_loop_offs_array[3]);
}