Skip to content

Commit d08dddd

Browse files
authored
Add message to end of failed pickup activity (CleverRaven#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
1 parent 8fa0f1f commit d08dddd

File tree

4 files changed

+35
-28
lines changed

4 files changed

+35
-28
lines changed

src/activity_actor.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2003,13 +2003,17 @@ void pickup_activity_actor::do_turn( player_activity &, Character &who )
20032003
const bool autopickup = who.activity.auto_resume;
20042004

20052005
// False indicates that the player canceled pickup when met with some prompt
2006-
const bool keep_going = Pickup::do_pickup( target_items, quantities, autopickup );
2006+
const bool keep_going = Pickup::do_pickup( target_items, quantities, autopickup, stash_successful );
20072007

20082008
// If there are items left we ran out of moves, so continue the activity
20092009
// Otherwise, we are done.
20102010
if( !keep_going || target_items.empty() ) {
20112011
cancel_pickup( who );
20122012

2013+
if( !stash_successful && !autopickup ) {
2014+
add_msg( m_bad, _( "Some items were not picked up" ) );
2015+
}
2016+
20132017
if( who.get_value( "THIEF_MODE_KEEP" ) != "YES" ) {
20142018
who.set_value( "THIEF_MODE", "THIEF_ASK" );
20152019
}
@@ -2030,6 +2034,7 @@ void pickup_activity_actor::serialize( JsonOut &jsout ) const
20302034
jsout.member( "target_items", target_items );
20312035
jsout.member( "quantities", quantities );
20322036
jsout.member( "starting_pos", starting_pos );
2037+
jsout.member( "stash_successful", stash_successful );
20332038

20342039
jsout.end_object();
20352040
}
@@ -2043,6 +2048,7 @@ std::unique_ptr<activity_actor> pickup_activity_actor::deserialize( JsonValue &j
20432048
data.read( "target_items", actor.target_items );
20442049
data.read( "quantities", actor.quantities );
20452050
data.read( "starting_pos", actor.starting_pos );
2051+
data.read( "stash_successful", actor.stash_successful );
20462052

20472053
return actor.clone();
20482054
}

src/activity_actor_definitions.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,13 @@ class pickup_activity_actor : public activity_actor
578578
pickup_activity_actor( const std::vector<item_location> &target_items,
579579
const std::vector<int> &quantities,
580580
const cata::optional<tripoint> &starting_pos ) : target_items( target_items ),
581-
quantities( quantities ), starting_pos( starting_pos ) {}
581+
quantities( quantities ), starting_pos( starting_pos ), stash_successful( true ) {}
582+
583+
/**
584+
* Used to check at the end of a pickup activity if the character was able
585+
* to stash everything. If not, a message is displayed to clarify.
586+
*/
587+
bool stash_successful;
582588

583589
activity_id get_type() const override {
584590
return activity_id( "ACT_PICKUP" );

src/pickup.cpp

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,21 @@ using PickupMap = std::map<std::string, ItemCount>;
6060

6161
static const zone_type_id zone_type_NO_AUTO_PICKUP( "NO_AUTO_PICKUP" );
6262

63-
// Pickup helper functions
64-
static bool pick_one_up( item_location &loc, int quantity, bool &got_water,
65-
PickupMap &mapPickup, bool autopickup );
66-
67-
static void show_pickup_message( const PickupMap &mapPickup );
63+
//helper function for Pickup::autopickup
64+
static void show_pickup_message( const PickupMap &mapPickup )
65+
{
66+
for( const auto &entry : mapPickup ) {
67+
if( entry.second.first.invlet != 0 ) {
68+
add_msg( _( "You pick up: %d %s [%c]" ), entry.second.second,
69+
entry.second.first.display_name( entry.second.second ), entry.second.first.invlet );
70+
} else if( entry.second.first.count_by_charges() ) {
71+
add_msg( _( "You pick up: %s" ), entry.second.first.display_name( entry.second.second ) );
72+
} else {
73+
add_msg( _( "You pick up: %d %s" ), entry.second.second,
74+
entry.second.first.display_name( entry.second.second ) );
75+
}
76+
}
77+
}
6878

6979
struct pickup_count {
7080
bool pick = false;
@@ -199,8 +209,8 @@ bool Pickup::query_thief()
199209
}
200210

201211
// Returns false if pickup caused a prompt and the player selected to cancel pickup
202-
bool pick_one_up( item_location &loc, int quantity, bool &got_water, PickupMap &mapPickup,
203-
bool autopickup )
212+
static bool pick_one_up( item_location &loc, int quantity, bool &got_water, PickupMap &mapPickup,
213+
bool autopickup, bool &stash_successful )
204214
{
205215
Character &player_character = get_player_character();
206216
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 &
248258
} else if( !player_character.can_pickWeight_partial( newit, false ) ||
249259
!player_character.can_stash_partial( newit ) ) {
250260
option = CANCEL;
261+
stash_successful = false;
251262
} else if( newit.is_bucket_nonempty() ) {
252263
if( !autopickup ) {
253264
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 &
347358
}
348359

349360
bool Pickup::do_pickup( std::vector<item_location> &targets, std::vector<int> &quantities,
350-
bool autopickup )
361+
bool autopickup, bool &stash_successful )
351362
{
352363
bool got_water = false;
353364
Character &player_character = get_player_character();
@@ -371,7 +382,7 @@ bool Pickup::do_pickup( std::vector<item_location> &targets, std::vector<int> &q
371382
continue;
372383
}
373384

374-
problem = !pick_one_up( target, quantity, got_water, mapPickup, autopickup );
385+
problem = !pick_one_up( target, quantity, got_water, mapPickup, autopickup, stash_successful );
375386
}
376387

377388
if( !mapPickup.empty() ) {
@@ -495,22 +506,6 @@ void Pickup::autopickup( const tripoint &p )
495506
player_character.activity.auto_resume = true;
496507
}
497508

498-
//helper function for Pickup::autopickup
499-
void show_pickup_message( const PickupMap &mapPickup )
500-
{
501-
for( const auto &entry : mapPickup ) {
502-
if( entry.second.first.invlet != 0 ) {
503-
add_msg( _( "You pick up: %d %s [%c]" ), entry.second.second,
504-
entry.second.first.display_name( entry.second.second ), entry.second.first.invlet );
505-
} else if( entry.second.first.count_by_charges() ) {
506-
add_msg( _( "You pick up: %s" ), entry.second.first.display_name( entry.second.second ) );
507-
} else {
508-
add_msg( _( "You pick up: %d %s" ), entry.second.second,
509-
entry.second.first.display_name( entry.second.second ) );
510-
}
511-
}
512-
}
513-
514509
int Pickup::cost_to_move_item( const Character &who, const item &it )
515510
{
516511
// Do not involve inventory capacity, it's not like you put it in backpack

src/pickup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Pickup
1818
* `true` in other cases.
1919
*/
2020
bool do_pickup( std::vector<item_location> &targets, std::vector<int> &quantities,
21-
bool autopickup );
21+
bool autopickup, bool &stash_successful );
2222
bool query_thief();
2323

2424
enum from_where : int {

0 commit comments

Comments
 (0)