(svn r14670) -Codechange: use better readable (I hope) and branchless (for some archs/compilers) code for cargo value computation
--- a/src/economy.cpp Sat Dec 13 15:59:25 2008 +0000
+++ b/src/economy.cpp Sat Dec 13 16:16:44 2008 +0000
@@ -1213,7 +1213,8 @@
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 @@
* - 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);
}