summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--intro_gui.c11
-rw-r--r--main_gui.c28
-rw-r--r--misc_cmd.c15
-rw-r--r--misc_gui.c2
-rw-r--r--network_client.c3
-rw-r--r--settings.c23
-rw-r--r--settings_gui.c159
-rw-r--r--town_cmd.c2
-rw-r--r--ttd.c85
-rw-r--r--variables.h28
10 files changed, 171 insertions, 185 deletions
diff --git a/intro_gui.c b/intro_gui.c
index 9850f5f4c..13bb1958b 100644
--- a/intro_gui.c
+++ b/intro_gui.c
@@ -45,8 +45,8 @@ extern void HandleOnEditTextCancel(void);
static void SelectGameWndProc(Window *w, WindowEvent *e) {
switch(e->event) {
case WE_PAINT:
- w->click_state = (w->click_state & ~(0xC0) & ~(0xF << 12)) | (1 << (_new_opt.landscape+12)) | (1<<6);
- SetDParam(0, STR_6801_EASY + _new_opt.diff_level);
+ w->click_state = (w->click_state & ~(0xC0) & ~(0xF << 12)) | (1 << (_opt_newgame.landscape + 12)) | (1<<6);
+ SetDParam(0, STR_6801_EASY + _opt_newgame.diff_level);
DrawWindowWidgets(w);
break;
@@ -74,10 +74,6 @@ static void SelectGameWndProc(Window *w, WindowEvent *e) {
DoCommandP(0, e->click.widget - 12, 0, NULL, CMD_SET_NEW_LANDSCAPE_TYPE);
break;
}
- case WE_KEYPRESS:
- switch(e->keypress.keycode) {
- case WKC_BACKQUOTE: IConsoleSwitch(); break;
- }
break;
case WE_ON_EDIT_TEXT: HandleOnEditText(e); break;
@@ -293,8 +289,7 @@ void AskExitToGameMenu(void)
int32 CmdSetNewLandscapeType(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
if (flags & DC_EXEC) {
- // XXX: some stuff
- _new_opt.landscape = p1;
+ _opt_newgame.landscape = p1;
InvalidateWindowClasses(WC_SELECT_GAME);
}
return 0;
diff --git a/main_gui.c b/main_gui.c
index d397074f5..3c411122e 100644
--- a/main_gui.c
+++ b/main_gui.c
@@ -1298,7 +1298,7 @@ static void ScenEditLandGenWndProc(Window *w, WindowEvent *e)
}
break;
case WE_CLICK:
- switch(e->click.widget) {
+ switch (e->click.widget) {
case 3: /* raise corner */
HandlePlacePushButton(w, 3, ANIMCURSOR_RAISELAND, 2, PlaceProc_RaiseBigLand);
break;
@@ -1355,7 +1355,7 @@ terraform_size_common:;
}
break;
case WE_TIMEOUT:
- UnclickSomeWindowButtons(w, ~(1<<3 | 1<<4 | 1<<5 | 1<<10|1<<11|1<<12));
+ UnclickSomeWindowButtons(w, ~(1<<3 | 1<<4 | 1<<5 | 1<<10 | 1<<11 | 1<<12));
break;
case WE_PLACE_OBJ:
_place_proc(e->place.tile);
@@ -1826,8 +1826,7 @@ static void MainToolbarWndProc(Window *w, WindowEvent *e)
if (local == 0xff) local = 0; // spectator
switch(e->keypress.keycode) {
- case WKC_F1:
- case WKC_PAUSE:
+ case WKC_F1: case WKC_PAUSE:
ToolbarPauseClick(w);
break;
case WKC_F2: ShowGameOptions(); break;
@@ -1856,6 +1855,8 @@ static void MainToolbarWndProc(Window *w, WindowEvent *e)
case WKC_CTRL | 'S': _make_screenshot = 1; break;
case WKC_CTRL | 'G': _make_screenshot = 2; break;
case WKC_CTRL | WKC_ALT | 'C': if (!_networking) ShowCheatWindow(); break;
+ default: return;
+ e->keypress.cont = false;
}
} break;
@@ -2260,14 +2261,18 @@ static void MainWindowWndProc(Window *w, WindowEvent *e) {
break;
case WE_KEYPRESS:
+ if (e->keypress.keycode == WKC_BACKQUOTE) {
+ IConsoleSwitch();
+ e->keypress.cont = false;
+ break;
+ }
+
if (_game_mode == GM_MENU)
break;
- switch(e->keypress.keycode) {
- case 'C':
- case 'Z': {
- Point pt;
- pt = GetTileBelowCursor();
+ switch (e->keypress.keycode) {
+ case 'C': case 'Z': {
+ Point pt = GetTileBelowCursor();
if (pt.x != -1) {
ScrollMainWindowTo(pt.x, pt.y);
if (e->keypress.keycode == 'Z')
@@ -2306,11 +2311,6 @@ static void MainWindowWndProc(Window *w, WindowEvent *e) {
MarkWholeScreenDirty();
break;
- case WKC_BACKQUOTE:
- IConsoleSwitch();
- e->keypress.cont=false;
- break;
-
#ifdef ENABLE_NETWORK
case WKC_RETURN:
case 'T' | WKC_SHIFT:
diff --git a/misc_cmd.c b/misc_cmd.c
index d45a6978c..1ecc9c24e 100644
--- a/misc_cmd.c
+++ b/misc_cmd.c
@@ -1,4 +1,3 @@
-
#include "stdafx.h"
#include "ttd.h"
#include "string.h"
@@ -7,6 +6,7 @@
#include "player.h"
#include "gfx.h"
#include "window.h"
+#include "gui.h"
#include "saveload.h"
#include "economy.h"
#include "network.h"
@@ -222,15 +222,14 @@ int32 CmdChangeDifficultyLevel(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
if (flags & DC_EXEC) {
if (p1 != (uint32)-1L) {
- ((int*)&_opt_mod_ptr->diff)[p1] = p2;
- _opt_mod_ptr->diff_level = 3;
- } else {
- _opt_mod_ptr->diff_level = p2;
- }
+ ((int*)&_opt_ptr->diff)[p1] = p2;
+ _opt_ptr->diff_level = 3;
+ } else
+ _opt_ptr->diff_level = p2;
+
// If we are a network-client, update the difficult setting (if it is open)
if (_networking && !_network_server && FindWindowById(WC_GAME_OPTIONS, 0) != NULL)
- memcpy(&_opt_mod_temp, _opt_mod_ptr, sizeof(GameOptions));
- InvalidateWindow(WC_GAME_OPTIONS, 0);
+ ShowGameDifficulty();
}
return 0;
}
diff --git a/misc_gui.c b/misc_gui.c
index 788aac809..4811a8228 100644
--- a/misc_gui.c
+++ b/misc_gui.c
@@ -1267,7 +1267,7 @@ static void SaveLoadDlgWndProc(Window *w, WindowEvent *e)
strcpy(_file_to_saveload.name, name);
DeleteWindow(w);
} else if (_saveload_mode == SLD_LOAD_SCENARIO) {
- _switch_mode = SM_LOAD_SCENARIO;
+ _switch_mode = (_game_mode == GM_MENU) ? SM_LOAD : SM_LOAD_SCENARIO;
SetFiosType(file->type);
strcpy(_file_to_saveload.name, name);
DeleteWindow(w);
diff --git a/network_client.c b/network_client.c
index d2aa72e72..abc8cb4b7 100644
--- a/network_client.c
+++ b/network_client.c
@@ -516,7 +516,8 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP)
_switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR;
return NETWORK_RECV_STATUS_SAVEGAME;
}
- _opt_mod_ptr = &_opt;
+
+ _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/settings.c b/settings.c
index 59ac388ed..3623c6ca7 100644
--- a/settings.c
+++ b/settings.c
@@ -781,19 +781,18 @@ static const SettingDesc debug_settings[] = {
{NULL, 0, NULL, NULL, NULL}
};
-
+/* The settings showed when opened in the intro-menu. These values also are saved to
+ * openttd.cfg, thus _opt_newgame is used here (not _opt which is used ingame with loaded games!) */
static const SettingDesc gameopt_settings[] = {
- {"diff_level", SDT_UINT8, (void*)9, &_new_opt.diff_level, NULL},
- {"diff_custom", SDT_INTLIST | SDT_UINT32 | (sizeof(GameDifficulty)/4) << 16, NULL, &_new_opt.diff, NULL},
- {"currency", SDT_UINT8 | SDT_ONEOFMANY, (void*)0, &_new_opt.currency, "GBP|USD|EUR|YEN|ATS|BEF|CHF|CZK|DEM|DKK|ESP|FIM|FRF|GRD|HUF|ISK|ITL|NLG|NOK|PLN|ROL|RUR|SEK|custom" },
- {"distances", SDT_UINT8 | SDT_ONEOFMANY, (void*)1, &_new_opt.kilometers, "imperial|metric" },
- // XXX: Slovakish is an awful nonsense. It is either Slovak or
- // Slovakian, I personally prefer the former. --pasky
- {"town_names", SDT_UINT8 | SDT_ONEOFMANY, (void*)0, &_new_opt.town_name, "english|french|german|american|latin|silly|swedish|dutch|finnish|polish|slovakish|norwegian|hungarian|austrian|romanian|czech|swiss" },
- {"landscape", SDT_UINT8 | SDT_ONEOFMANY, (void*)0, &_new_opt.landscape, "normal|hilly|desert|candy" },
- {"autosave", SDT_UINT8 | SDT_ONEOFMANY, (void*)1, &_new_opt.autosave, "off|monthly|quarterly|half year|yearly" },
- {"road_side", SDT_UINT8 | SDT_ONEOFMANY, (void*)1, &_new_opt.road_side, "left|right" },
- {NULL, 0, NULL, NULL, NULL}
+ {"diff_level", SDT_UINT8, (void*)9, &_opt_newgame.diff_level, NULL},
+ {"diff_custom", SDT_INTLIST | SDT_UINT32 | (sizeof(GameDifficulty)/4) << 16, NULL, &_opt_newgame.diff, NULL},
+ {"currency", SDT_UINT8 | SDT_ONEOFMANY, (void*)0, &_opt_newgame.currency, "GBP|USD|EUR|YEN|ATS|BEF|CHF|CZK|DEM|DKK|ESP|FIM|FRF|GRD|HUF|ISK|ITL|NLG|NOK|PLN|ROL|RUR|SEK|custom" },
+ {"distances", SDT_UINT8 | SDT_ONEOFMANY, (void*)1, &_opt_newgame.kilometers, "imperial|metric" },
+ {"town_names", SDT_UINT8 | SDT_ONEOFMANY, (void*)0, &_opt_newgame.town_name, "english|french|german|american|latin|silly|swedish|dutch|finnish|polish|slovakish|norwegian|hungarian|austrian|romanian|czech|swiss" },
+ {"landscape", SDT_UINT8 | SDT_ONEOFMANY, (void*)0, &_opt_newgame.landscape, "normal|hilly|desert|candy" },
+ {"autosave", SDT_UINT8 | SDT_ONEOFMANY, (void*)1, &_opt_newgame.autosave, "off|monthly|quarterly|half year|yearly" },
+ {"road_side", SDT_UINT8 | SDT_ONEOFMANY, (void*)1, &_opt_newgame.road_side, "left|right" },
+ {NULL, 0, NULL, NULL, NULL}
};
// The player-based settings (are not send over the network)
diff --git a/settings_gui.c b/settings_gui.c
index 18a6676f5..a0dc14d38 100644
--- a/settings_gui.c
+++ b/settings_gui.c
@@ -79,17 +79,17 @@ static inline bool RoadVehiclesAreBuilt(void)
static void GameOptionsWndProc(Window *w, WindowEvent *e)
{
- switch(e->event) {
+ switch (e->event) {
case WE_PAINT: {
int i;
StringID str = STR_02BE_DEFAULT;
w->disabled_state = (_vehicle_design_names & 1) ? (++str, 0) : (1 << 21);
SetDParam(0, str);
- SetDParam(1, _currency_string_list[_opt_mod_ptr->currency]);
- SetDParam(2, _opt_mod_ptr->kilometers + STR_0139_IMPERIAL_MILES);
- SetDParam(3, STR_02E9_DRIVE_ON_LEFT + _opt_mod_ptr->road_side);
- SetDParam(4, STR_TOWNNAME_ORIGINAL_ENGLISH + _opt_mod_ptr->town_name);
- SetDParam(5, _autosave_dropdown[_opt_mod_ptr->autosave]);
+ SetDParam(1, _currency_string_list[_opt_ptr->currency]);
+ SetDParam(2, _opt_ptr->kilometers + STR_0139_IMPERIAL_MILES);
+ SetDParam(3, STR_02E9_DRIVE_ON_LEFT + _opt_ptr->road_side);
+ SetDParam(4, STR_TOWNNAME_ORIGINAL_ENGLISH + _opt_ptr->town_name);
+ SetDParam(5, _autosave_dropdown[_opt_ptr->autosave]);
SetDParam(6, SPECSTR_LANGUAGE_START + _dynlang.curr);
i = GetCurRes();
SetDParam(7, i == _num_resolutions ? STR_RES_OTHER : SPECSTR_RESOLUTION_START + i);
@@ -101,12 +101,12 @@ static void GameOptionsWndProc(Window *w, WindowEvent *e)
} break;
case WE_CLICK:
- switch(e->click.widget) {
+ switch (e->click.widget) {
case 5: /* Setup currencies dropdown */
- ShowDropDownMenu(w, _currency_string_list, _opt_mod_ptr->currency, e->click.widget, _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies(), 0);
+ ShowDropDownMenu(w, _currency_string_list, _opt_ptr->currency, e->click.widget, _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies(), 0);
return;
case 8: /* Setup distance unit dropdown */
- ShowDropDownMenu(w, _distances_dropdown, _opt_mod_ptr->kilometers, e->click.widget, 0, 0);
+ ShowDropDownMenu(w, _distances_dropdown, _opt_ptr->kilometers, e->click.widget, 0, 0);
return;
case 11: { /* Setup road-side dropdown */
int i = 0;
@@ -114,17 +114,17 @@ static void GameOptionsWndProc(Window *w, WindowEvent *e)
/* 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_mod_ptr->road_side); // disable the other value
+ i = (-1) ^ (1 << _opt_ptr->road_side); // disable the other value
- ShowDropDownMenu(w, _driveside_dropdown, _opt_mod_ptr->road_side, e->click.widget, i, 0);
+ ShowDropDownMenu(w, _driveside_dropdown, _opt_ptr->road_side, e->click.widget, i, 0);
} return;
case 14: { /* Setup townname dropdown */
- int i = _opt_mod_ptr->town_name;
+ int i = _opt_ptr->town_name;
ShowDropDownMenu(w, BuildDynamicDropdown(STR_TOWNNAME_ORIGINAL_ENGLISH, SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1), i, e->click.widget, (_game_mode == GM_MENU) ? 0 : (-1) ^ (1 << i), 0);
return;
}
case 17: /* Setup autosave dropdown */
- ShowDropDownMenu(w, _autosave_dropdown, _opt_mod_ptr->autosave, e->click.widget, 0, 0);
+ ShowDropDownMenu(w, _autosave_dropdown, _opt_ptr->autosave, e->click.widget, 0, 0);
return;
case 20: /* Setup customized vehicle-names dropdown */
ShowDropDownMenu(w, _designnames_dropdown, (_vehicle_design_names&1)?1:0, e->click.widget, (_vehicle_design_names&2)?0:2, 0);
@@ -149,12 +149,12 @@ static void GameOptionsWndProc(Window *w, WindowEvent *e)
break;
case WE_DROPDOWN_SELECT:
- switch(e->dropdown.button) {
+ switch (e->dropdown.button) {
case 20: /* Vehicle design names */
if (e->dropdown.index == 0) {
DeleteCustomEngineNames();
MarkWholeScreenDirty();
- } else if (!(_vehicle_design_names&1)) {
+ } else if (!(_vehicle_design_names & 1)) {
LoadCustomEngineNames();
MarkWholeScreenDirty();
}
@@ -162,15 +162,15 @@ static void GameOptionsWndProc(Window *w, WindowEvent *e)
case 5: /* Currency */
if (e->dropdown.index == 23)
ShowCustCurrency();
- _opt_mod_ptr->currency = _opt.currency = e->dropdown.index;
+ _opt_ptr->currency = e->dropdown.index;
MarkWholeScreenDirty();
break;
case 8: /* Distance units */
- _opt_mod_ptr->kilometers = e->dropdown.index;
+ _opt_ptr->kilometers = e->dropdown.index;
MarkWholeScreenDirty();
break;
case 11: /* Road side */
- if (_opt_mod_ptr->road_side != e->dropdown.index) { // only change if setting changed
+ if (_opt_ptr->road_side != e->dropdown.index) { // only change if setting changed
DoCommandP(0, e->dropdown.index, 0, NULL, CMD_SET_ROAD_DRIVE_SIDE | CMD_MSG(STR_EMPTY));
MarkWholeScreenDirty();
}
@@ -180,7 +180,7 @@ static void GameOptionsWndProc(Window *w, WindowEvent *e)
DoCommandP(0, e->dropdown.index, 0, NULL, CMD_SET_TOWN_NAME_TYPE | CMD_MSG(STR_EMPTY));
break;
case 17: /* Autosave options */
- _opt_mod_ptr->autosave = e->dropdown.index;
+ _opt_ptr->autosave = e->dropdown.index;
SetWindowDirty(w);
break;
case 24: /* Change interface language */
@@ -208,7 +208,7 @@ static void GameOptionsWndProc(Window *w, WindowEvent *e)
int32 CmdSetRoadDriveSide(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
if (flags & DC_EXEC) {
- _opt_mod_ptr->road_side = p1;
+ _opt_ptr->road_side = p1;
InvalidateWindow(WC_GAME_OPTIONS,0);
}
return 0;
@@ -217,7 +217,7 @@ int32 CmdSetRoadDriveSide(int x, int y, uint32 flags, uint32 p1, uint32 p2)
int32 CmdSetTownNameType(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
if (flags & DC_EXEC) {
- _opt_mod_ptr->town_name = p1;
+ _opt_ptr->town_name = p1;
InvalidateWindow(WC_GAME_OPTIONS,0);
}
return 0;
@@ -288,31 +288,31 @@ typedef struct {
} GameSettingData;
static const GameSettingData _game_setting_info[] = {
- {0,7,1,0},
- {0,3,1,STR_6830_IMMEDIATE},
- {0,2,1,STR_6816_LOW},
- {0,3,1,STR_26816_NONE},
- {100,500,50,0},
- {2,4,1,0},
- {0,2,1,STR_6820_LOW},
- {0,4,1,STR_681B_VERY_SLOW},
- {0,2,1,STR_6820_LOW},
- {0,2,1,STR_6823_NONE},
- {0,3,1,STR_6826_X1_5},
- {0,2,1,STR_6820_LOW},
- {0,3,1,STR_682A_VERY_FLAT},
- {0,3,1,STR_VERY_LOW},
- {0,1,1,STR_682E_STEADY},
- {0,1,1,STR_6834_AT_END_OF_LINE_AND_AT_STATIONS},
- {0,1,1,STR_6836_OFF},
- {0,2,1,STR_6839_PERMISSIVE},
+ { 0, 7, 1, STR_NULL},
+ { 0, 3, 1, STR_6830_IMMEDIATE},
+ { 0, 2, 1, STR_6816_LOW},
+ { 0, 3, 1, STR_26816_NONE},
+ {100, 500, 50, STR_NULL},
+ { 2, 4, 1, STR_NULL},
+ { 0, 2, 1, STR_6820_LOW},
+ { 0, 4, 1, STR_681B_VERY_SLOW},
+ { 0, 2, 1, STR_6820_LOW},
+ { 0, 2, 1, STR_6823_NONE},
+ { 0, 3, 1, STR_6826_X1_5},
+ { 0, 2, 1, STR_6820_LOW},
+ { 0, 3, 1, STR_682A_VERY_FLAT},
+ { 0, 3, 1, STR_VERY_LOW},
+ { 0, 1, 1, STR_682E_STEADY},
+ { 0, 1, 1, STR_6834_AT_END_OF_LINE_AND_AT_STATIONS},
+ { 0, 1, 1, STR_6836_OFF},
+ { 0, 2, 1, STR_6839_PERMISSIVE},
};
static inline bool GetBitAndShift(uint32 *b)
{
uint32 x = *b;
*b >>= 1;
- return (x&1) != 0;
+ return HASBIT(x, 0);
}
/*
@@ -349,7 +349,7 @@ void SetDifficultyLevel(int mode, GameOptions *gm_opt)
gm_opt->diff_level = mode;
if (mode != 3) { // not custom
- for(i = 0; i != GAME_DIFFICULTY_NUM; i++)
+ for (i = 0; i != GAME_DIFFICULTY_NUM; i++)
((int*)&gm_opt->diff)[i] = _default_game_diff[mode][i];
}
}
@@ -361,15 +361,21 @@ enum {
GAMEDIFF_WND_ROWSIZE = 9
};
+// Temporary holding place of values in the difficulty window until 'Save' is clicked
+static GameOptions _opt_mod_temp;
+// 0x383E = (1 << 13) | (1 << 12) | (1 << 11) | (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) | (1 << 1)
+#define DIFF_INGAME_DISABLED_BUTTONS 0x383E
+
static void GameDifficultyWndProc(Window *w, WindowEvent *e)
{
- switch(e->event) {
+ switch (e->event) {
case WE_PAINT: {
uint32 click_a, click_b, disabled;
int i;
- int x,y,value;
+ int y, value;
- w->click_state = (1 << 3) << _opt_mod_temp.diff_level;
+ w->click_state = (1 << 3) << _opt_mod_temp.diff_level; // have current difficulty button clicked
+ // disable all other difficulty buttons during gameplay except for 'custom'
w->disabled_state = (_game_mode != GM_NORMAL) ? 0 : (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6);
if (_game_mode == GM_EDITOR)
@@ -386,53 +392,47 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
click_a = _difficulty_click_a;
click_b = _difficulty_click_b;
- /* XXX - This is most likely the worst way I have ever seen
- to disable some buttons and to enable others.
- What the value means, is this:
- if bit1 is enabled, setting 1 is disabled
- then it is shifted to the left, and the story
- repeats....
- -- TrueLight */
- disabled = _game_mode == GM_NORMAL ? 0x383E : 0;
+ /* XXX - Disabled buttons in normal gameplay. Bitshifted for each button to see if
+ * that bit is set. If it is set, the button is disabled */
+ disabled = (_game_mode == GM_NORMAL) ? DIFF_INGAME_DISABLED_BUTTONS : 0;
- x = 0;
y = GAMEDIFF_WND_TOP_OFFSET;
for (i = 0; i != GAME_DIFFICULTY_NUM; i++) {
- DrawFrameRect(x+5, y, x+5+8, y+8, 3, GetBitAndShift(&click_a)?0x20:0);
- DrawFrameRect(x+15, y, x+15+8, y+8, 3, GetBitAndShift(&click_b)?0x20:0);
+ DrawFrameRect( 5, y, 5 + 8, y + 8, 3, GetBitAndShift(&click_a) ? (1 << 5) : 0);
+ DrawFrameRect(15, y, 15 + 8, y + 8, 3, GetBitAndShift(&click_b) ? (1 << 5) : 0);
if (GetBitAndShift(&disabled) || (_networking && !_network_server)) {
- int color = 0x8000 | _color_list[3].unk2;
- GfxFillRect(x+6, y+1, x+6+8, y+8, color);
- GfxFillRect(x+16, y+1, x+16+8, y+8, color);
+ int color = PALETTE_MODIFIER_COLOR | _color_list[3].unk2;
+ GfxFillRect( 6, y + 1, 6 + 8, y + 8, color);
+ GfxFillRect(16, y + 1, 16 + 8, y + 8, color);
}
- DrawStringCentered(x+10, y, STR_6819, 0);
- DrawStringCentered(x+20, y, STR_681A, 0);
+ DrawStringCentered(10, y, STR_6819, 0);
+ DrawStringCentered(20, y, STR_681A, 0);
value = _game_setting_info[i].str + ((int*)&_opt_mod_temp.diff)[i];
- if (i == 4) value *= 1000; // handle currency option
+ if (i == 4) value *= 1000; // XXX - handle currency option
SetDParam(0, value);
- DrawString(x+30, y, STR_6805_MAXIMUM_NO_COMPETITORS + i, 0);
+ DrawString(30, y, STR_6805_MAXIMUM_NO_COMPETITORS + i, 0);
y += GAMEDIFF_WND_ROWSIZE + 2; // space items apart a bit
}
} break;
case WE_CLICK:
- switch(e->click.widget) {
- case 8: {
- int x,y;
+ switch (e->click.widget) {
+ case 8: { /* Difficulty settings widget, decode click */
+ const GameSettingData *info;
+ int x, y;
uint btn, dis;
int val;
- const GameSettingData *info;
// Don't allow clients to make any changes
if (_networking && !_network_server)
return;
x = e->click.pt.x - 5;
- if (!IS_INT_INSIDE(x, 0, 21))
+ if (!IS_INT_INSIDE(x, 0, 21)) // Button area
return;
y = e->click.pt.y - GAMEDIFF_WND_TOP_OFFSET;
@@ -445,7 +445,7 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
return;
// Clicked disabled button?
- dis = (_game_mode == GM_NORMAL) ? 0x383E : 0;
+ dis = (_game_mode == GM_NORMAL) ? DIFF_INGAME_DISABLED_BUTTONS : 0;
if (HASBIT(dis, btn))
return;
@@ -454,7 +454,7 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
val = ((int*)&_opt_mod_temp.diff)[btn];
- info = &_game_setting_info[btn];
+ info = &_game_setting_info[btn]; // get information about the difficulty setting
if (x >= 10) {
// Increase button clicked
val = min(val + info->step, info->max);
@@ -469,8 +469,7 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
((int*)&_opt_mod_temp.diff)[btn] = val;
SetDifficultyLevel(3, &_opt_mod_temp); // set difficulty level to custom
SetWindowDirty(w);
- break;
- }
+ } break;
case 3: case 4: case 5: case 6: /* Easy / Medium / Hard / Custom */
// temporarily change difficulty level
SetDifficultyLevel(e->click.widget - 3, &_opt_mod_temp);
@@ -484,7 +483,7 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
for (btn = 0; btn != GAME_DIFFICULTY_NUM; btn++) {
val = ((int*)&_opt_mod_temp.diff)[btn];
// if setting has changed, change it
- if (val != ((int*)&_opt_mod_ptr->diff)[btn])
+ if (val != ((int*)&_opt_mod_temp.diff)[btn])
DoCommandP(0, btn, val, NULL, CMD_CHANGE_DIFFICULTY_LEVEL);
}
DoCommandP(0, -1, _opt_mod_temp.diff_level, NULL, CMD_CHANGE_DIFFICULTY_LEVEL);
@@ -496,13 +495,12 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
StartupEconomy();
break;
}
- case 11: // Cancel button - close window
+ case 11: /* Cancel button - close window, abandon changes */
DeleteWindow(w);
break;
- }
- break;
+ } break;
- case WE_MOUSELOOP:
+ case WE_MOUSELOOP: /* Handle the visual 'clicking' of the buttons */
if (_difficulty_timeout != 0 && !--_difficulty_timeout) {
_difficulty_click_a = 0;
_difficulty_click_b = 0;
@@ -512,6 +510,8 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
}
}
+#undef DIFF_INGAME_DISABLED_BUTTONS
+
static const Widget _game_difficulty_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 10, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 10, 11, 369, 0, 13, STR_6800_DIFFICULTY_LEVEL, STR_018C_WINDOW_TITLE_DRAG_THIS},
@@ -539,10 +539,9 @@ static const WindowDesc _game_difficulty_desc = {
void ShowGameDifficulty(void)
{
DeleteWindowById(WC_GAME_OPTIONS, 0);
- /* copy current settings to temporary holding place
- * change that when setting stuff, copy back on clicking 'OK'
- */
- memcpy(&_opt_mod_temp, _opt_mod_ptr, sizeof(GameOptions));
+ /* Copy current settings (ingame or in intro) to temporary holding place
+ * change that when setting stuff, copy back on clicking 'OK' */
+ memcpy(&_opt_mod_temp, _opt_ptr, sizeof(GameOptions));
AllocateWindowDesc(&_game_difficulty_desc);
}
diff --git a/town_cmd.c b/town_cmd.c
index b7a33a516..7846d3fc0 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -1872,7 +1872,7 @@ bool CheckforTownRating(uint tile, uint32 flags, Town *t, byte type)
* owned by a town no removal if rating is lower than ... depends now on
* difficulty setting. Minimum town rating selected by difficulty level
*/
- modemod = _default_rating_settings[_opt_mod_ptr->diff.town_council_tolerance][type];
+ modemod = _default_rating_settings[_opt.diff.town_council_tolerance][type];
if (t->ratings[_current_player] < 16 + modemod && !(flags & DC_NO_TOWN_RATING)) {
SetDParam(0, t->index);
diff --git a/ttd.c b/ttd.c
index a230a5ab2..18f4de4a2 100644
--- a/ttd.c
+++ b/ttd.c
@@ -460,10 +460,11 @@ static void UnInitializeGame(void)
static void LoadIntroGame(void)
{
char filename[256];
+
_game_mode = GM_MENU;
- _display_opt &= ~DO_TRANS_BUILDINGS; // don't make buildings transparent in intro
+ CLRBITS(_display_opt, DO_TRANS_BUILDINGS); // don't make buildings transparent in intro
+ _opt_ptr = &_opt_newgame;
- _opt_mod_ptr = &_new_opt;
GfxLoadSprites();
LoadStringWidthTable();
@@ -480,7 +481,6 @@ static void LoadIntroGame(void)
#endif
GenerateWorld(1, 6, 6); // if failed loading, make empty world.
}
- _opt.currency = _new_opt.currency;
_pause = 0;
_local_player = 0;
@@ -648,12 +648,11 @@ int ttd_main(int argc, char* argv[])
NetworkStartUp();
#endif /* ENABLE_NETWORK */
- // Default difficulty level
- _opt_mod_ptr = &_new_opt;
+ _opt_ptr = &_opt_newgame;
- // ugly hack, if diff_level is 9, it means we got no setting from the config file, so we load the default settings.
- if (_opt_mod_ptr->diff_level == 9)
- SetDifficultyLevel(0, _opt_mod_ptr);
+ /* XXX - ugly hack, if diff_level is 9, it means we got no setting from the config file */
+ if (_opt_newgame.diff_level == 9)
+ SetDifficultyLevel(0, &_opt_newgame);
// initialize the ingame console
IConsoleInit();
@@ -734,8 +733,8 @@ static void MakeNewGame(void)
_game_mode = GM_NORMAL;
// Copy in game options
- _opt_mod_ptr = &_opt;
- memcpy(&_opt, &_new_opt, sizeof(_opt));
+ _opt_ptr = &_opt;
+ memcpy(_opt_ptr, &_opt_newgame, sizeof(GameOptions));
GfxLoadSprites();
@@ -766,8 +765,8 @@ static void MakeNewEditorWorld(void)
_game_mode = GM_EDITOR;
// Copy in game options
- _opt_mod_ptr = &_opt;
- memcpy(&_opt, &_new_opt, sizeof(_opt));
+ _opt_ptr = &_opt;
+ memcpy(_opt_ptr, &_opt_newgame, sizeof(GameOptions));
GfxLoadSprites();
@@ -787,6 +786,12 @@ static void MakeNewEditorWorld(void)
void StartupPlayers(void);
void StartupDisasters(void);
+/**
+ * Start Scenario starts a new game based on a scenario.
+ * Eg 'New Game' --> select a preset scenario
+ * This starts a scenario based on your current difficulty settings just
+ * fix the landscape as that can be different from what is selected in the intro
+ */
static void StartScenario(void)
{
_game_mode = GM_NORMAL;
@@ -799,11 +804,6 @@ static void StartScenario(void)
return;
}
- // Copy in game options
- // Removed copying of game options when using "new game". --dominik
- // _opt_mod_ptr = &_opt;
- // memcpy(&_opt, &_new_opt, sizeof(_opt));
-
GfxLoadSprites();
// Reinitialize windows
@@ -818,16 +818,18 @@ static void StartScenario(void)
ShowErrorMessage(_error_message, STR_4009_GAME_LOAD_FAILED, 0, 0);
}
+ {
+ byte landscape = _opt.landscape; // backup loaded landscape;
+ _opt_ptr = &_opt;
+ memcpy(_opt_ptr, &_opt_newgame, sizeof(GameOptions));
+ _opt_ptr->landscape = landscape;
+ }
+
// Inititalize data
StartupPlayers();
StartupEngines();
StartupDisasters();
- // When starting a scenario, is it really a load..
- // and in AfterLoad a player is started when it is
- // a scenario.. so we do not need it here.
-// DoStartupNewPlayer(false);
-
_local_player = 0;
MarkWholeScreenDirty();
@@ -886,12 +888,12 @@ void SwitchMode(int new_mode)
}
#endif /* ENABLE_NETWORK */
- switch(new_mode) {
- case SM_EDITOR: // Switch to scenario editor
+ switch (new_mode) {
+ case SM_EDITOR: /* Switch to scenario editor */
MakeNewEditorWorld();
break;
- case SM_NEWGAME:
+ case SM_NEWGAME: /* New Game --> 'Random game' */
#ifdef ENABLE_NETWORK
if (_network_server)
snprintf(_network_game_info.map_name, 40, "Random");
@@ -899,12 +901,12 @@ void SwitchMode(int new_mode)
MakeNewGame();
break;
- case SM_START_SCENARIO:
+ case SM_START_SCENARIO: /* New Game --> Choose one of the preset scenarios */
StartScenario();
break;
-normal_load:
- case SM_LOAD: { // Load game
+ case SM_LOAD: { /* Load game, Play Scenario */
+ _opt_ptr = &_opt;
_error_message = INVALID_STRING_ID;
if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL)) {
@@ -921,19 +923,16 @@ normal_load:
break;
}
- case SM_LOAD_SCENARIO: {
+ case SM_LOAD_SCENARIO: { /* Load scenario from scenario editor */
int i;
- if (_game_mode == GM_MENU) goto normal_load;
-
if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR)) {
- _opt_mod_ptr = &_opt;
- _opt_mod_temp = _opt;
+ _opt_ptr = &_opt;
_local_player = OWNER_NONE;
_generating_world = true;
// delete all players.
- for(i=0; i != MAX_PLAYERS; i++) {
+ for (i = 0; i != MAX_PLAYERS; i++) {
ChangeOwnershipOfPlayerItems(i, 0xff);
_players[i].is_active = false;
}
@@ -952,18 +951,18 @@ normal_load:
}
- case SM_MENU: // Switch to game menu
+ case SM_MENU: /* Switch to game intro menu */
LoadIntroGame();
break;
- case SM_SAVE: // Save game
+ case SM_SAVE: /* Save game */
if (SaveOrLoad(_file_to_saveload.name, SL_SAVE) != SL_OK)
ShowErrorMessage(INVALID_STRING_ID, STR_4007_GAME_SAVE_FAILED, 0, 0);
else
DeleteWindowById(WC_SAVELOAD, 0);
break;
- case SM_GENRANDLAND:
+ case SM_GENRANDLAND: /* Generate random land within scenario editor */
GenerateWorld(2, _patches.map_x, _patches.map_y);
// XXX: set date
_local_player = OWNER_NONE;
@@ -971,7 +970,7 @@ normal_load:
break;
}
- if (_switch_mode_errorstr!=INVALID_STRING_ID)
+ if (_switch_mode_errorstr != INVALID_STRING_ID)
ShowErrorMessage(INVALID_STRING_ID,_switch_mode_errorstr,0,0);
_in_state_game_loop = false;
@@ -1037,16 +1036,16 @@ static void DoAutosave(void)
char buf[200];
if (_patches.keep_all_autosave && _local_player != OWNER_SPECTATOR) {
- Player *p;
+ const Player *p = DEREF_PLAYER(_local_player);
char *s;
sprintf(buf, "%s%s", _path.autosave_dir, PATHSEP);
- p = DEREF_PLAYER(_local_player);
+
SetDParam(0, p->name_1);
SetDParam(1, p->name_2);
SetDParam(2, _date);
- s= (char*)GetString(buf + strlen(_path.autosave_dir) + strlen(PATHSEP), STR_4004);
+ s = (char*)GetString(buf + strlen(_path.autosave_dir) + strlen(PATHSEP), STR_4004);
strcpy(s, ".sav");
- } else {
+ } else { /* Save a maximum of 15 autosaves */
int n = _autosave_ctr;
_autosave_ctr = (_autosave_ctr + 1) & 15;
sprintf(buf, "%s%sautosave%d.sav", _path.autosave_dir, PATHSEP, n);
@@ -1231,7 +1230,7 @@ static void UpdateExclusiveRights(void)
*/
}
-byte convert_currency[] = {
+const byte convert_currency[] = {
0, 1, 12, 8, 3,
10, 14, 19, 4, 5,
9, 11, 13, 6, 17,
diff --git a/variables.h b/variables.h
index 3149f827b..575f7920e 100644
--- a/variables.h
+++ b/variables.h
@@ -2,11 +2,8 @@
#define VARIABLES_H
#include "player.h"
-//enum { DPARAM_SIZE = 32 };
-
// ********* START OF SAVE REGION
-
#if !defined(MAX_PATH)
# define MAX_PATH 260
#endif
@@ -32,11 +29,15 @@ typedef struct {
byte road_side;
} GameOptions;
-// These are the options for the current game
+/* These are the options for the current game
+ * either ingame, or loaded. Also used for networking games */
VARDEF GameOptions _opt;
-// These are the options for the new game
-VARDEF GameOptions _new_opt;
+/* These are the default options for a new game */
+VARDEF GameOptions _opt_newgame;
+
+// Pointer to one of the two _opt OR _opt_newgame structs
+VARDEF GameOptions *_opt_ptr;
enum {
CF_NOEURO = 0,
@@ -242,10 +243,6 @@ typedef struct Paths {
VARDEF Paths _path;
-// Which options struct does options modify?
-VARDEF GameOptions *_opt_mod_ptr;
-VARDEF GameOptions _opt_mod_temp;
-
// NOSAVE: Used in palette animations only, not really important.
VARDEF int _timer_counter;
@@ -331,19 +328,16 @@ VARDEF char _savedump_path[64];
VARDEF uint _savedump_first, _savedump_freq, _savedump_last;
// end of debug features
-
-typedef struct {
- char *name;
- char *file;
-} DynLangEnt;
-
// Used for dynamic language support
typedef struct {
int num; // number of languages
int curr; // currently selected language index
char curr_file[32]; // currently selected language file
StringID dropdown[32 + 1]; // used in settings dialog
- DynLangEnt ent[32];
+ struct {
+ char *name;
+ char *file;
+ } ent[32];
} DynamicLanguages;
VARDEF DynamicLanguages _dynlang;