mirror of https://github.com/OpenTTD/OpenTTD
(svn r18803) -Feature [FS#3318]: make building (long) roads work like building rail; build upon the first obstruction instead of failing totally. Patch by Terkhen.
parent
ed83388faa
commit
c390e8f00e
|
@ -697,9 +697,9 @@ do_clear:;
|
|||
}
|
||||
|
||||
/** Build a long piece of road.
|
||||
* @param end_tile end tile of drag
|
||||
* @param start_tile start tile of drag (the building cost will appear over this tile)
|
||||
* @param flags operation to perform
|
||||
* @param p1 start tile of drag
|
||||
* @param p1 end tile of drag
|
||||
* @param p2 various bitstuffed elements
|
||||
* - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
|
||||
* - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
|
||||
|
@ -709,7 +709,7 @@ do_clear:;
|
|||
* @param text unused
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
CommandCost CmdBuildLongRoad(TileIndex end_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||
CommandCost CmdBuildLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||
{
|
||||
CommandCost cost(EXPENSES_CONSTRUCTION);
|
||||
bool had_bridge = false;
|
||||
|
@ -721,7 +721,7 @@ CommandCost CmdBuildLongRoad(TileIndex end_tile, DoCommandFlag flags, uint32 p1,
|
|||
|
||||
if (p1 >= MapSize()) return CMD_ERROR;
|
||||
|
||||
TileIndex start_tile = p1;
|
||||
TileIndex end_tile = p1;
|
||||
RoadType rt = (RoadType)GB(p2, 3, 2);
|
||||
if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
|
||||
|
||||
|
@ -730,12 +730,12 @@ CommandCost CmdBuildLongRoad(TileIndex end_tile, DoCommandFlag flags, uint32 p1,
|
|||
if (axis == AXIS_X && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
|
||||
if (axis == AXIS_Y && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
|
||||
|
||||
/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */
|
||||
DiagDirection dir = AxisToDiagDir(axis);
|
||||
|
||||
/* Swap direction, also the half-tile drag var (bit 0 and 1) */
|
||||
if (start_tile > end_tile || (start_tile == end_tile && HasBit(p2, 0))) {
|
||||
TileIndex t = start_tile;
|
||||
start_tile = end_tile;
|
||||
end_tile = t;
|
||||
p2 ^= IsInsideMM(p2 & 3, 1, 3) ? 3 : 0;
|
||||
dir = ReverseDiagDir(dir);
|
||||
p2 ^= 3;
|
||||
drd = DRD_SOUTHBOUND;
|
||||
}
|
||||
|
||||
|
@ -747,28 +747,29 @@ CommandCost CmdBuildLongRoad(TileIndex end_tile, DoCommandFlag flags, uint32 p1,
|
|||
if (!HasBit(p2, 5)) drd = DRD_NONE;
|
||||
|
||||
TileIndex tile = start_tile;
|
||||
/* Start tile is the small number. */
|
||||
/* Start tile is the first tile clicked by the user. */
|
||||
for (;;) {
|
||||
RoadBits bits = AxisToRoadBits(axis);
|
||||
|
||||
if (tile == end_tile && !HasBit(p2, 1)) bits &= ROAD_NW | ROAD_NE;
|
||||
if (tile == start_tile && HasBit(p2, 0)) bits &= ROAD_SE | ROAD_SW;
|
||||
/* Road parts only have to be built at the start tile or at the end tile. */
|
||||
if (tile == end_tile && !HasBit(p2, 1)) bits &= DiagDirToRoadBits(ReverseDiagDir(dir));
|
||||
if (tile == start_tile && HasBit(p2, 0)) bits &= DiagDirToRoadBits(dir);
|
||||
|
||||
_error_message = INVALID_STRING_ID;
|
||||
CommandCost ret = DoCommand(tile, drd << 6 | rt << 4 | bits, 0, flags, CMD_BUILD_ROAD);
|
||||
if (CmdFailed(ret)) {
|
||||
if (_error_message != STR_ERROR_ALREADY_BUILT) return CMD_ERROR;
|
||||
if (_error_message != STR_ERROR_ALREADY_BUILT) break;
|
||||
} else {
|
||||
had_success = true;
|
||||
/* Only pay for the upgrade on one side of the bridges and tunnels */
|
||||
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
|
||||
if (IsBridge(tile)) {
|
||||
if ((!had_bridge || GetTunnelBridgeDirection(tile) == DIAGDIR_SE || GetTunnelBridgeDirection(tile) == DIAGDIR_SW)) {
|
||||
if ((!had_bridge || GetTunnelBridgeDirection(tile) == dir)) {
|
||||
cost.AddCost(ret);
|
||||
}
|
||||
had_bridge = true;
|
||||
} else { // IsTunnel(tile)
|
||||
if ((!had_tunnel || GetTunnelBridgeDirection(tile) == DIAGDIR_SE || GetTunnelBridgeDirection(tile) == DIAGDIR_SW)) {
|
||||
if ((!had_tunnel || GetTunnelBridgeDirection(tile) == dir)) {
|
||||
cost.AddCost(ret);
|
||||
}
|
||||
had_tunnel = true;
|
||||
|
@ -780,7 +781,7 @@ CommandCost CmdBuildLongRoad(TileIndex end_tile, DoCommandFlag flags, uint32 p1,
|
|||
|
||||
if (tile == end_tile) break;
|
||||
|
||||
tile += (axis == AXIS_Y) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
|
||||
tile += TileOffsByDiagDir(dir);
|
||||
}
|
||||
|
||||
return !had_success ? CMD_ERROR : cost;
|
||||
|
|
|
@ -605,7 +605,7 @@ struct BuildRoadToolbarWindow : Window {
|
|||
* not the 3rd bit set) */
|
||||
_place_road_flag = (RoadFlags)((_place_road_flag & RF_DIR_Y) ? (_place_road_flag & 0x07) : (_place_road_flag >> 3));
|
||||
|
||||
DoCommandP(end_tile, start_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5),
|
||||
DoCommandP(start_tile, end_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5),
|
||||
_remove_button_clicked ?
|
||||
CMD_REMOVE_LONG_ROAD | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_road) :
|
||||
CMD_BUILD_LONG_ROAD | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_road), CcPlaySound1D);
|
||||
|
|
Loading…
Reference in New Issue