1
0
Fork 0

(svn r21919) -Fix: Converting an expensive rail type to a cheap one could give more money than removing and rebuilding cost

release/1.1
planetmaker 2011-01-27 00:38:12 +00:00
parent 62e5afcdf8
commit 5e82fee690
1 changed files with 14 additions and 18 deletions

View File

@ -337,26 +337,22 @@ static inline Money RailClearCost(RailType railtype)
*/ */
static inline Money RailConvertCost(RailType from, RailType to) static inline Money RailConvertCost(RailType from, RailType to)
{ {
/* rail -> el. rail /* Get the costs for removing and building anew
* calculate the price as 5 / 4 of (cost build el. rail) - (cost build rail) * A conversion can never be more costly */
* (the price of workers to get to place is that 1/4) Money rebuildcost = RailBuildCost(to) + RailClearCost(from);
*/
if (HasPowerOnRail(from, to)) { /* Conversion between somewhat compatible railtypes:
Money cost = ((RailBuildCost(to) - RailBuildCost(from)) * 5) >> 2; * Pay 1/8 of the target rail cost (labour costs) and additionally any difference in the
if (cost != 0) return cost; * 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);
} }
/* el. rail -> rail /* make the price the same as remove + build new type for rail types
* calculate the price as 1 / 4 of (cost build el. rail) - (cost build rail) * which are not compatible in any way */
* (the price of workers is 1 / 4 + price of copper sold to a recycle center) return rebuildcost;
*/
if (HasPowerOnRail(to, from)) {
Money cost = (RailBuildCost(from) - RailBuildCost(to)) >> 2;
if (cost != 0) return cost;
}
/* make the price the same as remove + build new type */
return RailBuildCost(to) + RailClearCost(from);
} }
void DrawTrainDepotSprite(int x, int y, int image, RailType railtype); void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);