Changeset - r15455:028ab2136a1a
[Not reviewed]
master
0 2 0
terkhen - 14 years ago 2010-07-10 20:15:35
terkhen@openttd.org
(svn r20114) -Add: Show an specific error message when trying to remove rail or build/convert/remove signals over nonexistant railways.
2 files changed with 12 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -3540,24 +3540,25 @@ STR_ERROR_AUTOREPLACE_MONEY_LIMIT       
 
# Rail construction errors
 
STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION                          :{WHITE}Impossible track combination
 
STR_ERROR_MUST_REMOVE_SIGNALS_FIRST                             :{WHITE}Must remove signals first
 
STR_ERROR_NO_SUITABLE_RAILROAD_TRACK                            :{WHITE}No suitable railway track
 
STR_ERROR_MUST_REMOVE_RAILROAD_TRACK                            :{WHITE}Must remove railway track first
 
STR_ERROR_CROSSING_ON_ONEWAY_ROAD                               :{WHITE}Road is one way or blocked
 
STR_ERROR_CROSSING_DISALLOWED                                   :{WHITE}Level crossings not allowed for this rail type
 
STR_ERROR_CAN_T_BUILD_SIGNALS_HERE                              :{WHITE}Can't build signals here...
 
STR_ERROR_CAN_T_BUILD_RAILROAD_TRACK                            :{WHITE}Can't build railway track here...
 
STR_ERROR_CAN_T_REMOVE_RAILROAD_TRACK                           :{WHITE}Can't remove railway track from here...
 
STR_ERROR_CAN_T_REMOVE_SIGNALS_FROM                             :{WHITE}Can't remove signals from here...
 
STR_ERROR_SIGNAL_CAN_T_CONVERT_SIGNALS_HERE                     :{WHITE}Can't convert signals here...
 
STR_ERROR_THERE_IS_NO_RAILROAD_TRACK                            :{WHITE}...there is no railway track
 

	
 
STR_ERROR_CAN_T_CONVERT_RAIL                                    :{WHITE}Can't convert railtype here...
 

	
 
# Road construction errors
 
STR_ERROR_MUST_REMOVE_ROAD_FIRST                                :{WHITE}Must remove road first
 
STR_ERROR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION                      :{WHITE}... one way roads can't have junctions
 
STR_ERROR_CAN_T_BUILD_ROAD_HERE                                 :{WHITE}Can't build road here...
 
STR_ERROR_CAN_T_BUILD_TRAMWAY_HERE                              :{WHITE}Can't build tramway here...
 
STR_ERROR_CAN_T_REMOVE_ROAD_FROM                                :{WHITE}Can't remove road from here...
 
STR_ERROR_CAN_T_REMOVE_TRAMWAY_FROM                             :{WHITE}Can't remove tramway from here...
 
STR_ERROR_THERE_IS_NO_ROAD                                      :{WHITE}...there is no road
 
STR_ERROR_THERE_IS_NO_TRAMWAY                                   :{WHITE}...there is no tramway
src/rail_cmd.cpp
Show inline comments
 
