(svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
authormaedhros
Wed, 23 May 2007 17:33:03 +0000
changeset 7170 bd34b6d0e4f1
parent 7169 f66b869f439f
child 7171 87515d9cb3e6
(svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
src/airport_gui.cpp
src/dock_gui.cpp
src/lang/english.txt
src/rail_gui.cpp
src/road_gui.cpp
src/saveload.cpp
src/settings.cpp
src/settings_gui.cpp
src/station_cmd.cpp
src/variables.h
--- a/src/airport_gui.cpp	Wed May 23 16:40:40 2007 +0000
+++ b/src/airport_gui.cpp	Wed May 23 17:33:03 2007 +0000
@@ -34,7 +34,7 @@
 
 static void PlaceAirport(TileIndex tile)
 {
-	DoCommandP(tile, _selected_airport_type, 0, CcBuildAirport, CMD_BUILD_AIRPORT | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_A001_CAN_T_BUILD_AIRPORT_HERE));
+	DoCommandP(tile, _selected_airport_type, _ctrl_pressed, CcBuildAirport, CMD_BUILD_AIRPORT | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_A001_CAN_T_BUILD_AIRPORT_HERE));
 }
 
 static void PlaceAir_DemolishArea(TileIndex tile)
--- a/src/dock_gui.cpp	Wed May 23 16:40:40 2007 +0000
+++ b/src/dock_gui.cpp	Wed May 23 17:33:03 2007 +0000
@@ -38,7 +38,7 @@
 
 static void PlaceDocks_Dock(TileIndex tile)
 {
-	DoCommandP(tile, 0, 0, CcBuildDocks, CMD_BUILD_DOCK | CMD_AUTO | CMD_MSG(STR_9802_CAN_T_BUILD_DOCK_HERE));
+	DoCommandP(tile, _ctrl_pressed, 0, CcBuildDocks, CMD_BUILD_DOCK | CMD_AUTO | CMD_MSG(STR_9802_CAN_T_BUILD_DOCK_HERE));
 }
 
 static void PlaceDocks_Depot(TileIndex tile)
--- a/src/lang/english.txt	Wed May 23 16:40:40 2007 +0000
+++ b/src/lang/english.txt	Wed May 23 17:33:03 2007 +0000
@@ -1048,6 +1048,7 @@
 STR_CONFIG_PATCHES_NEW_PATHFINDING_ALL                          :{LTBLUE}New global pathfinding (NPF, overrides NTP): {ORANGE}{STRING1}
 STR_CONFIG_PATCHES_FREIGHT_TRAINS                               :{LTBLUE}Weight multiplier for freight to simulate heavy trains: {ORANGE}{STRING}
 STR_CONFIG_PATCHES_STOP_ON_TOWN_ROAD                            :{LTBLUE}Allow drive-through road stops on town owned roads: {ORANGE}{STRING}
+STR_CONFIG_PATCHES_ADJACENT_STATIONS                            :{LTBLUE}Allow building adjacent stations: {ORANGE}{STRING}
 
 STR_CONFIG_PATCHES_SMALL_AIRPORTS                               :{LTBLUE}Always allow small airports: {ORANGE}{STRING1}
 
@@ -1588,6 +1589,7 @@
 STR_RAILROAD_TRACK_WITH_PRESIGNALS                              :Railway track with pre-signals
 STR_RAILROAD_TRACK_WITH_EXITSIGNALS                             :Railway track with exit-signals
 STR_RAILROAD_TRACK_WITH_COMBOSIGNALS                            :Railway track with combo-signals
+STR_MUST_REMOVE_RAILWAY_STATION_FIRST                           :{WHITE}Must remove railway station first
 
 
 
--- a/src/rail_gui.cpp	Wed May 23 16:40:40 2007 +0000
+++ b/src/rail_gui.cpp	Wed May 23 17:33:03 2007 +0000
@@ -157,7 +157,7 @@
 		VpSetPlaceSizingLimit(_patches.station_spread);
 	} else {
 		DoCommandP(tile,
-				_railstation.orientation | (_railstation.numtracks << 8) | (_railstation.platlength << 16),
+				_railstation.orientation | (_railstation.numtracks << 8) | (_railstation.platlength << 16) | (_ctrl_pressed << 24),
 				_cur_railtype | (_railstation.station_class << 8) | (_railstation.station_type << 16), CcStation,
 				CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_AUTO | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION));
 	}
@@ -665,7 +665,7 @@
 	if (!_railstation.orientation) Swap(w, h);
 
 	DoCommandP(TileXY(sx, sy),
-			_railstation.orientation | (w << 8) | (h << 16),
+			_railstation.orientation | (w << 8) | (h << 16) | (_ctrl_pressed << 24),
 			_cur_railtype | (_railstation.station_class << 8) | (_railstation.station_type << 16), CcStation,
 			CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_AUTO | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION));
 }
