(svn r2487) Replace TILE_XY by TileXY/TileDiffXY

pull/155/head
tron 19 years ago
parent 2b73dec567
commit 9617614b04

26
ai.c

@ -633,7 +633,7 @@ static byte AiGetDirectionBetweenTiles(TileIndex a, TileIndex b)
static TileIndex AiGetPctTileBetween(TileIndex a, TileIndex b, byte pct)
{
return TILE_XY(
return TileXY(
TileX(a) + ((TileX(b) - TileX(a)) * pct >> 8),
TileY(a) + ((TileY(b) - TileY(a)) * pct >> 8)
);
@ -3656,7 +3656,7 @@ is_rail_crossing:;
if (m5&0x25) {
pos_0:
if (!(GetRailTrackStatus(TILE_MASK(tile-TILE_XY(1,0)))&0x19)) {
if (!(GetRailTrackStatus(TILE_MASK(tile - TileDiffXY(1, 0))) & 0x19)) {
p->ai.cur_dir_a = 0;
p->ai.cur_tile_a = tile;
p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE;
@ -3666,7 +3666,7 @@ pos_0:
if (m5&0x2A) {
pos_1:
if (!(GetRailTrackStatus(TILE_MASK(tile+TILE_XY(0,1)))&0x16)) {
if (!(GetRailTrackStatus(TILE_MASK(tile + TileDiffXY(0, 1))) & 0x16)) {
p->ai.cur_dir_a = 1;
p->ai.cur_tile_a = tile;
p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE;
@ -3676,7 +3676,7 @@ pos_1:
if (m5&0x19) {
pos_2:
if (!(GetRailTrackStatus(TILE_MASK(tile+TILE_XY(1,0)))&0x25)) {
if (!(GetRailTrackStatus(TILE_MASK(tile + TileDiffXY(1, 0))) & 0x25)) {
p->ai.cur_dir_a = 2;
p->ai.cur_tile_a = tile;
p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE;
@ -3686,7 +3686,7 @@ pos_2:
if (m5&0x16) {
pos_3:
if (!(GetRailTrackStatus(TILE_MASK(tile-TILE_XY(0,1)))&0x2A)) {
if (!(GetRailTrackStatus(TILE_MASK(tile - TileDiffXY(0, 1))) & 0x2A)) {
p->ai.cur_dir_a = 3;
p->ai.cur_tile_a = tile;
p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE;
@ -3712,20 +3712,20 @@ pos_3:
int dir;
// Check if there are any stations around.
if (IsTileType(tile + TILE_XY(-1,0), MP_STATION) &&
IsTileOwner(tile + TILE_XY(-1, 0), _current_player))
if (IsTileType(tile + TileDiffXY(-1, 0), MP_STATION) &&
IsTileOwner(tile + TileDiffXY(-1, 0), _current_player))
return;
if (IsTileType(tile + TILE_XY(1,0), MP_STATION) &&
IsTileOwner(tile + TILE_XY(1, 0), _current_player))
if (IsTileType(tile + TileDiffXY(1, 0), MP_STATION) &&
IsTileOwner(tile + TileDiffXY(1, 0), _current_player))
return;
if (IsTileType(tile + TILE_XY(0,-1), MP_STATION) &&
IsTileOwner(tile + TILE_XY(0, -1), _current_player))
if (IsTileType(tile + TileDiffXY(0, -1), MP_STATION) &&
IsTileOwner(tile + TileDiffXY(0, -1), _current_player))
return;
if (IsTileType(tile + TILE_XY(0,1), MP_STATION) &&
IsTileOwner(tile + TILE_XY(0, 1), _current_player))
if (IsTileType(tile + TileDiffXY(0, 1), MP_STATION) &&
IsTileOwner(tile + TileDiffXY(0, 1), _current_player))
return;
dir = _map5[tile] & 3;

@ -222,7 +222,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(MapMaxX(), MapMaxY())
#define AI_STATION_RANGE TileXY(MapMaxX(), MapMaxY())
#define AI_PATHFINDER_NO_DIRECTION (byte)-1

@ -621,7 +621,7 @@ static void AiNew_State_FindStation(Player *p) {
// taking eachothers passangers away (bad result when it does not)
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);
new_tile = TileXY(x, y);
if (IsTileType(new_tile, MP_CLEAR) || IsTileType(new_tile, MP_TREES)) {
// This tile we can build on!
// Check acceptance
@ -695,8 +695,8 @@ static void AiNew_State_FindPath(Player *p) {
// Init path_info
if (p->ainew.from_tile == AI_STATION_RANGE) {
// For truck routes we take a range around the industry
p->ainew.path_info.start_tile_tl = GetIndustry(p->ainew.from_ic)->xy - TILE_XY(1,1);
p->ainew.path_info.start_tile_br = GetIndustry(p->ainew.from_ic)->xy + TILE_XY(GetIndustry(p->ainew.from_ic)->width, GetIndustry(p->ainew.from_ic)->height) + TILE_XY(1,1);
p->ainew.path_info.start_tile_tl = GetIndustry(p->ainew.from_ic)->xy - TileDiffXY(1, 1);
p->ainew.path_info.start_tile_br = GetIndustry(p->ainew.from_ic)->xy + TileDiffXY(GetIndustry(p->ainew.from_ic)->width, GetIndustry(p->ainew.from_ic)->height) + TileDiffXY(1, 1);
p->ainew.path_info.start_direction = p->ainew.from_direction;
} else {
p->ainew.path_info.start_tile_tl = p->ainew.from_tile;
@ -705,8 +705,8 @@ static void AiNew_State_FindPath(Player *p) {
}
if (p->ainew.to_tile == AI_STATION_RANGE) {
p->ainew.path_info.end_tile_tl = GetIndustry(p->ainew.to_ic)->xy - TILE_XY(1,1);
p->ainew.path_info.end_tile_br = GetIndustry(p->ainew.to_ic)->xy + TILE_XY(GetIndustry(p->ainew.to_ic)->width, GetIndustry(p->ainew.to_ic)->height) + TILE_XY(1,1);
p->ainew.path_info.end_tile_tl = GetIndustry(p->ainew.to_ic)->xy - TileDiffXY(1, 1);
p->ainew.path_info.end_tile_br = GetIndustry(p->ainew.to_ic)->xy + TileDiffXY(GetIndustry(p->ainew.to_ic)->width, GetIndustry(p->ainew.to_ic)->height) + TileDiffXY(1, 1);
p->ainew.path_info.end_direction = p->ainew.to_direction;
} else {
p->ainew.path_info.end_tile_tl = p->ainew.to_tile;

@ -115,7 +115,7 @@ AyStar *new_AyStar_AiPathFinder(int max_tiles_around, Ai_PathFinderInfo *PathFin
// Now we add all the starting tiles
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);
start_node.node.tile = TileXY(x, y);
result->addstart(result, &start_node.node, 0);
}
}
@ -144,9 +144,9 @@ void clean_AyStar_AiPathFinder(AyStar *aystar, Ai_PathFinderInfo *PathFinderInfo
// Now we add all the starting tiles
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 (!(IsTileType(TILE_XY(x, y), MP_CLEAR) || IsTileType(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);
if (!(IsTileType(TileXY(x, y), MP_CLEAR) || IsTileType(TileXY(x, y), MP_TREES))) continue;
if (!TestCanBuildStationHere(TileXY(x, y), TEST_STATION_NO_DIR)) continue;
start_node.node.tile = TileXY(x, y);
aystar->addstart(aystar, &start_node.node, 0);
}
}

@ -76,9 +76,9 @@ static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile)
static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile)
{
TerraformAddDirtyTile(ts, tile+TILE_XY(0,-1));
TerraformAddDirtyTile(ts, tile+TILE_XY(-1,-1));
TerraformAddDirtyTile(ts, tile+TILE_XY(-1,0));
TerraformAddDirtyTile(ts, tile + TileDiffXY( 0, -1));
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, -1));
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, 0));
TerraformAddDirtyTile(ts, tile);
}
@ -152,17 +152,10 @@ static bool TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height
if (nh < 0 || height == nh)
return false;
if (TerraformProc(ts, tile, 0)<0)
return false;
if (TerraformProc(ts, tile + TILE_XY(0,-1), 1)<0)
return false;
if (TerraformProc(ts, tile + TILE_XY(-1,-1), 2)<0)
return false;
if (TerraformProc(ts, tile + TILE_XY(-1,0), 3)<0)
return false;
if (TerraformProc(ts, tile, 0) < 0) return false;
if (TerraformProc(ts, tile + TileDiffXY( 0, -1), 1) < 0) return false;
if (TerraformProc(ts, tile + TileDiffXY(-1, -1), 2) < 0) return false;
if (TerraformProc(ts, tile + TileDiffXY(-1, 0), 3) < 0) return false;
mod = ts->modheight;
count = ts->modheight_count;
@ -239,29 +232,29 @@ int32 CmdTerraformLand(int x, int y, uint32 flags, uint32 p1, uint32 p2)
tile = TileVirtXY(x, y);
/* Make an extra check for map-bounds cause we add tiles to the originating tile */
if (tile + TILE_XY(1,1) > MapSize()) return CMD_ERROR;
if (tile + TileDiffXY(1, 1) > MapSize()) return CMD_ERROR;
if (p1 & 1) {
if (!TerraformTileHeight(&ts, tile+TILE_XY(1,0),
TileHeight(tile + TILE_XY(1, 0)) + direction))
if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 0),
TileHeight(tile + TileDiffXY(1, 0)) + direction))
return CMD_ERROR;
}
if (p1 & 2) {
if (!TerraformTileHeight(&ts, tile+TILE_XY(1,1),
TileHeight(tile + TILE_XY(1, 1)) + direction))
if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 1),
TileHeight(tile + TileDiffXY(1, 1)) + direction))
return CMD_ERROR;
}
if (p1 & 4) {
if (!TerraformTileHeight(&ts, tile+TILE_XY(0,1),
TileHeight(tile + TILE_XY(0, 1)) + direction))
if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 1),
TileHeight(tile + TileDiffXY(0, 1)) + direction))
return CMD_ERROR;
}
if (p1 & 8) {
if (!TerraformTileHeight(&ts, tile+TILE_XY(0,0),
TileHeight(tile + TILE_XY(0, 0)) + direction))
if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 0),
TileHeight(tile + TileDiffXY(0, 0)) + direction))
return CMD_ERROR;
}
@ -274,12 +267,12 @@ int32 CmdTerraformLand(int x, int y, uint32 flags, uint32 p1, uint32 p2)
uint z, t;
TileIndex tile = *ti;
z = TerraformGetHeightOfTile(&ts, tile + TILE_XY(0,0));
t = TerraformGetHeightOfTile(&ts, tile + TILE_XY(1,0));
z = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0));
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0));
if (t <= z) z = t;
t = TerraformGetHeightOfTile(&ts, tile + TILE_XY(1,1));
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1));
if (t <= z) z = t;
t = TerraformGetHeightOfTile(&ts, tile + TILE_XY(0,1));
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1));
if (t <= z) z = t;
if (!CheckTunnelInWay(tile, z*8))
@ -351,7 +344,7 @@ int32 CmdLevelLand(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
sy = TileY(p1);
if (ex < sx) intswap(ex, sx);
if (ey < sy) intswap(ey, sy);
tile = TILE_XY(sx,sy);
tile = TileXY(sx, sy);
size_x = ex-sx+1;
size_y = ey-sy+1;
@ -710,11 +703,11 @@ static void TileLoopClearDesert(TileIndex tile)
if (GetMapExtraBits(tile) == 1) {
_map5[tile] = 0x17;
} else {
if (GetMapExtraBits(tile+TILE_XY(1,0)) != 1 &&
GetMapExtraBits(tile+TILE_XY(-1,0)) != 1 &&
GetMapExtraBits(tile+TILE_XY(0,1)) != 1 &&
GetMapExtraBits(tile+TILE_XY(0,-1)) != 1)
return;
if (GetMapExtraBits(tile + TileDiffXY( 1, 0)) != 1 &&
GetMapExtraBits(tile + TileDiffXY(-1, 0)) != 1 &&
GetMapExtraBits(tile + TileDiffXY( 0, 1)) != 1 &&
GetMapExtraBits(tile + TileDiffXY( 0, -1)) != 1)
return;
_map5[tile] = 0x15;
}

@ -627,10 +627,10 @@ static void DisasterTick_4b(Vehicle *v)
EV_EXPLOSION_SMALL);
}
BEGIN_TILE_LOOP(tile,6,6,v->tile - TILE_XY(3,3))
BEGIN_TILE_LOOP(tile, 6, 6, v->tile - TileDiffXY(3, 3))
tile = TILE_MASK(tile);
DisasterClearSquare(tile);
END_TILE_LOOP(tile,6,6,v->tile - TILE_XY(3,3))
END_TILE_LOOP(tile, 6, 6, v->tile - TileDiffXY(3, 3))
}
}
@ -744,7 +744,7 @@ static void Disaster1_Init(void)
x = TileX(Random()) * 16 + 8;
InitializeDisasterVehicle(v, x, 0, 135, 3, 2);
v->dest_tile = TILE_XY(MapSizeX() / 2, MapSizeY() / 2);
v->dest_tile = TileXY(MapSizeX() / 2, MapSizeY() / 2);
v->age = 0;
// Allocate shadow too?
@ -846,7 +846,7 @@ static void Disaster4_Init(void)
y = MapMaxX() * 16 - 1;
InitializeDisasterVehicle(v, x, y, 135, 7, 9);
v->dest_tile = TILE_XY(MapSizeX() / 2, MapSizeY() / 2);
v->dest_tile = TileXY(MapSizeX() / 2, MapSizeY() / 2);
v->age = 0;
// Allocate shadow too?
@ -912,7 +912,7 @@ static void Disaster7_Init(void)
SetDParam(0, i->town->index);
AddNewsItem(STR_B005_COAL_MINE_SUBSIDENCE_LEAVES,
NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ACCIDENT,0), i->xy + TILE_XY(1,1), 0);
NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ACCIDENT,0), i->xy + TileDiffXY(1, 1), 0);
{
TileIndex tile = i->xy;

@ -168,11 +168,11 @@ static void BuildDocksToolbWndProc(Window *w, WindowEvent *e)
TileIndex tile_to;
tile_from = tile_to = e->place.tile;
switch(GetTileSlope(tile_from, NULL)) {
case 3: tile_to += TILE_XY(-1,0); break;
case 6: tile_to += TILE_XY(0,-1); break;
case 9: tile_to += TILE_XY(0,1); break;
case 12:tile_to += TILE_XY(1,0); break;
switch (GetTileSlope(tile_from, NULL)) {
case 3: tile_to += TileDiffXY(-1, 0); break;
case 6: tile_to += TileDiffXY( 0, -1); break;
case 9: tile_to += TileDiffXY( 0, 1); break;
case 12: tile_to += TileDiffXY( 1, 0); break;
}
VpSetPresizeRange(tile_from, tile_to);
} break;

@ -62,15 +62,15 @@ void UpdatePlayerHouse(Player *p, uint score)
if (val <= _map5[tile])
return;
_map5[tile + TILE_XY(0,0)] = val;
_map5[tile + TILE_XY(0,1)] = ++val;
_map5[tile + TILE_XY(1,0)] = ++val;
_map5[tile + TILE_XY(1,1)] = ++val;
MarkTileDirtyByTile(tile + TILE_XY(0,0));
MarkTileDirtyByTile(tile + TILE_XY(0,1));
MarkTileDirtyByTile(tile + TILE_XY(1,0));
MarkTileDirtyByTile(tile + TILE_XY(1,1));
_map5[tile + TileDiffXY(0, 0)] = val;
_map5[tile + TileDiffXY(0, 1)] = ++val;
_map5[tile + TileDiffXY(1, 0)] = ++val;
_map5[tile + TileDiffXY(1, 1)] = ++val;
MarkTileDirtyByTile(tile + TileDiffXY(0, 0));
MarkTileDirtyByTile(tile + TileDiffXY(0, 1));
MarkTileDirtyByTile(tile + TileDiffXY(1, 0));
MarkTileDirtyByTile(tile + TileDiffXY(1, 1));
}
int64 CalculateCompanyValue(Player *p) {

@ -692,9 +692,7 @@ static void MakeIndustryTileBigger(TileIndex tile, byte size)
break;
case 24:
if (_map5[tile + TILE_XY(0,1)] == 24) {
BuildOilRig(tile);
}
if (_map5[tile + TileDiffXY(0, 1)] == 24) BuildOilRig(tile);
break;
case 143:
@ -943,7 +941,7 @@ static void SetupFarmFieldFence(TileIndex tile, int size, byte type, int directi
_map3_hi[tile] = (_map3_hi[tile] & and) | or;
}
tile += direction ? TILE_XY(0,1) : TILE_XY(1,0);
tile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
} while (--size);
}
@ -966,7 +964,7 @@ static void PlantFarmField(TileIndex tile)
size_y = r >> 8;
/* offset tile to match size */
tile = tile - TILE_XY(size_x>>1, size_y>>1);
tile -= TileDiffXY(size_x / 2, size_y / 2);
/* check the amount of bad tiles */
count = 0;
@ -1000,10 +998,10 @@ static void PlantFarmField(TileIndex tile)
type = _plantfarmfield_type[Random() & 0xF];
}
SetupFarmFieldFence(tile-TILE_XY(1,0), size_y, type, 1);
SetupFarmFieldFence(tile-TILE_XY(0,1), size_x, type, 0);
SetupFarmFieldFence(tile+TILE_XY(1,0) * (size_x-1), size_y, type, 1);
SetupFarmFieldFence(tile+TILE_XY(0,1) * (size_y-1), size_x, type, 0);
SetupFarmFieldFence(tile - TileDiffXY(1, 0), size_y, type, 1);
SetupFarmFieldFence(tile - TileDiffXY(0, 1), size_x, type, 0);
SetupFarmFieldFence(tile + TileDiffXY(size_x - 1, 0), size_y, type, 1);
SetupFarmFieldFence(tile + TileDiffXY(0, size_y - 1), size_x, type, 0);
}
static void MaybePlantFarmField(Industry *i)
@ -1060,7 +1058,7 @@ static void ChopLumberMillTrees(Industry *i)
tile += ToTileIndexDiff(_chop_dir[dir]);
} while (--j);
}
tile -= TILE_XY(1,1);
tile -= TileDiffXY(1, 1);
}
}
@ -1532,7 +1530,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const Ind
i->height++;
if (i->type == IT_FARM || i->type == IT_FARM_2) {
tile = i->xy + TILE_XY((i->width >> 1), (i->height >> 1));
tile = i->xy + TileDiffXY(i->width / 2, i->height / 2);
for(j=0; j!=50; j++) {
int x = Random() % 31 - 16;
int y = Random() % 31 - 16;
@ -1728,7 +1726,7 @@ static void ExtChangeIndustryProduction(Industry *i)
SetDParam(2, i->type + STR_4802_COAL_MINE);
AddNewsItem(percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN,
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0),
i->xy + TILE_XY(1,1), 0);
i->xy + TileDiffXY(1, 1), 0);
}
}
break;
@ -1740,7 +1738,7 @@ static void ExtChangeIndustryProduction(Industry *i)
SetDParam(0, i->town->index);
AddNewsItem(_industry_close_strings[i->type],
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0),
i->xy + TILE_XY(1,1), 0);
i->xy + TileDiffXY(1, 1), 0);
}
}
@ -1887,7 +1885,7 @@ static void ChangeIndustryProduction(Industry *i)
if (str != STR_NULL) {
SetDParam(1, type + STR_4802_COAL_MINE);
SetDParam(0, i->town->index);
AddNewsItem(str, NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), i->xy + TILE_XY(1,1), 0);
AddNewsItem(str, NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), i->xy + TileDiffXY(1, 1), 0);
}
}

