Merge branch 'custom_bridgeheads' into jgrpp
# Conflicts: # docs/landscape.html # src/bridge_map.h # src/pbs.cpp # src/saveload/company_sl.cpp # src/saveload/extended_ver_sl.cpp # src/settings_type.h # src/signal.cpp # src/train_cmd.cpp # src/tunnel_map.h # src/tunnelbridge_cmd.cpp # src/tunnelbridge_map.h # src/vehicle.cpp # src/viewport.cpp
This commit is contained in:
105
src/signal.cpp
105
src/signal.cpp
@@ -217,7 +217,9 @@ static Vehicle *TrainInWormholeTileEnum(Vehicle *v, void *data)
|
||||
{
|
||||
/* Only look for front engine or last wagon. */
|
||||
if (v->type != VEH_TRAIN || (v->Previous() != NULL && v->Next() != NULL)) return NULL;
|
||||
if (*(TileIndex *)data != TileVirtXY(v->x_pos, v->y_pos)) return NULL;
|
||||
TileIndex tile = *(TileIndex *)data;
|
||||
if (tile != TileVirtXY(v->x_pos, v->y_pos)) return NULL;
|
||||
if (!(Train::From(v)->track & TRACK_BIT_WORMHOLE) && !(Train::From(v)->track & GetAcrossTunnelBridgeTrackBits(tile))) return NULL;
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -407,11 +409,29 @@ static SigInfo ExploreSegment(Owner owner)
|
||||
case MP_TUNNELBRIDGE: {
|
||||
if (!IsOneSignalBlock(owner, GetTileOwner(tile))) continue;
|
||||
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) continue;
|
||||
DiagDirection dir = GetTunnelBridgeDirection(tile);
|
||||
DiagDirection tunnel_bridge_dir = GetTunnelBridgeDirection(tile);
|
||||
TrackBits tracks = GetTunnelBridgeTrackBits(tile);
|
||||
TrackBits across_tracks = GetAcrossTunnelBridgeTrackBits(tile);
|
||||
|
||||
auto check_train_present = [tile, tracks, across_tracks](DiagDirection enterdir) -> bool {
|
||||
if (tracks == TRACK_BIT_HORZ || tracks == TRACK_BIT_VERT) {
|
||||
if (_enterdir_to_trackbits[enterdir] & across_tracks) {
|
||||
return EnsureNoTrainOnTrackBits(tile, TRACK_BIT_WORMHOLE | across_tracks).Failed();
|
||||
} else {
|
||||
return EnsureNoTrainOnTrackBits(tile, tracks & (~across_tracks)).Failed();
|
||||
}
|
||||
} else {
|
||||
return HasVehicleOnPos(tile, NULL, &TrainOnTileEnum);
|
||||
}
|
||||
};
|
||||
|
||||
TrackBits tracks_masked = (TrackBits)(tracks & _enterdir_to_trackbits[enterdir == INVALID_DIAGDIR ? tunnel_bridge_dir : enterdir]); // only incidating trackbits
|
||||
if (tracks == TRACK_BIT_HORZ || tracks == TRACK_BIT_VERT) tracks = tracks_masked;
|
||||
|
||||
if (IsTunnelBridgeWithSignalSimulation(tile)) {
|
||||
if (enterdir == INVALID_DIAGDIR) { // incoming from the wormhole
|
||||
if (!(info.flags & SF_TRAIN) && IsTunnelBridgeSignalSimulationExit(tile)) { // tunnel entrence is ignored
|
||||
if (enterdir == INVALID_DIAGDIR) {
|
||||
// incoming from the wormhole, onto signal
|
||||
if (!(info.flags & SF_TRAIN) && IsTunnelBridgeSignalSimulationExit(tile)) { // tunnel entrance is ignored
|
||||
if (HasVehicleOnPos(GetOtherTunnelBridgeEnd(tile), &tile, &TrainInWormholeTileEnum)) info.flags |= SF_TRAIN;
|
||||
if (!(info.flags & SF_TRAIN) && HasVehicleOnPos(tile, &tile, &TrainInWormholeTileEnum)) info.flags |= SF_TRAIN;
|
||||
}
|
||||
@@ -419,11 +439,13 @@ static SigInfo ExploreSegment(Owner owner)
|
||||
info.flags |= SF_FULL;
|
||||
return info;
|
||||
}
|
||||
enterdir = dir;
|
||||
exitdir = ReverseDiagDir(dir);
|
||||
Trackdir exit_track = TrackEnterdirToTrackdir(FindFirstTrack(GetAcrossTunnelBridgeTrackBits(tile)), ReverseDiagDir(tunnel_bridge_dir));
|
||||
exitdir = TrackdirToExitdir(exit_track);
|
||||
enterdir = ReverseDiagDir(exitdir);
|
||||
tile += TileOffsByDiagDir(exitdir); // just skip to next tile
|
||||
} else { // NOT incoming from the wormhole!
|
||||
if (ReverseDiagDir(enterdir) != dir) continue;
|
||||
break;
|
||||
} else if (_enterdir_to_trackbits[enterdir] & GetAcrossTunnelBridgeTrackBits(tile)) {
|
||||
// NOT incoming from the wormhole!
|
||||
if (IsTunnelBridgeSignalSimulationExit(tile)) {
|
||||
if (IsTunnelBridgePBS(tile)) {
|
||||
info.flags |= SF_PBS;
|
||||
@@ -440,22 +462,33 @@ static SigInfo ExploreSegment(Owner owner)
|
||||
}
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (enterdir == INVALID_DIAGDIR) { // incoming from the wormhole
|
||||
if (!(info.flags & SF_TRAIN) && HasVehicleOnPos(tile, NULL, &TrainOnTileEnum)) info.flags |= SF_TRAIN;
|
||||
enterdir = dir;
|
||||
exitdir = ReverseDiagDir(dir);
|
||||
tile += TileOffsByDiagDir(exitdir); // just skip to next tile
|
||||
} else { // NOT incoming from the wormhole!
|
||||
if (ReverseDiagDir(enterdir) != dir) continue;
|
||||
if (!(info.flags & SF_TRAIN) && HasVehicleOnPos(tile, NULL, &TrainOnTileEnum)) info.flags |= SF_TRAIN;
|
||||
tile = GetOtherTunnelBridgeEnd(tile); // just skip to exit tile
|
||||
enterdir = INVALID_DIAGDIR;
|
||||
exitdir = INVALID_DIAGDIR;
|
||||
}
|
||||
if (enterdir == INVALID_DIAGDIR) { // incoming from the wormhole
|
||||
if (!(info.flags & SF_TRAIN) && check_train_present(tunnel_bridge_dir)) info.flags |= SF_TRAIN;
|
||||
enterdir = tunnel_bridge_dir;
|
||||
} else if (enterdir != tunnel_bridge_dir) { // NOT incoming from the wormhole!
|
||||
if (tracks_masked == TRACK_BIT_NONE) continue; // no incidating track
|
||||
if (!(info.flags & SF_TRAIN) && check_train_present(enterdir)) info.flags |= SF_TRAIN;
|
||||
}
|
||||
for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) { // test all possible exit directions
|
||||
if (dir != enterdir && (tracks & _enterdir_to_trackbits[dir])) { // any track incidating?
|
||||
if (dir == tunnel_bridge_dir) {
|
||||
if (!MaybeAddToTodoSet(GetOtherTunnelBridgeEnd(tile), INVALID_DIAGDIR, tile, INVALID_DIAGDIR)) {
|
||||
info.flags |= SF_FULL;
|
||||
return info;
|
||||
}
|
||||
} else {
|
||||
TileIndex newtile = tile + TileOffsByDiagDir(dir); // new tile to check
|
||||
DiagDirection newdir = ReverseDiagDir(dir); // direction we are entering from
|
||||
if (!MaybeAddToTodoSet(newtile, newdir, tile, dir)) {
|
||||
info.flags |= SF_FULL;
|
||||
return info;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
continue; // continue the while() loop
|
||||
}
|
||||
|
||||
default:
|
||||
continue; // continue the while() loop
|
||||
@@ -593,18 +626,23 @@ static SigSegState UpdateSignalsInBuffer(Owner owner)
|
||||
* train entering/leaving block, train leaving depot...
|
||||
*/
|
||||
switch (GetTileType(tile)) {
|
||||
case MP_TUNNELBRIDGE:
|
||||
case MP_TUNNELBRIDGE: {
|
||||
/* 'optimization assert' - do not try to update signals when it is not needed */
|
||||
assert(GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL);
|
||||
assert(dir == INVALID_DIAGDIR || dir == ReverseDiagDir(GetTunnelBridgeDirection(tile)));
|
||||
_tbdset.Add(tile, INVALID_DIAGDIR); // we can safely start from wormhole centre
|
||||
if (!IsTunnelBridgeWithSignalSimulation(tile)) { // Don't worry with other side of tunnel.
|
||||
_tbdset.Add(GetOtherTunnelBridgeEnd(tile), INVALID_DIAGDIR);
|
||||
if (IsTunnel(tile)) assert(dir == INVALID_DIAGDIR || dir == ReverseDiagDir(GetTunnelBridgeDirection(tile)));
|
||||
TrackBits across = GetAcrossTunnelBridgeTrackBits(tile);
|
||||
if (dir == INVALID_DIAGDIR || _enterdir_to_trackbits[dir] & across) {
|
||||
_tbdset.Add(tile, INVALID_DIAGDIR); // we can safely start from wormhole centre
|
||||
if (!IsTunnelBridgeWithSignalSimulation(tile)) { // Don't worry with other side of tunnel.
|
||||
_tbdset.Add(GetOtherTunnelBridgeEnd(tile), INVALID_DIAGDIR);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
FALLTHROUGH;
|
||||
|
||||
case MP_RAILWAY:
|
||||
if (IsRailDepot(tile)) {
|
||||
if (IsRailDepotTile(tile)) {
|
||||
/* 'optimization assert' do not try to update signals in other cases */
|
||||
assert(dir == INVALID_DIAGDIR || dir == GetRailDepotDirection(tile));
|
||||
_tbdset.Add(tile, INVALID_DIAGDIR); // start from depot inside
|
||||
@@ -704,8 +742,13 @@ void AddTrackToSignalBuffer(TileIndex tile, Track track, Owner owner)
|
||||
|
||||
_last_owner = owner;
|
||||
|
||||
_globset.Add(tile, _search_dir_1[track]);
|
||||
_globset.Add(tile, _search_dir_2[track]);
|
||||
DiagDirection wormhole_dir = IsTileType(tile, MP_TUNNELBRIDGE) ? GetTunnelBridgeDirection(tile) : INVALID_DIAGDIR;
|
||||
|
||||
auto add_dir = [&](DiagDirection dir) {
|
||||
_globset.Add(tile, dir == wormhole_dir ? INVALID_DIAGDIR : dir);
|
||||
};
|
||||
add_dir(_search_dir_1[track]);
|
||||
add_dir(_search_dir_2[track]);
|
||||
|
||||
if (_globset.Items() >= SIG_GLOB_UPDATE) {
|
||||
/* too many items, force update */
|
||||
|
Reference in New Issue
Block a user