--- a/src/road_gui.cpp	Wed May 23 16:40:40 2007 +0000
+++ b/src/road_gui.cpp	Wed May 23 17:33:03 2007 +0000
@@ -119,7 +119,7 @@
 	if (_remove_button_clicked) {
 		DoCommandP(tile, 0, RoadStop::BUS, CcPlaySound1D, CMD_REMOVE_ROAD_STOP | CMD_MSG(STR_CAN_T_REMOVE_BUS_STATION));
 	} else {
-		PlaceRoadStop(tile, ROADTYPES_ROAD << 2 | RoadStop::BUS, CMD_BUILD_ROAD_STOP | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1808_CAN_T_BUILD_BUS_STATION));
+		PlaceRoadStop(tile, (_ctrl_pressed << 5) | ROADTYPES_ROAD << 2 | RoadStop::BUS, CMD_BUILD_ROAD_STOP | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1808_CAN_T_BUILD_BUS_STATION));
 	}
 }
 
@@ -128,7 +128,7 @@
 	if (_remove_button_clicked) {
 		DoCommandP(tile, 0, RoadStop::TRUCK, CcPlaySound1D, CMD_REMOVE_ROAD_STOP | CMD_MSG(STR_CAN_T_REMOVE_TRUCK_STATION));
 	} else {
-		PlaceRoadStop(tile, ROADTYPES_ROAD << 2 | RoadStop::TRUCK, CMD_BUILD_ROAD_STOP | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1809_CAN_T_BUILD_TRUCK_STATION));
+		PlaceRoadStop(tile, (_ctrl_pressed << 5) | ROADTYPES_ROAD << 2 | RoadStop::TRUCK, CMD_BUILD_ROAD_STOP | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1809_CAN_T_BUILD_TRUCK_STATION));
 	}
 }
 
--- a/src/saveload.cpp	Wed May 23 16:40:40 2007 +0000
+++ b/src/saveload.cpp	Wed May 23 17:33:03 2007 +0000
@@ -29,7 +29,7 @@
 #include <setjmp.h>
 #include <list>
 
-extern const uint16 SAVEGAME_VERSION = 61;
+extern const uint16 SAVEGAME_VERSION = 62;
 uint16 _sl_version;       ///< the major savegame version identifier
 byte   _sl_minor_version; ///< the minor savegame version, DO NOT USE!
 
--- a/src/settings.cpp	Wed May 23 16:40:40 2007 +0000
+++ b/src/settings.cpp	Wed May 23 17:33:03 2007 +0000
@@ -1402,6 +1402,7 @@
 	SDT_BOOL(Patches, modified_catchment,      0, 0,  true,        STR_CONFIG_PATCHES_CATCHMENT,          NULL),
 	SDT_CONDBOOL(Patches, gradual_loading, 40, SL_MAX_VERSION, 0, 0,  true, STR_CONFIG_PATCHES_GRADUAL_LOADING,    NULL),
 	SDT_CONDBOOL(Patches, road_stop_on_town_road, 47, SL_MAX_VERSION, 0, 0, false, STR_CONFIG_PATCHES_STOP_ON_TOWN_ROAD, NULL),
+	SDT_CONDBOOL(Patches, adjacent_stations,      62, SL_MAX_VERSION, 0, 0, true,  STR_CONFIG_PATCHES_ADJACENT_STATIONS, NULL),
 
 	/***************************************************************************/
 	/* Economy section of the GUI-configure patches window */
--- a/src/settings_gui.cpp	Wed May 23 16:40:40 2007 +0000
+++ b/src/settings_gui.cpp	Wed May 23 17:33:03 2007 +0000
@@ -625,6 +625,7 @@
 	"modified_catchment",
 	"gradual_loading",
 	"road_stop_on_town_road",
