(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)

This commit is contained in:
celestar
2006-12-27 12:38:02 +00:00
parent d92103d6ff
commit d95e2c2dd1
39 changed files with 845 additions and 1179 deletions

View File

@@ -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 (!EnsureNoVehicle(tile)) return CMD_ERROR;
if (!IsBridge(tile) ||
!IsBridgeMiddle(tile) ||
!IsTransportUnderBridge(tile) ||
GetTransportTypeUnderBridge(tile) != TRANSPORT_ROAD ||
(pieces & ComplementRoadBits(GetRoadBitsUnderBridge(tile))) != 0) {
// 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;
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;
}
// 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);
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);
SetClearUnderBridge(tile);
MakeRailNormal(tile, GetTileOwner(tile), GetCrossingRailBits(tile), GetRailTypeCrossing(tile));
MarkTileDirtyByTile(tile);
YapfNotifyTrackLayoutChange(tile, FIND_FIRST_BIT(GetTrackBits(tile)));
}
return _price.remove_road * 2;
}
case MP_STREET:
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;
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 (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;
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;
}
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);
MakeRailNormal(tile, GetTileOwner(tile), GetCrossingRailBits(tile), GetRailTypeCrossing(tile));
MarkTileDirtyByTile(tile);
YapfNotifyTrackLayoutChange(tile, FIND_FIRST_BIT(GetTrackBits(tile)));
}
return _price.remove_road * 2;
}
default:
case ROAD_TILE_DEPOT:
return CMD_ERROR;
}
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)