mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2026-07-15 15:19:52 +00:00
Codechange: use Currency for GetNewgrfCurrencyIdConverted
This commit is contained in:
+5
-5
@@ -85,8 +85,7 @@ std::array<CurrencySpec, CURRENCY_END> _currency_specs;
|
||||
* When a grf sends currencies, they are based on the order defined by TTDPatch.
|
||||
* So, we must reindex them to our own order.
|
||||
*/
|
||||
const uint8_t TTDPatch_To_OTTDIndex[] =
|
||||
{
|
||||
const Currency _ttdpatch_to_ottd_currency[] = {
|
||||
CURRENCY_GBP,
|
||||
CURRENCY_USD,
|
||||
CURRENCY_FRF,
|
||||
@@ -114,11 +113,12 @@ const uint8_t TTDPatch_To_OTTDIndex[] =
|
||||
* it is a grf written for ottd, thus returning the same id.
|
||||
* Only called from newgrf.cpp
|
||||
* @param grfcurr_id currency id coming from newgrf
|
||||
* @return the corrected index
|
||||
* @return The corrected index, or \c CURRENCY_END when invalid.
|
||||
*/
|
||||
uint8_t GetNewgrfCurrencyIdConverted(uint8_t grfcurr_id)
|
||||
Currency GetNewgrfCurrencyIdConverted(uint8_t grfcurr_id)
|
||||
{
|
||||
return (grfcurr_id >= lengthof(TTDPatch_To_OTTDIndex)) ? grfcurr_id : TTDPatch_To_OTTDIndex[grfcurr_id];
|
||||
if (grfcurr_id >= std::size(_ttdpatch_to_ottd_currency)) return CURRENCY_END;
|
||||
return _ttdpatch_to_ottd_currency[grfcurr_id];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -35,6 +35,6 @@ inline const CurrencySpec &GetCurrency()
|
||||
|
||||
Currencies GetMaskOfAllowedCurrencies();
|
||||
void ResetCurrencies(bool preserve_custom = true);
|
||||
uint8_t GetNewgrfCurrencyIdConverted(uint8_t grfcurr_id);
|
||||
Currency GetNewgrfCurrencyIdConverted(uint8_t grfcurr_id);
|
||||
|
||||
#endif /* CURRENCY_FUNC_H */
|
||||
|
||||
@@ -146,7 +146,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint first, uint last, int prop, Byt
|
||||
}
|
||||
|
||||
case 0x0A: { // Currency display names
|
||||
uint curidx = GetNewgrfCurrencyIdConverted(id);
|
||||
Currency curidx = GetNewgrfCurrencyIdConverted(id);
|
||||
if (curidx < CURRENCY_END) {
|
||||
AddStringForMapping(GRFStringID{buf.ReadWord()}, [curidx](StringID str) {
|
||||
_currency_specs[curidx].name = str;
|
||||
@@ -159,7 +159,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint first, uint last, int prop, Byt
|
||||
}
|
||||
|
||||
case 0x0B: { // Currency multipliers
|
||||
uint curidx = GetNewgrfCurrencyIdConverted(id);
|
||||
Currency curidx = GetNewgrfCurrencyIdConverted(id);
|
||||
uint32_t rate = buf.ReadDWord();
|
||||
|
||||
if (curidx < CURRENCY_END) {
|
||||
@@ -168,13 +168,13 @@ static ChangeInfoResult GlobalVarChangeInfo(uint first, uint last, int prop, Byt
|
||||
* to be compatible */
|
||||
_currency_specs[curidx].rate = rate / 1000;
|
||||
} else {
|
||||
GrfMsg(1, "GlobalVarChangeInfo: Currency multipliers {} out of range, ignoring", curidx);
|
||||
GrfMsg(1, "GlobalVarChangeInfo: Currency multipliers {} out of range, ignoring", id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x0C: { // Currency options
|
||||
uint curidx = GetNewgrfCurrencyIdConverted(id);
|
||||
Currency curidx = GetNewgrfCurrencyIdConverted(id);
|
||||
uint16_t options = buf.ReadWord();
|
||||
|
||||
if (curidx < CURRENCY_END) {
|
||||
@@ -185,43 +185,43 @@ static ChangeInfoResult GlobalVarChangeInfo(uint first, uint last, int prop, Byt
|
||||
* since newgrf specs said that only 0 and 1 can be set for symbol_pos */
|
||||
_currency_specs[curidx].symbol_pos = HasBit(options, 8) ? CurrencySymbolPosition::Suffix : CurrencySymbolPosition::Prefix;
|
||||
} else {
|
||||
GrfMsg(1, "GlobalVarChangeInfo: Currency option {} out of range, ignoring", curidx);
|
||||
GrfMsg(1, "GlobalVarChangeInfo: Currency option {} out of range, ignoring", id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x0D: { // Currency prefix symbol
|
||||
uint curidx = GetNewgrfCurrencyIdConverted(id);
|
||||
Currency curidx = GetNewgrfCurrencyIdConverted(id);
|
||||
std::string prefix = ReadDWordAsString(buf);
|
||||
|
||||
if (curidx < CURRENCY_END) {
|
||||
_currency_specs[curidx].prefix = std::move(prefix);
|
||||
} else {
|
||||
GrfMsg(1, "GlobalVarChangeInfo: Currency symbol {} out of range, ignoring", curidx);
|
||||
GrfMsg(1, "GlobalVarChangeInfo: Currency symbol {} out of range, ignoring", id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x0E: { // Currency suffix symbol
|
||||
uint curidx = GetNewgrfCurrencyIdConverted(id);
|
||||
Currency curidx = GetNewgrfCurrencyIdConverted(id);
|
||||
std::string suffix = ReadDWordAsString(buf);
|
||||
|
||||
if (curidx < CURRENCY_END) {
|
||||
_currency_specs[curidx].suffix = std::move(suffix);
|
||||
} else {
|
||||
GrfMsg(1, "GlobalVarChangeInfo: Currency symbol {} out of range, ignoring", curidx);
|
||||
GrfMsg(1, "GlobalVarChangeInfo: Currency symbol {} out of range, ignoring", id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x0F: { // Euro introduction dates
|
||||
uint curidx = GetNewgrfCurrencyIdConverted(id);
|
||||
Currency curidx = GetNewgrfCurrencyIdConverted(id);
|
||||
TimerGameCalendar::Year year_euro{buf.ReadWord()};
|
||||
|
||||
if (curidx < CURRENCY_END) {
|
||||
_currency_specs[curidx].to_euro = year_euro;
|
||||
} else {
|
||||
GrfMsg(1, "GlobalVarChangeInfo: Euro intro date {} out of range, ignoring", curidx);
|
||||
GrfMsg(1, "GlobalVarChangeInfo: Euro intro date {} out of range, ignoring", id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user