diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1217,14 +1217,16 @@ restart: * @param affected_stations the stations affected * @param flags the command flags * @param removal_cost the cost for removing the tile + * @param keep_rail whether to keep the rail of the station * @tparam T the type of station to remove * @return the number of cleared tiles or an error */ template -CommandCost RemoveFromRailBaseStation(TileArea ta, SmallVector &affected_stations, DoCommandFlag flags, Money removal_cost) +CommandCost RemoveFromRailBaseStation(TileArea ta, SmallVector &affected_stations, DoCommandFlag flags, Money removal_cost, bool keep_rail) { /* Count of the number of tiles removed */ int quantity = 0; + CommandCost total_cost(EXPENSES_CONSTRUCTION); /* Do the action for every tile into the area */ TILE_LOOP(tile, ta.w, ta.h, ta.tile) { @@ -1267,7 +1269,7 @@ CommandCost RemoveFromRailBaseStation(Ti } } - if (st->facilities & FACIL_WAYPOINT) { + if (keep_rail) { MakeRailNormal(tile, owner, TrackToTrackBits(track), rt); } else { DoClearSquare(tile); @@ -1288,6 +1290,10 @@ CommandCost RemoveFromRailBaseStation(Ti if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(ReverseTrackdir(v->GetVehicleTrackdir())), true); } } + if (keep_rail) { + /* Don't refund the 'steel' of the track! */ + total_cost.AddCost(-_price.remove_rail); + } } if (quantity == 0) return CMD_ERROR; @@ -1310,7 +1316,8 @@ CommandCost RemoveFromRailBaseStation(Ti } } - return CommandCost(EXPENSES_CONSTRUCTION, quantity * removal_cost); + total_cost.AddCost(quantity * removal_cost); + return total_cost; } /** Remove a single tile from a rail station. @@ -1318,7 +1325,8 @@ CommandCost RemoveFromRailBaseStation(Ti * @param start tile of station piece to remove * @param flags operation to perform * @param p1 start_tile - * @param p2 unused + * @param p2 various bitstuffed elements + * - p2 = bit 0 - if set keep the rail * @param text unused * @return cost of operation or error */ @@ -1330,7 +1338,7 @@ CommandCost CmdRemoveFromRailStation(Til TileArea ta(start, end); SmallVector affected_stations; - CommandCost ret = RemoveFromRailBaseStation(ta, affected_stations, flags, _price.remove_rail_station); + CommandCost ret = RemoveFromRailBaseStation(ta, affected_stations, flags, _price.remove_rail_station, HasBit(p2, 0)); if (ret.Failed()) return ret; /* Do all station specific functions here. */ @@ -1351,7 +1359,8 @@ CommandCost CmdRemoveFromRailStation(Til * @param start tile of waypoint piece to remove * @param flags operation to perform * @param p1 start_tile - * @param p2 unused + * @param p2 various bitstuffed elements + * - p2 = bit 0 - if set keep the rail * @param text unused * @return cost of operation or error */ @@ -1363,7 +1372,7 @@ CommandCost CmdRemoveFromRailWaypoint(Ti TileArea ta(start, end); SmallVector affected_stations; - return RemoveFromRailBaseStation(ta, affected_stations, flags, _price.remove_train_depot); + return RemoveFromRailBaseStation(ta, affected_stations, flags, _price.remove_train_depot, HasBit(p2, 0)); }