summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorplanetmaker <planetmaker@openttd.org>2011-01-27 00:38:12 +0000
committerplanetmaker <planetmaker@openttd.org>2011-01-27 00:38:12 +0000
commit5e82fee6900f4aa0c2561efd8823c73eb982243c (patch)
treef4ee3754ae28897fdf330e3af95d1c90b4fef762
parent62e5afcdf87c5d2d147b9491c88c6c0c937db54e (diff)
downloadopenttd-5e82fee6900f4aa0c2561efd8823c73eb982243c.tar.xz
(svn r21919) -Fix: Converting an expensive rail type to a cheap one could give more money than removing and rebuilding cost
-rw-r--r--src/rail.h32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/rail.h b/src/rail.h
index f7d97daf4..586b85324 100644
--- a/src/rail.h
+++ b/src/rail.h
@@ -337,26 +337,22 @@ static inline Money RailClearCost(RailType railtype)
*/
static inline Money RailConvertCost(RailType from, RailType to)
{
- /* rail -> el. rail
- * calculate the price as 5 / 4 of (cost build el. rail) - (cost build rail)
- * (the price of workers to get to place is that 1/4)
- */
- if (HasPowerOnRail(from, to)) {
- Money cost = ((RailBuildCost(to) - RailBuildCost(from)) * 5) >> 2;
- if (cost != 0) return cost;
- }
-
- /* el. rail -> rail
- * calculate the price as 1 / 4 of (cost build el. rail) - (cost build rail)
- * (the price of workers is 1 / 4 + price of copper sold to a recycle center)
- */
- if (HasPowerOnRail(to, from)) {
- Money cost = (RailBuildCost(from) - RailBuildCost(to)) >> 2;
- if (cost != 0) return cost;
+ /* Get the costs for removing and building anew
+ * A conversion can never be more costly */
+ Money rebuildcost = RailBuildCost(to) + RailClearCost(from);
+
+ /* Conversion between somewhat compatible railtypes:
+ * Pay 1/8 of the target rail cost (labour costs) and additionally any difference in the
+ * build costs, if the target type is more expensive (material upgrade costs).
+ * Upgrade can never be more expensive than re-building. */
+ if (HasPowerOnRail(from, to) || HasPowerOnRail(to, from)) {
+ Money upgradecost = RailBuildCost(to) / 8 + max((Money)0, RailBuildCost(to) - RailBuildCost(from));
+ return min(upgradecost, rebuildcost);
}
- /* make the price the same as remove + build new type */
- return RailBuildCost(to) + RailClearCost(from);
+ /* make the price the same as remove + build new type for rail types
+ * which are not compatible in any way */
+ return rebuildcost;
}
void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);