(svn r2994) Another small hack regarding currencies: add a #define to emulate a variable, that holds the current currency; again this should increase readability
--- a/currency.c Tue Sep 27 19:16:37 2005 +0000
+++ b/currency.c Tue Sep 27 20:55:42 2005 +0000
@@ -89,12 +89,6 @@
}
-uint GetCurrentCurrencyRate(void)
-{
- return _currency_specs[_opt_ptr->currency].rate;
-}
-
-
void CheckSwitchToEuro(void)
{
if (_currency_specs[_opt.currency].to_euro != CF_NOEURO &&
--- a/currency.h Tue Sep 27 19:16:37 2005 +0000
+++ b/currency.h Tue Sep 27 20:55:42 2005 +0000
@@ -21,9 +21,9 @@
// XXX small hack, but makes the rest of the code a bit nicer to read
#define _custom_currency (_currency_specs[23])
+#define _currency ((const CurrencySpec*)&_currency_specs[_opt_ptr->currency])
uint GetMaskOfAllowedCurrencies(void);
-uint GetCurrentCurrencyRate(void);
void CheckSwitchToEuro(void);
#endif /* CURRENCY_H */
--- a/main_gui.c Tue Sep 27 19:16:37 2005 +0000
+++ b/main_gui.c Tue Sep 27 20:55:42 2005 +0000
@@ -83,7 +83,7 @@
break;
case 3: { /* Give money, you can only give money in excess of loan */
const Player *p = GetPlayer(_current_player);
- int32 money = min(p->money64 - p->current_loan, atoi(e->edittext.str) / GetCurrentCurrencyRate());
+ int32 money = min(p->money64 - p->current_loan, atoi(e->edittext.str) / _currency->rate);
char msg[20];
money = clamp(money, 0, 20000000); // Clamp between 20 million and 0
--- a/settings_gui.c Tue Sep 27 19:16:37 2005 +0000
+++ b/settings_gui.c Tue Sep 27 20:55:42 2005 +0000
@@ -785,7 +785,7 @@
case PE_INT16: return *(int16*)pe->variable;
case PE_UINT16: return *(uint16*)pe->variable;
case PE_INT32: return *(int32*)pe->variable;
- case PE_CURRENCY: return (*(int32*)pe->variable) * GetCurrentCurrencyRate();
+ case PE_CURRENCY: return (*(int32*)pe->variable) * _currency->rate;
default: NOT_REACHED();
}
@@ -878,8 +878,7 @@
DrawStringCentered(x+20, y+1, STR_681A, 0);
val = ReadPE(pe);
- if (pe->type == PE_CURRENCY)
- val /= GetCurrentCurrencyRate();
+ if (pe->type == PE_CURRENCY) val /= _currency->rate;
disabled = ((val == 0) && (pe->flags & PF_0ISDIS));
if (disabled) {
SetDParam(0, STR_CONFIG_PATCHES_DISABLED);
@@ -970,9 +969,7 @@
}
if (val != oval) {
// To make patch-changes network-safe
- if (pe->type == PE_CURRENCY) {
- val /= GetCurrentCurrencyRate();
- }
+ if (pe->type == PE_CURRENCY) val /= _currency->rate;
// If an item is playerbased, we do not send it over the network (if any)
if (pe->flags & PF_PLAYERBASED) {
WritePE(pe, val);
@@ -1014,9 +1011,7 @@
const PatchEntry *pe = &page->entries[WP(w,def_d).data_3];
int32 val;
val = atoi(e->edittext.str);
- if (pe->type == PE_CURRENCY) {
- val /= GetCurrentCurrencyRate();
- }
+ if (pe->type == PE_CURRENCY) val /= _currency->rate;
// If an item is playerbased, we do not send it over the network (if any)
if (pe->flags & PF_PLAYERBASED) {
WritePE(pe, val);
@@ -1099,7 +1094,7 @@
sscanf(value, "%d", &val);
if (pe->type == PE_CURRENCY) // currency can be different on each client
- val /= GetCurrentCurrencyRate();
+ val /= _currency->rate;
// If an item is playerbased, we do not send it over the network (if any)
if (pe->flags & PF_PLAYERBASED) {
--- a/strings.c Tue Sep 27 19:16:37 2005 +0000
+++ b/strings.c Tue Sep 27 20:55:42 2005 +0000
@@ -526,7 +526,7 @@
case 0x85:
switch (*str++) {
case 0: /* {CURRCOMPACT} */
- buff = FormatGenericCurrency(buff, &_currency_specs[_opt_ptr->currency], GetInt32(&argv), true);
+ buff = FormatGenericCurrency(buff, _currency, GetInt32(&argv), true);
break;
case 2: /* {REV} */
buff = strecpy(buff, _openttd_revision, NULL);
@@ -544,7 +544,7 @@
} break;
case 4: {/* {CURRCOMPACT64} */
// 64 bit compact currency-unit
- buff = FormatGenericCurrency(buff, &_currency_specs[_opt_ptr->currency], GetInt64(&argv), true);
+ buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), true);
break;
}
case 5: { /* {STRING1} */
@@ -684,7 +684,7 @@
break;
case 0x8F: // {CURRENCY}
- buff = FormatGenericCurrency(buff, &_currency_specs[_opt_ptr->currency], GetInt32(&argv), false);
+ buff = FormatGenericCurrency(buff, _currency, GetInt32(&argv), false);
break;
case 0x99: { // {WAYPOINT}
@@ -726,7 +726,7 @@
}
case 0x9C: { // {CURRENCY64}
- buff = FormatGenericCurrency(buff, &_currency_specs[_opt_ptr->currency], GetInt64(&argv), false);
+ buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), false);
break;
}