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

Method destroyTrain

src/OpenLoco/src/Vehicles/Vehicle.cpp:172–249  ·  view source on GitHub ↗

0x004AA464

Source from the content-addressed store, hash-verified

170
171 // 0x004AA464
172 void VehicleBase::destroyTrain()
173 {
174 Vehicle train(this->getHead());
175
176 if (train.head->status != Status::crashed && train.head->status != Status::stuck)
177 {
178 train.head->status = Status::crashed;
179 train.head->crashedTimeout = 0;
180
181 if (train.head->owner == getGameState().playerCompanies[0])
182 {
183 MessageManager::post(
184 MessageType::vehicleCrashed,
185 train.head->owner,
186 (uint16_t)train.head->id,
187 0xFFFF,
188 0xFFFF);
189 }
190 }
191
192 train.cars.applyToComponents([](auto& carComponent) { carComponent.refundCost = 0; });
193
194 train.head->totalRefundCost = 0;
195
196 Speed32 currentSpeed = train.veh2->currentSpeed;
197 train.veh2->motorState = MotorState::stopped;
198
199 train.cars.applyToComponents([&](auto& carComponent) {
200 if (carComponent.isVehicleBogie())
201 {
202 carComponent.asVehicleBogie()->var_5A = currentSpeed.getRaw();
203 }
204 });
205
206 if (this->getSubType() == VehicleEntityType::vehicle_2)
207 {
208 auto* bogie = train.cars.firstCar.front;
209
210 if (!train.cars.empty())
211 {
212 bogie->var_5A |= (1U << 31);
213 bogie->tileX = 0;
214 bogie->tileY = 0;
215 bogie->tileBaseZ = 0;
216 }
217 }
218 else if (this->getSubType() == VehicleEntityType::bogie)
219 {
220 VehicleBogie* bogie = this->asVehicleBogie();
221
222 bogie->var_5A |= (1U << 31);
223 bogie->tileX = 0;
224 bogie->tileY = 0;
225 bogie->tileBaseZ = 0;
226 }
227 else
228 {
229 VehicleBogie* explodeBogie = nullptr;

Callers 3

tryReverseMethod · 0.80
collisionMethod · 0.80

Calls 8

getHeadMethod · 0.95
asVehicleBogieMethod · 0.95
getSubTypeMethod · 0.95
postFunction · 0.85
isVehicleBogieMethod · 0.80
applyToComponentsMethod · 0.45
getRawMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected