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