Fix ApplyLookAheadItem assuming current_order == order in order list
Fixes trains with no orders failing to brake in advance of stations
This commit is contained in:
@@ -827,7 +827,7 @@ static void LimitSpeedFromLookAhead(int &max_speed, const TrainDecelerationStats
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void ApplyLookAheadItem(const Train *v, const TrainReservationLookAheadItem &item, int &max_speed, int &advisory_max_speed,
|
static void ApplyLookAheadItem(const Train *v, const TrainReservationLookAheadItem &item, int &max_speed, int &advisory_max_speed,
|
||||||
VehicleOrderID ¤t_order_index, const TrainDecelerationStats &stats, int current_position)
|
VehicleOrderID ¤t_order_index, const Order *&order, const TrainDecelerationStats &stats, int current_position)
|
||||||
{
|
{
|
||||||
auto limit_speed = [&](int position, int end_speed, int z) {
|
auto limit_speed = [&](int position, int end_speed, int z) {
|
||||||
LimitSpeedFromLookAhead(max_speed, stats, current_position, position, end_speed, z - stats.z_pos);
|
LimitSpeedFromLookAhead(max_speed, stats, current_position, position, end_speed, z - stats.z_pos);
|
||||||
@@ -839,19 +839,17 @@ static void ApplyLookAheadItem(const Train *v, const TrainReservationLookAheadIt
|
|||||||
|
|
||||||
switch (item.type) {
|
switch (item.type) {
|
||||||
case TRLIT_STATION: {
|
case TRLIT_STATION: {
|
||||||
if (current_order_index < v->GetNumOrders()) {
|
if (order->ShouldStopAtStation(nullptr, item.data_id, Waypoint::GetIfValid(item.data_id) != nullptr)) {
|
||||||
const Order *order = v->GetOrder(current_order_index);
|
limit_advisory_speed(item.start + PredictStationStoppingLocation(v, order, item.end - item.start, item.data_id), 0, item.z_pos);
|
||||||
if (order->ShouldStopAtStation(nullptr, item.data_id, Waypoint::GetIfValid(item.data_id) != nullptr)) {
|
} else if (order->IsType(OT_GOTO_WAYPOINT) && order->GetDestination() == item.data_id && (order->GetWaypointFlags() & OWF_REVERSE)) {
|
||||||
limit_advisory_speed(item.start + PredictStationStoppingLocation(v, order, item.end - item.start, item.data_id), 0, item.z_pos);
|
limit_advisory_speed(item.start + v->gcache.cached_total_length, 0, item.z_pos);
|
||||||
} else if (order->IsType(OT_GOTO_WAYPOINT) && order->GetDestination() == item.data_id && (order->GetWaypointFlags() & OWF_REVERSE)) {
|
}
|
||||||
limit_advisory_speed(item.start + v->gcache.cached_total_length, 0, item.z_pos);
|
if (order->IsBaseStationOrder() && order->GetDestination() == item.data_id && v->GetNumOrders() > 0) {
|
||||||
}
|
current_order_index++;
|
||||||
if (order->IsBaseStationOrder() && order->GetDestination() == item.data_id) {
|
AdvanceOrderIndex(v, current_order_index);
|
||||||
current_order_index++;
|
order = v->GetOrder(current_order_index);
|
||||||
AdvanceOrderIndex(v, current_order_index);
|
uint16 max_speed = order->GetMaxSpeed();
|
||||||
uint16 max_speed = v->GetOrder(current_order_index)->GetMaxSpeed();
|
if (max_speed < UINT16_MAX) limit_advisory_speed(item.start, max_speed, item.z_pos);
|
||||||
if (max_speed < UINT16_MAX) limit_advisory_speed(item.start, max_speed, item.z_pos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1003,8 +1001,9 @@ Train::MaxSpeedInfo Train::GetCurrentMaxSpeedInfoInternal(bool update_state) con
|
|||||||
LimitSpeedFromLookAhead(max_speed, stats, this->lookahead->current_position, this->lookahead->reservation_end_position, 0, this->lookahead->reservation_end_z - stats.z_pos);
|
LimitSpeedFromLookAhead(max_speed, stats, this->lookahead->current_position, this->lookahead->reservation_end_position, 0, this->lookahead->reservation_end_z - stats.z_pos);
|
||||||
}
|
}
|
||||||
VehicleOrderID current_order_index = this->cur_real_order_index;
|
VehicleOrderID current_order_index = this->cur_real_order_index;
|
||||||
|
const Order *order = &(this->current_order);
|
||||||
for (const TrainReservationLookAheadItem &item : this->lookahead->items) {
|
for (const TrainReservationLookAheadItem &item : this->lookahead->items) {
|
||||||
ApplyLookAheadItem(this, item, max_speed, advisory_max_speed, current_order_index, stats, this->lookahead->current_position);
|
ApplyLookAheadItem(this, item, max_speed, advisory_max_speed, current_order_index, order, stats, this->lookahead->current_position);
|
||||||
}
|
}
|
||||||
if (HasBit(this->lookahead->flags, TRLF_APPLY_ADVISORY)) {
|
if (HasBit(this->lookahead->flags, TRLF_APPLY_ADVISORY)) {
|
||||||
max_speed = std::min(max_speed, advisory_max_speed);
|
max_speed = std::min(max_speed, advisory_max_speed);
|
||||||
|
Reference in New Issue
Block a user