(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
authorrubidium
Wed, 27 Jun 2007 14:15:48 +0000
changeset 7582 9f23c01ae23d
parent 7581 c943cdf602f0
child 7583 b614fd5bf454
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
src/dock_gui.cpp
src/lang/english.txt
src/main_gui.cpp
src/road_gui.cpp
src/settings.cpp
src/settings_gui.cpp
src/variables.h
src/vehicle.cpp
src/vehicle.h
--- a/src/dock_gui.cpp	Wed Jun 27 10:02:55 2007 +0000
+++ b/src/dock_gui.cpp	Wed Jun 27 14:15:48 2007 +0000
@@ -94,16 +94,19 @@
 
 static void BuildDocksClick_Depot(Window *w)
 {
+	if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
 	if (HandlePlacePushButton(w, DTW_DEPOT, SPR_CURSOR_SHIP_DEPOT, 1, PlaceDocks_Depot)) ShowBuildDocksDepotPicker();
 }
 
 static void BuildDocksClick_Dock(Window *w)
 {
+	if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
 	if (HandlePlacePushButton(w, DTW_STATION, SPR_CURSOR_DOCK, 3, PlaceDocks_Dock)) ShowBuildDockStationPicker();
 }
 
 static void BuildDocksClick_Buoy(Window *w)
 {
+	if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
 	HandlePlacePushButton(w, DTW_BUOY, SPR_CURSOR_BOUY, 1, PlaceDocks_Buoy);
 }
 
@@ -124,6 +127,7 @@
 	switch (e->event) {
 	case WE_PAINT:
 		DrawWindowWidgets(w);
+		SetWindowWidgetsDisabledState(w, !CanBuildVehicleInfrastructure(VEH_SHIP), 7, 8, 9, WIDGET_LIST_END);
 		break;
 
 	case WE_CLICK:
--- a/src/lang/english.txt	Wed Jun 27 10:02:55 2007 +0000
+++ b/src/lang/english.txt	Wed Jun 27 14:15:48 2007 +0000
@@ -1115,6 +1115,7 @@
 STR_CONFIG_PATCHES_DEFAULT_RAIL_TYPE_LAST                       :Last available
 STR_CONFIG_PATCHES_DEFAULT_RAIL_TYPE_MOST_USED                  :Most used
 
+STR_CONFIG_PATCHES_ALWAYS_BUILD_INFRASTRUCTURE                  :{LTBLUE}Show building tools when no suitable vehicles are available: {ORANGE}{STRING1}
 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}
 STR_CONFIG_PATCHES_MAX_AIRCRAFT                                 :{LTBLUE}Max aircraft per player: {ORANGE}{STRING1}
--- a/src/main_gui.cpp	Wed Jun 27 10:02:55 2007 +0000
+++ b/src/main_gui.cpp	Wed Jun 27 14:15:48 2007 +0000
@@ -1867,6 +1867,9 @@
 		/* disable company list drop downs, if there are no companies */
 		SetWindowWidgetsDisabledState(w, ActivePlayerCount() == 0, 7, 8, 13, 14, 15, 16, WIDGET_LIST_END);
 
+		SetWindowWidgetDisabledState(w, 19, !CanBuildVehicleInfrastructure(VEH_TRAIN));
+		SetWindowWidgetDisabledState(w, 22, !CanBuildVehicleInfrastructure(VEH_AIRCRAFT));
+
 		DrawWindowWidgets(w);
 		break;
 
@@ -1895,16 +1898,16 @@
 		case WKC_SHIFT | WKC_F4: ShowVehicleListWindow(_local_player, VEH_AIRCRAFT); break;
 		case WKC_SHIFT | WKC_F5: ToolbarZoomInClick(w); break;
 		case WKC_SHIFT | WKC_F6: ToolbarZoomOutClick(w); break;
-		case WKC_SHIFT | WKC_F7: ShowBuildRailToolbar(_last_built_railtype, -1); break;
+		case WKC_SHIFT | WKC_F7: if (CanBuildVehicleInfrastructure(VEH_TRAIN)) ShowBuildRailToolbar(_last_built_railtype, -1); break;
 		case WKC_SHIFT | WKC_F8: ShowBuildRoadToolbar(_last_built_roadtype); break;
 		case WKC_SHIFT | WKC_F9: ShowBuildDocksToolbar(); break;
-		case WKC_SHIFT | WKC_F10: ShowBuildAirToolbar(); break;
+		case WKC_SHIFT | WKC_F10: if (CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) ShowBuildAirToolbar(); break;
 		case WKC_SHIFT | WKC_F11: ShowBuildTreesToolbar(); break;
 		case WKC_SHIFT | WKC_F12: ShowMusicWindow(); break;
 		case WKC_CTRL  | 'S': MenuClickSmallScreenshot(); break;
 		case WKC_CTRL  | 'G': MenuClickWorldScreenshot(); break;
 		case WKC_CTRL | WKC_ALT | 'C': if (!_networking) ShowCheatWindow(); break;
-		case 'A': ShowBuildRailToolbar(_last_built_railtype, 4); break; /* Invoke Autorail */
+		case 'A': if (CanBuildVehicleInfrastructure(VEH_TRAIN)) ShowBuildRailToolbar(_last_built_railtype, 4); break; /* Invoke Autorail */
 		case 'L': ShowTerraformToolbar(); break;
 		default: return;
 		}
