From d08ddddf30863dbdf7cd0df3f4040cc592fc2e50 Mon Sep 17 00:00:00 2001 From: Rob Kuijper Date: Sun, 6 Feb 2022 08:55:56 +0100 Subject: [PATCH] Add message to end of failed pickup activity (#55136) * Add message to end of failed pickup activity Currently mass-picking up using g interface will sometimes fail silently. This change seems to at least give the player a small hint * Add stash status to pickup activity serialisation --- src/activity_actor.cpp | 8 +++++- src/activity_actor_definitions.h | 8 +++++- src/pickup.cpp | 45 ++++++++++++++------------------ src/pickup.h | 2 +- 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index d812371852c8b..d065af88186a0 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -2003,13 +2003,17 @@ void pickup_activity_actor::do_turn( player_activity &, Character &who ) const bool autopickup = who.activity.auto_resume; // False indicates that the player canceled pickup when met with some prompt - const bool keep_going = Pickup::do_pickup( target_items, quantities, autopickup ); + const bool keep_going = Pickup::do_pickup( target_items, quantities, autopickup, stash_successful ); // If there are items left we ran out of moves, so continue the activity // Otherwise, we are done. if( !keep_going || target_items.empty() ) { cancel_pickup( who ); + if( !stash_successful && !autopickup ) { + add_msg( m_bad, _( "Some items were not picked up" ) ); + } + if( who.get_value( "THIEF_MODE_KEEP" ) != "YES" ) { who.set_value( "THIEF_MODE", "THIEF_ASK" ); } @@ -2030,6 +2034,7 @@ void pickup_activity_actor::serialize( JsonOut &jsout ) const jsout.member( "target_items", target_items ); jsout.member( "quantities", quantities ); jsout.member( "starting_pos", starting_pos ); + jsout.member( "stash_successful", stash_successful ); jsout.end_object(); } @@ -2043,6 +2048,7 @@ std::unique_ptr pickup_activity_actor::deserialize( JsonValue &j data.read( "target_items", actor.target_items ); data.read( "quantities", actor.quantities ); data.read( "starting_pos", actor.starting_pos ); + data.read( "stash_successful", actor.stash_successful ); return actor.clone(); } diff --git a/src/activity_actor_definitions.h b/src/activity_actor_definitions.h index 37d551446201b..f02d102bc5aea 100644 --- a/src/activity_actor_definitions.h +++ b/src/activity_actor_definitions.h @@ -578,7 +578,13 @@ class pickup_activity_actor : public activity_actor pickup_activity_actor( const std::vector &target_items, const std::vector &quantities, const cata::optional &starting_pos ) : target_items( target_items ), - quantities( quantities ), starting_pos( starting_pos ) {} + quantities( quantities ), starting_pos( starting_pos ), stash_successful( true ) {} + + /** + * Used to check at the end of a pickup activity if the character was able + * to stash everything. If not, a message is displayed to clarify. + */ + bool stash_successful; activity_id get_type() const override { return activity_id( "ACT_PICKUP" ); diff --git a/src/pickup.cpp b/src/pickup.cpp index 9c39dbdf8de62..9b1fa5227a0d8 100644 --- a/src/pickup.cpp +++ b/src/pickup.cpp @@ -60,11 +60,21 @@ using PickupMap = std::map; static const zone_type_id zone_type_NO_AUTO_PICKUP( "NO_AUTO_PICKUP" ); -// Pickup helper functions -static bool pick_one_up( item_location &loc, int quantity, bool &got_water, - PickupMap &mapPickup, bool autopickup ); - -static void show_pickup_message( const PickupMap &mapPickup ); +//helper function for Pickup::autopickup +static void show_pickup_message( const PickupMap &mapPickup ) +{ + for( const auto &entry : mapPickup ) { + if( entry.second.first.invlet != 0 ) { + add_msg( _( "You pick up: %d %s [%c]" ), entry.second.second, + entry.second.first.display_name( entry.second.second ), entry.second.first.invlet ); + } else if( entry.second.first.count_by_charges() ) { + add_msg( _( "You pick up: %s" ), entry.second.first.display_name( entry.second.second ) ); + } else { + add_msg( _( "You pick up: %d %s" ), entry.second.second, + entry.second.first.display_name( entry.second.second ) ); + } + } +} struct pickup_count { bool pick = false; @@ -199,8 +209,8 @@ bool Pickup::query_thief() } // Returns false if pickup caused a prompt and the player selected to cancel pickup -bool pick_one_up( item_location &loc, int quantity, bool &got_water, PickupMap &mapPickup, - bool autopickup ) +static bool pick_one_up( item_location &loc, int quantity, bool &got_water, PickupMap &mapPickup, + bool autopickup, bool &stash_successful ) { Character &player_character = get_player_character(); int moves_taken = loc.obtain_cost( player_character, quantity ); @@ -248,6 +258,7 @@ bool pick_one_up( item_location &loc, int quantity, bool &got_water, PickupMap & } else if( !player_character.can_pickWeight_partial( newit, false ) || !player_character.can_stash_partial( newit ) ) { option = CANCEL; + stash_successful = false; } else if( newit.is_bucket_nonempty() ) { if( !autopickup ) { const std::string &explain = string_format( _( "Can't stash %s while it's not empty" ), @@ -347,7 +358,7 @@ bool pick_one_up( item_location &loc, int quantity, bool &got_water, PickupMap & } bool Pickup::do_pickup( std::vector &targets, std::vector &quantities, - bool autopickup ) + bool autopickup, bool &stash_successful ) { bool got_water = false; Character &player_character = get_player_character(); @@ -371,7 +382,7 @@ bool Pickup::do_pickup( std::vector &targets, std::vector &q continue; } - problem = !pick_one_up( target, quantity, got_water, mapPickup, autopickup ); + problem = !pick_one_up( target, quantity, got_water, mapPickup, autopickup, stash_successful ); } if( !mapPickup.empty() ) { @@ -495,22 +506,6 @@ void Pickup::autopickup( const tripoint &p ) player_character.activity.auto_resume = true; } -//helper function for Pickup::autopickup -void show_pickup_message( const PickupMap &mapPickup ) -{ - for( const auto &entry : mapPickup ) { - if( entry.second.first.invlet != 0 ) { - add_msg( _( "You pick up: %d %s [%c]" ), entry.second.second, - entry.second.first.display_name( entry.second.second ), entry.second.first.invlet ); - } else if( entry.second.first.count_by_charges() ) { - add_msg( _( "You pick up: %s" ), entry.second.first.display_name( entry.second.second ) ); - } else { - add_msg( _( "You pick up: %d %s" ), entry.second.second, - entry.second.first.display_name( entry.second.second ) ); - } - } -} - int Pickup::cost_to_move_item( const Character &who, const item &it ) { // Do not involve inventory capacity, it's not like you put it in backpack diff --git a/src/pickup.h b/src/pickup.h index 7f47813aea18c..4797e58493904 100644 --- a/src/pickup.h +++ b/src/pickup.h @@ -18,7 +18,7 @@ namespace Pickup * `true` in other cases. */ bool do_pickup( std::vector &targets, std::vector &quantities, - bool autopickup ); + bool autopickup, bool &stash_successful ); bool query_thief(); enum from_where : int {