@ -376,7 +376,7 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
break;
case 6:
i = GetIndustry(w->window_number);
ScrollMainWindowToTile(i->xy + TILE_XY(1,1));
ScrollMainWindowToTile(i->xy + TileDiffXY(1, 1));
break;
}
}
@ -450,7 +450,7 @@ void ShowIndustryViewWindow(int industry)
WP(w,vp2_d).data_2 = 0;
WP(w,vp2_d).data_3 = 0;
i = GetIndustry(w->window_number);
AssignWindowViewport(w, 3, 17, 0xFE, 0x56, i->xy + TILE_XY(1,1), 1);
AssignWindowViewport(w, 3, 17, 0xFE, 0x56, i->xy + TileDiffXY(1, 1), 1);
}
}

@ -412,7 +412,7 @@ void RunTileLoop(void)
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 */
tile = TILE_MASK(tile - TILELOOP_SIZE * (MapSizeX() / TILELOOP_SIZE - 1) + TileDiffXY(0, TILELOOP_SIZE)); /* x would overflow, also increase y */
}
} while (--count);
assert( (tile & ~TILELOOP_ASSERTMASK) == 0);
@ -525,7 +525,7 @@ static void GenerateTerrain(int type, int flag)
if (y + h >= MapMaxY() - 1)
return;
tile = &_map_type_and_height[TILE_XY(x, y)];
tile = &_map_type_and_height[TileXY(x, y)];
switch (direction) {
case 0:
@ -538,7 +538,7 @@ static void GenerateTerrain(int type, int flag)
p++;
tile_cur++;
}
tile += TILE_XY(0, 1);
tile += TileDiffXY(0, 1);
} while (--h != 0);
break;
@ -550,14 +550,14 @@ static void GenerateTerrain(int type, int flag)
for (h_cur = h; h_cur != 0; --h_cur) {
if (*p >= *tile_cur) *tile_cur = *p;
p++;
tile_cur += TILE_XY(0, 1);
tile_cur += TileDiffXY(0, 1);
}
tile++;
} while (--w != 0);
break;
case 2:
tile += TILE_XY(w - 1, 0);
tile += TileDiffXY(w - 1, 0);
do {
byte *tile_cur = tile;
uint w_cur;
@ -567,12 +567,12 @@ static void GenerateTerrain(int type, int flag)
p++;
tile_cur--;
}
tile += TILE_XY(0, 1);
tile += TileDiffXY(0, 1);
} while (--h != 0);
break;
case 3:
tile += TILE_XY(0, h - 1);
tile += TileDiffXY(0, h - 1);
do {
byte *tile_cur = tile;
uint h_cur;
@ -580,7 +580,7 @@ static void GenerateTerrain(int type, int flag)
for (h_cur = h; h_cur != 0; --h_cur) {
if (*p >= *tile_cur) *tile_cur = *p;
p++;
tile_cur -= TILE_XY(0, 1);
tile_cur -= TileDiffXY(0, 1);
}
tile++;
} while (--w != 0);
@ -684,7 +684,7 @@ TileIndex AdjustTileCoordRandomly(TileIndex a, byte rng)
int rn = rng;
uint32 r = Random();
return TILE_MASK(TILE_XY(
return TILE_MASK(TileXY(
TileX(a) + ((byte)r * rn * 2 >> 8) - rn,
TileY(a) + ((byte)(r >> 8) * rn * 2 >> 8) - rn
));

@ -119,7 +119,7 @@ static inline int KillFirstBit2x64(int value)
#define END_TILE_LOOP(var,w,h,tile) \
} while (++var, --w_cur != 0); \
} while (var += TILE_XY(0,1) - (w), --h_cur != 0);}
} while (var += TileDiffXY(0, 1) - (w), --h_cur != 0);}
#define for_each_bit(_i,_b) \

