From 7507200e22e601db6b28a5dff8cfb015aeb6dfd5 Mon Sep 17 00:00:00 2001 From: BevapDin Date: Sat, 24 Aug 2019 13:44:29 +0200 Subject: [PATCH] Move splitting vehicle move into horizontal and vertical into map::move_vehicle. So the caller does not have to do it. At least one caller (from `monster::shove_vehicle`) did not do this. --- src/map.cpp | 16 ++++++++++++++++ src/vehicle_move.cpp | 13 +------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/map.cpp b/src/map.cpp index 303fffe70e549..a2f2618f28ce1 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -434,6 +434,22 @@ static bool sees_veh( const Creature &c, vehicle &veh, bool force_recalc ) vehicle *map::move_vehicle( vehicle &veh, const tripoint &dp, const tileray &facing ) { + // 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 ); + if( !new_pointer ) { + return nullptr; + } + + vehicle *const result = move_vehicle( *new_pointer, tripoint( 0, 0, dp.z ), facing ); + if( !result ) { + return nullptr; + } + + 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 ) || diff --git a/src/vehicle_move.cpp b/src/vehicle_move.cpp index 3ecc5045dae30..d5b34ca5ed5f1 100644 --- a/src/vehicle_move.cpp +++ b/src/vehicle_move.cpp @@ -1335,18 +1335,7 @@ vehicle *vehicle::act_on_map() dp.z = -1; } - vehicle *new_pointer = this; - // Split the movement into horizontal and vertical for easier processing - if( dp.x != 0 || dp.y != 0 ) { - new_pointer = g->m.move_vehicle( *new_pointer, tripoint( dp.xy(), 0 ), mdir ); - } - - if( new_pointer != nullptr && dp.z != 0 ) { - new_pointer = g->m.move_vehicle( *new_pointer, tripoint( 0, 0, dp.z ), mdir ); - is_falling = false; - } - - return new_pointer; + return g->m.move_vehicle( *this, dp, mdir ); } void vehicle::check_falling_or_floating()