--- a/src/road_gui.cpp	Wed Jun 27 10:02:55 2007 +0000
+++ b/src/road_gui.cpp	Wed Jun 27 14:15:48 2007 +0000
@@ -213,19 +213,19 @@
 
 static void BuildRoadClick_Depot(Window *w)
 {
-	if (_game_mode == GM_EDITOR) return;
+	if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD)) return;
 	if (HandlePlacePushButton(w, RTW_DEPOT, SPR_CURSOR_ROAD_DEPOT, 1, PlaceRoad_Depot)) ShowRoadDepotPicker();
 }
 
 static void BuildRoadClick_BusStation(Window *w)
 {
-	if (_game_mode == GM_EDITOR) return;
+	if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD)) return;
 	if (HandlePlacePushButton(w, RTW_BUS_STATION, SPR_CURSOR_BUS_STATION, 1, PlaceRoad_BusStation)) ShowRVStationPicker(RoadStop::BUS);
 }
 
 static void BuildRoadClick_TruckStation(Window *w)
 {
-	if (_game_mode == GM_EDITOR) return;
+	if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD)) return;
 	if (HandlePlacePushButton(w, RTW_TRUCK_STATION, SPR_CURSOR_TRUCK_STATION, 1, PlaceRoad_TruckStation)) ShowRVStationPicker(RoadStop::TRUCK);
 }
 
@@ -270,6 +270,7 @@
 		if (IsWindowWidgetLowered(w, RTW_ROAD_X) || IsWindowWidgetLowered(w, RTW_ROAD_Y) || IsWindowWidgetLowered(w, RTW_BUS_STATION) || IsWindowWidgetLowered(w, RTW_TRUCK_STATION)) {
 			EnableWindowWidget(w, RTW_REMOVE);
 		}
+		SetWindowWidgetsDisabledState(w, !CanBuildVehicleInfrastructure(VEH_ROAD), 6, 7, 8, WIDGET_LIST_END);
 		DrawWindowWidgets(w);
 		break;
 
--- a/src/settings.cpp	Wed Jun 27 10:02:55 2007 +0000
+++ b/src/settings.cpp	Wed Jun 27 14:15:48 2007 +0000
@@ -1384,10 +1384,11 @@
 	SDT_BOOL(Patches, autorenew,                     S, 0, false,                    STR_CONFIG_PATCHES_AUTORENEW_VEHICLE,    EngineRenewUpdate),
 	 SDT_VAR(Patches, autorenew_months,   SLE_INT16, S, 0,     6,   -12,      12, 0, STR_CONFIG_PATCHES_AUTORENEW_MONTHS,     EngineRenewMonthsUpdate),
 	 SDT_VAR(Patches, autorenew_money,     SLE_UINT, S,CR,100000,     0, 2000000, 0, STR_CONFIG_PATCHES_AUTORENEW_MONEY,      EngineRenewMoneyUpdate),
-	 SDT_VAR(Patches, max_trains,        SLE_UINT16, 0, 0,   500,     0,    5000, 0, STR_CONFIG_PATCHES_MAX_TRAINS,           NULL),
-	 SDT_VAR(Patches, max_roadveh,       SLE_UINT16, 0, 0,   500,     0,    5000, 0, STR_CONFIG_PATCHES_MAX_ROADVEH,          NULL),
-	 SDT_VAR(Patches, max_aircraft,      SLE_UINT16, 0, 0,   200,     0,    5000, 0, STR_CONFIG_PATCHES_MAX_AIRCRAFT,         NULL),
-	 SDT_VAR(Patches, max_ships,         SLE_UINT16, 0, 0,   300,     0,    5000, 0, STR_CONFIG_PATCHES_MAX_SHIPS,            NULL),
+	SDT_BOOL(Patches, always_build_infrastructure,   S, 0, false,                    STR_CONFIG_PATCHES_ALWAYS_BUILD_INFRASTRUCTURE, RedrawScreen),
+	 SDT_VAR(Patches, max_trains,        SLE_UINT16, 0, 0,   500,     0,    5000, 0, STR_CONFIG_PATCHES_MAX_TRAINS,           RedrawScreen),
+	 SDT_VAR(Patches, max_roadveh,       SLE_UINT16, 0, 0,   500,     0,    5000, 0, STR_CONFIG_PATCHES_MAX_ROADVEH,          RedrawScreen),
+	 SDT_VAR(Patches, max_aircraft,      SLE_UINT16, 0, 0,   200,     0,    5000, 0, STR_CONFIG_PATCHES_MAX_AIRCRAFT,         RedrawScreen),
+	 SDT_VAR(Patches, max_ships,         SLE_UINT16, 0, 0,   300,     0,    5000, 0, STR_CONFIG_PATCHES_MAX_SHIPS,            RedrawScreen),
 	SDT_BOOL(Patches, servint_ispercent,             0, 0, false,                    STR_CONFIG_PATCHES_SERVINT_ISPERCENT,    CheckInterval),
 	 SDT_VAR(Patches, servint_trains,    SLE_UINT16, 0,D0,   150,     5,     800, 0, STR_CONFIG_PATCHES_SERVINT_TRAINS,       InValidateDetailsWindow),
 	 SDT_VAR(Patches, servint_roadveh,   SLE_UINT16, 0,D0,   150,     5,     800, 0, STR_CONFIG_PATCHES_SERVINT_ROADVEH,      InValidateDetailsWindow),
