60
src/pbs.cpp
60
src/pbs.cpp
@@ -356,10 +356,10 @@ static int LookaheadTileHeightForChunnel(int length, int offset)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint16 ApplyTunnelBridgeLookaheadSignalSpeedRestriction(TileIndex tile, Trackdir trackdir, const Train *v,
|
||||
uint16 initial_speed_restriction, TrainReservationLookAhead *lookahead, int offset, int16 z)
|
||||
static uint16_t ApplyTunnelBridgeLookaheadSignalSpeedRestriction(TileIndex tile, Trackdir trackdir, const Train *v,
|
||||
uint16_t initial_speed_restriction, TrainReservationLookAhead *lookahead, int offset, int16_t z)
|
||||
{
|
||||
uint16 speed_restriction = initial_speed_restriction;
|
||||
uint16_t speed_restriction = initial_speed_restriction;
|
||||
|
||||
if (v != nullptr && IsTunnelBridgeRestrictedSignal(tile)) {
|
||||
if (trackdir == INVALID_TRACKDIR) {
|
||||
@@ -389,9 +389,9 @@ static uint16 ApplyTunnelBridgeLookaheadSignalSpeedRestriction(TileIndex tile, T
|
||||
return speed_restriction;
|
||||
}
|
||||
|
||||
static uint16 GetTrainSpeedLimitForRailtype(const Train *v, RailType rt, TileIndex tile, Track track)
|
||||
static uint16_t GetTrainSpeedLimitForRailtype(const Train *v, RailType rt, TileIndex tile, Track track)
|
||||
{
|
||||
uint16 speed = GetRailTypeInfo(rt)->max_speed;
|
||||
uint16_t speed = GetRailTypeInfo(rt)->max_speed;
|
||||
if (v->tcache.cached_tflags & TCF_SPD_RAILTYPE) {
|
||||
for (const Train *u = v; u != nullptr; u = u->Next()) {
|
||||
if (u->GetEngine()->callbacks_used & SGCU_CB36_SPEED_RAILTYPE) {
|
||||
@@ -399,7 +399,7 @@ static uint16 GetTrainSpeedLimitForRailtype(const Train *v, RailType rt, TileInd
|
||||
const TrackBits prev_track = u->track;
|
||||
const_cast<Train *>(u)->tile = tile;
|
||||
const_cast<Train *>(u)->track = TrackToTrackBits(track);
|
||||
uint16 cb_speed = GetVehicleProperty(u, PROP_TRAIN_SPEED, speed);
|
||||
uint16_t cb_speed = GetVehicleProperty(u, PROP_TRAIN_SPEED, speed);
|
||||
if (cb_speed != 0 && (cb_speed < speed || speed == 0)) speed = cb_speed;
|
||||
const_cast<Train *>(u)->tile = prev_tile;
|
||||
const_cast<Train *>(u)->track = prev_track;
|
||||
@@ -409,7 +409,7 @@ static uint16 GetTrainSpeedLimitForRailtype(const Train *v, RailType rt, TileInd
|
||||
return speed;
|
||||
}
|
||||
|
||||
static void AddSignalToLookAhead(const Train *v, TrainReservationLookAhead *lookahead, uint16 signal_speed, uint16 signal_flags, TileIndex signal_tile, uint16 signal_track, int offset, int16 z_pos)
|
||||
static void AddSignalToLookAhead(const Train *v, TrainReservationLookAhead *lookahead, uint16_t signal_speed, uint16_t signal_flags, TileIndex signal_tile, uint16_t signal_track, int offset, int16_t z_pos)
|
||||
{
|
||||
lookahead->AddSignal(signal_speed, offset, z_pos, signal_flags);
|
||||
if (_settings_game.vehicle.train_speed_adaptation) {
|
||||
@@ -462,7 +462,7 @@ static PBSTileInfo FollowReservation(Owner o, RailTypes rts, TileIndex tile, Tra
|
||||
auto check_rail_type = [&](TileIndex t, Trackdir td, int offset) {
|
||||
RailType new_rt = GetRailTypeByTrack(t, TrackdirToTrack(td));
|
||||
if (new_rt != rt) {
|
||||
uint16 rail_speed = GetTrainSpeedLimitForRailtype(v, new_rt, t, TrackdirToTrack(td));
|
||||
uint16_t rail_speed = GetTrainSpeedLimitForRailtype(v, new_rt, t, TrackdirToTrack(td));
|
||||
if (rail_speed > 0) lookahead->AddTrackSpeedLimit(rail_speed, offset, 4, z);
|
||||
if (GetRailTypeInfo(rt)->curve_speed != GetRailTypeInfo(new_rt)->curve_speed) {
|
||||
CheckCurveLookAhead(v, lookahead, lookahead->RealEndPosition() + 4 + offset, z, new_rt);
|
||||
@@ -577,7 +577,7 @@ static PBSTileInfo FollowReservation(Owner o, RailTypes rts, TileIndex tile, Tra
|
||||
}
|
||||
check_direction(TrackdirToDirection(trackdir), ft.m_tiles_skipped * TILE_SIZE, tile);
|
||||
if (IsTileType(tile, MP_TUNNELBRIDGE) && TrackdirEntersTunnelBridge(tile, trackdir)) {
|
||||
uint16 bridge_speed = 0;
|
||||
uint16_t bridge_speed = 0;
|
||||
if (IsBridge(tile)) {
|
||||
bridge_speed = GetBridgeSpec(GetBridgeType(tile))->speed;
|
||||
lookahead->AddTrackSpeedLimit(bridge_speed, 0, 8, z);
|
||||
@@ -589,13 +589,13 @@ static PBSTileInfo FollowReservation(Owner o, RailTypes rts, TileIndex tile, Tra
|
||||
const int spacing = GetTunnelBridgeSignalSimulationSpacing(tile);
|
||||
const int signals = length / spacing;
|
||||
|
||||
uint16 speed_restriction = ApplyTunnelBridgeLookaheadSignalSpeedRestriction(tile, trackdir, v, lookahead->speed_restriction, lookahead, 0, z);
|
||||
uint16_t speed_restriction = ApplyTunnelBridgeLookaheadSignalSpeedRestriction(tile, trackdir, v, lookahead->speed_restriction, lookahead, 0, z);
|
||||
|
||||
uint16 signal_speed = GetRailTypeInfo(rt)->max_speed;
|
||||
uint16_t signal_speed = GetRailTypeInfo(rt)->max_speed;
|
||||
if (signal_speed == 0 || (speed_restriction != 0 && speed_restriction < signal_speed)) signal_speed = speed_restriction;
|
||||
if (signal_speed == 0 || (bridge_speed != 0 && bridge_speed < signal_speed)) signal_speed = bridge_speed;
|
||||
|
||||
const uint16 signal_flags = GetTunnelBridgeSignalStyle(tile) << 8;
|
||||
const uint16_t signal_flags = GetTunnelBridgeSignalStyle(tile) << 8;
|
||||
|
||||
/* Entrance signal */
|
||||
AddSignalToLookAhead(v, lookahead, signal_speed, signal_flags, tile, TrackdirToTrack(trackdir), 0, z);
|
||||
@@ -619,7 +619,7 @@ static PBSTileInfo FollowReservation(Owner o, RailTypes rts, TileIndex tile, Tra
|
||||
/* Exit signal */
|
||||
const int end_offset = start_offset + (TILE_SIZE * length);
|
||||
|
||||
uint16 exit_speed_restriction = ApplyTunnelBridgeLookaheadSignalSpeedRestriction(end, INVALID_TRACKDIR, v, lookahead->speed_restriction, lookahead, end_offset, z);
|
||||
uint16_t exit_speed_restriction = ApplyTunnelBridgeLookaheadSignalSpeedRestriction(end, INVALID_TRACKDIR, v, lookahead->speed_restriction, lookahead, end_offset, z);
|
||||
if (exit_speed_restriction != speed_restriction) {
|
||||
speed_restriction = exit_speed_restriction;
|
||||
signal_speed = GetRailTypeInfo(rt)->max_speed;
|
||||
@@ -647,7 +647,7 @@ static PBSTileInfo FollowReservation(Owner o, RailTypes rts, TileIndex tile, Tra
|
||||
/* Passing through a signal from the rear side */
|
||||
au_flags = TRPAUF_SPEED_RESTRICTION | TRPAUF_REVERSE;
|
||||
}
|
||||
uint16 speed_restriction = lookahead->speed_restriction;
|
||||
uint16_t speed_restriction = lookahead->speed_restriction;
|
||||
if (v != nullptr) {
|
||||
const TraceRestrictProgram *prog = GetExistingTraceRestrictProgram(tile, TrackdirToTrack(trackdir));
|
||||
if (prog && prog->actions_used_flags & au_flags) {
|
||||
@@ -668,10 +668,10 @@ static PBSTileInfo FollowReservation(Owner o, RailTypes rts, TileIndex tile, Tra
|
||||
}
|
||||
if (!(au_flags & TRPAUF_REVERSE)) {
|
||||
/* Passing through a signal from the front side */
|
||||
uint16 signal_speed = GetRailTypeInfo(rt)->max_speed;
|
||||
uint16_t signal_speed = GetRailTypeInfo(rt)->max_speed;
|
||||
if (signal_speed == 0 || (speed_restriction != 0 && speed_restriction < signal_speed)) signal_speed = speed_restriction;
|
||||
uint8 signal_style = GetSignalStyle(tile, TrackdirToTrack(trackdir));
|
||||
uint16 signal_flags = signal_style << 8;
|
||||
uint8_t signal_style = GetSignalStyle(tile, TrackdirToTrack(trackdir));
|
||||
uint16_t signal_flags = signal_style << 8;
|
||||
if (HasBit(_signal_style_masks.non_aspect_inc, signal_style)) {
|
||||
SetBit(signal_flags, TRSLAI_NO_ASPECT_INC);
|
||||
}
|
||||
@@ -859,7 +859,7 @@ static Vehicle *FindTrainOnTrackEnum(Vehicle *v, void *data)
|
||||
|
||||
void TrainReservationLookAhead::SetNextExtendPosition()
|
||||
{
|
||||
int32 threshold = this->current_position + 24;
|
||||
int32_t threshold = this->current_position + 24;
|
||||
for (const TrainReservationLookAheadItem &item : this->items) {
|
||||
if (item.type == TRLIT_SIGNAL && item.start > threshold) {
|
||||
this->next_extend_position = item.start - 24;
|
||||
@@ -972,7 +972,7 @@ void FillLookAheadCurveDataFromTrainPosition(Train *t)
|
||||
{
|
||||
TileIndex tile = TileVirtXY(t->x_pos, t->y_pos);
|
||||
Direction dir = t->direction;
|
||||
int32 current_pos = t->lookahead->reservation_end_position + 4 - ((dir & 1) ? 16 : 8);
|
||||
int32_t current_pos = t->lookahead->reservation_end_position + 4 - ((dir & 1) ? 16 : 8);
|
||||
for (Train *u = t->Next(); u != nullptr; u = u->Next()) {
|
||||
TileIndex cur_tile = TileVirtXY(u->x_pos, u->y_pos);
|
||||
if (cur_tile == tile) continue;
|
||||
@@ -1021,7 +1021,7 @@ static int ScanTrainPositionForLookAheadStation(Train *t, TileIndex start_tile)
|
||||
TileIndex new_tile = tile + (i * diff);
|
||||
RailType new_rt = GetRailTypeByTrack(new_tile, TrackdirToTrack(trackdir));
|
||||
if (new_rt != rt) {
|
||||
uint16 rail_speed = GetTrainSpeedLimitForRailtype(t, new_rt, new_tile, TrackdirToTrack(trackdir));
|
||||
uint16_t rail_speed = GetTrainSpeedLimitForRailtype(t, new_rt, new_tile, TrackdirToTrack(trackdir));
|
||||
if (rail_speed > 0) t->lookahead->AddTrackSpeedLimit(rail_speed, (i - 1) * TILE_SIZE, 4, z);
|
||||
rt = new_rt;
|
||||
}
|
||||
@@ -1064,20 +1064,20 @@ void TryCreateLookAheadForTrainInTunnelBridge(Train *t)
|
||||
if (IsTunnel(t->tile) && Tunnel::GetByTile(t->tile)->is_chunnel) SetBit(t->lookahead->flags, TRLF_CHUNNEL);
|
||||
|
||||
if (IsTunnelBridgeSignalSimulationEntrance(t->tile)) {
|
||||
const uint16 bridge_speed = IsBridge(t->tile) ? GetBridgeSpec(GetBridgeType(t->tile))->speed : 0;
|
||||
const uint16_t bridge_speed = IsBridge(t->tile) ? GetBridgeSpec(GetBridgeType(t->tile))->speed : 0;
|
||||
const TileIndex end = GetOtherTunnelBridgeEnd(t->tile);
|
||||
const int length = GetTunnelBridgeLength(t->tile, end);
|
||||
const int spacing = GetTunnelBridgeSignalSimulationSpacing(t->tile);
|
||||
const int signals = length / spacing;
|
||||
|
||||
const RailType rt = GetRailTypeByTrack(t->tile, TrackdirToTrack(t->lookahead->reservation_end_trackdir));
|
||||
uint16 signal_speed = GetRailTypeInfo(rt)->max_speed;
|
||||
uint16_t signal_speed = GetRailTypeInfo(rt)->max_speed;
|
||||
if (signal_speed == 0 || (t->speed_restriction != 0 && t->speed_restriction < signal_speed)) signal_speed = t->speed_restriction;
|
||||
if (signal_speed == 0 || (bridge_speed != 0 && bridge_speed < signal_speed)) signal_speed = bridge_speed;
|
||||
|
||||
int z = IsBridge(t->tile) ? GetBridgeHeight(t->tile) : GetTilePixelZ(t->tile);
|
||||
|
||||
const uint16 signal_flags = GetTunnelBridgeSignalStyle(t->tile) << 8;
|
||||
const uint16_t signal_flags = GetTunnelBridgeSignalStyle(t->tile) << 8;
|
||||
|
||||
/* Middle signals */
|
||||
int offset = -(int)TILE_SIZE;
|
||||
@@ -1090,7 +1090,7 @@ void TryCreateLookAheadForTrainInTunnelBridge(Train *t)
|
||||
/* Exit signal */
|
||||
const int end_offset = TILE_SIZE * length;
|
||||
|
||||
uint16 exit_speed_restriction = ApplyTunnelBridgeLookaheadSignalSpeedRestriction(end, INVALID_TRACKDIR, t, t->speed_restriction, t->lookahead.get(), end_offset, z);
|
||||
uint16_t exit_speed_restriction = ApplyTunnelBridgeLookaheadSignalSpeedRestriction(end, INVALID_TRACKDIR, t, t->speed_restriction, t->lookahead.get(), end_offset, z);
|
||||
if (exit_speed_restriction != t->speed_restriction) {
|
||||
signal_speed = GetRailTypeInfo(rt)->max_speed;
|
||||
if (signal_speed == 0 || (exit_speed_restriction != 0 && exit_speed_restriction < signal_speed)) signal_speed = exit_speed_restriction;
|
||||
@@ -1118,8 +1118,8 @@ int AdvanceTrainReservationLookaheadEnd(const Train *v, int lookahead_end_positi
|
||||
|
||||
if (lookahead_end_position > v->lookahead->reservation_end_position) return lookahead_end_position;
|
||||
|
||||
int32 threshold = v->lookahead->current_position + 24;
|
||||
uint8 known_signals_ahead = 1;
|
||||
int32_t threshold = v->lookahead->current_position + 24;
|
||||
uint8_t known_signals_ahead = 1;
|
||||
bool allow_skip_no_aspect_inc = false;
|
||||
if (v->IsInDepot()) {
|
||||
known_signals_ahead = _extra_aspects + 1;
|
||||
@@ -1142,8 +1142,8 @@ int AdvanceTrainReservationLookaheadEnd(const Train *v, int lookahead_end_positi
|
||||
|
||||
if (item.start <= threshold) {
|
||||
/* Signal is within visual range */
|
||||
uint8 style = item.data_aux >> 8;
|
||||
uint8 max_aspect = (style == 0) ? _extra_aspects : _new_signal_styles[style - 1].lookahead_extra_aspects;
|
||||
uint8_t style = item.data_aux >> 8;
|
||||
uint8_t max_aspect = (style == 0) ? _extra_aspects : _new_signal_styles[style - 1].lookahead_extra_aspects;
|
||||
if (max_aspect == 0xFF) {
|
||||
/* This signal has unlimited lookahead */
|
||||
return v->lookahead->reservation_end_position + 1;
|
||||
@@ -1185,7 +1185,7 @@ void FillTrainReservationLookAhead(Train *v)
|
||||
if (v->lookahead == nullptr) return;
|
||||
}
|
||||
|
||||
int32 old_reservation_end_position = 0;
|
||||
int32_t old_reservation_end_position = 0;
|
||||
|
||||
if (v->lookahead == nullptr) {
|
||||
v->lookahead.reset(new TrainReservationLookAhead());
|
||||
@@ -1281,7 +1281,7 @@ void FillTrainReservationLookAhead(Train *v)
|
||||
if (_settings_game.vehicle.train_speed_adaptation && v->signal_speed_restriction > 0 && v->lookahead->reservation_end_position > old_reservation_end_position) {
|
||||
for (const TrainReservationLookAheadItem &item : v->lookahead->items) {
|
||||
if (item.type == TRLIT_SPEED_ADAPTATION && item.end + 1 >= old_reservation_end_position && item.end + 1 < v->lookahead->reservation_end_position) {
|
||||
uint16 signal_speed = GetLowestSpeedTrainAdaptationSpeedAtSignal(item.data_id, item.data_aux);
|
||||
uint16_t signal_speed = GetLowestSpeedTrainAdaptationSpeedAtSignal(item.data_id, item.data_aux);
|
||||
|
||||
if (signal_speed == 0) {
|
||||
/* unrestricted signal ahead, remove current speed adaptation */
|
||||
|
Reference in New Issue
Block a user