52 static bool TrainCheckIfLineEnds(Vehicle *v); |
52 static bool TrainCheckIfLineEnds(Vehicle *v); |
53 static void TrainController(Vehicle *v, bool update_image); |
53 static void TrainController(Vehicle *v, bool update_image); |
54 |
54 |
55 static const byte _vehicle_initial_x_fract[4] = {10, 8, 4, 8}; |
55 static const byte _vehicle_initial_x_fract[4] = {10, 8, 4, 8}; |
56 static const byte _vehicle_initial_y_fract[4] = { 8, 4, 8, 10}; |
56 static const byte _vehicle_initial_y_fract[4] = { 8, 4, 8, 10}; |
57 static const TrackBits _state_dir_table[4] = { TRACK_BIT_RIGHT, TRACK_BIT_LOWER, TRACK_BIT_LEFT, TRACK_BIT_UPPER }; |
57 |
|
58 |
|
59 /** |
|
60 * Determine the side in which the train will leave the tile |
|
61 * |
|
62 * @param direction vehicle direction |
|
63 * @param track vehicle track bits |
|
64 * @return side of tile the train will leave |
|
65 */ |
|
66 static inline DiagDirection TrainExitDir(Direction direction, TrackBits track) |
|
67 { |
|
68 static const TrackBits state_dir_table[DIAGDIR_END] = { TRACK_BIT_RIGHT, TRACK_BIT_LOWER, TRACK_BIT_LEFT, TRACK_BIT_UPPER }; |
|
69 |
|
70 DiagDirection diagdir = DirToDiagDir(direction); |
|
71 |
|
72 /* Determine the diagonal direction in which we will exit this tile */ |
|
73 if (!HasBit(direction, 0) && track != state_dir_table[diagdir]) { |
|
74 diagdir = ChangeDiagDir(diagdir, DIAGDIRDIFF_90LEFT); |
|
75 } |
|
76 |
|
77 return diagdir; |
|
78 } |
58 |
79 |
59 |
80 |
60 /** Return the cargo weight multiplier to use for a rail vehicle |
81 /** Return the cargo weight multiplier to use for a rail vehicle |
61 * @param cargo Cargo type to get multiplier for |
82 * @param cargo Cargo type to get multiplier for |
62 * @return Cargo weight multiplier |
83 * @return Cargo weight multiplier |
1664 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
1685 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
1665 } |
1686 } |
1666 |
1687 |
1667 /* Check if we were approaching a rail/road-crossing */ |
1688 /* Check if we were approaching a rail/road-crossing */ |
1668 { |
1689 { |
1669 TileIndex tile = v->tile; |
|
1670 DiagDirection dir = DirToDiagDir(v->direction); |
|
1671 |
|
1672 /* Determine the diagonal direction in which we will exit this tile */ |
1690 /* Determine the diagonal direction in which we will exit this tile */ |
1673 if (!(v->direction & 1) && v->u.rail.track != _state_dir_table[dir]) { |
1691 DiagDirection dir = TrainExitDir(v->direction, v->u.rail.track); |
1674 dir = ChangeDiagDir(dir, DIAGDIRDIFF_90LEFT); |
|
1675 } |
|
1676 /* Calculate next tile */ |
1692 /* Calculate next tile */ |
1677 tile += TileOffsByDiagDir(dir); |
1693 TileIndex tile = v->tile + TileOffsByDiagDir(dir); |
1678 |
|
1679 /* Check if the train left a rail/road-crossing */ |
1694 /* Check if the train left a rail/road-crossing */ |
1680 DisableTrainCrossing(tile); |
1695 DisableTrainCrossing(tile); |
1681 } |
1696 } |
1682 |
1697 |
1683 /* count number of vehicles */ |
1698 /* count number of vehicles */ |
1936 tfdd.best_length = ftd.best_path_dist / NPF_TILE_LENGTH; |
1951 tfdd.best_length = ftd.best_path_dist / NPF_TILE_LENGTH; |
1937 if (NPFGetFlag(&ftd.node, NPF_FLAG_REVERSE)) tfdd.reverse = true; |
1952 if (NPFGetFlag(&ftd.node, NPF_FLAG_REVERSE)) tfdd.reverse = true; |
1938 } |
1953 } |
1939 } else { |
1954 } else { |
1940 /* search in the forward direction first. */ |
1955 /* search in the forward direction first. */ |
1941 DiagDirection i = DirToDiagDir(v->direction); |
1956 DiagDirection i = TrainExitDir(v->direction, v->u.rail.track); |
1942 if (!(v->direction & 1) && v->u.rail.track != _state_dir_table[i]) { |
|
1943 i = ChangeDiagDir(i, DIAGDIRDIFF_90LEFT); |
|
1944 } |
|
1945 NewTrainPathfind(tile, 0, v->u.rail.compatible_railtypes, i, (NTPEnumProc*)NtpCallbFindDepot, &tfdd); |
1957 NewTrainPathfind(tile, 0, v->u.rail.compatible_railtypes, i, (NTPEnumProc*)NtpCallbFindDepot, &tfdd); |
1946 if (tfdd.best_length == (uint)-1){ |
1958 if (tfdd.best_length == (uint)-1){ |
1947 tfdd.reverse = true; |
1959 tfdd.reverse = true; |
1948 /* search in backwards direction */ |
1960 /* search in backwards direction */ |
1949 i = ReverseDiagDir(DirToDiagDir(v->direction)); |
1961 i = TrainExitDir(ReverseDir(v->direction), v->u.rail.track); |
1950 if (!(v->direction & 1) && v->u.rail.track != _state_dir_table[i]) { |
|
1951 i = ChangeDiagDir(i, DIAGDIRDIFF_90LEFT); |
|
1952 } |
|
1953 NewTrainPathfind(tile, 0, v->u.rail.compatible_railtypes, i, (NTPEnumProc*)NtpCallbFindDepot, &tfdd); |
1962 NewTrainPathfind(tile, 0, v->u.rail.compatible_railtypes, i, (NTPEnumProc*)NtpCallbFindDepot, &tfdd); |
1954 } |
1963 } |
1955 } |
1964 } |
1956 |
1965 |
1957 return tfdd; |
1966 return tfdd; |
3249 (by building a depot right against a station) */ |
3258 (by building a depot right against a station) */ |
3250 /* if (IsTileType(tile, MP_RAILWAY) && GetRailTileType(tile) == RAIL_TILE_DEPOT_WAYPOINT) |
3259 /* if (IsTileType(tile, MP_RAILWAY) && GetRailTileType(tile) == RAIL_TILE_DEPOT_WAYPOINT) |
3251 return true;*/ |
3260 return true;*/ |
3252 |
3261 |
3253 /* Determine the non-diagonal direction in which we will exit this tile */ |
3262 /* Determine the non-diagonal direction in which we will exit this tile */ |
3254 DiagDirection dir = DirToDiagDir(v->direction); |
3263 DiagDirection dir = TrainExitDir(v->direction, v->u.rail.track); |
3255 if (!(v->direction & 1) && v->u.rail.track != _state_dir_table[dir]) { |
|
3256 dir = ChangeDiagDir(dir, DIAGDIRDIFF_90LEFT); |
|
3257 } |
|
3258 /* Calculate next tile */ |
3264 /* Calculate next tile */ |
3259 tile += TileOffsByDiagDir(dir); |
3265 tile += TileOffsByDiagDir(dir); |
3260 // determine the track status on the next tile. |
3266 // determine the track status on the next tile. |
3261 uint32 ts = GetTileTrackStatus(tile, TRANSPORT_RAIL, 0) & _reachable_tracks[dir]; |
3267 uint32 ts = GetTileTrackStatus(tile, TRANSPORT_RAIL, 0) & _reachable_tracks[dir]; |
3262 |
3268 |