Changeset - r14089:6395a7eff659
[Not reviewed]
master
0 1 0
michi_cc - 15 years ago 2009-12-27 14:37:46
michi_cc@openttd.org
(svn r18646) -Fix [FS#3418]: [YAPP] Don't extend the reserved path through a newly built path signal directly in front of a stopped or loading train. Also restore the reserved path in more cases after removing a signal.
1 file changed with 19 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/rail_cmd.cpp
Show inline comments
 
@@ -964,25 +964,31 @@ CommandCost CmdBuildSingleSignal(TileInd
 
			SetSignalVariant(tile, track, sigvar);
 
			SetSignalType(tile, track, sigtype);
 
		}
 

	
 
		if (IsPbsSignal(sigtype)) {
 
			/* PBS signals should show red unless they are on a reservation. */
 
			uint mask = GetPresentSignals(tile) & SignalOnTrack(track);
 
			SetSignalStates(tile, (GetSignalStates(tile) & ~mask) | ((HasBit(GetRailReservationTrackBits(tile), track) ? UINT_MAX : 0) & mask));
 
		}
 
		MarkTileDirtyByTile(tile);
 
		AddTrackToSignalBuffer(tile, track, _current_company);
 
		YapfNotifyTrackLayoutChange(tile, track);
 
		if (v != NULL) TryPathReserve(v, true);
 
		if (v != NULL) {
 
			/* Extend the train's path if it's not stopped or loading, or not at a safe position. */
 
			if (!(((v->vehstatus & VS_STOPPED) && v->cur_speed == 0) || v->current_order.IsType(OT_LOADING)) ||
 
					!IsSafeWaitingPosition(v, v->tile, v->GetVehicleTrackdir(), true, _settings_game.pf.forbid_90_deg)) {
 
				TryPathReserve(v, true);
 
			}
 
		}
 
	}
 

	
 
	return cost;
 
}
 

	
 
static bool CheckSignalAutoFill(TileIndex &tile, Trackdir &trackdir, int &signal_ctr, bool remove)
 
{
 
	tile = AddTileIndexDiffCWrap(tile, _trackdelta[trackdir]);
 
	if (tile == INVALID_TILE) return false;
 

	
 
	/* Check for track bits on the new tile */
 
	TrackdirBits trackdirbits = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0));
 
@@ -1205,24 +1211,36 @@ CommandCost CmdRemoveSingleSignal(TileIn
 
			!HasSignalOnTrack(tile, track)) {
 
		return CMD_ERROR;
 
	}
 

	
 
	/* Only water can remove signals from anyone */
 
	if (_current_company != OWNER_WATER && !CheckTileOwnership(tile)) return CMD_ERROR;
 

	
 
	/* Do it? */
 
	if (flags & DC_EXEC) {
 
		Train *v = NULL;
 
		if (HasReservedTracks(tile, TrackToTrackBits(track))) {
 
			v = GetTrainForReservation(tile, track);
 
		} else if (IsPbsSignal(GetSignalType(tile, track))) {
 
			/* PBS signal, might be the end of a path reservation. */
 
			Trackdir td = TrackToTrackdir(track);
 
			for (int i = 0; v == NULL && i < 2; i++, td = ReverseTrackdir(td)) {
 
				/* Only test the active signal side. */
 
				if (!HasSignalOnTrackdir(tile, ReverseTrackdir(td))) continue;
 
				TileIndex next = TileAddByDiagDir(tile, TrackdirToExitdir(td));
 
				TrackBits tracks = TrackdirBitsToTrackBits(TrackdirReachesTrackdirs(td));
 
				if (HasReservedTracks(next, tracks)) {
 
					v = GetTrainForReservation(next, TrackBitsToTrack(GetReservedTrackbits(next) & tracks));
 
				}
 
			}
 
		}
 
		SetPresentSignals(tile, GetPresentSignals(tile) & ~SignalOnTrack(track));
 

	
 
		/* removed last signal from tile? */
 
		if (GetPresentSignals(tile) == 0) {
 
			SetSignalStates(tile, 0);
 
			SetHasSignals(tile, false);
 
			SetSignalVariant(tile, INVALID_TRACK, SIG_ELECTRIC); // remove any possible semaphores
 
		}
 

	
 
		AddTrackToSignalBuffer(tile, track, GetTileOwner(tile));
 
		YapfNotifyTrackLayoutChange(tile, track);
0 comments (0 inline, 0 general)