Skip to content

Commit

Permalink
Better error reporting from map::move_vehicle:
Browse files Browse the repository at this point in the history
Add two separate checks for 1) empty displacement vector and 2) for displacement vector being too large.

Changed third check into an assertion as it is ensured by the splitting code above.
  • Loading branch information
BevapDin committed Aug 24, 2019
1 parent 7507200 commit cac4f1d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,14 @@ static bool sees_veh( const Creature &c, vehicle &veh, bool force_recalc )

vehicle *map::move_vehicle( vehicle &veh, const tripoint &dp, const tileray &facing )
{
if( dp == tripoint_zero ) {
debugmsg( "Empty displacement vector" );
return &veh;
} else if( abs( dp.x ) > 1 || abs( dp.y ) > 1 || abs( dp.z ) > 1 ) {
debugmsg( "Invalid displacement vector: %d, %d, %d", dp.x, dp.y, dp.z );
return &veh;
}

// Split the movement into horizontal and vertical for easier processing
if( dp.xy() != point_zero && dp.z != 0 ) {
vehicle *const new_pointer = move_vehicle( veh, tripoint( dp.xy(), 0 ), facing );
Expand All @@ -449,14 +457,9 @@ vehicle *map::move_vehicle( vehicle &veh, const tripoint &dp, const tileray &fac
result->is_falling = false;
return result;
}

const bool vertical = dp.z != 0;
if( ( dp.x == 0 && dp.y == 0 && dp.z == 0 ) ||
( abs( dp.x ) > 1 || abs( dp.y ) > 1 || abs( dp.z ) > 1 ) ||
( vertical && ( dp.x != 0 || dp.y != 0 ) ) ) {
debugmsg( "move_vehicle called with %d,%d,%d displacement vector", dp.x, dp.y, dp.z );
return &veh;
}
// Ensured by the splitting above
assert( vertical == ( dp.xy() == point_zero ) );

const int target_z = dp.z + veh.sm_pos.z;
if( target_z < -OVERMAP_DEPTH || target_z > OVERMAP_HEIGHT ) {
Expand Down

0 comments on commit cac4f1d

Please sign in to comment.