summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-12-13 16:16:44 +0000
committersmatz <smatz@openttd.org>2008-12-13 16:16:44 +0000
commit28028cf755684688f5afb4c3c778100803c1f443 (patch)
tree0b706d632d005a2eca47dd9b6c093130651cdb60 /src
parent3cd29575445a7f4b9861f6f80d209244bf58a608 (diff)
downloadopenttd-28028cf755684688f5afb4c3c778100803c1f443.tar.xz
(svn r14670) -Codechange: use better readable (I hope) and branchless (for some archs/compilers) code for cargo value computation
Diffstat (limited to 'src')
-rw-r--r--src/economy.cpp14
1 files changed, 3 insertions, 11 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index f933c80cb..cf36d0945 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -1213,7 +1213,8 @@ Money GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, C
const int days1 = cs->transit_days[0];
const int days2 = cs->transit_days[1];
- const int days_over_days1 = transit_days - days1;
+ const int days_over_days1 = max( transit_days - days1, 0);
+ const int days_over_days2 = max(days_over_days1 - days2, 0);
/*
* The time factor is calculated based on the time it took
@@ -1225,16 +1226,7 @@ Money GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, C
* - 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 (time_factor < MIN_TIME_FACTOR) time_factor = MIN_TIME_FACTOR;
+ const int time_factor = max(MAX_TIME_FACTOR - days_over_days1 - days_over_days2, MIN_TIME_FACTOR);
return BigMulS(dist * time_factor * num_pieces, _cargo_payment_rates[cargo_type], 21);
}