(svn r13242) -Codechange: remove _opt_ptr.
authorrubidium
Sun, 25 May 2008 12:57:39 +0000
changeset 10695 95e0154da7a0
parent 10694 9f14c518f784
child 10696 efdc786ba921
(svn r13242) -Codechange: remove _opt_ptr.
src/currency.h
src/genworld_gui.cpp
src/misc_cmd.cpp
src/network/network_client.cpp
src/openttd.cpp
src/road_cmd.cpp
src/settings.cpp
src/settings_gui.cpp
src/settings_type.h
src/strings.cpp
--- a/src/currency.h	Sun May 25 11:18:57 2008 +0000
+++ b/src/currency.h	Sun May 25 12:57:39 2008 +0000
@@ -39,7 +39,7 @@
 
 // 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();
--- a/src/genworld_gui.cpp	Sun May 25 11:18:57 2008 +0000
+++ b/src/genworld_gui.cpp	Sun May 25 12:57:39 2008 +0000
@@ -207,7 +207,6 @@
 	/* 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);
--- a/src/misc_cmd.cpp	Sun May 25 11:18:57 2008 +0000
+++ b/src/misc_cmd.cpp	Sun May 25 12:57:39 2008 +0000
@@ -395,12 +395,14 @@
 {
 	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,
--- a/src/network/network_client.cpp	Sun May 25 11:18:57 2008 +0000
+++ b/src/network/network_client.cpp	Sun May 25 12:57:39 2008 +0000
@@ -622,8 +622,6 @@
 		/* 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)();
 
--- a/src/openttd.cpp	Sun May 25 11:18:57 2008 +0000
+++ b/src/openttd.cpp	Sun May 25 12:57:39 2008 +0000
@@ -330,7 +330,6 @@
 {
 	_game_mode = GM_MENU;
 
-	_opt_ptr = &_opt_newgame;
 	ResetGRFConfig(false);
 
 	/* Setup main window */
@@ -584,7 +583,6 @@
 
 	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 @@
 		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 @@
 			break;
 
 		case SM_LOAD: { /* Load game, Play Scenario */
-			_opt_ptr = &_opt;
 			ResetGRFConfig(true);
 			ResetWindowSystem();
 
@@ -921,8 +917,6 @@
 
 		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 {
--- a/src/road_cmd.cpp	Sun May 25 11:18:57 2008 +0000
+++ b/src/road_cmd.cpp	Sun May 25 12:57:39 2008 +0000
@@ -68,7 +68,11 @@
 	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();
--- a/src/settings.cpp	Sun May 25 11:18:57 2008 +0000
+++ b/src/settings.cpp	Sun May 25 12:57:39 2008 +0000
@@ -65,7 +65,6 @@
 
 GameOptions _opt;
 GameOptions _opt_newgame;
-GameOptions *_opt_ptr;
 Patches _patches;
 Patches _patches_newgame;
 
--- a/src/settings_gui.cpp	Sun May 25 11:18:57 2008 +0000
+++ b/src/settings_gui.cpp	Sun May 25 12:57:39 2008 +0000
@@ -142,8 +142,11 @@
 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 @@
 		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 @@
 	{
 		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 @@
 				/* 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 @@
 
 			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 @@
 
 			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 @@
 	{
 		/* 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 @@
 
 			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;
--- a/src/settings_type.h	Sun May 25 11:18:57 2008 +0000
+++ b/src/settings_type.h	Sun May 25 12:57:39 2008 +0000
@@ -74,9 +74,6 @@
 /* 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
--- a/src/strings.cpp	Sun May 25 11:18:57 2008 +0000
+++ b/src/strings.cpp	Sun May 25 12:57:39 2008 +0000
@@ -546,7 +546,7 @@
  */
 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 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 @@
 
 			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 @@
 				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 @@
 
 			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 @@
 
 			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 @@
 	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 @@
 		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 {