summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-07-25 19:26:33 +0000
committerrubidium <rubidium@openttd.org>2007-07-25 19:26:33 +0000
commitaa36c607b40fa499780e3818a032788afa19bd1f (patch)
treec315a57a2b67b85e01a0aaf487b9e8ff445f2fff
parent9e3ee0e689343c7701453c0fa4220d21fa3c46ce (diff)
downloadopenttd-aa36c607b40fa499780e3818a032788afa19bd1f.tar.xz
(svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
-rw-r--r--src/economy.cpp46
1 files changed, 28 insertions, 18 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index e3074fe00..b82496791 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -1168,7 +1168,6 @@ static void Load_SUBS()
Money GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, CargoID cargo_type)
{
const CargoSpec *cs = GetCargo(cargo_type);
- byte f;
/* Use callback to calculate cargo profit, if available */
if (HASBIT(cs->callback_mask, CBM_CARGO_PROFIT_CALC)) {
@@ -1187,28 +1186,39 @@ Money GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, C
}
}
- /* zero the distance if it's the bank and very short transport. */
- if (_opt.landscape == LT_TEMPERATE && cs->label == 'VALU' && dist < 10)
- dist = 0;
+ /* zero the distance (thus income) if it's the bank and very short transport. */
+ if (_opt.landscape == LT_NORMAL && cs->label == 'VALU' && dist < 10) return 0;
- f = 255;
- if (transit_days > cs->transit_days[0]) {
- transit_days -= cs->transit_days[0];
- f -= transit_days;
- if (transit_days > cs->transit_days[1]) {
- transit_days -= cs->transit_days[1];
+ static const int MIN_TIME_FACTOR = 31;
+ static const int MAX_TIME_FACTOR = 255;
- if (f < transit_days) {
- f = 0;
- } else {
- f -= transit_days;
- }
- }
+ const int days1 = cs->transit_days[0];
+ const int days2 = cs->transit_days[1];
+ const int days_over_days1 = transit_days - days1;
+
+ /*
+ * 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
+ *
+ */
+ int time_factor;
+ 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 (f < 31) f = 31;
- return BIGMULSS(dist * f * num_pieces, _cargo_payment_rates[cargo_type], 21);
+ if (time_factor < MIN_TIME_FACTOR) time_factor = MIN_TIME_FACTOR;
+
+ return BIGMULSS(dist * time_factor * num_pieces, _cargo_payment_rates[cargo_type], 21);
}
static void DeliverGoodsToIndustry(TileIndex xy, CargoID cargo_type, int num_pieces)