summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-08-07 12:41:57 +0000
committertron <tron@openttd.org>2005-08-07 12:41:57 +0000
commit14e80ca15968476fffdbc64c5dc5edae9145c0d8 (patch)
tree48e4b97d4e158c2a7f487423c480569db2b96b82
parent59da8350c137a14dfbd194128a37591634247e46 (diff)
downloadopenttd-14e80ca15968476fffdbc64c5dc5edae9145c0d8.tar.xz
(svn r2830) Move CheckSwitchToEuro() to currency.[ch] and hide the truth about the custom currency behind a #define
-rw-r--r--currency.c12
-rw-r--r--currency.h4
-rw-r--r--economy.c10
-rw-r--r--functions.h2
-rw-r--r--settings.c12
-rw-r--r--settings_gui.c41
6 files changed, 42 insertions, 39 deletions
diff --git a/currency.c b/currency.c
index 29a698bd3..b6d5c14d4 100644
--- a/currency.c
+++ b/currency.c
@@ -3,6 +3,7 @@
#include "stdafx.h"
#include "openttd.h"
#include "currency.h"
+#include "news.h"
#include "variables.h"
#include "table/strings.h"
@@ -92,3 +93,14 @@ uint GetCurrentCurrencyRate(void)
{
return _currency_specs[_opt_ptr->currency].rate;
}
+
+
+void CheckSwitchToEuro(void)
+{
+ if (_currency_specs[_opt.currency].to_euro != CF_NOEURO &&
+ _currency_specs[_opt.currency].to_euro != CF_ISEURO &&
+ MAX_YEAR_BEGIN_REAL + _cur_year >= _currency_specs[_opt.currency].to_euro) {
+ _opt.currency = 2; // this is the index of euro above.
+ AddNewsItem(STR_EURO_INTRODUCE, NEWS_FLAGS(NM_NORMAL, 0, NT_ECONOMY, 0), 0, 0);
+ }
+}
diff --git a/currency.h b/currency.h
index 7c368267d..5b3300773 100644
--- a/currency.h
+++ b/currency.h
@@ -19,7 +19,11 @@ typedef struct {
extern CurrencySpec _currency_specs[];
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])
+
uint GetMaskOfAllowedCurrencies(void);
uint GetCurrentCurrencyRate(void);
+void CheckSwitchToEuro(void);
#endif
diff --git a/economy.c b/economy.c
index 8bbc13c49..1c4cd70e7 100644
--- a/economy.c
+++ b/economy.c
@@ -42,16 +42,6 @@ const ScoreInfo _score_info[] = {
int _score_part[MAX_PLAYERS][NUM_SCORE];
-void CheckSwitchToEuro(void)
-{
- if (_currency_specs[_opt.currency].to_euro != CF_NOEURO &&
- _currency_specs[_opt.currency].to_euro != CF_ISEURO &&
- _cur_year >= (_currency_specs[_opt.currency].to_euro-MAX_YEAR_BEGIN_REAL)) {
- _opt.currency = 2; // this is the index of euro above.
- AddNewsItem(STR_EURO_INTRODUCE, NEWS_FLAGS(NM_NORMAL,0,NT_ECONOMY,0), 0, 0);
- }
-}
-
void UpdatePlayerHouse(Player *p, uint score)
{
byte val;
diff --git a/functions.h b/functions.h
index f0763acb9..3c4af9c3c 100644
--- a/functions.h
+++ b/functions.h
@@ -268,8 +268,6 @@ void InitializeLanguagePacks(void);
void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize);
int GetLanguageList(char **languages, int max);
-void CheckSwitchToEuro(void);
-
void LoadFromConfig(void);
void SaveToConfig(void);
void CheckConfig(void);
diff --git a/settings.c b/settings.c
index 37f8872d5..7f9575c8d 100644
--- a/settings.c
+++ b/settings.c
@@ -990,12 +990,12 @@ const SettingDesc patch_settings[] = {
};
static const SettingDesc currency_settings[] = {
- {"rate", SDT_UINT16, (void*)1, &_currency_specs[23].rate, NULL},
- {"separator", SDT_STRINGQUOT | (2) << 16, ".", &_currency_specs[23].separator, NULL},
- {"to_euro", SDT_UINT16, (void*)0, &_currency_specs[23].to_euro, NULL},
- {"prefix", SDT_STRINGQUOT | (16) << 16, NULL, &_currency_specs[23].prefix, NULL},
- {"suffix", SDT_STRINGQUOT | (16) << 16, " credits", &_currency_specs[23].suffix, NULL},
- {NULL, 0, NULL, NULL, NULL}
+ { "rate", SDT_UINT16, (void*)1, &_custom_currency.rate, NULL },
+ { "separator", SDT_STRINGQUOT | (2) << 16, ".", &_custom_currency.separator, NULL },
+ { "to_euro", SDT_UINT16, (void*)0, &_custom_currency.to_euro, NULL },
+ { "prefix", SDT_STRINGQUOT | (16) << 16, NULL, &_custom_currency.prefix, NULL },
+ { "suffix", SDT_STRINGQUOT | (16) << 16, " credits", &_custom_currency.suffix, NULL },
+ { NULL, 0, NULL, NULL, NULL }
};
typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const void *grpname);
diff --git a/settings_gui.c b/settings_gui.c
index 8fce9348e..f4e03980b 100644
--- a/settings_gui.c
+++ b/settings_gui.c
@@ -1349,7 +1349,7 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e)
// prefix
DrawFrameRect(10, y+1, 29, y+9, 0, ((clk >> (i*2)) & 0x03) ? FR_LOWERED : 0);
x = DrawString(x, y + 1, STR_CURRENCY_PREFIX, 0);
- DoDrawString(_currency_specs[23].prefix, x + 4, y + 1, 6);
+ DoDrawString(_custom_currency.prefix, x + 4, y + 1, 6);
x = 35;
y+=12;
i++;
@@ -1357,15 +1357,15 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e)
// suffix
DrawFrameRect(10, y+1, 29, y+9, 0, ((clk >> (i*2)) & 0x03) ? FR_LOWERED : 0);
x = DrawString(x, y + 1, STR_CURRENCY_SUFFIX, 0);
- DoDrawString(_currency_specs[23].suffix, x + 4, y + 1, 6);
+ DoDrawString(_custom_currency.suffix, x + 4, y + 1, 6);
x = 35;
y+=12;
i++;
// switch to euro
DrawArrowButtons(10, y, (clk >> (i*2)) & 0x03);
- SetDParam(0, _currency_specs[23].to_euro);
- DrawString(x, y + 1, (_currency_specs[23].to_euro)?STR_CURRENCY_SWITCH_TO_EURO:STR_CURRENCY_SWITCH_TO_EURO_NEVER, 0);
+ SetDParam(0, _custom_currency.to_euro);
+ DrawString(x, y + 1, (_custom_currency.to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER, 0);
x = 35;
y+=12;
i++;
@@ -1387,14 +1387,14 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e)
case 0: // rate
if ( IS_INT_INSIDE(x, 10, 30) ) { // clicked buttons
if (x < 20) {
- _currency_specs[23].rate = max(1, _currency_specs[23].rate-1);
+ if (_custom_currency.rate > 1) _custom_currency.rate--;
WP(w,def_d).data_1 = (1 << (line * 2 + 0));
} else {
- _currency_specs[23].rate = min(5000, _currency_specs[23].rate+1);
+ if (_custom_currency.rate < 5000) _custom_currency.rate++;
WP(w,def_d).data_1 = (1 << (line * 2 + 1));
}
} else { // enter text
- SetDParam(0, _currency_specs[23].rate);
+ SetDParam(0, _custom_currency.rate);
str = STR_CONFIG_PATCHES_INT32;
len = 4;
edittext = true;
@@ -1410,31 +1410,30 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e)
case 2: // prefix
if ( IS_INT_INSIDE(x, 10, 30) ) // clicked button
WP(w,def_d).data_1 = (1 << (line * 2 + 1));
- str = BindCString(_currency_specs[23].prefix);
+ str = BindCString(_custom_currency.prefix);
len = 12;
edittext = true;
break;
case 3: // suffix
if ( IS_INT_INSIDE(x, 10, 30) ) // clicked button
WP(w,def_d).data_1 = (1 << (line * 2 + 1));
- str = BindCString(_currency_specs[23].suffix);
+ str = BindCString(_custom_currency.suffix);
len = 12;
edittext = true;
break;
case 4: // to euro
if ( IS_INT_INSIDE(x, 10, 30) ) { // clicked buttons
if (x < 20) {
- if(_currency_specs[23].to_euro <= 2000) _currency_specs[23].to_euro = 0;
- else _currency_specs[23].to_euro--;
+ _custom_currency.to_euro = (_custom_currency.to_euro <= 2000) ?
+ CF_NOEURO : _custom_currency.to_euro - 1;
WP(w,def_d).data_1 = (1 << (line * 2 + 0));
} else {
- if(_currency_specs[23].to_euro == 0) _currency_specs[23].to_euro = 2000;
- else _currency_specs[23].to_euro++;
- _currency_specs[23].to_euro = min(MAX_YEAR_END_REAL, _currency_specs[23].to_euro);
+ _custom_currency.to_euro =
+ clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR_END_REAL);
WP(w,def_d).data_1 = (1 << (line * 2 + 1));
}
} else { // enter text
- SetDParam(0, _currency_specs[23].to_euro);
+ SetDParam(0, _custom_currency.to_euro);
str = STR_CONFIG_PATCHES_INT32;
len = 4;
edittext = true;
@@ -1464,23 +1463,23 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e)
case 0: /* Exchange rate */
val = atoi(b);
val = clamp(val, 1, 5000);
- _currency_specs[23].rate = val;
+ _custom_currency.rate = val;
break;
case 1: /* Thousands seperator */
- _currency_specs[23].separator = (b[0] == '\0') ? ' ' : b[0];
+ _custom_currency.separator = (b[0] == '\0') ? ' ' : b[0];
ttd_strlcpy(_str_separator, b, 16);
break;
case 2: /* Currency prefix */
- ttd_strlcpy(_currency_specs[23].prefix, b, 16);
+ ttd_strlcpy(_custom_currency.prefix, b, lengthof(_custom_currency.prefix));
break;
case 3: /* Currency suffix */
- ttd_strlcpy(_currency_specs[23].suffix, b, 16);
+ ttd_strlcpy(_custom_currency.suffix, b, lengthof(_custom_currency.suffix));
break;
case 4: /* Year to switch to euro */
val = atoi(b);
val = clamp(val, 1999, MAX_YEAR_END_REAL);
if (val == 1999) val = 0;
- _currency_specs[23].to_euro = val;
+ _custom_currency.to_euro = val;
break;
}
MarkWholeScreenDirty();
@@ -1519,7 +1518,7 @@ void ShowCustCurrency(void)
{
Window *w;
- _str_separator[0] = _currency_specs[23].separator;
+ _str_separator[0] = _custom_currency.separator;
_str_separator[1] = '\0';
DeleteWindowById(WC_CUSTOM_CURRENCY, 0);