CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.58k stars 4.16k forks source link

Boats not updating player position and leaving the player behind after collision with creatures in water #53072

Open GoLoT opened 2 years ago

GoLoT commented 2 years ago

Describe the bug

Water vehicles sometimes don't update the player position, leaving the player behind and most likely resulting in death if they fall overboard. When this happens there is no feedback and it can't be prevented by seatbelts.

AFAICT, this is caused by the monsters not being pushed far enough from the boat when hit. If they are pushed to the same location the player should be after the boat moves, the player position isn't updated to prevent stacking multiple creatures on the same tile.

The code in https://github.com/CleverRaven/Cataclysm-DDA/blob/fdeff510ae1cd6cc4cbb49e7de208b0119179950/src/vehicle_move.cpp#L837 deals with enemy collisions in water, pushing enemies 2 tiles away. For a motorboat (30mph max speed) this is not enough. Changing it to 3 tiles mitigates the issue (i.e. I can't reproduce the bug with a motorboat after the change) but it's a hacky solution that might not work for faster vehicles or for different vehicle layouts.

This block https://github.com/CleverRaven/Cataclysm-DDA/blob/fdeff510ae1cd6cc4cbb49e7de208b0119179950/src/map.cpp#L1215 can be changed to always move the passenger but it sometimes results in having 2 creatures in the same tile. Maybe a solution is to push the existing creature away in the same direction the vehicle is moving one tile at a time until a valid tile is found or find a valid position for the creature around the current tile, so the passenger can be placed where it should be.

Maybe someone with more knowledge of the vehicle code can find a proper solution.

Steps to reproduce

  1. Spawn a motor boat.
  2. Spawn a few enemies in the water (in a 10x10 area to help testing).
  3. "Drive" through the mass of enemies in circles until the character is left behind and falls into the water.

Expected behavior

Player isn't magically pulled from the seat when colliding with creatures in water.

Screenshots

No response

Versions and configuration

Additional context

No response

Nymall commented 2 years ago

Confirmed, Version: C117979

The width of the boat and speed seems to affect the issue - in my long-play I have a houseboat built and I can survive collisions in that(4x6), but any 1 tile wide boats going above 10 MPH will occasionally do this. I've noticed the problem is worse when the boat is going diagonal.

hexagonrecursion commented 2 years ago

Confirmed

When trying to move after triggering this I get:

 DEBUG    : map::unboard_vehicle: vehicle not found

 FUNCTION : void map::unboard_vehicle(const tripoint&, bool)
 FILE     : src/map.cpp
 LINE     : 1077
 VERSION  : cfc00fa

When trying to take control of the boat again again I get:

 DEBUG    : map::board_vehicle: passenger (Alice Smith) is already there

 FUNCTION : void map::board_vehicle(const tripoint&, Character*)
 FILE     : src/map.cpp
 LINE     : 1038
 VERSION  : cfc00fa