+	"adjacent_stations",
 };
 
 static const char *_patches_economy[] = {
--- a/src/station_cmd.cpp	Wed May 23 16:40:40 2007 +0000
+++ b/src/station_cmd.cpp	Wed May 23 17:33:03 2007 +0000
@@ -794,6 +794,7 @@
  * - p1 = (bit  0)    - orientation (Axis)
  * - p1 = (bit  8-15) - number of tracks
  * - p1 = (bit 16-23) - platform length
+ * - p1 = (bit 24)    - allow stations directly adjacent to other stations.
  * @param p2 various bitstuffed elements
  * - p2 = (bit  0- 3) - railtype (p2 & 0xF)
  * - p2 = (bit  8-15) - custom station class
@@ -838,9 +839,33 @@
 	if (CmdFailed(ret)) return ret;
 	int32 cost = ret + (numtracks * _price.train_station_track + _price.train_station_length) * plat_len;
 
-	// Make sure there are no similar stations around us.
-	Station *st = GetStationAround(tile_org, w_org, h_org, est);
-	if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
+	Station *st = NULL;
+	bool check_surrounding = true;
+
+	if (_patches.adjacent_stations) {
+		if (est != INVALID_STATION) {
+			if (HASBIT(p1, 24)) {
+				/* You can't build an adjacent station over the top of one that
+				 * already exists. */
+				return_cmd_error(STR_MUST_REMOVE_RAILWAY_STATION_FIRST);
+			} else {
+				/* Extend the current station, and don't check whether it will
+				 * be near any other stations. */
+				st = GetStation(est);
+				check_surrounding = false;
+			}
+		} else {
+			/* There's no station here. Don't check the tiles surrounding this
+			 * one if the player wanted to build an adjacent station. */
+			if (HASBIT(p1, 24)) check_surrounding = false;
+		}
+	}
+
+	if (check_surrounding) {
+		// Make sure there are no similar stations around us.
+		st = GetStationAround(tile_org, w_org, h_org, est);
+		if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
+	}
 
 	// See if there is a deleted station close to us.
 	if (st == NULL) st = GetClosestStationFromTile(tile_org);
@@ -1215,6 +1240,7 @@
  * @param p2 bit 0: 0 for Bus stops, 1 for truck stops
  *           bit 1: 0 for normal, 1 for drive-through
  *           bit 2..4: the roadtypes
+ *           bit 5: allow stations directly adjacent to other stations.
  */
 int32 CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
@@ -1255,8 +1281,12 @@
 	if (CmdFailed(ret)) return ret;
 	int32 cost = build_over_road ? 0 : ret; // Don't add cost of clearing road when overbuilding
 
-	Station *st = GetStationAround(tile, 1, 1, INVALID_STATION);
-	if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
+	Station *st = NULL;
+
+	if (!_patches.adjacent_stations || !HASBIT(p2, 5)) {
+		st = GetStationAround(tile, 1, 1, INVALID_STATION);
+		if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
+	}
 
 	/* Find a station close to us */
 	if (st == NULL) st = GetClosestStationFromTile(tile);
@@ -1521,7 +1551,7 @@
  * @param tile tile where airport will be built
  * @param flags operation to perform
  * @param p1 airport type, @see airport.h
- * @param p2 unused
+ * @param p2 (bit 0) - allow airports directly adjacent to other airports.
  */
 int32 CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
@@ -1559,8 +1589,12 @@
 	if (CmdFailed(ret)) return ret;
 	int32 cost = ret;
 
-	Station *st = GetStationAround(tile, w, h, INVALID_STATION);
-	if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
+	Station *st = NULL;
+
+	if (!_patches.adjacent_stations || !HASBIT(p2, 0)) {
+		st = GetStationAround(tile, w, h, INVALID_STATION);
+		if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
+	}
 
 	/* Find a station close to us */
 	if (st == NULL) st = GetClosestStationFromTile(tile);
@@ -1805,7 +1839,7 @@
 /** Build a dock/haven.
  * @param tile tile where dock will be built
  * @param flags operation to perform
- * @param p1 unused
+ * @param p1 (bit 0) - allow docks directly adjacent to other docks.
  * @param p2 unused
  */
 int32 CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
@@ -1847,10 +1881,14 @@
 	}
 
 	/* middle */
-	Station *st = GetStationAround(
-		tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),
-		_dock_w_chk[direction], _dock_h_chk[direction], INVALID_STATION);
-	if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
+	Station *st = NULL;
+
+	if (!_patches.adjacent_stations || !HASBIT(p1, 0)) {
+		st = GetStationAround(
+				tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),
+				_dock_w_chk[direction], _dock_h_chk[direction], INVALID_STATION);
+		if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
+	}
 
 	/* Find a station close to us */
 	if (st == NULL) st = GetClosestStationFromTile(tile);
--- a/src/variables.h	Wed May 23 16:40:40 2007 +0000
+++ b/src/variables.h	Wed May 23 17:33:03 2007 +0000
@@ -118,6 +118,7 @@
 	byte se_flat_world_height;          // land height a flat world gets in SE
 	bool bribe;                         // enable bribing the local authority
 	bool nonuniform_stations;           // allow nonuniform train stations
+	bool adjacent_stations;             // allow stations to be built directly adjacent to other stations
 	bool always_small_airport;          // always allow small airports
 	bool realistic_acceleration;        // realistic acceleration for trains
 	bool wagon_speed_limits;            // enable wagon speed limits