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

Method collision

src/OpenLoco/src/Vehicles/VehicleBogie.cpp:300–357  ·  view source on GitHub ↗

0x004AA0DF

Source from the content-addressed store, hash-verified

298
299 // 0x004AA0DF
300 void VehicleBogie::collision(const EntityId collideEntityId)
301 {
302 destroyTrain();
303 applyDestructionToComponent(*this);
304 vehicleFlags |= VehicleFlags::unk_5;
305
306 // Apply collision to the whole car
307 Vehicle train(head);
308 bool end = false;
309 for (auto& car : train.cars)
310 {
311 for (auto& carComponent : car)
312 {
313 if (carComponent.front == this || carComponent.back == this)
314 {
315 applyDestructionToComponent(*carComponent.body);
316 end = true;
317 break;
318 }
319 }
320 if (end)
321 {
322 break;
323 }
324 }
325
326 // Apply Collision to collided train
327 auto* collideEntity = EntityManager::get<EntityBase>(collideEntityId);
328 auto* collideCarComponent = collideEntity->asBase<VehicleBase>();
329 if (collideCarComponent != nullptr)
330 {
331 Vehicle collideTrain(collideCarComponent->getHead());
332 if (collideTrain.head->status != Status::crashed)
333 {
334 collideCarComponent->destroyTrain();
335 }
336
337 for (auto& car : train.cars)
338 {
339 for (auto& carComponent : car)
340 {
341 if (carComponent.front == collideCarComponent)
342 {
343 applyDestructionToComponent(*carComponent.front);
344 }
345 if (carComponent.back == collideCarComponent)
346 {
347 applyDestructionToComponent(*carComponent.back);
348 }
349 if (carComponent.front == collideCarComponent || carComponent.back == collideCarComponent || carComponent.body == collideCarComponent)
350 {
351 applyDestructionToComponent(*carComponent.body);
352 return;
353 }
354 }
355 }
356 }
357 }

Callers

nothing calls this directly

Calls 3

getHeadMethod · 0.80
destroyTrainMethod · 0.80

Tested by

no test coverage detected