Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix calling map::move_vehicle with a combined horizontal and vertical movement #33506

Merged
merged 3 commits into from
Aug 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,14 +434,33 @@ static bool sees_veh( const Creature &c, vehicle &veh, bool force_recalc )

vehicle *map::move_vehicle( vehicle &veh, const tripoint &dp, const tileray &facing )
{
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 );
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 );
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;
// 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 ) {
return &veh;
Expand Down
3 changes: 3 additions & 0 deletions src/monmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,9 @@ void monster::shove_vehicle( const tripoint &remote_destination,
veh.skidding = true;
veh.velocity = shove_velocity;
if( shove_destination != tripoint_zero ) {
if( shove_destination.z != 0 ) {
veh.vertical_velocity = shove_destination.z < 0 ? -shove_velocity : +shove_velocity;
}
g->m.move_vehicle( veh, shove_destination, veh.face );
}
veh.move = tileray( destination_delta_x, destination_delta_y );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use the new vehicle pointer returned by move_vehicle?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't really matter. move_vehicle either returns null or the input vehicle. It never creates a new one. Those movement functions need a rework anyway (returning bool instead of pointers, displace_vehicle taking a vehicle reference instead of a point and so on).

Expand Down
13 changes: 1 addition & 12 deletions src/vehicle_move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down