Changeset - r11640:aa6c71abbdce
[Not reviewed]
master
0 3 0
rubidium - 16 years ago 2009-04-10 22:47:19
rubidium@openttd.org
(svn r16025) -Fix [FS#2818]: "build separate station" in the station picker would reuse deleted stations.
3 files changed with 14 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/station_cmd.cpp
Show inline comments
 
@@ -919,12 +919,14 @@ CommandCost CmdBuildRailroadStation(Tile
 
	} else {
 
		h_org = plat_len;
 
		w_org = numtracks;
 
	}
 

	
 
	StationID station_to_join = GB(p2, 16, 16);
 
	bool reuse = (station_to_join != NEW_STATION);
 
	if (!reuse) station_to_join = INVALID_STATION;
 
	bool distant_join = (station_to_join != INVALID_STATION);
 

	
 
	if (distant_join && (!_settings_game.station.distant_join_stations || !IsValidStationID(station_to_join))) return CMD_ERROR;
 

	
 
	if (h_org > _settings_game.station.station_spread || w_org > _settings_game.station.station_spread) return CMD_ERROR;
 

	
 
@@ -972,13 +974,13 @@ CommandCost CmdBuildRailroadStation(Tile
 
	}
 

	
 
	/* Distant join */
 
	if (st == NULL && distant_join) st = GetStation(station_to_join);
 

	
 
	/* See if there is a deleted station close to us. */
 
	if (st == NULL) st = GetClosestDeletedStation(tile_org);
 
	if (st == NULL && reuse) st = GetClosestDeletedStation(tile_org);
 

	
 
	if (st != NULL) {
 
		/* Reuse an existing station. */
 
		if (st->owner != _current_company)
 
			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
 

	
 
@@ -1400,12 +1402,14 @@ CommandCost CmdBuildRoadStop(TileIndex t
 
{
 
	bool type = HasBit(p2, 0);
 
	bool is_drive_through = HasBit(p2, 1);
 
	bool build_over_road  = is_drive_through && IsNormalRoadTile(tile);
 
	RoadTypes rts = (RoadTypes)GB(p2, 2, 2);
 
	StationID station_to_join = GB(p2, 16, 16);
 
	bool reuse = (station_to_join != NEW_STATION);
 
	if (!reuse) station_to_join = INVALID_STATION;
 
	bool distant_join = (station_to_join != INVALID_STATION);
 
	Owner tram_owner = _current_company;
 
	Owner road_owner = _current_company;
 

	
 
	if (distant_join && (!_settings_game.station.distant_join_stations || !IsValidStationID(station_to_join))) return CMD_ERROR;
 

	
 
@@ -1467,13 +1471,13 @@ CommandCost CmdBuildRoadStop(TileIndex t
 
	}
 

	
 
	/* Distant join */
 
	if (st == NULL && distant_join) st = GetStation(station_to_join);
 

	
 
	/* Find a deleted station close to us */
 
	if (st == NULL) st = GetClosestDeletedStation(tile);
 
	if (st == NULL && reuse) st = GetClosestDeletedStation(tile);
 

	
 
	/* give us a road stop in the list, and check if something went wrong */
 
	if (!RoadStop::CanAllocateItem()) return_cmd_error(type ? STR_TOO_MANY_TRUCK_STOPS : STR_TOO_MANY_BUS_STOPS);
 

	
 
	if (st != NULL &&
 
			GetNumRoadStopsInStation(st, ROADSTOP_BUS) + GetNumRoadStopsInStation(st, ROADSTOP_TRUCK) >= RoadStop::LIMIT) {
 
@@ -1852,12 +1856,14 @@ void UpdateAirportsNoise()
 
 * - p2 = (bit 16-31) - station ID to join (INVALID_STATION if build new one)
 
 */
 
CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	bool airport_upgrade = true;
 
	StationID station_to_join = GB(p2, 16, 16);
 
	bool reuse = (station_to_join != NEW_STATION);
 
	if (!reuse) station_to_join = INVALID_STATION;
 
	bool distant_join = (station_to_join != INVALID_STATION);
 

	
 
	if (distant_join && (!_settings_game.station.distant_join_stations || !IsValidStationID(station_to_join))) return CMD_ERROR;
 

	
 
	/* Check if a valid, buildable airport was chosen for construction */
 
	if (p1 > lengthof(_airport_sections) || !HasBit(GetValidAirports(), p1)) return CMD_ERROR;
 
@@ -1916,13 +1922,13 @@ CommandCost CmdBuildAirport(TileIndex ti
 
	}
 

	
 
	/* Distant join */
 
	if (st == NULL && distant_join) st = GetStation(station_to_join);
 

	
 
	/* Find a deleted station close to us */
 
	if (st == NULL) st = GetClosestDeletedStation(tile);
 
	if (st == NULL && reuse) st = GetClosestDeletedStation(tile);
 

	
 
	if (st != NULL) {
 
		if (st->owner != _current_company) {
 
			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
 
		}
 

	
 
@@ -2172,12 +2178,14 @@ static const byte _dock_h_chk[4] = { 1, 
 
 * @param p1 (bit 0) - allow docks directly adjacent to other docks.
 
 * @param p2 bit 16-31: station ID to join (INVALID_STATION if build new one)
 
 */
 
CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	StationID station_to_join = GB(p2, 16, 16);
 
	bool reuse = (station_to_join != NEW_STATION);
 
	if (!reuse) station_to_join = INVALID_STATION;
 
	bool distant_join = (station_to_join != INVALID_STATION);
 

	
 
	if (distant_join && (!_settings_game.station.distant_join_stations || !IsValidStationID(station_to_join))) return CMD_ERROR;
 

	
 
	DiagDirection direction = GetInclinedSlopeDirection(GetTileSlope(tile, NULL));
 
	if (direction == INVALID_DIAGDIR) return_cmd_error(STR_304B_SITE_UNSUITABLE);
 
@@ -2221,13 +2229,13 @@ CommandCost CmdBuildDock(TileIndex tile,
 
	}
 

	
 
	/* Distant join */
 
	if (st == NULL && distant_join) st = GetStation(station_to_join);
 

	
 
	/* Find a deleted station close to us */
 
	if (st == NULL) st = GetClosestDeletedStation(tile);
 
	if (st == NULL && reuse) st = GetClosestDeletedStation(tile);
 

	
 
	if (st != NULL) {
 
		if (st->owner != _current_company) {
 
			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
 
		}
 

	
src/station_gui.cpp
Show inline comments
 
@@ -1167,13 +1167,13 @@ struct SelectStationWindow : Window {
 
		if (distant_join) st_index--;
 

	
 
		if (distant_join && st_index >= _stations_nearby_list.Length()) return;
 

	
 
		/* Insert station to be joined into stored command */
 
		SB(this->select_station_cmd.p2, 16, 16,
 
		   (distant_join ? _stations_nearby_list[st_index] : INVALID_STATION));
 
		   (distant_join ? _stations_nearby_list[st_index] : NEW_STATION));
 

	
 
		/* Execute stored Command */
 
		DoCommandP(&this->select_station_cmd);
 

	
 
		/* Close Window; this might cause double frees! */
 
		DeleteWindowById(WC_SELECT_STATION, 0);
src/station_type.h
Show inline comments
 
@@ -9,12 +9,13 @@ typedef uint16 StationID;
 
typedef uint16 RoadStopID;
 

	
 
struct Station;
 
struct RoadStop;
 
struct StationSpec;
 

	
 
static const StationID NEW_STATION = 0xFFFE;
 
static const StationID INVALID_STATION = 0xFFFF;
 

	
 
/** Station types */
 
enum StationType {
 
	STATION_RAIL,
 
	STATION_AIRPORT,
0 comments (0 inline, 0 general)