diff options
author | Niels Martin Hansen <nielsm@indvikleren.dk> | 2018-11-01 18:46:19 +0100 |
---|---|---|
committer | Niels Martin Hansen <nielsm@indvikleren.dk> | 2018-11-25 00:48:34 +0100 |
commit | 810887af3043eed7506f5e0c3b7bc429cee8fa31 (patch) | |
tree | 848760876511e240f184e18ebc7edaf490c03ac2 /src | |
parent | c618a7c093cf0a0d0ad042ce7c382706d7f65cb1 (diff) | |
download | openttd-810887af3043eed7506f5e0c3b7bc429cee8fa31.tar.xz |
Fix #6498: Use int64 for all company rating calculations
Diffstat (limited to 'src')
-rw-r--r-- | src/economy.cpp | 14 | ||||
-rw-r--r-- | src/economy_func.h | 2 | ||||
-rw-r--r-- | src/graph_gui.cpp | 10 |
3 files changed, 13 insertions, 13 deletions
diff --git a/src/economy.cpp b/src/economy.cpp index ad9895ba9..c7ffa96cc 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -95,7 +95,7 @@ const ScoreInfo _score_info[] = { { 0, 0} // SCORE_TOTAL }; -int _score_part[MAX_COMPANIES][SCORE_END]; +int64 _score_part[MAX_COMPANIES][SCORE_END]; Economy _economy; Prices _price; Money _additional_cash_required; @@ -183,7 +183,7 @@ int UpdateCompanyRatingAndValue(Company *c, bool update) _score_part[owner][SCORE_VEHICLES] = num; /* Don't allow negative min_profit to show */ if (min_profit > 0) { - _score_part[owner][SCORE_MIN_PROFIT] = ClampToI32(min_profit); + _score_part[owner][SCORE_MIN_PROFIT] = min_profit; } } @@ -213,10 +213,10 @@ int UpdateCompanyRatingAndValue(Company *c, bool update) } while (++cee, --numec); if (min_income > 0) { - _score_part[owner][SCORE_MIN_INCOME] = ClampToI32(min_income); + _score_part[owner][SCORE_MIN_INCOME] = min_income; } - _score_part[owner][SCORE_MAX_INCOME] = ClampToI32(max_income); + _score_part[owner][SCORE_MAX_INCOME] = max_income; } } @@ -230,7 +230,7 @@ int UpdateCompanyRatingAndValue(Company *c, bool update) total_delivered += cee->delivered_cargo.GetSum<OverflowSafeInt64>(); } while (++cee, --numec); - _score_part[owner][SCORE_DELIVERED] = ClampToI32(total_delivered); + _score_part[owner][SCORE_DELIVERED] = total_delivered; } } @@ -242,13 +242,13 @@ int UpdateCompanyRatingAndValue(Company *c, bool update) /* Generate score for company's money */ { if (c->money > 0) { - _score_part[owner][SCORE_MONEY] = ClampToI32(c->money); + _score_part[owner][SCORE_MONEY] = c->money; } } /* Generate score for loan */ { - _score_part[owner][SCORE_LOAN] = ClampToI32(_score_info[SCORE_LOAN].needed - c->current_loan); + _score_part[owner][SCORE_LOAN] = _score_info[SCORE_LOAN].needed - c->current_loan; } /* Now we calculate the score for each item.. */ diff --git a/src/economy_func.h b/src/economy_func.h index 111ce85a2..7b369b7d6 100644 --- a/src/economy_func.h +++ b/src/economy_func.h @@ -22,7 +22,7 @@ void ResetPriceBaseMultipliers(); void SetPriceBaseMultiplier(Price price, int factor); extern const ScoreInfo _score_info[]; -extern int _score_part[MAX_COMPANIES][SCORE_END]; +extern int64 _score_part[MAX_COMPANIES][SCORE_END]; extern Economy _economy; /* Prices and also the fractional part. */ extern Prices _price; diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index f4334429f..48b8c4c84 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -1402,9 +1402,9 @@ struct PerformanceRatingDetailWindow : Window { int colour_notdone = _colour_gradient[COLOUR_RED][4]; /* Draw all the score parts */ - int val = _score_part[company][score_type]; - int needed = _score_info[score_type].needed; - int score = _score_info[score_type].score; + int64 val = _score_part[company][score_type]; + int64 needed = _score_info[score_type].needed; + int score = _score_info[score_type].score; /* SCORE_TOTAL has his own rules ;) */ if (score_type == SCORE_TOTAL) { @@ -1422,7 +1422,7 @@ struct PerformanceRatingDetailWindow : Window { DrawString(this->score_info_left, this->score_info_right, text_top, STR_BLACK_COMMA, TC_FROMSTRING, SA_RIGHT); /* Calculate the %-bar */ - uint x = Clamp(val, 0, needed) * this->bar_width / needed; + uint x = Clamp<int64>(val, 0, needed) * this->bar_width / needed; bool rtl = _current_text_dir == TD_RTL; if (rtl) { x = this->bar_right - x; @@ -1435,7 +1435,7 @@ struct PerformanceRatingDetailWindow : Window { if (x != this->bar_right) GfxFillRect(x, bar_top, this->bar_right, bar_top + this->bar_height, rtl ? colour_done : colour_notdone); /* Draw it */ - SetDParam(0, Clamp(val, 0, needed) * 100 / needed); + SetDParam(0, Clamp<int64>(val, 0, needed) * 100 / needed); DrawString(this->bar_left, this->bar_right, text_top, STR_PERFORMANCE_DETAIL_PERCENT, TC_FROMSTRING, SA_HOR_CENTER); /* SCORE_LOAN is inversed */ |