src/train_cmd.cpp
changeset 9093 49392c2d9ac7
parent 9052 392f5995d323
child 9094 58d1cddf1af6
equal deleted inserted replaced
9092:383a632de666 9093:49392c2d9ac7
  3038 				enterdir = DirToDiagDir(dir);
  3038 				enterdir = DirToDiagDir(dir);
  3039 				assert(IsValidDiagDirection(enterdir));
  3039 				assert(IsValidDiagDirection(enterdir));
  3040 
  3040 
  3041 				/* Get the status of the tracks in the new tile and mask
  3041 				/* Get the status of the tracks in the new tile and mask
  3042 				 * away the bits that aren't reachable. */
  3042 				 * away the bits that aren't reachable. */
  3043 				uint32 ts = GetTileTrackStatus(gp.new_tile, TRANSPORT_RAIL, 0) & _reachable_tracks[enterdir];
  3043 				uint32 ts = GetTileTrackStatus(gp.new_tile, TRANSPORT_RAIL, 0, ReverseDiagDir(enterdir)) & _reachable_tracks[enterdir];
  3044 
  3044 
  3045 				/* Combine the from & to directions.
  3045 				/* Combine the from & to directions.
  3046 				 * Now, the lower byte contains the track status, and the byte at bit 16 contains
  3046 				 * Now, the lower byte contains the track status, and the byte at bit 16 contains
  3047 				 * the signal status. */
  3047 				 * the signal status. */
  3048 				uint32 tracks = ts | (ts >> 8);
  3048 				uint32 tracks = ts | (ts >> 8);
  3473 	DiagDirection dir = TrainExitDir(v->direction, v->u.rail.track);
  3473 	DiagDirection dir = TrainExitDir(v->direction, v->u.rail.track);
  3474 	/* Calculate next tile */
  3474 	/* Calculate next tile */
  3475 	TileIndex tile = v->tile + TileOffsByDiagDir(dir);
  3475 	TileIndex tile = v->tile + TileOffsByDiagDir(dir);
  3476 
  3476 
  3477 	/* Determine the track status on the next tile */
  3477 	/* Determine the track status on the next tile */
  3478 	uint32 ts = GetTileTrackStatus(tile, TRANSPORT_RAIL, 0) & _reachable_tracks[dir];
  3478 	uint32 ts = GetTileTrackStatus(tile, TRANSPORT_RAIL, 0, ReverseDiagDir(dir)) & _reachable_tracks[dir];
  3479 
  3479 
  3480 	/* We are sure the train is not entering a depot, it is detected above */
  3480 	/* We are sure the train is not entering a depot, it is detected above */
  3481 
  3481 
  3482 	/* mask unreachable track bits if we are forbidden to do 90deg turns */
  3482 	/* mask unreachable track bits if we are forbidden to do 90deg turns */
  3483 	TrackBits bits = (TrackBits)((ts | (ts >> 8)) & TRACK_BIT_MASK);
  3483 	TrackBits bits = (TrackBits)((ts | (ts >> 8)) & TRACK_BIT_MASK);
  3484 	if (_patches.pathfinder_for_trains != VPF_NTP && _patches.forbid_90_deg) {
  3484 	if (_patches.pathfinder_for_trains != VPF_NTP && _patches.forbid_90_deg) {
  3485 		bits &= ~TrackCrossesTracks(FindFirstTrack(v->u.rail.track));
  3485 		bits &= ~TrackCrossesTracks(FindFirstTrack(v->u.rail.track));
  3486 	}
  3486 	}
  3487 
  3487 
  3488 	/* no suitable trackbits at all || wrong railtype || not our track ||
  3488 	/* no suitable trackbits at all || wrong railtype || not our track */
  3489 	 *   tunnel/bridge from opposite side || depot from opposite side */
  3489 	if (bits == TRACK_BIT_NONE || !CheckCompatibleRail(v, tile) || GetTileOwner(tile) != v->owner) {
  3490 	if (bits == TRACK_BIT_NONE || !CheckCompatibleRail(v, tile) || GetTileOwner(tile) != v->owner ||
       
  3491 			(IsTileType(tile, MP_TUNNELBRIDGE) && GetTunnelBridgeDirection(tile) != dir) ||
       
  3492 			(IsTileDepotType(tile, TRANSPORT_RAIL) && GetRailDepotDirection(tile) == dir) ) {
       
  3493 		return TrainApproachingLineEnd(v, false);
  3490 		return TrainApproachingLineEnd(v, false);
  3494 	}
  3491 	}
  3495 
  3492 
  3496 	/* approaching red signal */
  3493 	/* approaching red signal */
  3497 	if ((ts & (ts >> 16)) != 0) return TrainApproachingLineEnd(v, true);
  3494 	if ((ts & (ts >> 16)) != 0) return TrainApproachingLineEnd(v, true);