src/train_cmd.cpp
changeset 9819 e5c938adf4f3
parent 9818 bec6961fb6b6
child 9820 7838f660287a
equal deleted inserted replaced
9818:bec6961fb6b6 9819:e5c938adf4f3
    61 
    61 
    62 static Track ChooseTrainTrack(Vehicle* v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool force_res, bool *got_reservation, bool mark_stuck);
    62 static Track ChooseTrainTrack(Vehicle* v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool force_res, bool *got_reservation, bool mark_stuck);
    63 static bool TrainCheckIfLineEnds(Vehicle *v);
    63 static bool TrainCheckIfLineEnds(Vehicle *v);
    64 static void TrainController(Vehicle *v, Vehicle *nomove, bool update_image);
    64 static void TrainController(Vehicle *v, Vehicle *nomove, bool update_image);
    65 static TileIndex TrainApproachingCrossingTile(const Vehicle *v);
    65 static TileIndex TrainApproachingCrossingTile(const Vehicle *v);
       
    66 static void CheckNextTrainTile(Vehicle *v);
    66 
    67 
    67 static const byte _vehicle_initial_x_fract[4] = {10, 8, 4,  8};
    68 static const byte _vehicle_initial_x_fract[4] = {10, 8, 4,  8};
    68 static const byte _vehicle_initial_y_fract[4] = { 8, 4, 8, 10};
    69 static const byte _vehicle_initial_y_fract[4] = { 8, 4, 8, 10};
    69 
    70 
    70 
    71 
  1890 {
  1891 {
  1891 	if (IsRailDepotTile(v->tile)) {
  1892 	if (IsRailDepotTile(v->tile)) {
  1892 		InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
  1893 		InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
  1893 	}
  1894 	}
  1894 
  1895 
       
  1896 	/* Clear path reservation in front. */
       
  1897 	FreeTrainTrackReservation(v);
       
  1898 
  1895 	/* Check if we were approaching a rail/road-crossing */
  1899 	/* Check if we were approaching a rail/road-crossing */
  1896 	TileIndex crossing = TrainApproachingCrossingTile(v);
  1900 	TileIndex crossing = TrainApproachingCrossingTile(v);
  1897 
  1901 
  1898 	/* count number of vehicles */
  1902 	/* count number of vehicles */
  1899 	int r = CountVehiclesInChain(v) - 1;  // number of vehicles - 1
  1903 	int r = CountVehiclesInChain(v) - 1;  // number of vehicles - 1
  1926 	if (crossing != INVALID_TILE) UpdateLevelCrossing(crossing);
  1930 	if (crossing != INVALID_TILE) UpdateLevelCrossing(crossing);
  1927 
  1931 
  1928 	/* maybe we are approaching crossing now, after reversal */
  1932 	/* maybe we are approaching crossing now, after reversal */
  1929 	crossing = TrainApproachingCrossingTile(v);
  1933 	crossing = TrainApproachingCrossingTile(v);
  1930 	if (crossing != INVALID_TILE) MaybeBarCrossingWithSound(crossing);
  1934 	if (crossing != INVALID_TILE) MaybeBarCrossingWithSound(crossing);
       
  1935 
       
  1936 	/* If we are inside a depot after reversing, don't bother with path reserving. */
       
  1937 	if (v->u.rail.track & TRACK_BIT_DEPOT) return;
       
  1938 
       
  1939 	/* TrainExitDir does not always produce the desired dir for depots and
       
  1940 	 * tunnels/bridges that is needed for UpdateSignalsOnSegment. */
       
  1941 	DiagDirection dir = TrainExitDir(v->direction, v->u.rail.track);
       
  1942 	if (IsRailDepotTile(v->tile) || IsTileType(v->tile, MP_TUNNELBRIDGE)) dir = INVALID_DIAGDIR;
       
  1943 
       
  1944 	if (UpdateSignalsOnSegment(v->tile, dir, v->owner) == SIGSEG_PBS || _settings_game.pf.reserve_paths) {
       
  1945 		/* If we are currently on a tile with conventional signals, we can't treat the
       
  1946 		 * current tile as a safe tile or we would enter a PBS block without a reservation. */
       
  1947 		bool first_tile_okay = !(IsTileType(v->tile, MP_RAILWAY) &&
       
  1948 			HasSignalOnTrackdir(v->tile, GetVehicleTrackdir(v)) &&
       
  1949 			!IsPbsSignal(GetSignalType(v->tile, FindFirstTrack(v->u.rail.track))));
       
  1950 
       
  1951 		if (TryPathReserve(v, true, first_tile_okay)) {
       
  1952 			/* Do a look-ahead now in case our current tile was already a safe tile. */
       
  1953 			CheckNextTrainTile(v);
       
  1954 		}
       
  1955 	}
  1931 }
  1956 }
  1932 
  1957 
  1933 /** Reverse train.
  1958 /** Reverse train.
  1934  * @param tile unused
  1959  * @param tile unused
  1935  * @param flags type of operation
  1960  * @param flags type of operation