summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lang/english.txt8
-rw-r--r--src/openttd.cpp3
-rw-r--r--src/rail_gui.cpp58
-rw-r--r--src/settings.cpp1
-rw-r--r--src/settings_gui.cpp1
-rw-r--r--src/variables.h1
6 files changed, 72 insertions, 0 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt
index 2b02e21bf..0077089a0 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -1106,6 +1106,14 @@ STR_CONFIG_PATCHES_ADVANCED_VEHICLE_LISTS :{LTBLUE}Use the
STR_CONFIG_PATCHES_LOADING_INDICATORS :{LTBLUE}Use loading indicators: {ORANGE}{STRING1}
STR_CONFIG_PATCHES_TIMETABLE_ALLOW :{LTBLUE}Enable timetabling for vehicles: {ORANGE}{STRING1}
STR_CONFIG_PATCHES_TIMETABLE_IN_TICKS :{LTBLUE}Show timetable in ticks rather than days: {ORANGE}{STRING1}
+STR_CONFIG_PATCHES_DEFAULT_RAIL_TYPE :{LTBLUE}Default rail type (after new game/game load): {ORANGE}{STRING1}
+STR_CONFIG_PATCHES_DEFAULT_RAIL_TYPE_RAIL :Normal Rail
+STR_CONFIG_PATCHES_DEFAULT_RAIL_TYPE_ELRAIL :Electrified Rail
+STR_CONFIG_PATCHES_DEFAULT_RAIL_TYPE_MONORAIL :Monorail
+STR_CONFIG_PATCHES_DEFAULT_RAIL_TYPE_MAGLEV :Maglev
+STR_CONFIG_PATCHES_DEFAULT_RAIL_TYPE_FIRST :First available
+STR_CONFIG_PATCHES_DEFAULT_RAIL_TYPE_LAST :Last available
+STR_CONFIG_PATCHES_DEFAULT_RAIL_TYPE_MOST_USED :Most used
STR_CONFIG_PATCHES_MAX_TRAINS :{LTBLUE}Max trains per player: {ORANGE}{STRING1}
STR_CONFIG_PATCHES_MAX_ROADVEH :{LTBLUE}Max road vehicles per player: {ORANGE}{STRING1}
diff --git a/src/openttd.cpp b/src/openttd.cpp
index b3bd580c7..b05324862 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -85,6 +85,7 @@ void ResetMusic();
extern void SetDifficultyLevel(int mode, GameOptions *gm_opt);
extern Player* DoStartupNewPlayer(bool is_ai);
extern void ShowOSErrorBox(const char *buf);
+extern void SetDefaultRailGui();
const char *_default_blitter = "8bpp-optimized";
@@ -692,6 +693,7 @@ static void MakeNewGameDone()
DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
SettingsDisableElrail(_patches.disable_elrails);
+ SetDefaultRailGui();
MarkWholeScreenDirty();
}
@@ -1858,6 +1860,7 @@ bool AfterLoadGame()
if (CheckSavegameVersion(38)) _patches.disable_elrails = false;
/* do the same as when elrails were enabled/disabled manually just now */
SettingsDisableElrail(_patches.disable_elrails);
+ SetDefaultRailGui();
/* From version 53, the map array was changed for house tiles to allow
* space for newhouses grf features. A new byte, m7, was also added. */
diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp
index ff113c69a..1ee994b0e 100644
--- a/src/rail_gui.cpp
+++ b/src/rail_gui.cpp
@@ -26,6 +26,12 @@
#include "newgrf_station.h"
#include "train.h"
+#include "bridge_map.h"
+#include "rail_map.h"
+#include "road_map.h"
+#include "station_map.h"
+#include "tunnel_map.h"
+
static RailType _cur_railtype;
static bool _remove_button_clicked;
static DiagDirection _build_depot_direction;
@@ -1223,4 +1229,56 @@ void ReinitGuiAfterToggleElrail(bool disable)
MarkWholeScreenDirty();
}
+void SetDefaultRailGui()
+{
+ if (_local_player == PLAYER_SPECTATOR) return;
+
+ extern RailType _last_built_railtype;
+ RailType rt = (RailType)_patches.default_rail_type;
+ if (rt >= RAILTYPE_END) {
+ if (rt == RAILTYPE_END + 2) {
+ /* Find the most used rail type */
+ RailType count[RAILTYPE_END];
+ memset(count, 0, sizeof(count));
+ for (TileIndex t = 0; t < MapSize(); t++) {
+ if (IsTileType(t, MP_RAILWAY) ||
+ IsLevelCrossingTile(t) ||
+ IsRailwayStationTile(t) ||
+ (IsTunnelTile(t) && GetTunnelTransportType(t) == TRANSPORT_RAIL) ||
+ (IsBridgeTile(t) && GetBridgeTransportType(t) == TRANSPORT_RAIL)
+ ) {
+ count[GetRailType(t)]++;
+ }
+ }
+
+ rt = RAILTYPE_RAIL;
+ for (RailType r = RAILTYPE_ELECTRIC; r < RAILTYPE_END; r++) {
+ if (count[r] >= count[rt]) rt = r;
+ }
+
+ /* No rail, just get the first available one */
+ if (count[rt] == 0) rt = RAILTYPE_END;
+ }
+ switch (rt) {
+ case RAILTYPE_END + 0:
+ rt = RAILTYPE_RAIL;
+ while (rt < RAILTYPE_END && !HasRailtypeAvail(GetPlayer(_local_player), rt)) rt++;
+ break;
+
+ case RAILTYPE_END + 1:
+ rt = GetBestRailtype(GetPlayer(_local_player));
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ _last_built_railtype = _cur_railtype = rt;
+ Window *w = FindWindowById(WC_BUILD_TOOLBAR, 0);
+ if (w != NULL && w->wndproc == BuildRailToolbWndProc) {
+ SetupRailToolbar(_cur_railtype, w);
+ SetWindowDirty(w);
+ }
+}
diff --git a/src/settings.cpp b/src/settings.cpp
index 522063366..e7db26743 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1351,6 +1351,7 @@ const SettingDesc _patch_settings[] = {
SDT_BOOL(Patches, advanced_vehicle_list, S, 0, true, STR_CONFIG_PATCHES_ADVANCED_VEHICLE_LISTS, NULL),
SDT_BOOL(Patches, timetable_in_ticks, S, 0, false, STR_CONFIG_PATCHES_TIMETABLE_IN_TICKS, NULL),
SDT_BOOL(Patches, loading_indicators, S, 0, true, STR_CONFIG_PATCHES_LOADING_INDICATORS, RedrawScreen),
+ SDT_VAR(Patches, default_rail_type, SLE_UINT8, S,MS, 4, 0, 6, 0, STR_CONFIG_PATCHES_DEFAULT_RAIL_TYPE, NULL),
/***************************************************************************/
/* Construction section of the GUI-configure patches window */
diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp
index 8148f61df..e134a3540 100644
--- a/src/settings_gui.cpp
+++ b/src/settings_gui.cpp
@@ -654,6 +654,7 @@ static const char *_patches_ui[] = {
"advanced_vehicle_list",
"loading_indicators",
"timetable_in_ticks",
+ "default_rail_type",
};
static const char *_patches_construction[] = {
diff --git a/src/variables.h b/src/variables.h
index b3aec9f29..7ee345be5 100644
--- a/src/variables.h
+++ b/src/variables.h
@@ -134,6 +134,7 @@ struct Patches {
bool prefer_teamchat; // Choose the chat message target with <ENTER>, true=all players, false=your team
bool advanced_vehicle_list; // Use the "advanced" vehicle list
bool loading_indicators; // Show loading indicators
+ uint8 default_rail_type; ///< The default rail type for the rail GUI
uint8 toolbar_pos; // position of toolbars, 0=left, 1=center, 2=right
uint8 window_snap_radius; // Windows snap at each other if closer than this