MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / shouldStartWheelSlipping

Function shouldStartWheelSlipping

src/OpenLoco/src/Vehicles/Vehicle2.cpp:40–118  ·  view source on GitHub ↗

0x004A9BA0

Source from the content-addressed store, hash-verified

38
39 // 0x004A9BA0
40 static bool shouldStartWheelSlipping(const Vehicle& train, VehicleBogie& frontBogie)
41 {
42 const auto* vehObject = ObjectManager::get<VehicleObject>(frontBogie.objectId);
43 if (!vehObject->hasFlags(VehicleObjectFlags::canWheelslip) || vehObject->power == 0)
44 {
45 return false;
46 }
47
48 if (train.head->status != Status::travelling)
49 {
50 return false;
51 }
52
53 if (train.veh2->motorState == MotorState::coasting || train.veh2->currentSpeed > 10.0_mph)
54 {
55 return false;
56 }
57
58 // Only start wheel slipping if it is not wheel slipping already
59 if (frontBogie.wheelSlipping != 0)
60 {
61 return false;
62 }
63
64 if (Tutorial::state() != Tutorial::State::none)
65 {
66 return false;
67 }
68
69 if (train.head->hasVehicleFlags(VehicleFlags::manualControl) && train.head->manualPower <= 10)
70 {
71 return false;
72 }
73
74 const auto tot1 = 128ULL * vehObject->power * train.veh2->totalWeight;
75 const auto tot2 = frontBogie.totalCarWeight * train.veh2->totalPower;
76 auto fraction = tot2 == 0 ? tot1 : tot1 / tot2;
77 fraction = std::min(fraction, 2'000ULL);
78 if (fraction < static_cast<uint16_t>(gPrng1().randNext(0xFFFF)))
79 {
80 return false;
81 }
82 if (frontBogie.mode == TransportMode::rail)
83 {
84 const auto* trackObj = ObjectManager::get<TrackObject>(frontBogie.trackType);
85 if (trackObj->hasFlags(TrackObjectFlags::noSlipSurface))
86 {
87 return false;
88 }
89 if (trackObj->hasFlags(TrackObjectFlags::hasRackRail))
90 {
91 if (frontBogie.isOnRackRail())
92 {
93 return false;
94 }
95 }
96 }
97 else

Callers 1

updateMethod · 0.85

Calls 5

hasVehicleFlagsMethod · 0.80
isOnRackRailMethod · 0.80
stateFunction · 0.50
hasFlagsMethod · 0.45
randNextMethod · 0.45

Tested by

no test coverage detected