summaryrefslogtreecommitdiff
path: root/src/rail_gui.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-06-25 19:13:55 +0000
committerrubidium <rubidium@openttd.org>2007-06-25 19:13:55 +0000
commitf40646bf82f61aa24235fa60e57c6607a54be416 (patch)
tree876c5604e0a8e4c90ab0fe50fdcd128feef0fca5 /src/rail_gui.cpp
parent6b642ced3399c9491d84c3d9c3280068ecbb56ef (diff)
downloadopenttd-f40646bf82f61aa24235fa60e57c6607a54be416.tar.xz
(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.
Diffstat (limited to 'src/rail_gui.cpp')
-rw-r--r--src/rail_gui.cpp58
1 files changed, 58 insertions, 0 deletions
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);
+ }
+}