mirror of https://github.com/OpenTTD/OpenTTD
Add: Add IsStandard and IsExtendedRailDepotTile map functions.
parent
2654cfeae7
commit
8488abaf2f
|
@ -311,7 +311,7 @@ protected:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (IsRailTT() && IsDepotTypeTile(m_new_tile, TT())) {
|
if (IsRailTT() && IsStandardRailDepotTile(m_new_tile)) {
|
||||||
DiagDirection exitdir = GetRailDepotDirection(m_new_tile);
|
DiagDirection exitdir = GetRailDepotDirection(m_new_tile);
|
||||||
if (ReverseDiagDir(exitdir) != m_exitdir) {
|
if (ReverseDiagDir(exitdir) != m_exitdir) {
|
||||||
m_err = EC_NO_WAY;
|
m_err = EC_NO_WAY;
|
||||||
|
|
|
@ -389,13 +389,12 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
|
||||||
/* Tests for 'potential target' reasons to close the segment. */
|
/* Tests for 'potential target' reasons to close the segment. */
|
||||||
if (cur.tile == prev.tile) {
|
if (cur.tile == prev.tile) {
|
||||||
/* Penalty for reversing in a depot. */
|
/* Penalty for reversing in a depot. */
|
||||||
assert(IsRailDepot(cur.tile));
|
assert(IsStandardRailDepot(cur.tile));
|
||||||
segment_cost += Yapf().PfGetSettings().rail_depot_reverse_penalty;
|
segment_cost += Yapf().PfGetSettings().rail_depot_reverse_penalty;
|
||||||
|
|
||||||
} else if (IsRailDepotTile(cur.tile)) {
|
} else if (IsStandardRailDepotTile(cur.tile)) {
|
||||||
/* We will end in this pass (depot is possible target) */
|
/* We will end in this pass (depot is possible target) */
|
||||||
end_segment_reason |= ESRB_DEPOT;
|
end_segment_reason |= ESRB_DEPOT;
|
||||||
|
|
||||||
} else if (cur.tile_type == MP_STATION && IsRailWaypoint(cur.tile)) {
|
} else if (cur.tile_type == MP_STATION && IsRailWaypoint(cur.tile)) {
|
||||||
if (v->current_order.IsType(OT_GOTO_WAYPOINT) &&
|
if (v->current_order.IsType(OT_GOTO_WAYPOINT) &&
|
||||||
GetStationIndex(cur.tile) == v->current_order.GetDestination() &&
|
GetStationIndex(cur.tile) == v->current_order.GetDestination() &&
|
||||||
|
|
|
@ -240,7 +240,7 @@ static PBSTileInfo FollowReservation(Owner o, RailTypes rts, TileIndex tile, Tra
|
||||||
if (tile == start_tile && trackdir == start_trackdir) break;
|
if (tile == start_tile && trackdir == start_trackdir) break;
|
||||||
}
|
}
|
||||||
/* Depot tile? Can't continue. */
|
/* Depot tile? Can't continue. */
|
||||||
if (IsRailDepotTile(tile)) break;
|
if (IsStandardRailDepotTile(tile)) break;
|
||||||
/* Non-pbs signal? Reservation can't continue. */
|
/* Non-pbs signal? Reservation can't continue. */
|
||||||
if (IsTileType(tile, MP_RAILWAY) && HasSignalOnTrackdir(tile, trackdir) && !IsPbsSignal(GetSignalType(tile, TrackdirToTrack(trackdir)))) break;
|
if (IsTileType(tile, MP_RAILWAY) && HasSignalOnTrackdir(tile, trackdir) && !IsPbsSignal(GetSignalType(tile, TrackdirToTrack(trackdir)))) break;
|
||||||
}
|
}
|
||||||
|
@ -292,7 +292,7 @@ PBSTileInfo FollowTrainReservation(const Train *v, Vehicle **train_on_res)
|
||||||
TileIndex tile = v->tile;
|
TileIndex tile = v->tile;
|
||||||
Trackdir trackdir = v->GetVehicleTrackdir();
|
Trackdir trackdir = v->GetVehicleTrackdir();
|
||||||
|
|
||||||
if (IsRailDepotTile(tile) && !GetDepotReservationTrackBits(tile)) return PBSTileInfo(tile, trackdir, false);
|
if (IsStandardRailDepotTile(tile) && !GetDepotReservationTrackBits(tile)) return PBSTileInfo(tile, trackdir, false);
|
||||||
|
|
||||||
FindTrainOnTrackInfo ftoti;
|
FindTrainOnTrackInfo ftoti;
|
||||||
ftoti.res = FollowReservation(v->owner, GetRailTypeInfo(v->railtype)->compatible_railtypes, tile, trackdir);
|
ftoti.res = FollowReservation(v->owner, GetRailTypeInfo(v->railtype)->compatible_railtypes, tile, trackdir);
|
||||||
|
@ -379,7 +379,7 @@ Train *GetTrainForReservation(TileIndex tile, Track track)
|
||||||
*/
|
*/
|
||||||
bool IsSafeWaitingPosition(const Train *v, TileIndex tile, Trackdir trackdir, bool include_line_end, bool forbid_90deg)
|
bool IsSafeWaitingPosition(const Train *v, TileIndex tile, Trackdir trackdir, bool include_line_end, bool forbid_90deg)
|
||||||
{
|
{
|
||||||
if (IsRailDepotTile(tile)) return true;
|
if (IsStandardRailDepotTile(tile)) return true;
|
||||||
|
|
||||||
if (IsTileType(tile, MP_RAILWAY)) {
|
if (IsTileType(tile, MP_RAILWAY)) {
|
||||||
/* For non-pbs signals, stop on the signal tile. */
|
/* For non-pbs signals, stop on the signal tile. */
|
||||||
|
@ -432,7 +432,7 @@ bool IsWaitingPositionFree(const Train *v, TileIndex tile, Trackdir trackdir, bo
|
||||||
if (TrackOverlapsTracks(reserved, track)) return false;
|
if (TrackOverlapsTracks(reserved, track)) return false;
|
||||||
|
|
||||||
/* Not reserved and depot or not a pbs signal -> free. */
|
/* Not reserved and depot or not a pbs signal -> free. */
|
||||||
if (IsRailDepotTile(tile)) return true;
|
if (IsStandardRailDepotTile(tile)) return true;
|
||||||
if (IsTileType(tile, MP_RAILWAY) && HasSignalOnTrackdir(tile, trackdir) && !IsPbsSignal(GetSignalType(tile, track))) return true;
|
if (IsTileType(tile, MP_RAILWAY) && HasSignalOnTrackdir(tile, trackdir) && !IsPbsSignal(GetSignalType(tile, track))) return true;
|
||||||
|
|
||||||
/* Check the next tile, if it's a PBS signal, it has to be free as well. */
|
/* Check the next tile, if it's a PBS signal, it has to be free as well. */
|
||||||
|
|
|
@ -2960,6 +2960,7 @@ static const int8_t _deltacoord_leaveoffset[8] = {
|
||||||
*/
|
*/
|
||||||
int TicksToLeaveDepot(const Train *v)
|
int TicksToLeaveDepot(const Train *v)
|
||||||
{
|
{
|
||||||
|
assert(IsStandardRailDepotTile(v->tile));
|
||||||
DiagDirection dir = GetRailDepotDirection(v->tile);
|
DiagDirection dir = GetRailDepotDirection(v->tile);
|
||||||
int length = v->CalcNextVehicleOffset();
|
int length = v->CalcNextVehicleOffset();
|
||||||
|
|
||||||
|
|
|
@ -107,6 +107,50 @@ debug_inline static bool IsRailDepotTile(Tile t)
|
||||||
return IsTileType(t, MP_RAILWAY) && IsRailDepot(t);
|
return IsTileType(t, MP_RAILWAY) && IsRailDepot(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this rail depot tile an extended depot?
|
||||||
|
* @param t the tile to get the information from
|
||||||
|
* @pre IsRailDepotTile(t)
|
||||||
|
* @return true if and only if the tile is an extended rail depot
|
||||||
|
*/
|
||||||
|
static inline bool IsExtendedRailDepot(Tile t)
|
||||||
|
{
|
||||||
|
assert(IsRailDepotTile(t));
|
||||||
|
return HasBit(t.m5(), 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this rail tile a standard rail depot?
|
||||||
|
* @param t the tile to get the information from
|
||||||
|
* @pre IsTileType(t, MP_RAILWAY)
|
||||||
|
* @return true if and only if the tile is a standard rail depot
|
||||||
|
*/
|
||||||
|
static inline bool IsStandardRailDepot(Tile t)
|
||||||
|
{
|
||||||
|
assert(IsTileType(t, MP_RAILWAY));
|
||||||
|
return IsRailDepot(t) && !IsExtendedRailDepot(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this tile a standard rail depot?
|
||||||
|
* @param t the tile to get the information from
|
||||||
|
* @return true if and only if the tile is a standard rail depot
|
||||||
|
*/
|
||||||
|
static inline bool IsStandardRailDepotTile(TileIndex t)
|
||||||
|
{
|
||||||
|
return IsTileType(t, MP_RAILWAY) && IsStandardRailDepot(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this tile rail tile and an extended rail depot?
|
||||||
|
* @param t the tile to get the information from
|
||||||
|
* @return true if and only if the tile is an extended rail depot
|
||||||
|
*/
|
||||||
|
static inline bool IsExtendedRailDepotTile(TileIndex t)
|
||||||
|
{
|
||||||
|
return IsTileType(t, MP_RAILWAY) && IsRailDepotTile(t) && IsExtendedRailDepot(t);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the rail type of the given tile
|
* Gets the rail type of the given tile
|
||||||
* @param t the tile to get the rail type from
|
* @param t the tile to get the rail type from
|
||||||
|
|
|
@ -2181,7 +2181,7 @@ void ReverseTrainDirection(Train *v)
|
||||||
!IsPbsSignal(GetSignalType(v->tile, FindFirstTrack(v->track))));
|
!IsPbsSignal(GetSignalType(v->tile, FindFirstTrack(v->track))));
|
||||||
|
|
||||||
/* If we are on a depot tile facing outwards, do not treat the current tile as safe. */
|
/* If we are on a depot tile facing outwards, do not treat the current tile as safe. */
|
||||||
if (IsRailDepotTile(v->tile) && TrackdirToExitdir(v->GetVehicleTrackdir()) == GetRailDepotDirection(v->tile)) first_tile_okay = false;
|
if (IsStandardRailDepotTile(v->tile) && TrackdirToExitdir(v->GetVehicleTrackdir()) == GetRailDepotDirection(v->tile)) first_tile_okay = false;
|
||||||
|
|
||||||
if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(v->GetVehicleTrackdir()), true);
|
if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(v->GetVehicleTrackdir()), true);
|
||||||
if (TryPathReserve(v, false, first_tile_okay)) {
|
if (TryPathReserve(v, false, first_tile_okay)) {
|
||||||
|
@ -2549,7 +2549,7 @@ void FreeTrainTrackReservation(const Train *v)
|
||||||
StationID station_id = IsRailStationTile(v->tile) ? GetStationIndex(v->tile) : INVALID_STATION;
|
StationID station_id = IsRailStationTile(v->tile) ? GetStationIndex(v->tile) : INVALID_STATION;
|
||||||
|
|
||||||
/* Can't be holding a reservation if we enter a depot. */
|
/* Can't be holding a reservation if we enter a depot. */
|
||||||
if (IsRailDepotTile(tile) && TrackdirToExitdir(td) != GetRailDepotDirection(tile)) return;
|
if (IsStandardRailDepotTile(tile) && TrackdirToExitdir(td) != GetRailDepotDirection(tile)) return;
|
||||||
if (v->track == TRACK_BIT_DEPOT) {
|
if (v->track == TRACK_BIT_DEPOT) {
|
||||||
/* Front engine is in a depot. We enter if some part is not in the depot. */
|
/* Front engine is in a depot. We enter if some part is not in the depot. */
|
||||||
for (const Train *u = v; u != nullptr; u = u->Next()) {
|
for (const Train *u = v; u != nullptr; u = u->Next()) {
|
||||||
|
@ -3005,6 +3005,7 @@ bool TryPathReserve(Train *v, bool mark_as_stuck, bool first_tile_okay)
|
||||||
if (mark_as_stuck) MarkTrainAsStuck(v);
|
if (mark_as_stuck) MarkTrainAsStuck(v);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
assert(IsStandardRailDepotTile(v->tile));
|
||||||
/* Depot not reserved, but the next tile might be. */
|
/* Depot not reserved, but the next tile might be. */
|
||||||
TileIndex next_tile = TileAddByDiagDir(v->tile, GetRailDepotDirection(v->tile));
|
TileIndex next_tile = TileAddByDiagDir(v->tile, GetRailDepotDirection(v->tile));
|
||||||
if (HasReservedTracks(next_tile, DiagdirReachesTracks(GetRailDepotDirection(v->tile)))) return false;
|
if (HasReservedTracks(next_tile, DiagdirReachesTracks(GetRailDepotDirection(v->tile)))) return false;
|
||||||
|
@ -3823,7 +3824,7 @@ static void DeleteLastWagon(Train *v)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update signals */
|
/* Update signals */
|
||||||
if (IsTileType(tile, MP_TUNNELBRIDGE) || IsRailDepotTile(tile)) {
|
if (IsTileType(tile, MP_TUNNELBRIDGE) || IsStandardRailDepotTile(tile)) {
|
||||||
UpdateSignalsOnSegment(tile, INVALID_DIAGDIR, owner);
|
UpdateSignalsOnSegment(tile, INVALID_DIAGDIR, owner);
|
||||||
} else {
|
} else {
|
||||||
SetSignalsOnBothDir(tile, track, owner);
|
SetSignalsOnBothDir(tile, track, owner);
|
||||||
|
@ -3974,9 +3975,14 @@ static bool TrainCanLeaveTile(const Train *v)
|
||||||
|
|
||||||
/* entering a depot? */
|
/* entering a depot? */
|
||||||
if (IsRailDepotTile(tile)) {
|
if (IsRailDepotTile(tile)) {
|
||||||
|
if (IsExtendedRailDepot(tile)) {
|
||||||
|
Direction dir = DiagDirToDir(GetRailDepotDirection(tile));
|
||||||
|
if (dir == v->direction || ReverseDir(dir) == v->direction) return false;
|
||||||
|
} else {
|
||||||
DiagDirection dir = ReverseDiagDir(GetRailDepotDirection(tile));
|
DiagDirection dir = ReverseDiagDir(GetRailDepotDirection(tile));
|
||||||
if (DiagDirToDir(dir) == v->direction) return false;
|
if (DiagDirToDir(dir) == v->direction) return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue