From 0dd811048454b374291d8ba13449cdcafff40ed0 Mon Sep 17 00:00:00 2001 From: peter1138 Date: Tue, 16 Mar 2010 06:30:31 +0000 Subject: [PATCH] (svn r19433) -Codechange: Limit rail clearance earnings to 3/4s of rail build cost, to avoid money making loophole when rail build cost is less than rail removal earnings. --- src/rail.h | 18 +++++++++++++++++- src/rail_cmd.cpp | 6 +++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/rail.h b/src/rail.h index 3f401cd371..f0a5ef609e 100644 --- a/src/rail.h +++ b/src/rail.h @@ -269,6 +269,22 @@ static inline Money RailBuildCost(RailType railtype) return (_price[PR_BUILD_RAIL] * GetRailTypeInfo(railtype)->cost_multiplier) >> 3; } +/** + * Returns the 'cost' of clearing the specified railtype. + * @param railtype The railtype being removed. + * @return The cost. + */ +static inline Money RailClearCost(RailType railtype) +{ + /* Clearing rail in fact earns money, but if the build cost is set + * very low then a loophole exists where money can be made. + * In this case we limit the removal earnings to 3/4s of the build + * cost. + */ + assert(railtype < RAILTYPE_END); + return max(_price[PR_CLEAR_RAIL], -RailBuildCost(railtype) * 3 / 4); +} + /** * Calculates the cost of rail conversion * @param from The railtype we are converting from @@ -296,7 +312,7 @@ static inline Money RailConvertCost(RailType from, RailType to) } /* make the price the same as remove + build new type */ - return RailBuildCost(to) + _price[PR_CLEAR_RAIL]; + return RailBuildCost(to) + RailClearCost(from); } void DrawTrainDepotSprite(int x, int y, int image, RailType railtype); diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index f0b79a070c..7440f86ac6 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -503,7 +503,7 @@ CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, u CommandCost CmdRemoveSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { Track track = (Track)p2; - CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_RAIL] ); + CommandCost cost(EXPENSES_CONSTRUCTION); bool crossing = false; if (!ValParamTrackOrientation((Track)p2)) return CMD_ERROR; @@ -533,6 +533,8 @@ CommandCost CmdRemoveSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, if (ret.Failed()) return ret; } + cost.AddCost(RailClearCost(GetRailType(tile))); + if (flags & DC_EXEC) { if (HasReservedTracks(tile, trackbit)) { v = GetTrainForReservation(tile, track); @@ -563,6 +565,8 @@ CommandCost CmdRemoveSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, if ((present & trackbit) == 0) return CMD_ERROR; if (present == (TRACK_BIT_X | TRACK_BIT_Y)) crossing = true; + cost.AddCost(RailClearCost(GetRailType(tile))); + /* Charge extra to remove signals on the track, if they are there */ if (HasSignalOnTrack(tile, track)) cost.AddCost(DoCommand(tile, track, 0, flags, CMD_REMOVE_SIGNALS));