(svn r14767) -Codechange: remove some unneeded artificial limits from currencies and use the bounds of the data type.

pull/155/head
rubidium 16 years ago
parent 42fb037005
commit 5aa2dac751

@ -1511,11 +1511,11 @@ const SettingDesc _patch_settings[] = {
}; };
static const SettingDesc _currency_settings[] = { static const SettingDesc _currency_settings[] = {
SDT_VAR(CurrencySpec, rate, SLE_UINT16, S, 0, 1, 0, 100, 0, STR_NULL, NULL), SDT_VAR(CurrencySpec, rate, SLE_UINT16, S, 0, 1, 0, UINT16_MAX, 0, STR_NULL, NULL),
SDT_CHR(CurrencySpec, separator, S, 0, ".", STR_NULL, NULL), SDT_CHR(CurrencySpec, separator, S, 0, ".", STR_NULL, NULL),
SDT_VAR(CurrencySpec, to_euro, SLE_INT32, S, 0, 0, 0, 3000, 0, STR_NULL, NULL), SDT_VAR(CurrencySpec, to_euro, SLE_INT32, S, 0, 0, MIN_YEAR, MAX_YEAR, 0, STR_NULL, NULL),
SDT_STR(CurrencySpec, prefix, SLE_STRBQ, S, 0, NULL, STR_NULL, NULL), SDT_STR(CurrencySpec, prefix, SLE_STRBQ, S, 0, NULL, STR_NULL, NULL),
SDT_STR(CurrencySpec, suffix, SLE_STRBQ, S, 0, " credits", STR_NULL, NULL), SDT_STR(CurrencySpec, suffix, SLE_STRBQ, S, 0, " credits", STR_NULL, NULL),
SDT_END() SDT_END()
}; };

@ -1111,13 +1111,13 @@ struct CustomCurrencyWindow : Window {
if (_custom_currency.rate > 1) _custom_currency.rate--; if (_custom_currency.rate > 1) _custom_currency.rate--;
this->click = 1 << (line * 2 + 0); this->click = 1 << (line * 2 + 0);
} else { } else {
if (_custom_currency.rate < 5000) _custom_currency.rate++; if (_custom_currency.rate < UINT16_MAX) _custom_currency.rate++;
this->click = 1 << (line * 2 + 1); this->click = 1 << (line * 2 + 1);
} }
} else { // enter text } else { // enter text
SetDParam(0, _custom_currency.rate); SetDParam(0, _custom_currency.rate);
str = STR_CONFIG_PATCHES_INT32; str = STR_CONFIG_PATCHES_INT32;
len = 4; len = 5;
afilter = CS_NUMERAL; afilter = CS_NUMERAL;
} }
break; break;
@ -1152,18 +1152,16 @@ struct CustomCurrencyWindow : Window {
case CUSTCURR_TO_EURO: case CUSTCURR_TO_EURO:
if (IsInsideMM(x, 10, 30)) { // clicked buttons if (IsInsideMM(x, 10, 30)) { // clicked buttons
if (x < 20) { if (x < 20) {
_custom_currency.to_euro = (_custom_currency.to_euro <= 2000) ? _custom_currency.to_euro = (_custom_currency.to_euro <= 2000) ? CF_NOEURO : _custom_currency.to_euro - 1;
CF_NOEURO : _custom_currency.to_euro - 1;
this->click = 1 << (line * 2 + 0); this->click = 1 << (line * 2 + 0);
} else { } else {
_custom_currency.to_euro = _custom_currency.to_euro = Clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR);
Clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR);
this->click = 1 << (line * 2 + 1); this->click = 1 << (line * 2 + 1);
} }
} else { // enter text } else { // enter text
SetDParam(0, _custom_currency.to_euro); SetDParam(0, _custom_currency.to_euro);
str = STR_CONFIG_PATCHES_INT32; str = STR_CONFIG_PATCHES_INT32;
len = 4; len = 7;
afilter = CS_NUMERAL; afilter = CS_NUMERAL;
} }
break; break;
@ -1184,7 +1182,7 @@ struct CustomCurrencyWindow : Window {
switch (this->query_widget) { switch (this->query_widget) {
case CUSTCURR_EXCHANGERATE: case CUSTCURR_EXCHANGERATE:
_custom_currency.rate = Clamp(atoi(str), 1, 5000); _custom_currency.rate = Clamp(atoi(str), 1, UINT16_MAX);
break; break;
case CUSTCURR_SEPARATOR: /* Thousands seperator */ case CUSTCURR_SEPARATOR: /* Thousands seperator */

Loading…
Cancel
Save