@@ -508,25 +508,25 @@ CommandCost CmdRemoveSingleRail(TileInde
 
	TrackBits trackbit = TrackToTrackBits(track);
 

	
 
	/* Need to read tile owner now because it may change when the rail is removed
 
	 * Also, in case of floods, _current_company != owner
 
	 * There may be invalid tiletype even in exec run (when removing long track),
 
	 * so do not call GetTileOwner(tile) in any case here */
 
	Owner owner = INVALID_OWNER;
 

	
 
	Train *v = NULL;
 

	
 
	switch (GetTileType(tile)) {
 
		case MP_ROAD: {
 
			if (!IsLevelCrossing(tile) || GetCrossingRailBits(tile) != trackbit) return CMD_ERROR;
 
			if (!IsLevelCrossing(tile) || GetCrossingRailBits(tile) != trackbit) return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
 

	
 
			if (_current_company != OWNER_WATER) {
 
				CommandCost ret = CheckTileOwnership(tile);
 
				if (ret.Failed()) return ret;
 
			}
 

	
 
			if (!(flags & DC_BANKRUPT)) {
 
				CommandCost ret = EnsureNoVehicleOnGround(tile);
 
				if (ret.Failed()) return ret;
 
			}
 

	
 
			cost.AddCost(RailClearCost(GetRailType(tile)));
 
@@ -536,37 +536,37 @@ CommandCost CmdRemoveSingleRail(TileInde
 
					v = GetTrainForReservation(tile, track);
 
					if (v != NULL) FreeTrainTrackReservation(v);
 
				}
 
				owner = GetTileOwner(tile);
 
				MakeRoadNormal(tile, GetCrossingRoadBits(tile), GetRoadTypes(tile), GetTownIndex(tile), GetRoadOwner(tile, ROADTYPE_ROAD), GetRoadOwner(tile, ROADTYPE_TRAM));
 
				DeleteNewGRFInspectWindow(GSF_RAILTYPES, tile);
 
			}
 
			break;
 
		}
 

	
 
		case MP_RAILWAY: {
 
			TrackBits present;
 

	
 
			if (!IsPlainRail(tile)) return CMD_ERROR;
 
			/* There are no rails present at depots. */
 
			if (!IsPlainRail(tile)) return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
 

	
 
			if (_current_company != OWNER_WATER) {
 
				CommandCost ret = CheckTileOwnership(tile);
 
				if (ret.Failed()) return ret;
 
			}
 

	
 
			CommandCost ret = EnsureNoTrainOnTrack(tile, track);
 
			if (ret.Failed()) return ret;
 

	
 
			present = GetTrackBits(tile);
 
			if ((present & trackbit) == 0) return CMD_ERROR;
 
			if ((present & trackbit) == 0) return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
 
			if (present == (TRACK_BIT_X | TRACK_BIT_Y)) crossing = true;
 

	
 
			cost.AddCost(RailClearCost(GetRailType(tile)));
 

	
 
			/* Charge extra to remove signals on the track, if they are there */
 
			if (HasSignalOnTrack(tile, track))
 
				cost.AddCost(DoCommand(tile, track, 0, flags, CMD_REMOVE_SIGNALS));
 

	
 
			if (flags & DC_EXEC) {
 
				if (HasReservedTracks(tile, trackbit)) {
 
					v = GetTrainForReservation(tile, track);
 
					if (v != NULL) FreeTrainTrackReservation(v);
 
@@ -581,25 +581,25 @@ CommandCost CmdRemoveSingleRail(TileInde
 
					} else {
 
						DoClearSquare(tile);
 
					}
 
					DeleteNewGRFInspectWindow(GSF_RAILTYPES, tile);
 
				} else {
 
					SetTrackBits(tile, present);
 
					SetTrackReservation(tile, GetRailReservationTrackBits(tile) & present);
 
				}
 
			}
 
			break;
 
		}
 

	
 
		default: return CMD_ERROR;
 
		default: return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		/* if we got that far, 'owner' variable is set correctly */
 
		assert(Company::IsValidID(owner));
 

	
 
		MarkTileDirtyByTile(tile);
 
		if (crossing) {
 
			/* crossing is set when only TRACK_BIT_X and TRACK_BIT_Y are set. As we
 
			 * are removing one of these pieces, we'll need to update signals for
 
			 * both directions explicitly, as after the track is removed it won't
 
			 * 'connect' with the other piece. */
 
@@ -914,25 +914,25 @@ CommandCost CmdBuildSingleSignal(TileInd
 
	SignalType sigtype = Extract<SignalType, 5, 3>(p1); // the signal type of the new signal
 
	bool convert_signal = HasBit(p1, 8); // convert button pressed
 
	SignalType cycle_start = Extract<SignalType, 9, 3>(p1);
 
	SignalType cycle_stop = Extract<SignalType, 12, 3>(p1);
 
	uint num_dir_cycle = GB(p1, 15, 2);
 

	
 
	if (sigtype > SIGTYPE_LAST) return CMD_ERROR;
 
	if (cycle_start > cycle_stop || cycle_stop > SIGTYPE_LAST) return CMD_ERROR;
 

	
 
	/* You can only build signals on plain rail tiles, and the selected track must exist */
 
	if (!ValParamTrackOrientation(track) || !IsPlainRailTile(tile) ||
 
			!HasTrack(tile, track)) {
 
		return CMD_ERROR;
 
		return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
 
	}
 
	CommandCost ret = EnsureNoTrainOnTrack(tile, track);
 
	if (ret.Failed()) return ret;
 

	
 
	/* Protect against invalid signal copying */
 
	if (p2 != 0 && (p2 & SignalOnTrack(track)) == 0) return CMD_ERROR;
 

	
 
	ret = CheckTileOwnership(tile);
 
	if (ret.Failed()) return ret;
 

	
 
	{
 
		/* See if this is a valid track combination for signals, (ie, no overlap) */
 
@@ -1140,25 +1140,25 @@ static CommandCost CmdSignalTrackHelper(
 

	
 
	Track track = Extract<Track, 0, 3>(p2);
 
	bool mode = HasBit(p2, 3);
 
	bool semaphores = HasBit(p2, 4);
 
	bool remove = HasBit(p2, 5);
 
	bool autofill = HasBit(p2, 6);
 
	byte signal_density = GB(p2, 24, 8);
 

	
 
	if (p1 >= MapSize() || !ValParamTrackOrientation(track)) return CMD_ERROR;
 
	TileIndex end_tile = p1;
 
	if (signal_density == 0 || signal_density > 20) return CMD_ERROR;
 

	
 
	if (!IsPlainRailTile(tile)) return CMD_ERROR;
 
	if (!IsPlainRailTile(tile)) return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
 

	
 
	/* for vertical/horizontal tracks, double the given signals density
 
	 * since the original amount will be too dense (shorter tracks) */
 
	signal_density *= 2;
 

	
 
	Trackdir trackdir = TrackToTrackdir(track);
 
	CommandCost ret = ValidateAutoDrag(&trackdir, tile, end_tile);
 
	if (ret.Failed()) return ret;
 

	
 
	track = TrackdirToTrack(trackdir); // trackdir might have changed, keep track in sync
 
	Trackdir start_trackdir = trackdir;
 

	
 
@@ -1275,28 +1275,28 @@ CommandCost CmdBuildSignalTrack(TileInde
 
 * @param p1 various bitstuffed elements, only track information is used
 
 *           - (bit  0- 2) - track-orientation, valid values: 0-5 (Track enum)
 
 *           - (bit  3)    - override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
 
 *           - (bit  4)    - 0 = signals, 1 = semaphores
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRemoveSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Track track = Extract<Track, 0, 3>(p1);
 

	
 
	if (!ValParamTrackOrientation(track) ||
 
			!IsPlainRailTile(tile) ||
 
			!HasTrack(tile, track) ||
 
			!HasSignalOnTrack(tile, track)) {
 
	if (!ValParamTrackOrientation(track) || !IsPlainRailTile(tile) || !HasTrack(tile, track)) {
 
		return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
 
	}
 
	if (!HasSignalOnTrack(tile, track)) {
 
		return CMD_ERROR;
 
	}
 
	CommandCost ret = EnsureNoTrainOnTrack(tile, track);
 
	if (ret.Failed()) return ret;
 

	
 
	/* Only water can remove signals from anyone */
 
	if (_current_company != OWNER_WATER) {
 
		CommandCost ret = CheckTileOwnership(tile);
 
		if (ret.Failed()) return ret;
 
	}
 

	
 
	/* Do it? */
0 comments (0 inline, 0 general)