summaryrefslogtreecommitdiff
path: root/road_cmd.c
diff options
context:
space:
mode:
authorcelestar <celestar@openttd.org>2006-12-27 12:38:02 +0000
committercelestar <celestar@openttd.org>2006-12-27 12:38:02 +0000
commit8cd5daa5334e8193d47240b78a39afaed6a0473a (patch)
tree28100daed109de06e979123edd0601487ecc8261 /road_cmd.c
parent98e6c790e09e550a6cc0585b2084d26f8c7e51f5 (diff)
downloadopenttd-8cd5daa5334e8193d47240b78a39afaed6a0473a.tar.xz
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
Diffstat (limited to 'road_cmd.c')
-rw-r--r--road_cmd.c147
1 files changed, 47 insertions, 100 deletions
diff --git a/road_cmd.c b/road_cmd.c
index 116efd547..9f3bc3f6a 100644
--- a/road_cmd.c
+++ b/road_cmd.c
@@ -105,103 +105,73 @@ int32 CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (p1 >> 4) return CMD_ERROR;
pieces = p1;
- if (!IsTileType(tile, MP_STREET) && !IsTileType(tile, MP_TUNNELBRIDGE)) return CMD_ERROR;
+ if (!IsTileType(tile, MP_STREET)) return CMD_ERROR;
owner = IsLevelCrossingTile(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile);
if (owner == OWNER_TOWN && _game_mode != GM_EDITOR) {
- /* Are we removing a piece of road below a bridge, or not. If below
- * a bridge we need to calculate the town's index as it is not saved
- * in the map array (no space) */
- if (IsTileType(tile, MP_TUNNELBRIDGE)) {
- t = ClosestTownFromTile(tile, _patches.dist_local_authority);
- } else {
- t = GetTownByTile(tile);
- }
+ t = GetTownByTile(tile);
} else {
t = NULL;
}
if (!CheckAllowRemoveRoad(tile, pieces, &edge_road)) return CMD_ERROR;
- switch (GetTileType(tile)) {
- case MP_TUNNELBRIDGE:
- if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
-
- if (!IsBridge(tile) ||
- !IsBridgeMiddle(tile) ||
- !IsTransportUnderBridge(tile) ||
- GetTransportTypeUnderBridge(tile) != TRANSPORT_ROAD ||
- (pieces & ComplementRoadBits(GetRoadBitsUnderBridge(tile))) != 0) {
- return CMD_ERROR;
- }
-
- if (flags & DC_EXEC) {
- ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
- SetClearUnderBridge(tile);
- MarkTileDirtyByTile(tile);
- }
- return _price.remove_road * 2;
-
- case MP_STREET:
- if (!EnsureNoVehicle(tile)) return CMD_ERROR;
+ if (!EnsureNoVehicle(tile)) return CMD_ERROR;
- // check if you're allowed to remove the street owned by a town
- // removal allowance depends on difficulty setting
- if (!CheckforTownRating(flags, t, ROAD_REMOVE)) return CMD_ERROR;
+ // check if you're allowed to remove the street owned by a town
+ // removal allowance depends on difficulty setting
+ if (!CheckforTownRating(flags, t, ROAD_REMOVE)) return CMD_ERROR;
- switch (GetRoadTileType(tile)) {
- case ROAD_TILE_NORMAL: {
- RoadBits present = GetRoadBits(tile);
- RoadBits c = pieces;
+ switch (GetRoadTileType(tile)) {
+ case ROAD_TILE_NORMAL: {
+ RoadBits present = GetRoadBits(tile);
+ RoadBits c = pieces;
- if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
+ if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
- if (GetTileSlope(tile, NULL) != SLOPE_FLAT &&
- (present == ROAD_Y || present == ROAD_X)) {
- c |= (c & 0xC) >> 2;
- c |= (c & 0x3) << 2;
- }
+ if (GetTileSlope(tile, NULL) != SLOPE_FLAT &&
+ (present == ROAD_Y || present == ROAD_X)) {
+ c |= (c & 0xC) >> 2;
+ c |= (c & 0x3) << 2;
+ }
- // limit the bits to delete to the existing bits.
- c &= present;
- if (c == 0) return CMD_ERROR;
+ // limit the bits to delete to the existing bits.
+ c &= present;
+ if (c == 0) return CMD_ERROR;
- if (flags & DC_EXEC) {
- ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
+ if (flags & DC_EXEC) {
+ ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
- present ^= c;
- if (present == 0) {
- DoClearSquare(tile);
- } else {
- SetRoadBits(tile, present);
- MarkTileDirtyByTile(tile);
- }
- }
- return CountRoadBits(c) * _price.remove_road;
+ present ^= c;
+ if (present == 0) {
+ DoClearSquare(tile);
+ } else {
+ SetRoadBits(tile, present);
+ MarkTileDirtyByTile(tile);
}
+ }
+ return CountRoadBits(c) * _price.remove_road;
+ }
- case ROAD_TILE_CROSSING: {
- if (pieces & ComplementRoadBits(GetCrossingRoadBits(tile))) {
- return CMD_ERROR;
- }
-
- if (flags & DC_EXEC) {
- ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
+ case ROAD_TILE_CROSSING: {
+ if (pieces & ComplementRoadBits(GetCrossingRoadBits(tile))) {
+ return CMD_ERROR;
+ }
- MakeRailNormal(tile, GetTileOwner(tile), GetCrossingRailBits(tile), GetRailTypeCrossing(tile));
- MarkTileDirtyByTile(tile);
- YapfNotifyTrackLayoutChange(tile, FIND_FIRST_BIT(GetTrackBits(tile)));
- }
- return _price.remove_road * 2;
- }
+ if (flags & DC_EXEC) {
+ ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
- default:
- case ROAD_TILE_DEPOT:
- return CMD_ERROR;
+ MakeRailNormal(tile, GetTileOwner(tile), GetCrossingRailBits(tile), GetRailTypeCrossing(tile));
+ MarkTileDirtyByTile(tile);
+ YapfNotifyTrackLayoutChange(tile, FIND_FIRST_BIT(GetTrackBits(tile)));
}
+ return _price.remove_road * 2;
+ }
- default: return CMD_ERROR;
+ default:
+ case ROAD_TILE_DEPOT:
+ return CMD_ERROR;
}
}
@@ -362,32 +332,6 @@ int32 CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
return _price.build_road * 2;
}
- case MP_TUNNELBRIDGE:
- if (!IsBridge(tile) || !IsBridgeMiddle(tile)) goto do_clear;
-
- /* only allow roads pertendicular to bridge */
- if ((pieces & (GetBridgeAxis(tile) == AXIS_X ? ROAD_X : ROAD_Y)) != 0) {
- goto do_clear;
- }
-
- /* check if clear land under bridge */
- if (IsTransportUnderBridge(tile)) {
- switch (GetTransportTypeUnderBridge(tile)) {
- case TRANSPORT_ROAD: return_cmd_error(STR_1007_ALREADY_BUILT);
- default: return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK);
- }
- } else {
- if (IsWaterUnderBridge(tile)) {
- return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
- }
- }
-
- if (flags & DC_EXEC) {
- SetRoadUnderBridge(tile, _current_player);
- MarkTileDirtyByTile(tile);
- }
- return _price.build_road * 2;
-
default:
do_clear:;
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
@@ -587,6 +531,8 @@ int32 CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (CmdFailed(cost)) return CMD_ERROR;
+ if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
+
dep = AllocateDepot();
if (dep == NULL) return CMD_ERROR;
@@ -820,6 +766,7 @@ static void DrawTile_Road(TileInfo *ti)
break;
}
}
+ DrawBridgeMiddle(ti);
}
void DrawRoadDepotSprite(int x, int y, DiagDirection dir)