changeset 17080:8787df53489c draft

(svn r21817) -Change: only show rail/road types that will eventually be available in-game. For example don't show trams when there is no tram NewGRF loaded
author rubidium <rubidium@openttd.org>
date Sun, 16 Jan 2011 10:25:47 +0000
parents f0eb11e214d2
children bad424083a9b
files src/toolbar_gui.cpp
diffstat 1 files changed, 27 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/toolbar_gui.cpp
+++ b/src/toolbar_gui.cpp
@@ -44,6 +44,7 @@
 #include "textbuf_gui.h"
 #include "newgrf_debug.h"
 #include "hotkeys.h"
+#include "engine_base.h"
 
 #include "network/network.h"
 #include "network/network_gui.h"
@@ -692,9 +693,23 @@
 
 static CallBackFunction ToolbarBuildRailClick(Window *w)
 {
+	/* Use C++ spec to zero whole array. */
+	bool used_railtype[RAILTYPE_END] = { false };
+
+	/* Find the used railtypes. */
+	Engine *e;
+	FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
+		if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue;
+
+		used_railtype[e->u.rail.railtype] = true;
+	}
+
 	const Company *c = Company::Get(_local_company);
 	DropDownList *list = new DropDownList();
 	for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
+		/* If it's not used ever, don't show it to the user. */
+		if (!used_railtype[rt]) continue;
+
 		const RailtypeInfo *rti = GetRailTypeInfo(rt);
 		/* Skip rail type if it has no label */
 		if (rti->label == 0) continue;
@@ -723,9 +738,18 @@
 {
 	const Company *c = Company::Get(_local_company);
 	DropDownList *list = new DropDownList();
-	for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) {
-		/* The standard road button is *always* available */
-		list->push_back(new DropDownListStringItem(STR_ROAD_MENU_ROAD_CONSTRUCTION + rt, rt, !(HasBit(c->avail_roadtypes, rt) || rt == ROADTYPE_ROAD)));
+
+	/* Road is always visible and available. */
+	list->push_back(new DropDownListStringItem(STR_ROAD_MENU_ROAD_CONSTRUCTION, ROADTYPE_ROAD, false));
+
+	/* Tram is only visible when there will be a tram, and available when that has been introduced. */
+	Engine *e;
+	FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
+		if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue;
+		if (!HasBit(e->info.misc_flags, EF_ROAD_TRAM)) continue;
+
+		list->push_back(new DropDownListStringItem(STR_ROAD_MENU_TRAM_CONSTRUCTION, ROADTYPE_TRAM, !HasBit(c->avail_roadtypes, ROADTYPE_TRAM)));
+		break;
 	}
 	ShowDropDownList(w, list, _last_built_roadtype, TBN_ROADS, 140, true, true);
 	SndPlayFx(SND_15_BEEP);