0x004406A0
| 18 | |
| 19 | // 0x004406A0 |
| 20 | void VehicleCrashParticle::update() |
| 21 | { |
| 22 | invalidateSprite(); |
| 23 | |
| 24 | timeToLive--; |
| 25 | if (timeToLive == 0) |
| 26 | { |
| 27 | EntityManager::freeEntity(this); |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | // Apply gravity |
| 32 | accelerationZ -= kGravity; |
| 33 | |
| 34 | // Apply air resistance |
| 35 | accelerationX -= (accelerationX / 256); |
| 36 | accelerationY -= (accelerationY / 256); |
| 37 | accelerationZ -= (accelerationZ / 256); |
| 38 | |
| 39 | // Update velocity and position |
| 40 | int32_t vx = velocity.x + accelerationX; |
| 41 | int32_t vy = velocity.y + accelerationY; |
| 42 | int32_t vz = velocity.z + accelerationZ; |
| 43 | |
| 44 | auto newLoc = position + World::Pos3{ static_cast<coord_t>(vx >> 16), static_cast<coord_t>(vy >> 16), static_cast<coord_t>(vz >> 16) }; |
| 45 | |
| 46 | velocity = World::Pos3{ static_cast<coord_t>(vx & 0xFFFF), static_cast<coord_t>(vy & 0xFFFF), static_cast<coord_t>(vz & 0xFFFF) }; |
| 47 | |
| 48 | // Check collision with land / water |
| 49 | const auto tileHeight = World::TileManager::getHeight({ newLoc.x, newLoc.y }); |
| 50 | const auto landZ = tileHeight.landHeight; |
| 51 | const auto waterZ = tileHeight.waterHeight; |
| 52 | |
| 53 | if (waterZ != 0 && position.z >= waterZ && newLoc.z <= waterZ) |
| 54 | { |
| 55 | // We hit the water surface, create a splash effect. |
| 56 | const auto splashPos = World::Pos3{ position.x, position.y, waterZ }; |
| 57 | |
| 58 | Audio::playSound(Audio::SoundId::splash2, Audio::ChannelId::vehicles, splashPos); |
| 59 | Splash::create({ position.x, position.y, waterZ }); |
| 60 | |
| 61 | EntityManager::freeEntity(this); |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | if (position.z >= landZ && newLoc.z <= landZ) |
| 66 | { |
| 67 | // We hit land surface apply bounce. |
| 68 | accelerationZ = -accelerationZ; |
| 69 | newLoc.z = landZ; |
| 70 | } |
| 71 | |
| 72 | moveTo(newLoc); |
| 73 | |
| 74 | frame += kAnimationSpeed; |
| 75 | if (frame >= kMaxSplashFrames) |
| 76 | { |
| 77 | frame = 0; |
nothing calls this directly
no test coverage detected