@ -2421,14 +2421,14 @@ void SetupColorsAndInitialWindow(void)
switch(_game_mode) {
case GM_MENU:
w = AllocateWindow(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL);
AssignWindowViewport(w, 0, 0, width, height, TILE_XY(32, 32), 0);
AssignWindowViewport(w, 0, 0, width, height, TileXY(32, 32), 0);
// w = AllocateWindowDesc(&_toolb_intro_desc);
// w->flags4 &= ~WF_WHITE_BORDER_MASK;
ShowSelectGameWindow();
break;
case GM_NORMAL:
w = AllocateWindow(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL);
AssignWindowViewport(w, 0, 0, width, height, TILE_XY(32, 32), 0);
AssignWindowViewport(w, 0, 0, width, height, TileXY(32, 32), 0);
ShowVitalWindows();

10
map.c

@ -81,9 +81,9 @@ TileIndex TileAdd(TileIndex tile, TileIndexDiff add,
#endif
}
assert(TILE_XY(x,y) == TILE_MASK(tile + add));
assert(TileXY(x,y) == TILE_MASK(tile + add));
return TILE_XY(x,y);
return TileXY(x,y);
}
#endif
@ -115,7 +115,7 @@ uint ScaleByMapSize1D(uint n)
// addx = +3 and addy = -4. This function will now return
// INVALID_TILE, because the y is wrapped. This is needed in
// for example, farmland. When the tile is not wrapped,
// the result will be tile + TILE_XY(addx, addy)
// the result will be tile + TileDiffXY(addx, addy)
uint TileAddWrap(TileIndex tile, int addx, int addy)
{
uint x, y;
@ -123,8 +123,8 @@ uint TileAddWrap(TileIndex tile, int addx, int addy)
y = TileY(tile) + addy;
// Are we about to wrap?
if (x < MapMaxX() && y < MapMaxY())
return tile + TILE_XY(addx, addy);
if (x < MapMaxX() && y < MapMaxY())
return tile + TileDiffXY(addx, addy);
return INVALID_TILE;
}

