From 5fa0946c087408545c22250be1996f3433d94786 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 25 May 2008 12:57:39 +0000 Subject: (svn r13242) -Codechange: remove _opt_ptr. --- src/currency.h | 2 +- src/genworld_gui.cpp | 1 - src/misc_cmd.cpp | 8 +++--- src/network/network_client.cpp | 2 -- src/openttd.cpp | 8 +----- src/road_cmd.cpp | 6 ++++- src/settings.cpp | 1 - src/settings_gui.cpp | 39 +++++++++++++++------------ src/settings_type.h | 3 --- src/strings.cpp | 60 +++++++++++++++++++++--------------------- 10 files changed, 64 insertions(+), 66 deletions(-) diff --git a/src/currency.h b/src/currency.h index 08b839a72..f2ff11650 100644 --- a/src/currency.h +++ b/src/currency.h @@ -39,7 +39,7 @@ extern CurrencySpec _currency_specs[NUM_CURRENCY]; // XXX small hack, but makes the rest of the code a bit nicer to read #define _custom_currency (_currency_specs[CUSTOM_CURRENCY_ID]) -#define _currency ((const CurrencySpec*)&_currency_specs[_opt_ptr->currency]) +#define _currency ((const CurrencySpec*)&_currency_specs[(_game_mode == GM_MENU) ? _opt_newgame.currency : _opt.currency]) uint GetMaskOfAllowedCurrencies(); void CheckSwitchToEuro(); diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index 42336d9f9..114218f57 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -207,7 +207,6 @@ void StartGeneratingLandscape(glwp_modes mode) /* Copy all XXX_newgame to XXX when coming from outside the editor */ UpdatePatches(); _opt = _opt_newgame; - _opt_ptr = &_opt; ResetGRFConfig(true); SndPlayFx(SND_15_BEEP); diff --git a/src/misc_cmd.cpp b/src/misc_cmd.cpp index 0e6c2bc22..2dad0e297 100644 --- a/src/misc_cmd.cpp +++ b/src/misc_cmd.cpp @@ -395,12 +395,14 @@ CommandCost CmdChangeDifficultyLevel(TileIndex tile, uint32 flags, uint32 p1, ui { if (p1 != (uint32)-1L && ((int32)p1 >= GAME_DIFFICULTY_NUM || (int32)p1 < 0)) return CMD_ERROR; + GameOptions *opt_ptr = (_game_mode == GM_MENU) ? &_opt_newgame : &_opt; + if (flags & DC_EXEC) { if (p1 != (uint32)-1L) { - ((GDType*)&_opt_ptr->diff)[p1] = p2; - _opt_ptr->diff_level = 3; // custom difficulty level + ((GDType*)&opt_ptr->diff)[p1] = p2; + opt_ptr->diff_level = 3; // custom difficulty level } else { - _opt_ptr->diff_level = p2; + opt_ptr->diff_level = p2; } /* Since the tolerance of the town council has a direct impact on the noise generation/tolerance, diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index b9a1ea35c..d9fcb9a60 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -622,8 +622,6 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP) /* If the savegame has successfully loaded, ALL windows have been removed, * only toolbar/statusbar and gamefield are visible */ - _opt_ptr = &_opt; // during a network game you are always in-game - // Say we received the map and loaded it correctly! SEND_COMMAND(PACKET_CLIENT_MAP_OK)(); diff --git a/src/openttd.cpp b/src/openttd.cpp index 0466f0716..2b64822a1 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -330,7 +330,6 @@ static void LoadIntroGame() { _game_mode = GM_MENU; - _opt_ptr = &_opt_newgame; ResetGRFConfig(false); /* Setup main window */ @@ -584,7 +583,6 @@ int ttd_main(int argc, char *argv[]) ScanNewGRFFiles(); - _opt_ptr = &_opt_newgame; ResetGRFConfig(false); /* XXX - ugly hack, if diff_level is 9, it means we got no setting from the config file */ @@ -769,8 +767,7 @@ static void StartScenario() ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0); } - _opt_ptr = &_opt; - _opt_ptr->diff = _opt_newgame.diff; + _opt.diff = _opt_newgame.diff; _opt.diff_level = _opt_newgame.diff_level; /* Inititalize data */ @@ -877,7 +874,6 @@ void SwitchMode(int new_mode) break; case SM_LOAD: { /* Load game, Play Scenario */ - _opt_ptr = &_opt; ResetGRFConfig(true); ResetWindowSystem(); @@ -921,8 +917,6 @@ void SwitchMode(int new_mode) case SM_LOAD_SCENARIO: { /* Load scenario from scenario editor */ if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR, NO_DIRECTORY)) { - _opt_ptr = &_opt; - SetLocalPlayer(OWNER_NONE); _patches_newgame.starting_year = _cur_year; } else { diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index 26a36544f..ef193720d 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -68,7 +68,11 @@ CommandCost CmdSetRoadDriveSide(TileIndex tile, uint32 flags, uint32 p1, uint32 if (p1 > 1 || (_game_mode != GM_MENU && RoadVehiclesAreBuilt())) return CMD_ERROR; if (flags & DC_EXEC) { - _opt_ptr->road_side = p1; + if (_game_mode == GM_MENU) { + _opt_newgame.road_side = p1; + } else { + _opt.road_side = p1; + } InvalidateWindow(WC_GAME_OPTIONS, 0); } return CommandCost(); diff --git a/src/settings.cpp b/src/settings.cpp index a8096a75d..ee9a4c8e8 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -65,7 +65,6 @@ GameOptions _opt; GameOptions _opt_newgame; -GameOptions *_opt_ptr; Patches _patches; Patches _patches_newgame; diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index e294397d3..c0e36321f 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -142,8 +142,11 @@ static void ShowTownnameDropdown(Window *w, int sel) static void ShowCustCurrency(); struct GameOptionsWindow : Window { + GameOptions *opt; + GameOptionsWindow(const WindowDesc *desc) : Window(desc) { + this->opt = (_game_mode == GM_MENU) ? &_opt_newgame : &_opt; this->FindWindowPlacementAndResize(desc); } @@ -159,11 +162,11 @@ struct GameOptionsWindow : Window { this->SetWidgetDisabledState(GAMEOPT_VEHICLENAME_SAVE, !(_vehicle_design_names & 1)); if (!this->IsWidgetDisabled(GAMEOPT_VEHICLENAME_SAVE)) str = STR_02BF_CUSTOM; SetDParam(0, str); - SetDParam(1, _currency_specs[_opt_ptr->currency].name); - SetDParam(2, STR_UNITS_IMPERIAL + _opt_ptr->units); - SetDParam(3, STR_02E9_DRIVE_ON_LEFT + _opt_ptr->road_side); - SetDParam(4, TownName(_opt_ptr->town_name)); - SetDParam(5, _autosave_dropdown[_opt_ptr->autosave]); + SetDParam(1, _currency_specs[this->opt->currency].name); + SetDParam(2, STR_UNITS_IMPERIAL + this->opt->units); + SetDParam(3, STR_02E9_DRIVE_ON_LEFT + this->opt->road_side); + SetDParam(4, TownName(this->opt->town_name)); + SetDParam(5, _autosave_dropdown[this->opt->autosave]); SetDParam(6, SPECSTR_LANGUAGE_START + _dynlang.curr); int i = GetCurRes(); SetDParam(7, i == _num_resolutions ? STR_RES_OTHER : SPECSTR_RESOLUTION_START + i); @@ -178,11 +181,11 @@ struct GameOptionsWindow : Window { { switch (widget) { case GAMEOPT_CURRENCY_BTN: // Setup currencies dropdown - ShowDropDownMenu(this, BuildCurrencyDropdown(), _opt_ptr->currency, GAMEOPT_CURRENCY_BTN, _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies(), 0); + ShowDropDownMenu(this, BuildCurrencyDropdown(), this->opt->currency, GAMEOPT_CURRENCY_BTN, _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies(), 0); break; case GAMEOPT_DISTANCE_BTN: // Setup distance unit dropdown - ShowDropDownMenu(this, _units_dropdown, _opt_ptr->units, GAMEOPT_DISTANCE_BTN, 0, 0); + ShowDropDownMenu(this, _units_dropdown, this->opt->units, GAMEOPT_DISTANCE_BTN, 0, 0); break; case GAMEOPT_ROADSIDE_BTN: { // Setup road-side dropdown @@ -192,18 +195,18 @@ struct GameOptionsWindow : Window { /* You can only change the drive side if you are in the menu or ingame with * no vehicles present. In a networking game only the server can change it */ if ((_game_mode != GM_MENU && RoadVehiclesAreBuilt()) || (_networking && !_network_server)) { - i = (-1) ^ (1 << _opt_ptr->road_side); // disable the other value + i = (-1) ^ (1 << this->opt->road_side); // disable the other value } - ShowDropDownMenu(this, _driveside_dropdown, _opt_ptr->road_side, GAMEOPT_ROADSIDE_BTN, i, 0); + ShowDropDownMenu(this, _driveside_dropdown, this->opt->road_side, GAMEOPT_ROADSIDE_BTN, i, 0); } break; case GAMEOPT_TOWNNAME_BTN: // Setup townname dropdown - ShowTownnameDropdown(this, _opt_ptr->town_name); + ShowTownnameDropdown(this, this->opt->town_name); break; case GAMEOPT_AUTOSAVE_BTN: // Setup autosave dropdown - ShowDropDownMenu(this, _autosave_dropdown, _opt_ptr->autosave, GAMEOPT_AUTOSAVE_BTN, 0, 0); + ShowDropDownMenu(this, _autosave_dropdown, this->opt->autosave, GAMEOPT_AUTOSAVE_BTN, 0, 0); break; case GAMEOPT_VEHICLENAME_BTN: // Setup customized vehicle-names dropdown @@ -262,17 +265,17 @@ struct GameOptionsWindow : Window { case GAMEOPT_CURRENCY_BTN: /* Currency */ if (index == CUSTOM_CURRENCY_ID) ShowCustCurrency(); - _opt_ptr->currency = index; + this->opt->currency = index; MarkWholeScreenDirty(); break; case GAMEOPT_DISTANCE_BTN: // Measuring units - _opt_ptr->units = index; + this->opt->units = index; MarkWholeScreenDirty(); break; case GAMEOPT_ROADSIDE_BTN: // Road side - if (_opt_ptr->road_side != index) { // only change if setting changed + if (this->opt->road_side != index) { // only change if setting changed DoCommandP(0, index, 0, NULL, CMD_SET_ROAD_DRIVE_SIDE | CMD_MSG(STR_00B4_CAN_T_DO_THIS)); MarkWholeScreenDirty(); } @@ -280,7 +283,7 @@ struct GameOptionsWindow : Window { case GAMEOPT_TOWNNAME_BTN: // Town names if (_game_mode == GM_MENU) { - _opt_ptr->town_name = index; + this->opt->town_name = index; InvalidateWindow(WC_GAME_OPTIONS, 0); } break; @@ -507,7 +510,7 @@ public: { /* Copy current settings (ingame or in intro) to temporary holding place * change that when setting stuff, copy back on clicking 'OK' */ - this->opt_mod_temp = *_opt_ptr; + this->opt_mod_temp = (_game_mode == GM_MENU) ? _opt_newgame : _opt; this->clicked_increase = false; this->clicked_button = NO_SETTINGS_BUTTON; this->timeout = 0; @@ -624,11 +627,13 @@ public: case GDW_ACCEPT: { // Save button - save changes GDType btn, val; + GameOptions *opt_ptr = (_game_mode == GM_MENU) ? &_opt_newgame : &_opt; for (btn = 0; btn != GAME_DIFFICULTY_NUM; btn++) { val = ((GDType*)&this->opt_mod_temp.diff)[btn]; /* if setting has changed, change it */ - if (val != ((GDType*)&_opt_ptr->diff)[btn]) + if (val != ((GDType*)&opt_ptr->diff)[btn]) { DoCommandP(0, btn, val, NULL, CMD_CHANGE_DIFFICULTY_LEVEL); + } } DoCommandP(0, UINT_MAX, this->opt_mod_temp.diff_level, NULL, CMD_CHANGE_DIFFICULTY_LEVEL); delete this; diff --git a/src/settings_type.h b/src/settings_type.h index 2233c856d..d3f3b611e 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -74,9 +74,6 @@ extern GameOptions _opt; /* These are the default options for a new game */ extern GameOptions _opt_newgame; -/* Pointer to one of the two _opt OR _opt_newgame structs */ -extern GameOptions *_opt_ptr; - struct Patches { bool modified_catchment; ///< different-size catchment areas bool vehicle_speed; ///< show vehicle speed diff --git a/src/strings.cpp b/src/strings.cpp index 06681ea00..6deec5263 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -546,7 +546,7 @@ static const Units units[] = { */ uint ConvertSpeedToDisplaySpeed(uint speed) { - return (speed * units[_opt_ptr->units].s_m) >> units[_opt_ptr->units].s_s; + return (speed * units[_opt.units].s_m) >> units[_opt.units].s_s; } /** @@ -556,7 +556,7 @@ uint ConvertSpeedToDisplaySpeed(uint speed) */ uint ConvertDisplaySpeedToSpeed(uint speed) { - return ((speed << units[_opt_ptr->units].s_s) + units[_opt_ptr->units].s_m / 2) / units[_opt_ptr->units].s_m; + return ((speed << units[_opt.units].s_s) + units[_opt.units].s_m / 2) / units[_opt.units].s_m; } static char* FormatString(char* buff, const char* str, const int64* argv, uint casei, const char* last) @@ -602,9 +602,9 @@ static char* FormatString(char* buff, const char* str, const int64* argv, uint c case SCC_VELOCITY: {// {VELOCITY} int64 args[1]; - assert(_opt_ptr->units < lengthof(units)); + assert(_opt.units < lengthof(units)); args[0] = ConvertSpeedToDisplaySpeed(GetInt32(&argv)); - buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].velocity), args, modifier >> 24, last); + buff = FormatString(buff, GetStringPtr(units[_opt.units].velocity), args, modifier >> 24, last); modifier = 0; break; } @@ -625,18 +625,18 @@ static char* FormatString(char* buff, const char* str, const int64* argv, uint c switch (cargo_str) { case STR_TONS: { int64 args[1]; - assert(_opt_ptr->units < lengthof(units)); - args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s; - buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_weight), args, modifier >> 24, last); + assert(_opt.units < lengthof(units)); + args[0] = GetInt32(&argv) * units[_opt.units].w_m >> units[_opt.units].w_s; + buff = FormatString(buff, GetStringPtr(units[_opt.units].l_weight), args, modifier >> 24, last); modifier = 0; break; } case STR_LITERS: { int64 args[1]; - assert(_opt_ptr->units < lengthof(units)); - args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s; - buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_volume), args, modifier >> 24, last); + assert(_opt.units < lengthof(units)); + args[0] = GetInt32(&argv) * units[_opt.units].v_m >> units[_opt.units].v_s; + buff = FormatString(buff, GetStringPtr(units[_opt.units].l_volume), args, modifier >> 24, last); modifier = 0; break; } @@ -718,9 +718,9 @@ static char* FormatString(char* buff, const char* str, const int64* argv, uint c case SCC_VOLUME: { // {VOLUME} int64 args[1]; - assert(_opt_ptr->units < lengthof(units)); - args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s; - buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_volume), args, modifier >> 24, last); + assert(_opt.units < lengthof(units)); + args[0] = GetInt32(&argv) * units[_opt.units].v_m >> units[_opt.units].v_s; + buff = FormatString(buff, GetStringPtr(units[_opt.units].l_volume), args, modifier >> 24, last); modifier = 0; break; } @@ -763,45 +763,45 @@ static char* FormatString(char* buff, const char* str, const int64* argv, uint c case SCC_POWER: { // {POWER} int64 args[1]; - assert(_opt_ptr->units < lengthof(units)); - args[0] = GetInt32(&argv) * units[_opt_ptr->units].p_m >> units[_opt_ptr->units].p_s; - buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].power), args, modifier >> 24, last); + assert(_opt.units < lengthof(units)); + args[0] = GetInt32(&argv) * units[_opt.units].p_m >> units[_opt.units].p_s; + buff = FormatString(buff, GetStringPtr(units[_opt.units].power), args, modifier >> 24, last); modifier = 0; break; } case SCC_VOLUME_SHORT: { // {VOLUME_S} int64 args[1]; - assert(_opt_ptr->units < lengthof(units)); - args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s; - buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_volume), args, modifier >> 24, last); + assert(_opt.units < lengthof(units)); + args[0] = GetInt32(&argv) * units[_opt.units].v_m >> units[_opt.units].v_s; + buff = FormatString(buff, GetStringPtr(units[_opt.units].s_volume), args, modifier >> 24, last); modifier = 0; break; } case SCC_WEIGHT: { // {WEIGHT} int64 args[1]; - assert(_opt_ptr->units < lengthof(units)); - args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s; - buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_weight), args, modifier >> 24, last); + assert(_opt.units < lengthof(units)); + args[0] = GetInt32(&argv) * units[_opt.units].w_m >> units[_opt.units].w_s; + buff = FormatString(buff, GetStringPtr(units[_opt.units].l_weight), args, modifier >> 24, last); modifier = 0; break; } case SCC_WEIGHT_SHORT: { // {WEIGHT_S} int64 args[1]; - assert(_opt_ptr->units < lengthof(units)); - args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s; - buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_weight), args, modifier >> 24, last); + assert(_opt.units < lengthof(units)); + args[0] = GetInt32(&argv) * units[_opt.units].w_m >> units[_opt.units].w_s; + buff = FormatString(buff, GetStringPtr(units[_opt.units].s_weight), args, modifier >> 24, last); modifier = 0; break; } case SCC_FORCE: { // {FORCE} int64 args[1]; - assert(_opt_ptr->units < lengthof(units)); - args[0] = GetInt32(&argv) * units[_opt_ptr->units].f_m >> units[_opt_ptr->units].f_s; - buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].force), args, modifier >> 24, last); + assert(_opt.units < lengthof(units)); + args[0] = GetInt32(&argv) * units[_opt.units].f_m >> units[_opt.units].f_s; + buff = FormatString(buff, GetStringPtr(units[_opt.units].force), args, modifier >> 24, last); modifier = 0; break; } @@ -1137,7 +1137,7 @@ static char *GenAndCoName(char *buff, uint32 arg, const char* last) const char* const* base; uint num; - if (_opt_ptr->landscape == LT_TOYLAND) { + if (_opt.landscape == LT_TOYLAND) { base = _silly_surname_list; num = lengthof(_silly_surname_list); } else { @@ -1167,7 +1167,7 @@ static char *GenPresidentName(char *buff, uint32 x, const char* last) buff = strecpy(buff, initial, last); } - if (_opt_ptr->landscape == LT_TOYLAND) { + if (_opt.landscape == LT_TOYLAND) { base = _silly_surname_list; num = lengthof(_silly_surname_list); } else { -- cgit v1.2.3-70-g09d2