mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r19230) -Feature: Allow to remove multiple road stops using drag and drop.
This commit is contained in:
parent
70b1bc5048
commit
aba24e44cf
|
@ -578,7 +578,7 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia
|
||||||
EnforcePrecondition(false, IsTileType(tile, MP_STATION));
|
EnforcePrecondition(false, IsTileType(tile, MP_STATION));
|
||||||
EnforcePrecondition(false, IsRoadStop(tile));
|
EnforcePrecondition(false, IsRoadStop(tile));
|
||||||
|
|
||||||
return AIObject::DoCommand(tile, 0, GetRoadStopType(tile), CMD_REMOVE_ROAD_STOP);
|
return AIObject::DoCommand(tile, 1 | 1 << 8, GetRoadStopType(tile), CMD_REMOVE_ROAD_STOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ Money AIRoad::GetBuildCost(RoadType roadtype, BuildType build_type)
|
/* static */ Money AIRoad::GetBuildCost(RoadType roadtype, BuildType build_type)
|
||||||
|
|
|
@ -260,7 +260,7 @@ static void PlaceRoadStop(TileIndex start_tile, TileIndex end_tile, uint32 p2, u
|
||||||
static void PlaceRoad_BusStation(TileIndex tile)
|
static void PlaceRoad_BusStation(TileIndex tile)
|
||||||
{
|
{
|
||||||
if (_remove_button_clicked) {
|
if (_remove_button_clicked) {
|
||||||
DoCommandP(tile, 0, ROADSTOP_BUS, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[ROADSTOP_BUS]), CcPlaySound1D);
|
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_REMOVE_BUSSTOP);
|
||||||
} else {
|
} else {
|
||||||
if (_road_station_picker_orientation < DIAGDIR_END) { // Not a drive-through stop.
|
if (_road_station_picker_orientation < DIAGDIR_END) { // Not a drive-through stop.
|
||||||
VpStartPlaceSizing(tile, (DiagDirToAxis(_road_station_picker_orientation) == AXIS_X) ? VPM_X_LIMITED : VPM_Y_LIMITED, DDSP_BUILD_BUSSTOP);
|
VpStartPlaceSizing(tile, (DiagDirToAxis(_road_station_picker_orientation) == AXIS_X) ? VPM_X_LIMITED : VPM_Y_LIMITED, DDSP_BUILD_BUSSTOP);
|
||||||
|
@ -274,7 +274,7 @@ static void PlaceRoad_BusStation(TileIndex tile)
|
||||||
static void PlaceRoad_TruckStation(TileIndex tile)
|
static void PlaceRoad_TruckStation(TileIndex tile)
|
||||||
{
|
{
|
||||||
if (_remove_button_clicked) {
|
if (_remove_button_clicked) {
|
||||||
DoCommandP(tile, 0, ROADSTOP_TRUCK, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[ROADSTOP_TRUCK]), CcPlaySound1D);
|
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_REMOVE_TRUCKSTOP);
|
||||||
} else {
|
} else {
|
||||||
if (_road_station_picker_orientation < DIAGDIR_END) { // Not a drive-through stop.
|
if (_road_station_picker_orientation < DIAGDIR_END) { // Not a drive-through stop.
|
||||||
VpStartPlaceSizing(tile, (DiagDirToAxis(_road_station_picker_orientation) == AXIS_X) ? VPM_X_LIMITED : VPM_Y_LIMITED, DDSP_BUILD_TRUCKSTOP);
|
VpStartPlaceSizing(tile, (DiagDirToAxis(_road_station_picker_orientation) == AXIS_X) ? VPM_X_LIMITED : VPM_Y_LIMITED, DDSP_BUILD_TRUCKSTOP);
|
||||||
|
@ -664,6 +664,16 @@ struct BuildRoadToolbarWindow : Window {
|
||||||
case DDSP_BUILD_TRUCKSTOP:
|
case DDSP_BUILD_TRUCKSTOP:
|
||||||
PlaceRoadStop(start_tile, end_tile, (_ctrl_pressed << 5) | RoadTypeToRoadTypes(_cur_roadtype) << 2 | ROADSTOP_TRUCK, CMD_BUILD_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_station[ROADSTOP_TRUCK]));
|
PlaceRoadStop(start_tile, end_tile, (_ctrl_pressed << 5) | RoadTypeToRoadTypes(_cur_roadtype) << 2 | ROADSTOP_TRUCK, CMD_BUILD_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_station[ROADSTOP_TRUCK]));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case DDSP_REMOVE_BUSSTOP: {
|
||||||
|
TileArea ta(start_tile, end_tile);
|
||||||
|
DoCommandP(ta.tile, ta.w | ta.h << 8, ROADSTOP_BUS, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[ROADSTOP_BUS]), CcPlaySound1D);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case DDSP_REMOVE_TRUCKSTOP: {
|
||||||
|
TileArea ta(start_tile, end_tile);
|
||||||
|
DoCommandP(ta.tile, ta.w | ta.h << 8, ROADSTOP_TRUCK, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[ROADSTOP_TRUCK]), CcPlaySound1D);
|
||||||
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1834,40 +1834,57 @@ static CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlag flags)
|
||||||
return CommandCost(EXPENSES_CONSTRUCTION, _price[is_truck ? PR_CLEAR_STATION_TRUCK : PR_CLEAR_STATION_BUS]);
|
return CommandCost(EXPENSES_CONSTRUCTION, _price[is_truck ? PR_CLEAR_STATION_TRUCK : PR_CLEAR_STATION_BUS]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Remove a bus or truck stop
|
/** Remove bus or truck stops.
|
||||||
* @param tile tile to remove the stop from
|
* @param tile Northernmost tile of the removal area.
|
||||||
* @param flags operation to perform
|
* @param flags Operation to perform.
|
||||||
* @param p1 not used
|
* @param p1 bit 0..7: Width of the removal area.
|
||||||
* @param p2 bit 0: 0 for Bus stops, 1 for truck stops
|
* bit 8..15: Height of the removal area.
|
||||||
* @param text unused
|
* @param p2 bit 0: 0 For bus stops, 1 for truck stops.
|
||||||
* @return the cost of this operation or an error
|
* @param text Unused.
|
||||||
|
* @return The cost of this operation or an error.
|
||||||
*/
|
*/
|
||||||
CommandCost CmdRemoveRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdRemoveRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
/* Make sure the specified tile is a road stop of the correct type */
|
uint8 width = (uint8)GB(p1, 0, 8);
|
||||||
if (!IsTileType(tile, MP_STATION) || !IsRoadStop(tile) || (uint32)GetRoadStopType(tile) != GB(p2, 0, 1)) return CMD_ERROR;
|
uint8 height = (uint8)GB(p1, 8, 8);
|
||||||
|
|
||||||
/* Save the stop info before it is removed */
|
/* Check for incorrect width / height. */
|
||||||
bool is_drive_through = IsDriveThroughStopTile(tile);
|
if (width == 0 || height == 0) return CMD_ERROR;
|
||||||
RoadTypes rts = GetRoadTypes(tile);
|
/* Check if the first tile and the last tile are valid */
|
||||||
RoadBits road_bits = IsDriveThroughStopTile(tile) ?
|
if (!IsValidTile(tile) || TileAddWrap(tile, width - 1, height - 1) == INVALID_TILE) return CMD_ERROR;
|
||||||
((GetRoadStopDir(tile) == DIAGDIR_NE) ? ROAD_X : ROAD_Y) :
|
|
||||||
DiagDirToRoadBits(GetRoadStopDir(tile));
|
|
||||||
|
|
||||||
Owner road_owner = GetRoadOwner(tile, ROADTYPE_ROAD);
|
TileArea roadstop_area(tile, width, height);
|
||||||
Owner tram_owner = GetRoadOwner(tile, ROADTYPE_TRAM);
|
|
||||||
CommandCost ret = RemoveRoadStop(tile, flags);
|
|
||||||
|
|
||||||
/* If the stop was a drive-through stop replace the road */
|
int quantity = 0;
|
||||||
if ((flags & DC_EXEC) && ret.Succeeded() && is_drive_through) {
|
CommandCost cost(EXPENSES_CONSTRUCTION);
|
||||||
/* Rebuild the drive throuhg road stop. As a road stop can only be
|
TILE_AREA_LOOP(cur_tile, roadstop_area) {
|
||||||
* removed by the owner of the roadstop, _current_company is the
|
/* Make sure the specified tile is a road stop of the correct type */
|
||||||
* owner of the road stop. */
|
if (!IsTileType(cur_tile, MP_STATION) || !IsRoadStop(cur_tile) || (uint32)GetRoadStopType(cur_tile) != GB(p2, 0, 1)) continue;
|
||||||
MakeRoadNormal(tile, road_bits, rts, ClosestTownFromTile(tile, UINT_MAX)->index,
|
|
||||||
road_owner, tram_owner);
|
/* Save the stop info before it is removed */
|
||||||
|
bool is_drive_through = IsDriveThroughStopTile(cur_tile);
|
||||||
|
RoadTypes rts = GetRoadTypes(cur_tile);
|
||||||
|
RoadBits road_bits = IsDriveThroughStopTile(cur_tile) ?
|
||||||
|
((GetRoadStopDir(cur_tile) == DIAGDIR_NE) ? ROAD_X : ROAD_Y) :
|
||||||
|
DiagDirToRoadBits(GetRoadStopDir(cur_tile));
|
||||||
|
|
||||||
|
Owner road_owner = GetRoadOwner(cur_tile, ROADTYPE_ROAD);
|
||||||
|
Owner tram_owner = GetRoadOwner(cur_tile, ROADTYPE_TRAM);
|
||||||
|
CommandCost ret = RemoveRoadStop(cur_tile, flags);
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
cost.AddCost(ret);
|
||||||
|
|
||||||
|
quantity++;
|
||||||
|
/* If the stop was a drive-through stop replace the road */
|
||||||
|
if ((flags & DC_EXEC) && is_drive_through) {
|
||||||
|
MakeRoadNormal(cur_tile, road_bits, rts, ClosestTownFromTile(cur_tile, UINT_MAX)->index,
|
||||||
|
road_owner, tram_owner);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
if (quantity == 0) return CMD_ERROR;
|
||||||
|
|
||||||
|
return cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -111,6 +111,8 @@ enum ViewportDragDropSelectionProcess {
|
||||||
DDSP_PLACE_AUTOROAD, ///< Road placement (auto)
|
DDSP_PLACE_AUTOROAD, ///< Road placement (auto)
|
||||||
DDSP_BUILD_BUSSTOP, ///< Road stop placement (buses)
|
DDSP_BUILD_BUSSTOP, ///< Road stop placement (buses)
|
||||||
DDSP_BUILD_TRUCKSTOP, ///< Road stop placement (trucks)
|
DDSP_BUILD_TRUCKSTOP, ///< Road stop placement (trucks)
|
||||||
|
DDSP_REMOVE_BUSSTOP, ///< Road stop removal (buses)
|
||||||
|
DDSP_REMOVE_TRUCKSTOP, ///< Road stop removal (trucks)
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* VIEWPORT_TYPE_H */
|
#endif /* VIEWPORT_TYPE_H */
|
||||||
|
|
Loading…
Reference in New Issue