Mercurial > hg > openttd
changeset 7064:a1b4950870eb draft
(svn r10329) -Feature [FS#812]: (patch) option to select the "default" rail type when you start a new game or load a game. This is done either static, i.e. rail, electrified rail, monorail and maglev, or dynamic which takes either the first or last available railtype or the railtype that is used most on the map.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Mon, 25 Jun 2007 19:13:55 +0000 |
parents | ec920a4e40bd |
children | 9ff8482e093f |
files | src/lang/english.txt src/openttd.cpp src/rail_gui.cpp src/settings.cpp src/settings_gui.cpp src/variables.h |
diffstat | 6 files changed, 72 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1106,6 +1106,14 @@ 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}
--- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -85,6 +85,7 @@ 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 @@ 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 @@ 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. */
--- 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 @@ 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); + } +} +
--- a/src/settings.cpp +++ b/src/settings.cpp @@ -1351,6 +1351,7 @@ 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 */
--- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -654,6 +654,7 @@ "advanced_vehicle_list", "loading_indicators", "timetable_in_ticks", + "default_rail_type", }; static const char *_patches_construction[] = {
--- a/src/variables.h +++ b/src/variables.h @@ -134,6 +134,7 @@ 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