mirror of https://github.com/OpenTTD/OpenTTD
(svn r4263) -Codechange: Road building no longer uses FindLandscapeHeight. Last occurence of FindLandscapeTile in the tile-specific functions gone. Thanks to Tron for doing lots of work in this direction
parent
1b51ad3dde
commit
857ccb97c9
20
road_cmd.c
20
road_cmd.c
|
@ -277,12 +277,12 @@ static uint32 CheckRoadSlope(int tileh, RoadBits* pieces, RoadBits existing)
|
||||||
*/
|
*/
|
||||||
int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
{
|
{
|
||||||
TileInfo ti;
|
|
||||||
int32 cost = 0;
|
int32 cost = 0;
|
||||||
int32 ret;
|
int32 ret;
|
||||||
RoadBits existing = 0;
|
RoadBits existing = 0;
|
||||||
RoadBits pieces;
|
RoadBits pieces;
|
||||||
TileIndex tile;
|
TileIndex tile;
|
||||||
|
byte tileh;
|
||||||
|
|
||||||
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
||||||
|
|
||||||
|
@ -291,10 +291,10 @@ int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
if ((p1 >> 4) || (_current_player < MAX_PLAYERS && p2 != 0) || !IsTownIndex(p2)) return CMD_ERROR;
|
if ((p1 >> 4) || (_current_player < MAX_PLAYERS && p2 != 0) || !IsTownIndex(p2)) return CMD_ERROR;
|
||||||
pieces = p1;
|
pieces = p1;
|
||||||
|
|
||||||
FindLandscapeHeight(&ti, x, y);
|
tile = TileVirtXY(x, y);
|
||||||
tile = ti.tile;
|
tileh = GetTileSlope(tile, NULL);
|
||||||
|
|
||||||
switch (ti.type) {
|
switch (GetTileType(tile)) {
|
||||||
case MP_STREET:
|
case MP_STREET:
|
||||||
switch (GetRoadType(tile)) {
|
switch (GetRoadType(tile)) {
|
||||||
case ROAD_NORMAL:
|
case ROAD_NORMAL:
|
||||||
|
@ -320,13 +320,13 @@ int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
case MP_RAILWAY: {
|
case MP_RAILWAY: {
|
||||||
Axis roaddir;
|
Axis roaddir;
|
||||||
|
|
||||||
if (IsSteepTileh(ti.tileh)) { // very steep tile
|
if (IsSteepTileh(tileh)) { // very steep tile
|
||||||
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define M(x) (1 << (x))
|
#define M(x) (1 << (x))
|
||||||
/* Level crossings may only be built on these slopes */
|
/* Level crossings may only be built on these slopes */
|
||||||
if (!HASBIT(M(14) | M(13) | M(11) | M(10) | M(7) | M(5) | M(0), ti.tileh)) {
|
if (!HASBIT(M(14) | M(13) | M(11) | M(10) | M(7) | M(5) | M(0), tileh)) {
|
||||||
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
||||||
}
|
}
|
||||||
#undef M
|
#undef M
|
||||||
|
@ -357,7 +357,7 @@ int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
|
|
||||||
case MP_TUNNELBRIDGE:
|
case MP_TUNNELBRIDGE:
|
||||||
/* check for flat land */
|
/* check for flat land */
|
||||||
if (IsSteepTileh(ti.tileh)) { // very steep tile
|
if (IsSteepTileh(tileh)) { // very steep tile
|
||||||
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,14 +393,14 @@ do_clear:;
|
||||||
cost += ret;
|
cost += ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = CheckRoadSlope(ti.tileh, &pieces, existing);
|
ret = CheckRoadSlope(tileh, &pieces, existing);
|
||||||
if (CmdFailed(ret)) return_cmd_error(STR_1800_LAND_SLOPED_IN_WRONG_DIRECTION);
|
if (CmdFailed(ret)) return_cmd_error(STR_1800_LAND_SLOPED_IN_WRONG_DIRECTION);
|
||||||
if (ret != 0 && (!_patches.build_on_slopes || _is_old_ai_player)) {
|
if (ret != 0 && (!_patches.build_on_slopes || _is_old_ai_player)) {
|
||||||
return CMD_ERROR;
|
return CMD_ERROR;
|
||||||
}
|
}
|
||||||
cost += ret;
|
cost += ret;
|
||||||
|
|
||||||
if (ti.type == MP_STREET) {
|
if (IsTileType(tile, MP_STREET)) {
|
||||||
// Don't put the pieces that already exist
|
// Don't put the pieces that already exist
|
||||||
pieces &= ComplementRoadBits(existing);
|
pieces &= ComplementRoadBits(existing);
|
||||||
}
|
}
|
||||||
|
@ -408,7 +408,7 @@ do_clear:;
|
||||||
cost += CountRoadBits(pieces) * _price.build_road;
|
cost += CountRoadBits(pieces) * _price.build_road;
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
if (ti.type == MP_STREET) {
|
if (IsTileType(tile, MP_STREET)) {
|
||||||
SetRoadBits(tile, existing | pieces);
|
SetRoadBits(tile, existing | pieces);
|
||||||
} else {
|
} else {
|
||||||
MakeRoadNormal(tile, _current_player, pieces, p2);
|
MakeRoadNormal(tile, _current_player, pieces, p2);
|
||||||
|
|
Loading…
Reference in New Issue