--- a/src/settings_gui.cpp	Wed Jun 27 10:02:55 2007 +0000
+++ b/src/settings_gui.cpp	Wed Jun 27 14:15:48 2007 +0000
@@ -655,6 +655,7 @@
 	"loading_indicators",
 	"timetable_in_ticks",
 	"default_rail_type",
+	"always_build_infrastructure",
 };
 
 static const char *_patches_construction[] = {
--- a/src/variables.h	Wed Jun 27 10:02:55 2007 +0000
+++ b/src/variables.h	Wed Jun 27 14:15:48 2007 +0000
@@ -139,6 +139,7 @@
 	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
 
+	bool always_build_infrastructure;   ///< Always allow building of infrastructure, even when you do not have the vehicles for it
 	UnitID max_trains;                  // max trains in game per player (these are 16bit because the unitnumber field can't hold more)
 	UnitID max_roadveh;                 // max trucks in game per player
 	UnitID max_aircraft;                // max planes in game per player
--- a/src/vehicle.cpp	Wed Jun 27 10:02:55 2007 +0000
+++ b/src/vehicle.cpp	Wed Jun 27 14:15:48 2007 +0000
@@ -2615,6 +2615,50 @@
 }
 
 
+/**
+ * Check whether we can build infrastructure for the given
+ * vehicle type. This to disable building stations etc. when
+ * you are not allowed/able to have the vehicle type yet.
+ * @param type the vehicle type to check this for
+ * @return true if there is any reason why you may build
+ *         the infrastructure for the given vehicle type
+ */
+bool CanBuildVehicleInfrastructure(VehicleType type)
+{
+	assert(IsPlayerBuildableVehicleType(type));
+
+	if (_patches.always_build_infrastructure) return true;
+
+	UnitID max;
+	switch (type) {
+		case VEH_TRAIN:    max = _patches.max_trains; break;
+		case VEH_ROAD:     max = _patches.max_roadveh; break;
+		case VEH_SHIP:     max = _patches.max_ships; break;
+		case VEH_AIRCRAFT: max = _patches.max_aircraft; break;
+		default: NOT_REACHED();
+	}
+
+	/* We can build vehicle infrastructure when we may build the vehicle type */
+	if (max > 0) {
+
+		/* Can we actually build the vehicle type? */
+		EngineID e;
+		FOR_ALL_ENGINEIDS_OF_TYPE(e, type) {
+			if (HASBIT(GetEngine(e)->player_avail, _local_player)) return true;
+		}
+		return false;
+	}
+
+	/* We should be able to build infrastructure when we have the actual vehicle type */
+	const Vehicle *v;
+	FOR_ALL_VEHICLES(v) {
+		if (v->owner == _local_player && v->type == type) return true;
+	}
+
+	return false;
+}
+
+
 const Livery *GetEngineLivery(EngineID engine_type, PlayerID player, EngineID parent_engine_type, const Vehicle *v)
 {
 	const Player *p = GetPlayer(player);
--- a/src/vehicle.h	Wed Jun 27 10:02:55 2007 +0000
+++ b/src/vehicle.h	Wed Jun 27 14:15:48 2007 +0000
@@ -77,6 +77,7 @@
 	VEH_END,
 	VEH_INVALID = 0xFF,
 };
+DECLARE_POSTFIX_INCREMENT(VehicleType);
 template <> struct EnumPropsT<VehicleType> : MakeEnumPropsT<VehicleType, byte, VEH_TRAIN, VEH_END, VEH_INVALID> {};
 typedef TinyEnumT<VehicleType> VehicleTypeByte;
 
@@ -569,6 +570,7 @@
 void InvalidateAutoreplaceWindow(EngineID e);
 
 CommandCost MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs);
+bool CanBuildVehicleInfrastructure(VehicleType type);
 
 /* Flags to add to p2 for goto depot commands */
 /* Note: bits 8-10 are used for VLW flags */