mirror of https://github.com/OpenTTD/OpenTTD
(svn r2830) Move CheckSwitchToEuro() to currency.[ch] and hide the truth about the custom currency behind a #define
parent
59da8350c1
commit
14e80ca159
12
currency.c
12
currency.c
|
@ -3,6 +3,7 @@
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "openttd.h"
|
#include "openttd.h"
|
||||||
#include "currency.h"
|
#include "currency.h"
|
||||||
|
#include "news.h"
|
||||||
#include "variables.h"
|
#include "variables.h"
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
|
||||||
|
@ -92,3 +93,14 @@ uint GetCurrentCurrencyRate(void)
|
||||||
{
|
{
|
||||||
return _currency_specs[_opt_ptr->currency].rate;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -19,7 +19,11 @@ typedef struct {
|
||||||
extern CurrencySpec _currency_specs[];
|
extern CurrencySpec _currency_specs[];
|
||||||
extern const StringID _currency_string_list[];
|
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 GetMaskOfAllowedCurrencies(void);
|
||||||
uint GetCurrentCurrencyRate(void);
|
uint GetCurrentCurrencyRate(void);
|
||||||
|
void CheckSwitchToEuro(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
10
economy.c
10
economy.c
|
@ -42,16 +42,6 @@ const ScoreInfo _score_info[] = {
|
||||||
|
|
||||||
int _score_part[MAX_PLAYERS][NUM_SCORE];
|
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)
|
void UpdatePlayerHouse(Player *p, uint score)
|
||||||
{
|
{
|
||||||
byte val;
|
byte val;
|
||||||
|
|
|
@ -268,8 +268,6 @@ void InitializeLanguagePacks(void);
|
||||||
void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize);
|
void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize);
|
||||||
int GetLanguageList(char **languages, int max);
|
int GetLanguageList(char **languages, int max);
|
||||||
|
|
||||||
void CheckSwitchToEuro(void);
|
|
||||||
|
|
||||||
void LoadFromConfig(void);
|
void LoadFromConfig(void);
|
||||||
void SaveToConfig(void);
|
void SaveToConfig(void);
|
||||||
void CheckConfig(void);
|
void CheckConfig(void);
|
||||||
|
|
12
settings.c
12
settings.c
|
@ -990,12 +990,12 @@ const SettingDesc patch_settings[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static const SettingDesc currency_settings[] = {
|
static const SettingDesc currency_settings[] = {
|
||||||
{"rate", SDT_UINT16, (void*)1, &_currency_specs[23].rate, NULL},
|
{ "rate", SDT_UINT16, (void*)1, &_custom_currency.rate, NULL },
|
||||||
{"separator", SDT_STRINGQUOT | (2) << 16, ".", &_currency_specs[23].separator, NULL},
|
{ "separator", SDT_STRINGQUOT | (2) << 16, ".", &_custom_currency.separator, NULL },
|
||||||
{"to_euro", SDT_UINT16, (void*)0, &_currency_specs[23].to_euro, NULL},
|
{ "to_euro", SDT_UINT16, (void*)0, &_custom_currency.to_euro, NULL },
|
||||||
{"prefix", SDT_STRINGQUOT | (16) << 16, NULL, &_currency_specs[23].prefix, NULL},
|
{ "prefix", SDT_STRINGQUOT | (16) << 16, NULL, &_custom_currency.prefix, NULL },
|
||||||
{"suffix", SDT_STRINGQUOT | (16) << 16, " credits", &_currency_specs[23].suffix, NULL},
|
{ "suffix", SDT_STRINGQUOT | (16) << 16, " credits", &_custom_currency.suffix, NULL },
|
||||||
{NULL, 0, NULL, NULL, NULL}
|
{ NULL, 0, NULL, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const void *grpname);
|
typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const void *grpname);
|
||||||
|
|
|
@ -1349,7 +1349,7 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e)
|
||||||
// prefix
|
// prefix
|
||||||
DrawFrameRect(10, y+1, 29, y+9, 0, ((clk >> (i*2)) & 0x03) ? FR_LOWERED : 0);
|
DrawFrameRect(10, y+1, 29, y+9, 0, ((clk >> (i*2)) & 0x03) ? FR_LOWERED : 0);
|
||||||
x = DrawString(x, y + 1, STR_CURRENCY_PREFIX, 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;
|
x = 35;
|
||||||
y+=12;
|
y+=12;
|
||||||
i++;
|
i++;
|
||||||
|
@ -1357,15 +1357,15 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e)
|
||||||
// suffix
|
// suffix
|
||||||
DrawFrameRect(10, y+1, 29, y+9, 0, ((clk >> (i*2)) & 0x03) ? FR_LOWERED : 0);
|
DrawFrameRect(10, y+1, 29, y+9, 0, ((clk >> (i*2)) & 0x03) ? FR_LOWERED : 0);
|
||||||
x = DrawString(x, y + 1, STR_CURRENCY_SUFFIX, 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;
|
x = 35;
|
||||||
y+=12;
|
y+=12;
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
// switch to euro
|
// switch to euro
|
||||||
DrawArrowButtons(10, y, (clk >> (i*2)) & 0x03);
|
DrawArrowButtons(10, y, (clk >> (i*2)) & 0x03);
|
||||||
SetDParam(0, _currency_specs[23].to_euro);
|
SetDParam(0, _custom_currency.to_euro);
|
||||||
DrawString(x, y + 1, (_currency_specs[23].to_euro)?STR_CURRENCY_SWITCH_TO_EURO:STR_CURRENCY_SWITCH_TO_EURO_NEVER, 0);
|
DrawString(x, y + 1, (_custom_currency.to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER, 0);
|
||||||
x = 35;
|
x = 35;
|
||||||
y+=12;
|
y+=12;
|
||||||
i++;
|
i++;
|
||||||
|
@ -1387,14 +1387,14 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e)
|
||||||
case 0: // rate
|
case 0: // rate
|
||||||
if ( IS_INT_INSIDE(x, 10, 30) ) { // clicked buttons
|
if ( IS_INT_INSIDE(x, 10, 30) ) { // clicked buttons
|
||||||
if (x < 20) {
|
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));
|
WP(w,def_d).data_1 = (1 << (line * 2 + 0));
|
||||||
} else {
|
} 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));
|
WP(w,def_d).data_1 = (1 << (line * 2 + 1));
|
||||||
}
|
}
|
||||||
} else { // enter text
|
} else { // enter text
|
||||||
SetDParam(0, _currency_specs[23].rate);
|
SetDParam(0, _custom_currency.rate);
|
||||||
str = STR_CONFIG_PATCHES_INT32;
|
str = STR_CONFIG_PATCHES_INT32;
|
||||||
len = 4;
|
len = 4;
|
||||||
edittext = true;
|
edittext = true;
|
||||||
|
@ -1410,31 +1410,30 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e)
|
||||||
case 2: // prefix
|
case 2: // prefix
|
||||||
if ( IS_INT_INSIDE(x, 10, 30) ) // clicked button
|
if ( IS_INT_INSIDE(x, 10, 30) ) // clicked button
|
||||||
WP(w,def_d).data_1 = (1 << (line * 2 + 1));
|
WP(w,def_d).data_1 = (1 << (line * 2 + 1));
|
||||||
str = BindCString(_currency_specs[23].prefix);
|
str = BindCString(_custom_currency.prefix);
|
||||||
len = 12;
|
len = 12;
|
||||||
edittext = true;
|
edittext = true;
|
||||||
break;
|
break;
|
||||||
case 3: // suffix
|
case 3: // suffix
|
||||||
if ( IS_INT_INSIDE(x, 10, 30) ) // clicked button
|
if ( IS_INT_INSIDE(x, 10, 30) ) // clicked button
|
||||||
WP(w,def_d).data_1 = (1 << (line * 2 + 1));
|
WP(w,def_d).data_1 = (1 << (line * 2 + 1));
|
||||||
str = BindCString(_currency_specs[23].suffix);
|
str = BindCString(_custom_currency.suffix);
|
||||||
len = 12;
|
len = 12;
|
||||||
edittext = true;
|
edittext = true;
|
||||||
break;
|
break;
|
||||||
case 4: // to euro
|
case 4: // to euro
|
||||||
if ( IS_INT_INSIDE(x, 10, 30) ) { // clicked buttons
|
if ( IS_INT_INSIDE(x, 10, 30) ) { // clicked buttons
|
||||||
if (x < 20) {
|
if (x < 20) {
|
||||||
if(_currency_specs[23].to_euro <= 2000) _currency_specs[23].to_euro = 0;
|
_custom_currency.to_euro = (_custom_currency.to_euro <= 2000) ?
|
||||||
else _currency_specs[23].to_euro--;
|
CF_NOEURO : _custom_currency.to_euro - 1;
|
||||||
WP(w,def_d).data_1 = (1 << (line * 2 + 0));
|
WP(w,def_d).data_1 = (1 << (line * 2 + 0));
|
||||||
} else {
|
} else {
|
||||||
if(_currency_specs[23].to_euro == 0) _currency_specs[23].to_euro = 2000;
|
_custom_currency.to_euro =
|
||||||
else _currency_specs[23].to_euro++;
|
clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR_END_REAL);
|
||||||
_currency_specs[23].to_euro = min(MAX_YEAR_END_REAL, _currency_specs[23].to_euro);
|
|
||||||
WP(w,def_d).data_1 = (1 << (line * 2 + 1));
|
WP(w,def_d).data_1 = (1 << (line * 2 + 1));
|
||||||
}
|
}
|
||||||
} else { // enter text
|
} else { // enter text
|
||||||
SetDParam(0, _currency_specs[23].to_euro);
|
SetDParam(0, _custom_currency.to_euro);
|
||||||
str = STR_CONFIG_PATCHES_INT32;
|
str = STR_CONFIG_PATCHES_INT32;
|
||||||
len = 4;
|
len = 4;
|
||||||
edittext = true;
|
edittext = true;
|
||||||
|
@ -1464,23 +1463,23 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e)
|
||||||
case 0: /* Exchange rate */
|
case 0: /* Exchange rate */
|
||||||
val = atoi(b);
|
val = atoi(b);
|
||||||
val = clamp(val, 1, 5000);
|
val = clamp(val, 1, 5000);
|
||||||
_currency_specs[23].rate = val;
|
_custom_currency.rate = val;
|
||||||
break;
|
break;
|
||||||
case 1: /* Thousands seperator */
|
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);
|
ttd_strlcpy(_str_separator, b, 16);
|
||||||
break;
|
break;
|
||||||
case 2: /* Currency prefix */
|
case 2: /* Currency prefix */
|
||||||
ttd_strlcpy(_currency_specs[23].prefix, b, 16);
|
ttd_strlcpy(_custom_currency.prefix, b, lengthof(_custom_currency.prefix));
|
||||||
break;
|
break;
|
||||||
case 3: /* Currency suffix */
|
case 3: /* Currency suffix */
|
||||||
ttd_strlcpy(_currency_specs[23].suffix, b, 16);
|
ttd_strlcpy(_custom_currency.suffix, b, lengthof(_custom_currency.suffix));
|
||||||
break;
|
break;
|
||||||
case 4: /* Year to switch to euro */
|
case 4: /* Year to switch to euro */
|
||||||
val = atoi(b);
|
val = atoi(b);
|
||||||
val = clamp(val, 1999, MAX_YEAR_END_REAL);
|
val = clamp(val, 1999, MAX_YEAR_END_REAL);
|
||||||
if (val == 1999) val = 0;
|
if (val == 1999) val = 0;
|
||||||
_currency_specs[23].to_euro = val;
|
_custom_currency.to_euro = val;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
MarkWholeScreenDirty();
|
MarkWholeScreenDirty();
|
||||||
|
@ -1519,7 +1518,7 @@ void ShowCustCurrency(void)
|
||||||
{
|
{
|
||||||
Window *w;
|
Window *w;
|
||||||
|
|
||||||
_str_separator[0] = _currency_specs[23].separator;
|
_str_separator[0] = _custom_currency.separator;
|
||||||
_str_separator[1] = '\0';
|
_str_separator[1] = '\0';
|
||||||
|
|
||||||
DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
|
DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
|
||||||
|
|
Loading…
Reference in New Issue