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

Method update

src/OpenLoco/src/Vehicles/Vehicle2.cpp:126–286  ·  view source on GitHub ↗

0x004A9B0B

Source from the content-addressed store, hash-verified

124
125 // 0x004A9B0B
126 bool Vehicle2::update()
127 {
128 if (mode == TransportMode::air || mode == TransportMode::water)
129 {
130 return true;
131 }
132 Vehicle train(head);
133
134 motorState = MotorState::accelerating;
135 const auto speedDiff = currentSpeed - train.veh1->targetSpeed;
136 if (speedDiff > 0.0_mph)
137 {
138 motorState = MotorState::braking;
139 const auto newSpeed = currentSpeed - (currentSpeed / 64 + 0.18311_mph);
140 currentSpeed = std::max(newSpeed, std::max<Speed32>(train.veh1->targetSpeed, 5.0_mph));
141 return sub_4A9F20();
142 }
143
144 if (!train.head->hasVehicleFlags(VehicleFlags::manualControl))
145 {
146 if (speedDiff >= -1.5_mph)
147 {
148 motorState = MotorState::coasting;
149 }
150 if (currentSpeed == 0.0_mph)
151 {
152 motorState = MotorState::stopped;
153 }
154 }
155
156 train.cars.applyToComponents([](auto& component) {
157 // If the vehicle is wheel slipping, then its wheel slipping value is incremented.
158 if (component.wheelSlipping != 0)
159 {
160 component.wheelSlipping++;
161 if (component.wheelSlipping >= kWheelSlippingDuration)
162 {
163 component.wheelSlipping = 0;
164 }
165 }
166 });
167
168 bool isOnRackRail = true; // Note has been inverted
169 bool isWheelSlipping = false;
170 int32_t ebp = 0;
171 for (auto& car : train.cars)
172 {
173 auto* frontBogie = car.front;
174 if (shouldStartWheelSlipping(train, *frontBogie))
175 {
176 car.applyToComponents([](auto& component) {
177 component.wheelSlipping = 1;
178 });
179 }
180
181 if (frontBogie->wheelSlipping != 0)
182 {
183 isWheelSlipping = true;

Callers

nothing calls this directly

Calls 9

shouldStartWheelSlippingFunction · 0.85
enumValueFunction · 0.85
getControllingIdFunction · 0.85
postFunction · 0.85
toSpeed16Function · 0.85
hasVehicleFlagsMethod · 0.80
isOnRackRailMethod · 0.80
applyToComponentsMethod · 0.45
getRawMethod · 0.45

Tested by

no test coverage detected