19
map.h

@ -3,8 +3,6 @@
#include "stdafx.h"
#define TILE_XY(x,y) (((y) << MapLogX()) + (x))
#define TILE_MASK(x) ((x) & ((1 << (MapLogX() + MapLogY())) - 1))
#define TILE_ASSERT(x) assert(TILE_MASK(x) == (x));
@ -35,6 +33,17 @@ uint ScaleByMapSize(uint); // Scale relative to the number of tiles
uint ScaleByMapSize1D(uint); // Scale relative to the circumference of the map
typedef uint32 TileIndex;
typedef int32 TileIndexDiff;
static inline TileIndex TileXY(uint x, uint y)
{
return (y << MapLogX()) + x;
}
static inline TileIndexDiff TileDiffXY(int x, int y)
{
return (y << MapLogX()) + x;
}
static inline TileIndex TileVirtXY(uint x, uint y)
{
@ -70,8 +79,6 @@ static inline uint TileY(TileIndex tile)
}
typedef int32 TileIndexDiff;
typedef struct TileIndexDiffC {
int16 x;
int16 y;
@ -91,7 +98,7 @@ static inline TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
#define TILE_ADD(x, y) (TileAdd((x), (y), #x " + " #y, __FILE__, __LINE__))
#endif
#define TILE_ADDXY(tile, x, y) TILE_ADD(tile, TILE_XY(x, y))
#define TILE_ADDXY(tile, x, y) TILE_ADD(tile, TileDiffXY(x, y))
uint TileAddWrap(TileIndex tile, int addx, int addy);
@ -109,7 +116,7 @@ static inline TileIndex AddTileIndexDiffCWrap(TileIndex tile, TileIndexDiffC dif
if (x < 0 || y < 0 || x > (int)MapMaxX() || y > (int)MapMaxY())
return INVALID_TILE;
else
return TILE_XY(x, y);
return TileXY(x, y);
}
// Functions to calculate distances

@ -81,7 +81,7 @@ TileIndex CalcClosestStationTile(int station, TileIndex tile) {
ty = y3;
// return the tile of our target coordinates
return TILE_XY(tx,ty);
return TileXY(tx, ty);
};
/* Calcs the heuristic to the target station or tile. For train stations, it

@ -1292,7 +1292,7 @@ bool AfterLoadGame(uint version)
(0x402) version, so I just check when versions are older, and then
walk through the whole map.. */
if (version <= 0x402) {
TileIndex tile = TILE_XY(0,0);
TileIndex tile = TileXY(0, 0);
uint w = MapSizeX();
uint h = MapSizeY();

@ -227,8 +227,8 @@ static Order GetOrderCmdFromTile(Vehicle *v, TileIndex tile)
if (IsTileDepotType(tile, TRANSPORT_WATER) &&
IsTileOwner(tile, _local_player)) {
switch (_map5[tile]) {
case 0x81: tile--; break;
case 0x83: tile-= TILE_XY(0,1); break;
case 0x81: tile -= TileDiffXY(1, 0); break;
case 0x83: tile -= TileDiffXY(0, 1); break;
}
order.type = OT_GOTO_DEPOT;
order.flags = OF_PART_OF_ORDERS;

@ -1891,30 +1891,30 @@ static void TileLoop_Track(TileIndex tile)
owner = GetTileOwner(tile);
if ( (!(rail&(TRACK_BIT_DIAG2|TRACK_BIT_UPPER|TRACK_BIT_LEFT)) && (rail&TRACK_BIT_DIAG1)) || rail==(TRACK_BIT_LOWER|TRACK_BIT_RIGHT)) {
if (!IsTileType(tile + TILE_XY(0,-1), MP_RAILWAY) ||
!IsTileOwner(tile + TILE_XY(0, -1), owner) ||
(_map5[tile + TILE_XY(0,-1)]==TRACK_BIT_UPPER || _map5[tile + TILE_XY(0,-1)]==TRACK_BIT_LEFT))
if (!IsTileType(tile + TileDiffXY(0, -1), MP_RAILWAY) ||
!IsTileOwner(tile + TileDiffXY(0, -1), owner) ||
(_map5[tile + TileDiffXY(0, -1)] == TRACK_BIT_UPPER || _map5[tile + TileDiffXY(0, -1)] == TRACK_BIT_LEFT))
a2 = RAIL_GROUND_FENCE_NW;
}
if ( (!(rail&(TRACK_BIT_DIAG2|TRACK_BIT_LOWER|TRACK_BIT_RIGHT)) && (rail&TRACK_BIT_DIAG1)) || rail==(TRACK_BIT_UPPER|TRACK_BIT_LEFT)) {
if (!IsTileType(tile + TILE_XY(0,1), MP_RAILWAY) ||
!IsTileOwner(tile + TILE_XY(0, 1), owner) ||
(_map5[tile + TILE_XY(0,1)]==TRACK_BIT_LOWER || _map5[tile + TILE_XY(0,1)]==TRACK_BIT_RIGHT))
if (!IsTileType(tile + TileDiffXY(0, 1), MP_RAILWAY) ||
!IsTileOwner(tile + TileDiffXY(0, 1), owner) ||
(_map5[tile + TileDiffXY(0, 1)] == TRACK_BIT_LOWER || _map5[tile + TileDiffXY(0, 1)] == TRACK_BIT_RIGHT))
a2 = (a2 == RAIL_GROUND_FENCE_NW) ? RAIL_GROUND_FENCE_SENW : RAIL_GROUND_FENCE_SE;
}
if ( (!(rail&(TRACK_BIT_DIAG1|TRACK_BIT_UPPER|TRACK_BIT_RIGHT)) && (rail&TRACK_BIT_DIAG2)) || rail==(TRACK_BIT_LOWER|TRACK_BIT_LEFT)) {
if (!IsTileType(tile + TILE_XY(-1,0), MP_RAILWAY) ||
!IsTileOwner(tile + TILE_XY(-1, 0), owner) ||
(_map5[tile + TILE_XY(-1,0)]==TRACK_BIT_UPPER || _map5[tile + TILE_XY(-1,0)]==TRACK_BIT_RIGHT))
if (!IsTileType(tile + TileDiffXY(-1, 0), MP_RAILWAY) ||
!IsTileOwner(tile + TileDiffXY(-1, 0), owner) ||
(_map5[tile + TileDiffXY(-1, 0)] == TRACK_BIT_UPPER || _map5[tile + TileDiffXY(-1, 0)] == TRACK_BIT_RIGHT))
a2 = RAIL_GROUND_FENCE_NE;
}
if ( (!(rail&(TRACK_BIT_DIAG1|TRACK_BIT_LOWER|TRACK_BIT_LEFT)) && (rail&TRACK_BIT_DIAG2)) || rail==(TRACK_BIT_UPPER|TRACK_BIT_RIGHT)) {
if (!IsTileType(tile + TILE_XY(1,0), MP_RAILWAY) ||
!IsTileOwner(tile + TILE_XY(1, 0), owner) ||
(_map5[tile + TILE_XY(1,0)]==TRACK_BIT_LOWER || _map5[tile + TILE_XY(1,0)]==TRACK_BIT_LEFT))
if (!IsTileType(tile + TileDiffXY(1, 0), MP_RAILWAY) ||
!IsTileOwner(tile + TileDiffXY(1, 0), owner) ||
(_map5[tile + TileDiffXY(1, 0)] == TRACK_BIT_LOWER || _map5[tile + TileDiffXY(1, 0)] == TRACK_BIT_LEFT))
a2 = (a2 == RAIL_GROUND_FENCE_NE) ? RAIL_GROUND_FENCE_NESW : RAIL_GROUND_FENCE_SW;
}
}

@ -636,7 +636,7 @@ static void HandleStationPlacement(TileIndex start, TileIndex end)
// TODO: Custom station selector GUI. Now we just try using first custom station
// (and fall back to normal stations if it isn't available).
DoCommandP(TILE_XY(sx,sy), _railstation.orientation | (w<<8) | (h<<16),_cur_railtype|1<<4, CcStation,
DoCommandP(TileXY(sx, sy), _railstation.orientation | (w << 8) | (h << 16), _cur_railtype | 1 << 4, CcStation,
CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_AUTO | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION));
}

@ -548,7 +548,7 @@ int32 CmdBuildLongRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (tile == end_tile) break;
tile += HASBIT(p2, 2) ? TILE_XY(0, 1) : TILE_XY(1, 0);
tile += HASBIT(p2, 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
}
return (cost == 0) ? CMD_ERROR : cost;
@ -602,7 +602,7 @@ int32 CmdRemoveLongRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (tile == end_tile) break;
tile += HASBIT(p2, 2) ? TILE_XY(0, 1) : TILE_XY(1, 0);
tile += HASBIT(p2, 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
}
return (cost == 0) ? CMD_ERROR : cost;

@ -333,7 +333,7 @@ static void DrawSmallMapStuff(byte *dst, uint xc, uint yc, int pitch, int reps,
if (xc < MapMaxX() && yc < MapMaxY()) {
// check if the dst pointer points to a pixel inside the screen buffer
if (dst > _screen.dst_ptr && dst < dst_ptr_end)
WRITE_PIXELS_OR(dst, proc(TILE_XY(xc, yc)) & mask );
WRITE_PIXELS_OR(dst, proc(TileXY(xc, yc)) & mask);
}
// switch to next tile in the column
} while (xc++, yc++, dst += pitch, --reps != 0);

@ -175,7 +175,7 @@ static byte FindCatchmentRadius(Station *st)
static Station *GetStationAround(TileIndex tile, int w, int h, int closest_station)
{
// check around to see if there's any stations there
BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TILE_XY(1,1))
BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
if (IsTileType(tile_cur, MP_STATION)) {
int t;
t = _map2[tile_cur];
@ -193,7 +193,7 @@ static Station *GetStationAround(TileIndex tile, int w, int h, int closest_stati
return CHECK_STATIONS_ERR;
}
}
END_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TILE_XY(1,1))
END_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
return (closest_station == -1) ? NULL : GetStation(closest_station);
}
@ -550,7 +550,7 @@ void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile,
for (xc = x1; xc != x2; xc++) {
if (!(IS_INSIDE_1D(xc, x, w) && IS_INSIDE_1D(yc, y, h))) {
GetProducedCargoProc *gpc;
TileIndex tile = TILE_XY(xc, yc);
TileIndex tile = TileXY(xc, yc);
gpc = _tile_type_procs[GetTileType(tile)]->get_produced_cargo_proc;
if (gpc != NULL) {
@ -596,7 +596,7 @@ void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile,
for (yc = y1; yc != y2; yc++) {
for (xc = x1; xc != x2; xc++) {
TileIndex tile = TILE_XY(xc, yc);
TileIndex tile = TileXY(xc, yc);
if (!IsTileType(tile, MP_STATION)) {
AcceptedCargo ac;
@ -653,14 +653,14 @@ static void UpdateStationAcceptance(Station *st, bool show_msg)
if (st->train_tile != 0) {
MergePoint(&rect, st->train_tile);
MergePoint(&rect,
st->train_tile + TILE_XY(st->trainst_w - 1, st->trainst_h - 1)
st->train_tile + TileDiffXY(st->trainst_w - 1, st->trainst_h - 1)
);
}
if (st->airport_tile != 0) {
MergePoint(&rect, st->airport_tile);
MergePoint(&rect,
st->airport_tile + TILE_XY(
st->airport_tile + TileDiffXY(
_airport_size_x[st->airport_type] - 1,
_airport_size_y[st->airport_type] - 1
)
@ -687,7 +687,7 @@ static void UpdateStationAcceptance(Station *st, bool show_msg)
if (rect.max_x >= rect.min_x) {
GetAcceptanceAroundTiles(
accepts,
TILE_XY(rect.min_x, rect.min_y),
TileXY(rect.min_x, rect.min_y),
rect.max_x - rect.min_x + 1,
rect.max_y - rect.min_y + 1,
rad
@ -831,7 +831,7 @@ static bool CanExpandRailroadStation(Station *st, uint *fin, int direction)
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);
tile = TileXY(x, y);
} else {
// check so the direction is the same
if ((_map5[st->train_tile] & 1) != direction) {
@ -840,19 +840,19 @@ static bool CanExpandRailroadStation(Station *st, uint *fin, int direction)
}
// check if the new station adjoins the old station in either direction
if (curw == w && st->train_tile == tile + TILE_XY(0, h)) {
if (curw == w && st->train_tile == tile + TileDiffXY(0, h)) {
// above
curh += h;
} else if (curw == w && st->train_tile == tile - TILE_XY(0, curh)) {
} else if (curw == w && st->train_tile == tile - TileDiffXY(0, curh)) {
// below
tile -= TILE_XY(0, curh);
tile -= TileDiffXY(0, curh);
curh += h;
} else if (curh == h && st->train_tile == tile + TILE_XY(w, 0)) {
} else if (curh == h && st->train_tile == tile + TileDiffXY(w, 0)) {
// to the left
curw += w;
} else if (curh == h && st->train_tile == tile - TILE_XY(curw, 0)) {
} else if (curh == h && st->train_tile == tile - TileDiffXY(curw, 0)) {
// to the right
tile -= TILE_XY(curw, 0);
tile -= TileDiffXY(curw, 0);
curw += w;
} else {
_error_message = STR_306D_NONUNIFORM_STATIONS_DISALLOWED;
@ -1040,7 +1040,7 @@ int32 CmdBuildRailroadStation(int x, int y, uint32 flags, uint32 p1, uint32 p2)
st->build_date = _date;
tile_delta = direction ? TILE_XY(0,1) : TILE_XY(1,0);
tile_delta = direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
statspec = (p2 & 0x10) != 0 ? GetCustomStation(STAT_CLASS_DFLT, p2 >> 8) : NULL;
layout_ptr = alloca(numtracks * plat_len);
@ -1062,7 +1062,7 @@ int32 CmdBuildRailroadStation(int x, int y, uint32 flags, uint32 p1, uint32 p2)
tile += tile_delta;
} while (--w);
tile_org += tile_delta ^ TILE_XY(1,1);
tile_org += tile_delta ^ TileDiffXY(1, 1); // perpendicular to tile_delta
} while (--numtracks);
UpdateStationVirtCoordDirty(st);
@ -1090,24 +1090,42 @@ restart:
// too small?
if (w != 0 && h != 0) {
// check the left side, x = constant, y changes
for(i=0; !TileBelongsToRailStation(st, tile + TILE_XY(0,i)) ;)
for (i = 0; !TileBelongsToRailStation(st, tile + TileDiffXY(0, i));) {
// the left side is unused?
if (++i==h) { tile += TILE_XY(1, 0); w--; goto restart; }
if (++i == h) {
tile += TileDiffXY(1, 0);
w--;
goto restart;
}
}
// check the right side, x = constant, y changes
for(i=0; !TileBelongsToRailStation(st, tile + TILE_XY(w-1,i)) ;)
for (i = 0; !TileBelongsToRailStation(st, tile + TileDiffXY(w - 1, i));) {
// the right side is unused?
if (++i==h) { w--; goto restart; }
if (++i == h) {
w--;
goto restart;
}
}
// check the upper side, y = constant, x changes
for(i=0; !TileBelongsToRailStation(st, tile + TILE_XY(i,0)) ;)
for (i = 0; !TileBelongsToRailStation(st, tile + TileDiffXY(i, 0));) {
// the left side is unused?
if (++i==w) { tile += TILE_XY(0, 1); h--; goto restart; }
if (++i == w) {
tile += TileDiffXY(0, 1);
h--;
goto restart;
}
}
// check the lower side, y = constant, x changes
for(i=0; !TileBelongsToRailStation(st, tile + TILE_XY(i,h-1)) ;)
for (i = 0; !TileBelongsToRailStation(st, tile + TileDiffXY(i, h - 1));) {
// the left side is unused?
if (++i==w) { h--; goto restart; }
if (++i == w) {
h--;
goto restart;
}
}
} else {
tile = 0;
}
@ -1162,7 +1180,7 @@ uint GetStationPlatforms(Station *st, TileIndex tile)
len = 0;
dir = _map5[tile]&1;
delta = dir ? TILE_XY(0,1) : TILE_XY(1,0);
delta = dir ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
// find starting tile..
t = tile;
@ -1373,10 +1391,10 @@ static int32 RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags)
if (flags & DC_EXEC)
DoClearSquare(tile);
}
tile += TILE_XY(1, 0);
tile += TileDiffXY(1, 0);
} while (--w);
w = w_bak;
tile = tile + TILE_XY(-w, 1);
tile += TileDiffXY(-w, 1);
} while (--h);
if (flags & DC_EXEC) {
@ -2712,7 +2730,7 @@ uint MoveGoodsToStation(TileIndex tile, int w, int h, int type, uint amount)
max_rad = 4;
}
BEGIN_TILE_LOOP(cur_tile, w, h, tile - TILE_XY(max_rad,max_rad))
BEGIN_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad))
cur_tile = TILE_MASK(cur_tile);
if (IsTileType(cur_tile, MP_STATION)) {
st_index = _map2[cur_tile];
@ -2761,7 +2779,7 @@ uint MoveGoodsToStation(TileIndex tile, int w, int h, int type, uint amount)
break;
}
}
END_TILE_LOOP(cur_tile, w, h, tile - TILE_XY(max_rad, max_rad))
END_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad))
/* no stations around at all? */
if (around[0] == INVALID_STATION)

@ -47,7 +47,7 @@ static void GenerateDesertArea(TileIndex end, TileIndex start)
size_y = (ey - sy) + 1;
_generating_world = true;
BEGIN_TILE_LOOP(tile, size_x, size_y, TILE_XY(sx, sy)) {
BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
if (GetTileType(tile) != MP_WATER) {
SetMapExtraBits(tile, (_ctrl_pressed) ? 0 : 1);
DoCommandP(tile, 0, 0, NULL, CMD_LANDSCAPE_CLEAR);

@ -31,11 +31,11 @@ uint GetTileSlope(TileIndex tile, uint *h)
}
min = a = TileHeight(tile);
b = TileHeight(tile + TILE_XY(1,0));
b = TileHeight(tile + TileDiffXY(1, 0));
if (min >= b) min = b;
c = TileHeight(tile + TILE_XY(0,1));
c = TileHeight(tile + TileDiffXY(0, 1));
if (min >= c) min = c;
d = TileHeight(tile + TILE_XY(1,1));
d = TileHeight(tile + TileDiffXY(1, 1));
if (min >= d) min = d;
r = 0;

@ -1254,26 +1254,24 @@ static void DoBuildTownHouse(Town *t, TileIndex tile)
continue;
if (_housetype_extra_flags[house]&0x10) {
if (CheckFree2x2Area(t,tile) ||
CheckFree2x2Area(t,(tile+=TILE_XY(-1,0))) ||
CheckFree2x2Area(t,(tile+=TILE_XY(0,-1))) ||
CheckFree2x2Area(t,(tile+=TILE_XY(1,0))))
break;
tile += TILE_XY(0,1);
} else if (_housetype_extra_flags[house]&4) {
if (CheckBuildHouseMode(t, tile+TILE_XY(1,0), slope, 0))
if (CheckFree2x2Area(t, tile) ||
CheckFree2x2Area(t, (tile += TileDiffXY(-1, 0))) ||
CheckFree2x2Area(t, (tile += TileDiffXY( 0, -1))) ||
CheckFree2x2Area(t, (tile += TileDiffXY( 1, 0))))
break;
tile += TileDiffXY(0,1);
} else if (_housetype_extra_flags[house]&4) {
if (CheckBuildHouseMode(t, tile + TileDiffXY(1, 0), slope, 0)) break;
if (CheckBuildHouseMode(t, tile+TILE_XY(-1,0), slope, 1)) {
tile += TILE_XY(-1,0);
if (CheckBuildHouseMode(t, tile + TileDiffXY(-1, 0), slope, 1)) {
tile += TileDiffXY(-1, 0);
break;
}
} else if (_housetype_extra_flags[house]&8) {
if (CheckBuildHouseMode(t, tile+TILE_XY(0,1), slope, 2))
break;
if (CheckBuildHouseMode(t, tile + TileDiffXY(0, 1), slope, 2)) break;
if (CheckBuildHouseMode(t, tile+TILE_XY(0,-1), slope, 3)) {
tile += TILE_XY(0,-1);
if (CheckBuildHouseMode(t, tile + TileDiffXY(0, -1), slope, 3)) {
tile += TileDiffXY(0, -1);
break;
}
} else
@ -1320,8 +1318,8 @@ static void DoBuildTownHouse(Town *t, TileIndex tile)
eflags = _housetype_extra_flags[house];
if (eflags&0x18) {
assert(IsTileType(tile + TILE_XY(0,1), MP_CLEAR));
ModifyTile(tile + TILE_XY(0,1),
assert(IsTileType(tile + TileDiffXY(0, 1), MP_CLEAR));
ModifyTile(tile + TileDiffXY(0, 1),
MP_SETTYPE(MP_HOUSE) | MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5 | MP_MAPOWNER,
t->index,
m3lo, /* map3_lo */
@ -1332,8 +1330,8 @@ static void DoBuildTownHouse(Town *t, TileIndex tile)
}
if (eflags&0x14) {
assert(IsTileType(tile + TILE_XY(1,0), MP_CLEAR));
ModifyTile(tile + TILE_XY(1,0),
assert(IsTileType(tile + TileDiffXY(1, 0), MP_CLEAR));
ModifyTile(tile + TileDiffXY(1, 0),
MP_SETTYPE(MP_HOUSE) | MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5 | MP_MAPOWNER,
t->index,
m3lo, /* map3_lo */
@ -1344,8 +1342,8 @@ static void DoBuildTownHouse(Town *t, TileIndex tile)
}
if (eflags&0x10) {
assert(IsTileType(tile + TILE_XY(1,1), MP_CLEAR));
ModifyTile(tile + TILE_XY(1,1),
assert(IsTileType(tile + TileDiffXY(1, 1), MP_CLEAR));
ModifyTile(tile + TileDiffXY(1, 1),
MP_SETTYPE(MP_HOUSE) | MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5 | MP_MAPOWNER,
t->index,
m3lo, /* map3_lo */
@ -1393,16 +1391,16 @@ static void ClearTownHouse(Town *t, TileIndex tile)
if (house >= 3) { // house id 0,1,2 MUST be single tile houses, or this code breaks.
if (_housetype_extra_flags[house-1] & 0x04) {
house--;
tile += TILE_XY(-1,0);
tile += TileDiffXY(-1, 0);
} else if (_housetype_extra_flags[house-1] & 0x18) {
house--;
tile += TILE_XY(0,-1);
tile += TileDiffXY(0, -1);
} else if (_housetype_extra_flags[house-2] & 0x10) {
house-=2;
tile += TILE_XY(-1,0);
tile += TileDiffXY(-1, 0);
} else if (_housetype_extra_flags[house-3] & 0x10) {
house-=3;
tile += TILE_XY(-1,-1);
tile += TileDiffXY(-1, -1);
}
}
@ -1434,9 +1432,9 @@ static void ClearTownHouse(Town *t, TileIndex tile)
// Do the actual clearing of tiles
eflags = _housetype_extra_flags[house];
DoClearTownHouseHelper(tile);
if (eflags & 0x14) DoClearTownHouseHelper(tile + TILE_XY(1,0));
if (eflags & 0x18) DoClearTownHouseHelper(tile + TILE_XY(0,1));
if (eflags & 0x10) DoClearTownHouseHelper(tile + TILE_XY(1,1));
if (eflags & 0x14) DoClearTownHouseHelper(tile + TileDiffXY(1, 0));
if (eflags & 0x18) DoClearTownHouseHelper(tile + TileDiffXY(0, 1));
if (eflags & 0x10) DoClearTownHouseHelper(tile + TileDiffXY(1, 1));
}
/** Rename a town (server-only).

@ -81,7 +81,7 @@ static void DoPlaceMoreTrees(TileIndex tile)
dist = myabs(x) + myabs(y);
cur_tile = TILE_MASK(tile + TILE_XY(x,y));
cur_tile = TILE_MASK(tile + TileDiffXY(x, y));
/* Only on tiles within 13 squares from tile,
on clear tiles, and NOT on farm-tiles or rocks */

@ -669,7 +669,7 @@ static TileIndex FindEdgesOfBridge(TileIndex tile, TileIndex *endtile)
for(;;) {
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xE0) == 0x80)
break;
tile += direction ? TILE_XY(0,-1) : TILE_XY(-1,0);
tile += direction ? TileDiffXY(0, -1) : TileDiffXY(-1, 0);
}
start = tile;
@ -678,7 +678,7 @@ static TileIndex FindEdgesOfBridge(TileIndex tile, TileIndex *endtile)
for(;;) {
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xE0) == 0xA0)
break;
tile += direction ? TILE_XY(0,1) : TILE_XY(1,0);
tile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
}
*endtile = tile;
@ -745,8 +745,8 @@ static int32 DoClearBridge(TileIndex tile, uint32 flags)
Omit tile and endtile, since these are already checked, thus solving the problem
of bridges over water, or higher bridges, where z is not increased, eg level bridge
*/
tile += direction ? TILE_XY(0, 1) : TILE_XY( 1,0);
endtile -= direction ? TILE_XY(0, 1) : TILE_XY( 1,0);
tile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
endtile -= direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
/* Bridges on slopes might have their Z-value offset..correct this */
if ((v = FindVehicleBetween(tile, endtile, TilePixelHeight(tile) + 8 + GetCorrectTileHeight(tile))) != NULL) {
VehicleInTheWayErrMsg(v);
@ -754,8 +754,8 @@ static int32 DoClearBridge(TileIndex tile, uint32 flags)
}
/* Put the tiles back to start/end position */
tile -= direction ? TILE_XY(0, 1) : TILE_XY( 1,0);
endtile += direction ? TILE_XY(0, 1) : TILE_XY( 1,0);
tile -= direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
endtile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty
@ -798,7 +798,7 @@ static int32 DoClearBridge(TileIndex tile, uint32 flags)
clear_it:;
DoClearSquare(c);
}
c += direction ? TILE_XY(0,1) : TILE_XY(1,0);
c += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
} while (c <= endtile);
SetSignalsOnBothDir(tile, direction);
@ -898,7 +898,7 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec)
MarkTileDirtyByTile(tile);
}
cost += (_price.build_rail>>1);
tile += _map5[tile]&1 ? TILE_XY(0,1) : TILE_XY(1,0);
tile += _map5[tile] & 1 ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
} while (tile <= endtile);
return cost;
@ -910,11 +910,11 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec)
// fast routine for getting the height of a middle bridge tile. 'tile' MUST be a middle bridge tile.
static uint GetBridgeHeight(const TileInfo *ti)
{
uint delta;
TileIndexDiff delta;
TileIndex tile = ti->tile;
// find the end tile of the bridge.
delta = (_map5[tile] & 1) ? TILE_XY(0,1) : TILE_XY(1,0);
delta = (_map5[tile] & 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
do {
assert((_map5[tile] & 0xC0) == 0xC0); // bridge and middle part
tile += delta;
@ -1267,8 +1267,6 @@ static const StringID _bridge_tile_str[(MAX_BRIDGES + 3) + (MAX_BRIDGES + 3)] =
static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
{
int delta;
if ((_map5[tile] & 0x80) == 0) {
td->str = STR_5017_RAILROAD_TUNNEL + ((_map5[tile] >> 2) & 3);
} else {
@ -1276,7 +1274,8 @@ static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
/* scan to the end of the bridge, that's where the owner is stored */
if (_map5[tile] & 0x40) {
delta = _map5[tile] & 1 ? TILE_XY(0,-1) : TILE_XY(-1,0);
TileIndexDiff delta = _map5[tile] & 1 ? TileDiffXY(0, -1) : TileDiffXY(-1, 0);
do tile += delta; while (_map5[tile] & 0x40);
}
}
@ -1495,7 +1494,7 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y
TileIndex GetVehicleOutOfTunnelTile(const Vehicle *v)
{
TileIndex tile;
TileIndexDiff delta = (v->direction & 2) ? TILE_XY(0, 1) : TILE_XY(1, 0);
TileIndexDiff delta = (v->direction & 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
byte z = v->z_pos;
for (tile = v->tile;; tile += delta) {

@ -41,10 +41,10 @@ int32 DestroyCompanyHQ(TileIndex tile, uint32 flags)
if (p->location_of_house == 0) return CMD_ERROR;
if (flags & DC_EXEC) {
DoClearSquare(p->location_of_house + TILE_XY(0,0));
DoClearSquare(p->location_of_house + TILE_XY(0,1));
DoClearSquare(p->location_of_house + TILE_XY(1,0));
DoClearSquare(p->location_of_house + TILE_XY(1,1));
DoClearSquare(p->location_of_house + TileDiffXY(0, 0));
DoClearSquare(p->location_of_house + TileDiffXY(0, 1));
DoClearSquare(p->location_of_house + TileDiffXY(1, 0));
DoClearSquare(p->location_of_house + TileDiffXY(1, 1));
p->location_of_house = 0; // reset HQ position
InvalidateWindow(WC_COMPANY, (int)p->index);
}
@ -89,10 +89,10 @@ int32 CmdBuildCompanyHQ(int x, int y, uint32 flags, uint32 p1, uint32 p2)
p->location_of_house = tile;
ModifyTile(tile + TILE_XY(0,0), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x80);
ModifyTile(tile + TILE_XY(0,1), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x81);
ModifyTile(tile + TILE_XY(1,0), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x82);
ModifyTile(tile + TILE_XY(1,1), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x83);
ModifyTile(tile + TileDiffXY(0, 0), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x80);
ModifyTile(tile + TileDiffXY(0, 1), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x81);
ModifyTile(tile + TileDiffXY(1, 0), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x82);
ModifyTile(tile + TileDiffXY(1, 1), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x83);
UpdatePlayerHouse(p, score);
InvalidateWindow(WC_COMPANY, (int)p->index);
}
@ -322,9 +322,7 @@ static const TileIndexDiffC _tile_add[] = {
/* checks, if a radio tower is within a 9x9 tile square around tile */
static bool checkRadioTowerNearby(TileIndex tile)
{
TileIndex tile_s;
tile_s = TILE_XY(TileX(tile) - 4, TileY(tile) - 4);
TileIndex tile_s = tile - TileDiffXY(4, 4);
BEGIN_TILE_LOOP(tile, 9, 9, tile_s)
// already a radio tower here?
@ -375,10 +373,10 @@ restart:
dir = r >> 30;
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(MapMaxX(), r) : 0 + // right
(dir == 3) ? TILE_XY(r, MapMaxY()) : 0; // bottom
(dir == 0) ? TileXY(0, r) : 0 + // left
(dir == 1) ? TileXY(r, 0) : 0 + // top
(dir == 2) ? TileXY(MapMaxX(), r) : 0 + // right
(dir == 3) ? TileXY(r, MapMaxY()) : 0; // bottom
j = 20;
do {
if (--j == 0)

@ -41,7 +41,7 @@ int32 CmdBuildShipDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
tile = TileVirtXY(x, y);
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
tile2 = tile + (p1 ? TILE_XY(0,1) : TILE_XY(1,0));
tile2 = tile + (p1 ? TileDiffXY(0, 1) : TileDiffXY(1, 0));
if (!EnsureNoVehicle(tile2)) return CMD_ERROR;
if (!IsClearWaterTile(tile) || !IsClearWaterTile(tile2))
@ -87,7 +87,7 @@ static int32 RemoveShipDepot(TileIndex tile, uint32 flags)
if (!EnsureNoVehicle(tile))
return CMD_ERROR;
tile2 = tile + ((_map5[tile] & 2) ? TILE_XY(0,1) : TILE_XY(1,0));
tile2 = tile + ((_map5[tile] & 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0));
if (!EnsureNoVehicle(tile2))
return CMD_ERROR;
@ -210,7 +210,7 @@ int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (_game_mode != GM_EDITOR && (sx != x && sy != y)) return CMD_ERROR;
cost = 0;
BEGIN_TILE_LOOP(tile, size_x, size_y, TILE_XY(sx, sy)) {
BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
ret = 0;
if (GetTileSlope(tile, NULL) != 0) return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
@ -306,8 +306,8 @@ static int32 ClearTile_Water(TileIndex tile, byte flags)
return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
if (m5 == 0x80 || m5 == 0x82) {}
else if (m5 == 0x81) { tile -= TILE_XY(1,0); }
else if (m5 == 0x83) { tile -= TILE_XY(0,1); }
else if (m5 == 0x81) { tile -= TileDiffXY(1, 0); }
else if (m5 == 0x83) { tile -= TileDiffXY(0, 1); }
else
return CMD_ERROR;
@ -680,7 +680,7 @@ static void ClickTile_Water(TileIndex tile)
if (IS_BYTE_INSIDE(m5, 0, 3+1)) {
if (m5 & 1)
tile += (m5==1) ? TILE_XY(-1,0) : TILE_XY(0,-1);
tile += (m5 == 1) ? TileDiffXY(-1, 0) : TileDiffXY(0, -1);
ShowShipDepotWindow(tile);
}
}

Loading…
Cancel
Save