Skip to content

Commit

Permalink
Add message to end of failed pickup activity (CleverRaven#55136)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
robkuijper authored Feb 6, 2022
1 parent 8fa0f1f commit d08dddd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 28 deletions.
8 changes: 7 additions & 1 deletion src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
}
Expand All @@ -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();
}
Expand All @@ -2043,6 +2048,7 @@ std::unique_ptr<activity_actor> 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();
}
Expand Down
8 changes: 7 additions & 1 deletion src/activity_actor_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,13 @@ class pickup_activity_actor : public activity_actor
pickup_activity_actor( const std::vector<item_location> &target_items,
const std::vector<int> &quantities,
const cata::optional<tripoint> &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" );
Expand Down
45 changes: 20 additions & 25 deletions src/pickup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,21 @@ using PickupMap = std::map<std::string, ItemCount>;

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;
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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" ),
Expand Down Expand Up @@ -347,7 +358,7 @@ bool pick_one_up( item_location &loc, int quantity, bool &got_water, PickupMap &
}

bool Pickup::do_pickup( std::vector<item_location> &targets, std::vector<int> &quantities,
bool autopickup )
bool autopickup, bool &stash_successful )
{
bool got_water = false;
Character &player_character = get_player_character();
Expand All @@ -371,7 +382,7 @@ bool Pickup::do_pickup( std::vector<item_location> &targets, std::vector<int> &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() ) {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/pickup.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Pickup
* `true` in other cases.
*/
bool do_pickup( std::vector<item_location> &targets, std::vector<int> &quantities,
bool autopickup );
bool autopickup, bool &stash_successful );
bool query_thief();

enum from_where : int {
Expand Down

0 comments on commit d08dddd

Please sign in to comment.