# HG changeset patch # User smatz # Date 1229185004 0 # Node ID a1a6095668538e509c2f7d2b3e4c8a360d867ada # Parent b35c0a4c73c5f8d0e986dda83613b11906b373b7 (svn r14670) -Codechange: use better readable (I hope) and branchless (for some archs/compilers) code for cargo value computation diff -r b35c0a4c73c5 -r a1a609566853 src/economy.cpp --- 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); }