diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h index b45ffafd63..3fbe5407e3 100644 --- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -181,11 +181,29 @@ class NIHVehicle : public NIHelper { if (t->lookahead != nullptr) { print (" Look ahead:"); const TrainReservationLookAhead &l = *t->lookahead; - seprintf(buffer, lastof(buffer), " Position: current: %d, end: %d, remaining: %d", l.current_position, l.reservation_end_position, l.reservation_end_position - l.current_position); + TrainDecelerationStats stats(t); + + auto print_braking_speed = [&](int position, int end_speed, int end_z) { + extern void LimitSpeedFromLookAhead(int &max_speed, const TrainDecelerationStats &stats, int current_position, int position, int end_speed, int z_delta); + int speed = INT_MAX; + LimitSpeedFromLookAhead(speed, stats, l.current_position, position, end_speed, end_z - stats.z_pos); + if (speed != INT_MAX) { + b += seprintf(b, lastof(buffer), ", appr speed: %d", speed); + } + }; + + seprintf(buffer, lastof(buffer), " Position: current: %d, z: %d, end: %d, remaining: %d", l.current_position, stats.z_pos, l.reservation_end_position, l.reservation_end_position - l.current_position); print(buffer); - seprintf(buffer, lastof(buffer), " Reservation ends at %X (%u x %u), trackdir: %02X, z: %d", + + b = buffer + seprintf(buffer, lastof(buffer), " Reservation ends at %X (%u x %u), trackdir: %02X, z: %d", l.reservation_end_tile, TileX(l.reservation_end_tile), TileY(l.reservation_end_tile), l.reservation_end_trackdir, l.reservation_end_z); + if (HasBit(l.flags, TRLF_DEPOT_END)) { + print_braking_speed(l.reservation_end_position - TILE_SIZE, 61, l.reservation_end_z); + } else { + print_braking_speed(l.reservation_end_position, 0, l.reservation_end_z); + } print(buffer); + b = buffer + seprintf(buffer, lastof(buffer), " TB reserved tiles: %d, flags:", l.tunnel_bridge_reserved_tiles); if (HasBit(l.flags, TRLF_TB_EXIT_FREE)) b += seprintf(b, lastof(buffer), "x"); if (HasBit(l.flags, TRLF_DEPOT_END)) b += seprintf(b, lastof(buffer), "d"); @@ -204,18 +222,23 @@ class NIHVehicle : public NIHelper { break; case TRLIT_REVERSE: b += seprintf(b, lastof(buffer), "reverse"); + print_braking_speed(item.start + t->gcache.cached_total_length, 0, item.z_pos); break; case TRLIT_TRACK_SPEED: b += seprintf(b, lastof(buffer), "track speed: %u", item.data_id); + print_braking_speed(item.start, item.data_id, item.z_pos); break; case TRLIT_SPEED_RESTRICTION: b += seprintf(b, lastof(buffer), "speed restriction: %u", item.data_id); + if (item.data_id > 0) print_braking_speed(item.start, item.data_id, item.z_pos); break; case TRLIT_SIGNAL: b += seprintf(b, lastof(buffer), "signal: target speed: %u", item.data_id); break; case TRLIT_CURVE_SPEED: b += seprintf(b, lastof(buffer), "curve speed: %u", item.data_id); + if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL) print_braking_speed(item.start, item.data_id, item.z_pos); + break; } print(buffer); diff --git a/src/train.h b/src/train.h index 29317db1f2..01c3154aaf 100644 --- a/src/train.h +++ b/src/train.h @@ -473,6 +473,14 @@ protected: // These functions should not be called outside acceleration code. } }; +struct TrainDecelerationStats { + int deceleration_x2; + int uncapped_deceleration_x2; + int z_pos; + const Train *t; + + TrainDecelerationStats(const Train *t); +}; CommandCost CmdMoveRailVehicle(TileIndex, DoCommandFlag , uint32, uint32, const char *); CommandCost CmdMoveVirtualRailVehicle(TileIndex, DoCommandFlag, uint32, uint32, const char*); diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 5ea0a9e315..9abbc60794 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -783,28 +783,21 @@ int PredictStationStoppingLocation(const Train *v, const Order *order, int stati return stop + adjust; } -struct TrainDecelerationStats { - int deceleration_x2; - int uncapped_deceleration_x2; - int z_pos; - const Train *t; - - TrainDecelerationStats(const Train *t) - { - this->deceleration_x2 = 2 * t->tcache.cached_deceleration; - this->uncapped_deceleration_x2 = 2 * t->tcache.cached_uncapped_decel; - if (likely(HasBit(t->vcache.cached_veh_flags, VCF_GV_ZERO_SLOPE_RESIST))) { - this->z_pos = t->z_pos; - } else { - int64 sum = 0; - for (const Train *u = t; u != nullptr; u = u->Next()) { - sum += ((int)u->z_pos * (int)u->tcache.cached_veh_weight); - } - this->z_pos = sum / t->gcache.cached_weight; +TrainDecelerationStats::TrainDecelerationStats(const Train *t) +{ + this->deceleration_x2 = 2 * t->tcache.cached_deceleration; + this->uncapped_deceleration_x2 = 2 * t->tcache.cached_uncapped_decel; + if (likely(HasBit(t->vcache.cached_veh_flags, VCF_GV_ZERO_SLOPE_RESIST))) { + this->z_pos = t->z_pos; + } else { + int64 sum = 0; + for (const Train *u = t; u != nullptr; u = u->Next()) { + sum += ((int)u->z_pos * (int)u->tcache.cached_veh_weight); } - this->t = t; + this->z_pos = sum / t->gcache.cached_weight; } -}; + this->t = t; +} static int64 GetRealisticBrakingDistanceForSpeed(const TrainDecelerationStats &stats, int start_speed, int end_speed, int z_delta) { @@ -886,7 +879,7 @@ static int GetRealisticBrakingSpeedForDistance(const TrainDecelerationStats &sta return IntSqrt((uint) speed_sqr); } -static void LimitSpeedFromLookAhead(int &max_speed, const TrainDecelerationStats &stats, int current_position, int position, int end_speed, int z_delta) +void LimitSpeedFromLookAhead(int &max_speed, const TrainDecelerationStats &stats, int current_position, int position, int end_speed, int z_delta) { if (position <= current_position) { max_speed = std::min(max_speed, std::max(15, end_speed));