* Calculates the maximum speed of the vehicle under its current conditions. * @return Maximum speed of the vehicle. */
| 461 | * @return Maximum speed of the vehicle. |
| 462 | */ |
| 463 | inline int RoadVehicle::GetCurrentMaxSpeed() const |
| 464 | { |
| 465 | int max_speed = this->gcache.cached_max_track_speed; |
| 466 | |
| 467 | /* Limit speed to 50% while reversing, 75% in curves. */ |
| 468 | for (const RoadVehicle *u = this; u != nullptr; u = u->Next()) { |
| 469 | if (_settings_game.vehicle.roadveh_acceleration_model == AM_REALISTIC) { |
| 470 | if (this->state <= RVSB_TRACKDIR_MASK && IsReversingRoadTrackdir((Trackdir)this->state)) { |
| 471 | max_speed = this->gcache.cached_max_track_speed / 2; |
| 472 | break; |
| 473 | } else if ((u->direction & 1) == 0) { |
| 474 | max_speed = this->gcache.cached_max_track_speed * 3 / 4; |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | /* Vehicle is on the middle part of a bridge. */ |
| 479 | if (u->state == RVSB_WORMHOLE && !u->vehstatus.Test(VehState::Hidden)) { |
| 480 | max_speed = std::min(max_speed, GetBridgeSpec(GetBridgeType(u->tile))->speed * 2); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | return std::min(max_speed, this->current_order.GetMaxSpeed() * 2); |
| 485 | } |
| 486 | |
| 487 | /** |
| 488 | * Delete last vehicle of a chain road vehicles. |
no test coverage detected