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

Cancel pick up items activity if player moves during it #34537

Merged
merged 3 commits into from
Oct 9, 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
9 changes: 9 additions & 0 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,15 @@ void activity_on_turn_pickup()
return;
}

// If the player moves while picking up (ie: in a moving vehicle) cancel the activity, only populate coords when grabbing from the ground
if( g->u.activity.coords.size() > 0 && g->u.activity.coords.at( 0 ) != g->u.pos() ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

g->u.activity.coords.size() > 0

should be

!g->u.activity.coords.empty()

g->u.cancel_activity();
if( g->u.is_player() ) {
g->u.add_msg_if_player( _( "Moving cancelled auto-pickup." ) );
}
return;
}

// Auto_resume implies autopickup.
const bool autopickup = g->u.activity.auto_resume;

Expand Down
2 changes: 2 additions & 0 deletions src/advanced_inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,7 @@ bool advanced_inventory::move_all_items( bool nested_call )
} else {
if( dpane.get_area() == AIM_INVENTORY || dpane.get_area() == AIM_WORN ) {
g->u.assign_activity( activity_id( "ACT_PICKUP" ) );
g->u.activity.coords.push_back( g->u.pos() );
} else { // Vehicle and map destinations are handled the same.

// Check first if the destination area still have enough room for moving all.
Expand Down Expand Up @@ -1729,6 +1730,7 @@ void advanced_inventory::display()

if( destarea == AIM_INVENTORY ) {
g->u.assign_activity( activity_id( "ACT_PICKUP" ) );
g->u.activity.coords.push_back( g->u.pos() );
} else if( destarea == AIM_WORN ) {
g->u.assign_activity( activity_id( "ACT_WEAR" ) );
} else { // Vehicle and map destinations are handled similarly.
Expand Down
2 changes: 2 additions & 0 deletions src/pickup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ void Pickup::pick_up( const tripoint &p, int min, from_where get_items_from )
g->u.activity.targets.emplace_back( vehicle_cursor( *veh, cargo_part ), &*here.front() );
} else {
g->u.activity.targets.emplace_back( map_cursor( p ), &*here.front() );
g->u.activity.coords.push_back( g->u.pos() );
}
// auto-pickup means pick up all.
g->u.activity.values.push_back( 0 );
Expand Down Expand Up @@ -990,6 +991,7 @@ void Pickup::pick_up( const tripoint &p, int min, from_where get_items_from )

// At this point we've selected our items, register an activity to pick them up.
g->u.assign_activity( activity_id( "ACT_PICKUP" ) );
g->u.activity.coords.push_back( g->u.pos() );
if( min == -1 ) {
// Auto pickup will need to auto resume since there can be several of them on the stack.
g->u.activity.auto_resume = true;
Expand Down