MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / DoVehicleWaterMovement

Function DoVehicleWaterMovement

TombEngine/Objects/Utils/VehicleHelpers.cpp:225–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

223 }
224
225 int DoVehicleWaterMovement(ItemInfo* vehicleItem, ItemInfo* laraItem, int currentVelocity, int radius, short* turnRate, const Vector3& wakeOffset)
226 {
227 auto point = GetPointCollision(*vehicleItem);
228
229 if (point.GetWaterSurfaceHeight() == NO_HEIGHT || point.GetWaterSurfaceHeight() > vehicleItem->Pose.Position.y)
230 return currentVelocity;
231
232 int waterDepth = point.GetWaterBottomHeight();
233
234 // HACK: Sometimes quadbike test position may end up under non-portal ceiling block.
235 // GetWaterDepth returns DEEP_WATER constant in that case, which is too large for our needs.
236 if (waterDepth == DEEP_WATER)
237 waterDepth = VEHICLE_WATER_HEIGHT_MAX;
238
239 if (waterDepth <= VEHICLE_WATER_HEIGHT_MAX)
240 {
241 int bottomRoomNumber = FindRoomNumber(vehicleItem->Pose.Position, vehicleItem->RoomNumber, true);
242 bool isWater = TestEnvironment(ENV_FLAG_WATER, bottomRoomNumber);
243
244 if (currentVelocity != 0)
245 {
246 auto coeff = isWater ? VEHICLE_WATER_VELOCITY_COEFF : VEHICLE_SWAMP_VELOCITY_COEFF;
247 currentVelocity -= std::copysign(currentVelocity * ((waterDepth / VEHICLE_WATER_HEIGHT_MAX) / coeff), currentVelocity);
248
249 if (TEN::Math::Random::GenerateInt(0, 32) > 28)
250 SoundEffect(SFX_TR4_LARA_WADE, &Pose(vehicleItem->Pose.Position), SoundEnvironment::Land, isWater ? 0.8f : 0.7f);
251
252 if (isWater)
253 {
254 int waterHeight = GetPointCollision(*vehicleItem).GetWaterTopHeight();
255 SpawnVehicleWake(*vehicleItem, wakeOffset, waterHeight);
256 }
257 }
258
259 if (*turnRate)
260 {
261 auto coeff = isWater ? VEHICLE_WATER_TURN_RATE_COEFF : VEHICLE_SWAMP_TURN_RATE_COEFF;
262 *turnRate -= *turnRate * ((waterDepth / VEHICLE_WATER_HEIGHT_MAX) / coeff);
263 }
264 }
265 else
266 {
267 int waterHeight = vehicleItem->Pose.Position.y - GetPointCollision(*vehicleItem).GetWaterTopHeight();
268
269 if (waterDepth > VEHICLE_WATER_HEIGHT_MAX && waterHeight > VEHICLE_WATER_HEIGHT_MAX)
270 {
271 ExplodeVehicle(laraItem, vehicleItem);
272 }
273 else if (TEN::Math::Random::GenerateInt(0, 32) > 25)
274 {
275 Splash(vehicleItem);
276 }
277 }
278
279 return currentVelocity;
280 }
281
282 // TODO: Allow flares on every vehicle and see how that works. Boats already allowed them originally.

Callers 5

SkidooControlFunction · 0.85
QuadBikeControlFunction · 0.85
MoveCartFunction · 0.85
MotorbikeControlFunction · 0.85
JeepControlFunction · 0.85

Calls 12

GetPointCollisionFunction · 0.85
FindRoomNumberFunction · 0.85
TestEnvironmentFunction · 0.85
GenerateIntFunction · 0.85
SoundEffectFunction · 0.85
SpawnVehicleWakeFunction · 0.85
ExplodeVehicleFunction · 0.85
SplashFunction · 0.85
GetWaterBottomHeightMethod · 0.80
GetWaterTopHeightMethod · 0.80
PoseClass · 0.50
GetWaterSurfaceHeightMethod · 0.45

Tested by

no test coverage detected