summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-09-27 20:55:42 +0000
committertron <tron@openttd.org>2005-09-27 20:55:42 +0000
commit6249dd46ad3b1b23ae959f57a0def00cf98dd8ee (patch)
tree9531eb35ea928a52105ec058a27e4be704633242
parent5f3bb18eb70826d1e35351112b50a5bbce3af799 (diff)
downloadopenttd-6249dd46ad3b1b23ae959f57a0def00cf98dd8ee.tar.xz
(svn r2994) Another small hack regarding currencies: add a #define to emulate a variable, that holds the current currency; again this should increase readability
-rw-r--r--currency.c6
-rw-r--r--currency.h2
-rw-r--r--main_gui.c2
-rw-r--r--settings_gui.c15
-rw-r--r--strings.c8
5 files changed, 11 insertions, 22 deletions
diff --git a/currency.c b/currency.c
index b6d5c14d4..fef688596 100644
--- a/currency.c
+++ b/currency.c
@@ -89,12 +89,6 @@ uint GetMaskOfAllowedCurrencies(void)
}
-uint GetCurrentCurrencyRate(void)
-{
- return _currency_specs[_opt_ptr->currency].rate;
-}
-
-
void CheckSwitchToEuro(void)
{
if (_currency_specs[_opt.currency].to_euro != CF_NOEURO &&
diff --git a/currency.h b/currency.h
index 297346273..596428a40 100644
--- a/currency.h
+++ b/currency.h
@@ -21,9 +21,9 @@ extern const StringID _currency_string_list[];
// 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 */
diff --git a/main_gui.c b/main_gui.c
index 543b4c7e2..60119965d 100644
--- a/main_gui.c
+++ b/main_gui.c
@@ -83,7 +83,7 @@ void HandleOnEditText(WindowEvent *e)
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
diff --git a/settings_gui.c b/settings_gui.c
index b0c5f5011..2c245f468 100644
--- a/settings_gui.c
+++ b/settings_gui.c
@@ -785,7 +785,7 @@ static int32 ReadPE(const PatchEntry*pe)
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 @@ static void PatchesSelectionWndProc(Window *w, WindowEvent *e)
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 @@ static void PatchesSelectionWndProc(Window *w, WindowEvent *e)
}
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 @@ static void PatchesSelectionWndProc(Window *w, WindowEvent *e)
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 @@ void IConsoleSetPatchSetting(const char *name, const char *value)
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) {
diff --git a/strings.c b/strings.c
index 20211be36..a3fc3f1b1 100644
--- a/strings.c
+++ b/strings.c
@@ -526,7 +526,7 @@ static char *FormatString(char *buff, const char *str, const int32 *argv, uint c
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 @@ static char *FormatString(char *buff, const char *str, const int32 *argv, uint c
} 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 @@ static char *FormatString(char *buff, const char *str, const int32 *argv, uint c
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 @@ static char *FormatString(char *buff, const char *str, const int32 *argv, uint c
}
case 0x9C: { // {CURRENCY64}
- buff = FormatGenericCurrency(buff, &_currency_specs[_opt_ptr->currency], GetInt64(&argv), false);
+ buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), false);
break;
}