From a52cd653d454170f8163ff2a9f7836c4d8dd5bb6 Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 29 Jul 2009 22:13:12 +0000 Subject: (svn r16989) -Codechange: unify the code for demolishing (dynamite) stations and waypoints. --- src/station_cmd.cpp | 54 +++++++++++++++++++++++++++++++++++++++++----------- src/waypoint_cmd.cpp | 42 ---------------------------------------- src/waypoint_func.h | 1 - 3 files changed, 43 insertions(+), 54 deletions(-) (limited to 'src') diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 8c4041211..75eb04dcd 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1278,20 +1278,15 @@ CommandCost CmdRemoveTrainWaypoint(TileIndex start, DoCommandFlag flags, uint32 /** - * Remove a rail road station - * @param tile TileIndex been queried + * Remove a rail road station/waypoint + * @param st The station/waypoint to remove the rail part from * @param flags operation to perform + * @param T the type of station to remove * @return cost or failure of operation */ -static CommandCost RemoveRailroadStation(TileIndex tile, DoCommandFlag flags) +template +CommandCost RemoveRailStation(T *st, DoCommandFlag flags) { - /* if there is flooding and non-uniform stations are enabled, remove platforms tile by tile */ - if (_current_company == OWNER_WATER && _settings_game.station.nonuniform_stations) { - return DoCommand(tile, 0, 0, DC_EXEC, CMD_REMOVE_FROM_RAILROAD_STATION); - } - - Station *st = Station::GetByTile(tile); - /* Current company owns the station? */ if (_current_company != OWNER_WATER && !CheckOwnership(st->owner)) return CMD_ERROR; @@ -1341,13 +1336,50 @@ static CommandCost RemoveRailroadStation(TileIndex tile, DoCommandFlag flags) InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS); st->UpdateVirtCoord(); - st->RecomputeIndustriesNear(); DeleteStationIfEmpty(st); } return cost; } +/** + * Remove a rail road station + * @param tile TileIndex been queried + * @param flags operation to perform + * @return cost or failure of operation + */ +static CommandCost RemoveRailroadStation(TileIndex tile, DoCommandFlag flags) +{ + /* if there is flooding and non-uniform stations are enabled, remove platforms tile by tile */ + if (_current_company == OWNER_WATER && _settings_game.station.nonuniform_stations) { + return DoCommand(tile, 0, 0, DC_EXEC, CMD_REMOVE_FROM_RAILROAD_STATION); + } + + Station *st = Station::GetByTile(tile); + CommandCost cost = RemoveRailStation(st, flags); + + if (flags & DC_EXEC) st->RecomputeIndustriesNear(); + + return cost; +} + +/** + * Remove a rail waypoint + * @param tile TileIndex been queried + * @param flags operation to perform + * @return cost or failure of operation + */ +static CommandCost RemoveTrainWaypoint(TileIndex tile, DoCommandFlag flags) +{ + /* if there is flooding and non-uniform stations are enabled, remove waypoints tile by tile */ + if (_current_company == OWNER_WATER && _settings_game.station.nonuniform_stations) { + return DoCommand(tile, 0, 0, DC_EXEC, CMD_REMOVE_TRAIN_WAYPOINT); + } + + return RemoveRailStation(Waypoint::GetByTile(tile), flags); +} + + /** * @param truck_station Determines whether a stop is ROADSTOP_BUS or ROADSTOP_TRUCK * @param st The Station to do the whole procedure for diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp index 51db1a7ef..f0186b00f 100644 --- a/src/waypoint_cmd.cpp +++ b/src/waypoint_cmd.cpp @@ -210,48 +210,6 @@ CommandCost CmdBuildTrainWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1 return CommandCost(EXPENSES_CONSTRUCTION, _price.build_train_depot); } -/** - * Remove a waypoint - * @param tile from which to remove waypoint - * @param flags type of operation - * @param justremove will indicate if it is removed from rail or if rails are removed too - * @pre IsRailWaypointTile(tile) - * @return cost of operation or error - */ -CommandCost RemoveTrainWaypoint(TileIndex tile, DoCommandFlag flags) -{ - /* Make sure it's a waypoint */ - if (!IsRailWaypointTile(tile) || - (!CheckTileOwnership(tile) && _current_company != OWNER_WATER) || - !EnsureNoVehicleOnGround(tile)) { - return CMD_ERROR; - } - - if (flags & DC_EXEC) { - Track track = GetRailStationTrack(tile); - Waypoint *wp = Waypoint::GetByTile(tile); - - wp->sign.MarkDirty(); - wp->facilities &= ~FACIL_TRAIN; - - Train *v = NULL; - uint specindex = GetCustomStationSpecIndex(tile); - if (HasStationReservation(tile)) { - v = GetTrainForReservation(tile, track); - if (v != NULL) FreeTrainTrackReservation(v); - } - DoClearSquare(tile); - AddTrackToSignalBuffer(tile, track, wp->owner); - YapfNotifyTrackLayoutChange(tile, track); - if (v != NULL) TryPathReserve(v, true); - - DeallocateSpecFromStation(wp, specindex); - wp->rect.AfterRemoveTile(wp, tile); - } - - return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_train_depot); -} - /** Build a buoy. * @param tile tile where to place the bouy * @param flags operation to perform diff --git a/src/waypoint_func.h b/src/waypoint_func.h index 093a554f7..09b19650e 100644 --- a/src/waypoint_func.h +++ b/src/waypoint_func.h @@ -9,7 +9,6 @@ #include "command_type.h" #include "station_type.h" -CommandCost RemoveTrainWaypoint(TileIndex tile, DoCommandFlag flags); CommandCost RemoveBuoy(TileIndex tile, DoCommandFlag flags); void ShowWaypointWindow(const Waypoint *wp); -- cgit v1.2.3-70-g09d2