Index: src/economy.cpp =================================================================== --- src/economy.cpp (revision 9339) +++ src/economy.cpp (working copy) @@ -1114,32 +1114,41 @@ int32 GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, CargoID cargo_type) { - CargoID cargo = cargo_type; + const int MIN_TIME_FACTOR = 31; + const int MAX_TIME_FACTOR = 255; + const CargoSpec *cs = GetCargo(cargo_type); - byte f; + const int days1 = cs->transit_days[0]; + const int days2 = cs->transit_days[1]; + const int days_over_days1 = transit_days - days1; + int time_factor; + /* zero the distance if it's the bank and very short transport. */ if (_opt.landscape == LT_NORMAL && cs->label == 'VALU' && dist < 10) dist = 0; - f = 255; - if (transit_days > cs->transit_days[0]) { - transit_days -= cs->transit_days[0]; - f -= transit_days; + /* + * The time factor is calculated based on the time it took + * (transit_days) compared two cargo-depending values. The + * range is divided into three parts: + * + * - constant for fast transits + * - linear decreasing with time with a slope of -1 for medium transports + * - linear decreasing with time with a slope of -2 for slow transports + * + */ + if (days_over_days1 <= 0) + time_factor = MAX_TIME_FACTOR; + else if (days_over_days1 <= days2) + time_factor = MAX_TIME_FACTOR - days_over_days1; + else + time_factor = MAX_TIME_FACTOR - 2 * days_over_days1 + days2; - if (transit_days > cs->transit_days[1]) { - transit_days -= cs->transit_days[1]; + if (time_factor < MIN_TIME_FACTOR) + time_factor = MIN_TIME_FACTOR; - if (f < transit_days) { - f = 0; - } else { - f -= transit_days; - } - } - } - if (f < 31) f = 31; - - return BIGMULSS(dist * f * num_pieces, _cargo_payment_rates[cargo], 21); + return BIGMULSS(dist * time_factor * num_pieces, _cargo_payment_rates[cargo_type], 21); } static void DeliverGoodsToIndustry(TileIndex xy, CargoID cargo_type, int num_pieces)