MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetCurrentMaxSpeed

Method GetCurrentMaxSpeed

src/roadveh_cmd.cpp:463–485  ·  view source on GitHub ↗

* Calculates the maximum speed of the vehicle under its current conditions. * @return Maximum speed of the vehicle. */

Source from the content-addressed store, hash-verified

461 * @return Maximum speed of the vehicle.
462 */
463inline 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.

Callers 2

UpdateSpeedMethod · 0.95
RoadVehCheckOvertakeFunction · 0.45

Calls 6

IsReversingRoadTrackdirFunction · 0.85
GetBridgeSpecFunction · 0.85
GetBridgeTypeFunction · 0.85
TestMethod · 0.80
NextMethod · 0.45
GetMaxSpeedMethod · 0.45

Tested by

no test coverage detected