(svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
authorsmatz
Sat, 08 Dec 2007 19:53:30 +0000
changeset 8539 0ba5701ab630
parent 8538 e953a11779f4
child 8540 ec9383f17f85
(svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
src/rail.h
src/rail_cmd.cpp
src/road_cmd.cpp
src/station_cmd.cpp
src/tunnelbridge_cmd.cpp
--- a/src/rail.h	Sat Dec 08 18:53:49 2007 +0000
+++ b/src/rail.h	Sat Dec 08 19:53:30 2007 +0000
@@ -807,6 +807,34 @@
 	return (_price.build_rail * _railtype_cost_multiplier[railtype]) >> 3;
 }
 
+/**
+ * Calculates the cost of rail conversion
+ * @param from The railtype we are converting from
+ * @param to   The railtype we are converting to
+ * @return Cost per TrackBit
+ */
+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)) {
+		return ((RailBuildCost(to) - RailBuildCost(from)) * 5) >> 2;
+	}
+
+	/* 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)) {
+		return (RailBuildCost(from) - RailBuildCost(to)) >> 2;
+	}
+
+	/* make the price the same as remove + build new type */
+	return RailBuildCost(to) + _price.remove_rail;
+}
+
 void *UpdateTrainPowerProc(Vehicle *v, void *data);
 void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);
 void DrawDefaultWaypointSprite(int x, int y, RailType railtype);
--- a/src/rail_cmd.cpp	Sat Dec 08 18:53:49 2007 +0000
+++ b/src/rail_cmd.cpp	Sat Dec 08 19:53:30 2007 +0000
@@ -1201,7 +1201,7 @@
 		VehicleFromPos(tile, &tile, UpdateTrainPowerProc);
 	}
 
-	return CommandCost(RailBuildCost(totype) / 2);
+	return CommandCost(RailConvertCost(GetRailType(tile), totype) * CountBits(GetTrackBits(tile)));
 }
 
 extern CommandCost DoConvertStationRail(TileIndex tile, RailType totype, bool exec);
--- a/src/road_cmd.cpp	Sat Dec 08 18:53:49 2007 +0000
+++ b/src/road_cmd.cpp	Sat Dec 08 19:53:30 2007 +0000
@@ -606,7 +606,7 @@
 		VehicleFromPos(tile, &tile, UpdateTrainPowerProc);
 	}
 
-	return CommandCost(RailBuildCost(totype) / 2);
+	return CommandCost(RailConvertCost(GetRailType(tile), totype));
 }
 
 
--- a/src/station_cmd.cpp	Sat Dec 08 18:53:49 2007 +0000
+++ b/src/station_cmd.cpp	Sat Dec 08 19:53:30 2007 +0000
@@ -1309,7 +1309,7 @@
 		VehicleFromPos(tile, &tile, UpdateTrainPowerProc);
 	}
 
-	return CommandCost(RailBuildCost(totype) / 2);
+	return CommandCost(RailConvertCost(GetRailType(tile), totype));
 }
 
 /**
--- a/src/tunnelbridge_cmd.cpp	Sat Dec 08 18:53:49 2007 +0000
+++ b/src/tunnelbridge_cmd.cpp	Sat Dec 08 19:53:30 2007 +0000
@@ -774,7 +774,7 @@
 			VehicleFromPos(endtile, &endtile, UpdateTrainPowerProc);
 		}
 
-		return CommandCost((length + 1) * (RailBuildCost(totype) / 2));
+		return CommandCost((length + 1) * RailConvertCost(GetRailType(tile), totype));
 	} else if (IsBridge(tile) && GetBridgeTransportType(tile) == TRANSPORT_RAIL) {
 		TileIndex endtile = GetOtherBridgeEnd(tile);
 		byte bridge_height = GetBridgeHeight(tile);
@@ -806,7 +806,7 @@
 			}
 		}
 
-		return CommandCost((DistanceManhattan(tile, endtile) + 1) * (RailBuildCost(totype) / 2));
+		return CommandCost((DistanceManhattan(tile, endtile) + 1) * RailConvertCost(GetRailType(tile), totype));
 	} else {
 		return CMD_ERROR;
 	}