From 432073d1785bb89cb32ad6b79a11e9c884e68cc2 Mon Sep 17 00:00:00 2001 From: NotGura Date: Mon, 22 Nov 2021 10:27:50 -0300 Subject: [PATCH 01/11] Initial implementation of rummage_activity_actor --- data/json/player_activities.json | 8 ++ src/activity_actor.cpp | 129 +++++++++++++++++++++++++++++++ src/activity_actor_definitions.h | 43 +++++++++++ 3 files changed, 180 insertions(+) diff --git a/data/json/player_activities.json b/data/json/player_activities.json index bb131af919029..cc3b4c18e20fd 100644 --- a/data/json/player_activities.json +++ b/data/json/player_activities.json @@ -1077,5 +1077,13 @@ "interruptable": false, "suspendable": false, "interruptable_with_kb": false + }, + { + "id": "ACT_RUMMAGE_POCKET", + "type": "activity_type", + "activity_level": "NO_EXERCISE", + "verb": "rummaging pocket", + "based_on": "speed", + "no_resume": true } ] diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index 7c34bc7225369..f57fd5ce05962 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -29,6 +29,7 @@ #include "creature_tracker.h" #include "debug.h" #include "enums.h" +#include "enum_conversions.h" #include "event.h" #include "event_bus.h" #include "field_type.h" @@ -116,6 +117,7 @@ static const activity_id ACT_PLAY_WITH_PET( "ACT_PLAY_WITH_PET" ); static const activity_id ACT_PRYING( "ACT_PRYING" ); static const activity_id ACT_READ( "ACT_READ" ); static const activity_id ACT_RELOAD( "ACT_RELOAD" ); +static const activity_id ACT_RUMMAGE_POCKET( "ACT_RUMMAGE_POCKET" ); static const activity_id ACT_SHAVE( "ACT_SHAVE" ); static const activity_id ACT_SHEARING( "ACT_SHEARING" ); static const activity_id ACT_STASH( "ACT_STASH" ); @@ -5194,6 +5196,132 @@ std::unique_ptr haircut_activity_actor::deserialize( JsonValue & return haircut_activity_actor().clone(); } +void rummage_activity_actor::start( player_activity &act, Character &who ) +{ + /*int moves = item_loc.obtain_cost( who );*/ + int moves = 0; + for( drop_location i_loc : item_loc ) { + moves += i_loc.first.obtain_cost( who ); + } + act.moves_total = moves; + act.moves_left = moves; +} + +void rummage_activity_actor::do_turn( player_activity &act, Character &who ) +{ + who.add_msg_if_player( _( "You rummage your pockets for the item" ) ); +} + +void rummage_activity_actor::finish( player_activity &act, Character &who ) +{ + who.add_msg_if_player( m_good, _( "You rummaged your pockets to find the item" ) ); + // some function calls in the switch block spawn activities e.g. + // avatar::read spawns an ACT_READ activity, so we need to set + // this one to null before calling them + act.set_to_null(); + + switch( kind ) { + case action::activate: { + + return; + } + case action::drop: { + who.drop( item_loc, m_pnt ); + return; + } + case action::eat: { + + return; + } + case action::read: { + avatar &player_character = get_avatar(); + item_location i_loc = item_loc.front().first; + if( i_loc->type->can_use( "learn_spell" ) ) { + item spell_book = *i_loc.get_item(); + spell_book.get_use( "learn_spell" )->call( + player_character, spell_book, spell_book.active, player_character.pos() ); + } else { + player_character.read( i_loc ); + } + return; + } + case action::wear: { + avatar &player_character = get_avatar(); + player_character.wear( item_loc.front().first ); + return; + } + case action::wield: { + avatar &player_character = get_avatar(); + player_character.wield( item_loc.front().first ); + return; + } + default: + debugmsg( "Unexpected action kind in rummage_pocket_activity_actor::finish" ); + return; + } +} + +void rummage_activity_actor::serialize( JsonOut &jsout ) const +{ + jsout.start_object(); + + jsout.member( "item_loc", item_loc ); + jsout.member_as_string( "action", kind ); + jsout.member( "m_pnt", m_pnt ); + + jsout.end_object(); +} + +std::unique_ptr rummage_activity_actor::deserialize( JsonValue &jsin ) +{ + rummage_activity_actor actor( drop_locations{}, action::none, tripoint_zero ); + + JsonObject data = jsin.get_object(); + + data.read( "item_loc", actor.item_loc ); + const action k = data.get_enum_value( "action" ); + actor.kind = k; + data.read( "m_pnt", actor.m_pnt ); + + return actor.clone(); +} + +namespace io +{ +template<> +std::string enum_to_string( + const rummage_activity_actor::action kind ) +{ + switch( kind ) { + case rummage_activity_actor::action::activate: + return "activate"; + case rummage_activity_actor::action::drop: + return "drop"; + case rummage_activity_actor::action::eat: + return "eat"; + case rummage_activity_actor::action::none: + return "none"; + case rummage_activity_actor::action::read: + return "read"; + case rummage_activity_actor::action::wear: + return "wear"; + case rummage_activity_actor::action::wield: + return "wield"; + case rummage_activity_actor::action::last: + break; + } + debugmsg( "Invalid rummage_activity_actor::action" ); + abort(); +} +} //namespace io + +template<> +struct enum_traits { + static constexpr rummage_activity_actor::action last = + rummage_activity_actor::action::last; +}; + + namespace activity_actors { @@ -5234,6 +5362,7 @@ deserialize_functions = { { ACT_PLAY_WITH_PET, &play_with_pet_activity_actor::deserialize }, { ACT_READ, &read_activity_actor::deserialize }, { ACT_RELOAD, &reload_activity_actor::deserialize }, + { ACT_RUMMAGE_POCKET, &rummage_activity_actor::deserialize }, { ACT_SHAVE, &shave_activity_actor::deserialize }, { ACT_SHEARING, &shearing_activity_actor::deserialize }, { ACT_STASH, &stash_activity_actor::deserialize }, diff --git a/src/activity_actor_definitions.h b/src/activity_actor_definitions.h index 45b12d33392ac..55e5b78bc147e 100644 --- a/src/activity_actor_definitions.h +++ b/src/activity_actor_definitions.h @@ -1571,4 +1571,47 @@ class haircut_activity_actor : public activity_actor static std::unique_ptr deserialize( JsonValue & ); }; +class rummage_activity_actor : public activity_actor +{ + + public: + enum class action : int { + activate, + drop, + eat, + none, + read, + wear, + wield, + last + }; + using item_locations = drop_locations; + + private: + item_locations item_loc; + action kind; + tripoint m_pnt; + + public: + rummage_activity_actor() = default; + rummage_activity_actor( const item_location &i_loc, action act_kind ) + : item_loc( { std::make_pair( i_loc, i_loc->count() ) } ), kind( act_kind ) {} + rummage_activity_actor( const drop_locations &drop_loc, action act_kind, + const tripoint &pnt = tripoint_zero ) + : item_loc( drop_loc ), kind( act_kind ), m_pnt( pnt ) {} + activity_id get_type() const override { + return activity_id( "ACT_RUMMAGE_POCKET" ); + } + + void start( player_activity &act, Character & ) override; + void do_turn( player_activity &, Character & ) override; + void finish( player_activity &act, Character &who ) override; + + std::unique_ptr clone() const override { + return std::make_unique( *this ); + } + void serialize( JsonOut & ) const override; + static std::unique_ptr deserialize( JsonValue & ); +}; + #endif // CATA_SRC_ACTIVITY_ACTOR_DEFINITIONS_H From 4ce82ebf0df103eb10c49a4df262659562127cf4 Mon Sep 17 00:00:00 2001 From: NotGura Date: Mon, 22 Nov 2021 11:54:37 -0300 Subject: [PATCH 02/11] Work for the 'a'ctivate action case --- src/activity_actor.cpp | 4 +++- src/avatar_action.cpp | 9 +++++++-- src/game.cpp | 8 +++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index f57fd5ce05962..3abdb684b963b 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -5222,7 +5222,8 @@ void rummage_activity_actor::finish( player_activity &act, Character &who ) switch( kind ) { case action::activate: { - + avatar &player_character = get_avatar(); + avatar_action::use_item( player_character, item_loc.front().first ); return; } case action::drop: { @@ -5236,6 +5237,7 @@ void rummage_activity_actor::finish( player_activity &act, Character &who ) case action::read: { avatar &player_character = get_avatar(); item_location i_loc = item_loc.front().first; + if( i_loc->type->can_use( "learn_spell" ) ) { item spell_book = *i_loc.get_item(); spell_book.get_use( "learn_spell" )->call( diff --git a/src/avatar_action.cpp b/src/avatar_action.cpp index fac065c63d43d..510f160316864 100644 --- a/src/avatar_action.cpp +++ b/src/avatar_action.cpp @@ -1080,8 +1080,13 @@ static void update_lum( item_location loc, bool add ) void avatar_action::use_item( avatar &you ) { - item_location loc; - avatar_action::use_item( you, loc ); + item_location loc = game_menus::inv::use( you ); + if( loc.where() == item_location::type::container ) { + you.assign_activity( player_activity( rummage_activity_actor( loc, + rummage_activity_actor::action::activate ) ) ); + } else { + avatar_action::use_item( you, loc ); + } } void avatar_action::use_item( avatar &you, item_location &loc ) diff --git a/src/game.cpp b/src/game.cpp index 1af6c631cf1d3..640d924c33e7a 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1886,7 +1886,13 @@ int game::inventory_item_menu( item_location locThisItem, if( locThisItem.get_item()->type->has_use() && !locThisItem.get_item()->item_has_uses_recursive( true ) ) { // Item has uses and none of its contents (if any) has uses. - avatar_action::use_item( u, locThisItem ); + + if( locThisItem.where() == item_location::type::container ) { + u.assign_activity( player_activity( rummage_activity_actor( locThisItem, + rummage_activity_actor::action::activate ) ) ); + } else { + avatar_action::use_item( u, locThisItem ); + } } else if( locThisItem.get_item()->item_has_uses_recursive() ) { game::item_action_menu( locThisItem ); } else { From 5ae81bf09ac13caa5d95fd3e6b94020cf76b70a7 Mon Sep 17 00:00:00 2001 From: NotGura Date: Mon, 22 Nov 2021 14:22:44 -0300 Subject: [PATCH 03/11] Work for the 'E'at action case --- src/activity_actor.cpp | 3 ++- src/game.cpp | 8 +++++++- src/handle_action.cpp | 8 +++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index 3abdb684b963b..67dedeb7e69e9 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -5231,7 +5231,8 @@ void rummage_activity_actor::finish( player_activity &act, Character &who ) return; } case action::eat: { - + avatar& player_character = get_avatar(); + avatar_action::eat(player_character, item_loc.front().first); return; } case action::read: { diff --git a/src/game.cpp b/src/game.cpp index 640d924c33e7a..5d3d5abb9d58f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1904,7 +1904,13 @@ int game::inventory_item_menu( item_location locThisItem, } case 'E': if( !locThisItem.get_item()->is_container() ) { - avatar_action::eat( u, locThisItem ); + if( locThisItem.where() == item_location::type::container ) { + u.assign_activity( player_activity( rummage_activity_actor( locThisItem, + rummage_activity_actor::action::eat ) ) ) + ; + } else { + avatar_action::eat( u, locThisItem ); + } } else { avatar_action::eat( u, game_menus::inv::consume( u, locThisItem ) ); } diff --git a/src/handle_action.cpp b/src/handle_action.cpp index 6563a9743b1bc..75bffe94d61f0 100644 --- a/src/handle_action.cpp +++ b/src/handle_action.cpp @@ -2111,7 +2111,13 @@ bool game::do_regular_action( action_id &act, avatar &player_character, case ACTION_EAT: if( !avatar_action::eat_here( player_character ) ) { - avatar_action::eat( player_character, game_menus::inv::consume( player_character ) ); + item_location loc = game_menus::inv::consume( player_character ); + if( loc.where() == item_location::type::container ) { + u.assign_activity( player_activity( rummage_activity_actor( loc, + rummage_activity_actor::action::eat ) ) ); + } else { + avatar_action::eat( player_character, loc ); + } } break; From b8dbc491a9f364d589ed582f11570cd71bff7ab9 Mon Sep 17 00:00:00 2001 From: NotGura Date: Mon, 22 Nov 2021 14:43:32 -0300 Subject: [PATCH 04/11] Work for 'R'ead action case --- src/game.cpp | 10 ++++++++-- src/handle_action.cpp | 18 ++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 5d3d5abb9d58f..307163f851fdc 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1960,9 +1960,15 @@ int game::inventory_item_menu( item_location locThisItem, case 'm': avatar_action::mend( u, locThisItem ); break; - case 'R': - u.read( locThisItem ); + case 'R': { + if( locThisItem.where() == item_location::type::container ) { + u.assign_activity( player_activity( rummage_activity_actor( locThisItem, + rummage_activity_actor::action::read ) ) ); + } else { + u.read( locThisItem ); + } break; + } case 'D': u.disassemble( locThisItem, false ); break; diff --git a/src/handle_action.cpp b/src/handle_action.cpp index 75bffe94d61f0..37c07fd46bf74 100644 --- a/src/handle_action.cpp +++ b/src/handle_action.cpp @@ -1338,13 +1338,19 @@ static void read() item_location loc = game_menus::inv::read( player_character ); if( loc ) { - if( loc->type->can_use( "learn_spell" ) ) { - item spell_book = *loc.get_item(); - spell_book.get_use( "learn_spell" )->call( player_character, spell_book, - spell_book.active, player_character.pos() ); + if( loc.where() == item_location::type::container ) { + player_character.assign_activity( player_activity( rummage_activity_actor( + loc, rummage_activity_actor::action::read + ) ) ); } else { - loc = loc.obtain( player_character ); - player_character.read( loc ); + if( loc->type->can_use( "learn_spell" ) ) { + item spell_book = *loc.get_item(); + spell_book.get_use( "learn_spell" )->call( player_character, spell_book, spell_book.active, + player_character.pos() ); + } else { + loc = loc.obtain( player_character ); + player_character.read( loc ); + } } } else { add_msg( _( "Never mind." ) ); From 43515cfdd99d2fbe7d1f7d8235c2bcbd42717dc6 Mon Sep 17 00:00:00 2001 From: NotGura Date: Mon, 22 Nov 2021 14:56:11 -0300 Subject: [PATCH 05/11] Work for 'W'ear action case --- src/game.cpp | 7 ++++++- src/handle_action.cpp | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 307163f851fdc..c3e4cd191886f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1918,7 +1918,12 @@ int game::inventory_item_menu( item_location locThisItem, case 'W': { contents_change_handler handler; handler.unseal_pocket_containing( locThisItem ); - u.wear( locThisItem ); + if( locThisItem.where() == item_location::type::container ) { + u.assign_activity( player_activity( rummage_activity_actor( locThisItem, + rummage_activity_actor::action::wear ) ) ); + } else { + u.wear( locThisItem ); + } handler.handle_by( u ); break; } diff --git a/src/handle_action.cpp b/src/handle_action.cpp index 37c07fd46bf74..623f5f7566a17 100644 --- a/src/handle_action.cpp +++ b/src/handle_action.cpp @@ -1313,7 +1313,12 @@ static void wear() item_location loc = game_menus::inv::wear( player_character ); if( loc ) { - player_character.wear( loc ); + if( loc.where() == item_location::type::container ) { + player_character.assign_activity( player_activity( rummage_activity_actor( loc, + rummage_activity_actor::action::wear ) ) ); + } else { + player_character.wear( loc ); + } } else { add_msg( _( "Never mind." ) ); } From 0c9f1f1648135196d14dafdcc2cffdd790e52f26 Mon Sep 17 00:00:00 2001 From: NotGura Date: Mon, 22 Nov 2021 15:05:49 -0300 Subject: [PATCH 06/11] Work for 'w'ield action case --- src/game.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index c3e4cd191886f..e85f8a02b7fd9 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1931,7 +1931,12 @@ int game::inventory_item_menu( item_location locThisItem, if( u.can_wield( *locThisItem ).success() ) { contents_change_handler handler; handler.unseal_pocket_containing( locThisItem ); - wield( locThisItem ); + if( locThisItem.where() == item_location::type::container ) { + u.assign_activity( player_activity( rummage_activity_actor( locThisItem, + rummage_activity_actor::action::wield ) ) ); + } else { + wield( locThisItem ); + } handler.handle_by( u ); } else { add_msg( m_info, "%s", u.can_wield( *locThisItem ).c_str() ); @@ -8761,7 +8766,12 @@ void game::wield() item_location loc = game_menus::inv::wield( u ); if( loc ) { - wield( loc ); + if( loc.where() == item_location::type::container ) { + u.assign_activity( player_activity( rummage_activity_actor( loc, + rummage_activity_actor::action::wield ) ) ); + } else { + wield( loc ); + } } else { add_msg( _( "Never mind." ) ); } From 1db92c7561516f365936e0bfe762ad0279d8b436 Mon Sep 17 00:00:00 2001 From: NotGura Date: Mon, 22 Nov 2021 15:59:13 -0300 Subject: [PATCH 07/11] Work for 'd'rop action case --- src/activity_actor.cpp | 20 ++++++++++++++++---- src/activity_actor_definitions.h | 4 ++-- src/game.cpp | 22 +++++++++++++++++++--- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index 67dedeb7e69e9..a59701a50897b 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -5196,12 +5196,24 @@ std::unique_ptr haircut_activity_actor::deserialize( JsonValue & return haircut_activity_actor().clone(); } +bool item_is_in_container(const item_location& item_loc) +{ + return item_loc.where() == item_location::type::container; +} + void rummage_activity_actor::start( player_activity &act, Character &who ) { /*int moves = item_loc.obtain_cost( who );*/ int moves = 0; - for( drop_location i_loc : item_loc ) { - moves += i_loc.first.obtain_cost( who ); + if( kind == action::drop ) { + for( drop_location i_loc : item_loc ) { + //Only add the move cost for items inside a container + if( i_loc.first.where() == item_location::type::container ) { + moves += i_loc.first.obtain_cost( who ); + } + } + } else { + moves += item_loc.front().first.obtain_cost( who ); } act.moves_total = moves; act.moves_left = moves; @@ -5231,8 +5243,8 @@ void rummage_activity_actor::finish( player_activity &act, Character &who ) return; } case action::eat: { - avatar& player_character = get_avatar(); - avatar_action::eat(player_character, item_loc.front().first); + avatar &player_character = get_avatar(); + avatar_action::eat( player_character, item_loc.front().first ); return; } case action::read: { diff --git a/src/activity_actor_definitions.h b/src/activity_actor_definitions.h index 55e5b78bc147e..79b3744848a58 100644 --- a/src/activity_actor_definitions.h +++ b/src/activity_actor_definitions.h @@ -1594,8 +1594,8 @@ class rummage_activity_actor : public activity_actor public: rummage_activity_actor() = default; - rummage_activity_actor( const item_location &i_loc, action act_kind ) - : item_loc( { std::make_pair( i_loc, i_loc->count() ) } ), kind( act_kind ) {} + rummage_activity_actor( const item_location &i_loc, action act_kind, const tripoint &pnt = tripoint_zero ) + : item_loc( { std::make_pair( i_loc, i_loc->count() ) } ), kind( act_kind ), m_pnt(pnt) {} rummage_activity_actor( const drop_locations &drop_loc, action act_kind, const tripoint &pnt = tripoint_zero ) : item_loc( drop_loc ), kind( act_kind ), m_pnt( pnt ) {} diff --git a/src/game.cpp b/src/game.cpp index e85f8a02b7fd9..087a4d38d93c8 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -284,6 +284,8 @@ static const trap_str_id tr_unfinished_construction( "tr_unfinished_construction static const zone_type_id zone_type_LOOT_CUSTOM( "LOOT_CUSTOM" ); static const zone_type_id zone_type_NO_AUTO_PICKUP( "NO_AUTO_PICKUP" ); +bool item_is_in_container(const item_location&); + #if defined(TILES) #include "cata_tiles.h" #endif // TILES @@ -1955,9 +1957,15 @@ int game::inventory_item_menu( item_location locThisItem, case 'T': u.takeoff( locThisItem ); break; - case 'd': - u.drop( locThisItem, u.pos() ); + case 'd': { + if( item_is_in_container( locThisItem ) ) { + u.assign_activity( player_activity( rummage_activity_actor( locThisItem, + rummage_activity_actor::action::drop, u.pos() ) ) ); + } else { + u.drop( locThisItem, u.pos() ); + } break; + } case 'U': u.unload( locThisItem ); break; @@ -7920,7 +7928,15 @@ void game::unload_container() void game::drop_in_direction( const tripoint &pnt ) { - u.drop( game_menus::inv::multidrop( u ), pnt ); + drop_locations drop_loc = game_menus::inv::multidrop( u ); + for( drop_location d_loc : drop_loc ) { + if( item_is_in_container( d_loc.first ) ) { + u.assign_activity( player_activity( rummage_activity_actor( drop_loc, + rummage_activity_actor::action::drop, pnt ) ) ); + return; + } + } + u.drop( drop_loc, pnt ); } // Used to set up the first Hotkey in the display set From a78d0733b8f404addfb1130183e3c1f94820e72a Mon Sep 17 00:00:00 2001 From: NotGura Date: Tue, 23 Nov 2021 10:21:31 -0300 Subject: [PATCH 08/11] Clean up with item_is_in_container function and final touches --- src/activity_actor.cpp | 6 ++---- src/game.cpp | 12 ++++++------ src/handle_action.cpp | 8 +++++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index a59701a50897b..436dc0b02c6af 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -5196,19 +5196,18 @@ std::unique_ptr haircut_activity_actor::deserialize( JsonValue & return haircut_activity_actor().clone(); } -bool item_is_in_container(const item_location& item_loc) +bool item_is_in_container( const item_location &item_loc ) { return item_loc.where() == item_location::type::container; } void rummage_activity_actor::start( player_activity &act, Character &who ) { - /*int moves = item_loc.obtain_cost( who );*/ int moves = 0; if( kind == action::drop ) { for( drop_location i_loc : item_loc ) { //Only add the move cost for items inside a container - if( i_loc.first.where() == item_location::type::container ) { + if( item_is_in_container( i_loc.first ) ) { moves += i_loc.first.obtain_cost( who ); } } @@ -5221,7 +5220,6 @@ void rummage_activity_actor::start( player_activity &act, Character &who ) void rummage_activity_actor::do_turn( player_activity &act, Character &who ) { - who.add_msg_if_player( _( "You rummage your pockets for the item" ) ); } void rummage_activity_actor::finish( player_activity &act, Character &who ) diff --git a/src/game.cpp b/src/game.cpp index 087a4d38d93c8..4896dadc802bd 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -284,7 +284,7 @@ static const trap_str_id tr_unfinished_construction( "tr_unfinished_construction static const zone_type_id zone_type_LOOT_CUSTOM( "LOOT_CUSTOM" ); static const zone_type_id zone_type_NO_AUTO_PICKUP( "NO_AUTO_PICKUP" ); -bool item_is_in_container(const item_location&); +bool item_is_in_container( const item_location & ); #if defined(TILES) #include "cata_tiles.h" @@ -1889,7 +1889,7 @@ int game::inventory_item_menu( item_location locThisItem, !locThisItem.get_item()->item_has_uses_recursive( true ) ) { // Item has uses and none of its contents (if any) has uses. - if( locThisItem.where() == item_location::type::container ) { + if( item_is_in_container( locThisItem ) ) { u.assign_activity( player_activity( rummage_activity_actor( locThisItem, rummage_activity_actor::action::activate ) ) ); } else { @@ -1906,7 +1906,7 @@ int game::inventory_item_menu( item_location locThisItem, } case 'E': if( !locThisItem.get_item()->is_container() ) { - if( locThisItem.where() == item_location::type::container ) { + if( item_is_in_container( locThisItem ) ) { u.assign_activity( player_activity( rummage_activity_actor( locThisItem, rummage_activity_actor::action::eat ) ) ) ; @@ -1920,7 +1920,7 @@ int game::inventory_item_menu( item_location locThisItem, case 'W': { contents_change_handler handler; handler.unseal_pocket_containing( locThisItem ); - if( locThisItem.where() == item_location::type::container ) { + if( item_is_in_container( locThisItem ) ) { u.assign_activity( player_activity( rummage_activity_actor( locThisItem, rummage_activity_actor::action::wear ) ) ); } else { @@ -1933,7 +1933,7 @@ int game::inventory_item_menu( item_location locThisItem, if( u.can_wield( *locThisItem ).success() ) { contents_change_handler handler; handler.unseal_pocket_containing( locThisItem ); - if( locThisItem.where() == item_location::type::container ) { + if( item_is_in_container( locThisItem ) ) { u.assign_activity( player_activity( rummage_activity_actor( locThisItem, rummage_activity_actor::action::wield ) ) ); } else { @@ -1979,7 +1979,7 @@ int game::inventory_item_menu( item_location locThisItem, avatar_action::mend( u, locThisItem ); break; case 'R': { - if( locThisItem.where() == item_location::type::container ) { + if( item_is_in_container( locThisItem ) ) { u.assign_activity( player_activity( rummage_activity_actor( locThisItem, rummage_activity_actor::action::read ) ) ); } else { diff --git a/src/handle_action.cpp b/src/handle_action.cpp index 623f5f7566a17..a3873df727e0c 100644 --- a/src/handle_action.cpp +++ b/src/handle_action.cpp @@ -148,6 +148,8 @@ static const zone_type_id zone_type_VEHICLE_DECONSTRUCT( "VEHICLE_DECONSTRUCT" ) static const zone_type_id zone_type_VEHICLE_REPAIR( "VEHICLE_REPAIR" ); static const zone_type_id zone_type_zone_disassemble( "zone_disassemble" ); +bool item_is_in_container( const item_location & ); + #define dbg(x) DebugLog((x),D_GAME) << __FILE__ << ":" << __LINE__ << ": " #if defined(__ANDROID__) @@ -1313,7 +1315,7 @@ static void wear() item_location loc = game_menus::inv::wear( player_character ); if( loc ) { - if( loc.where() == item_location::type::container ) { + if( item_is_in_container( loc ) ) { player_character.assign_activity( player_activity( rummage_activity_actor( loc, rummage_activity_actor::action::wear ) ) ); } else { @@ -1343,7 +1345,7 @@ static void read() item_location loc = game_menus::inv::read( player_character ); if( loc ) { - if( loc.where() == item_location::type::container ) { + if( item_is_in_container( loc ) ) { player_character.assign_activity( player_activity( rummage_activity_actor( loc, rummage_activity_actor::action::read ) ) ); @@ -2123,7 +2125,7 @@ bool game::do_regular_action( action_id &act, avatar &player_character, case ACTION_EAT: if( !avatar_action::eat_here( player_character ) ) { item_location loc = game_menus::inv::consume( player_character ); - if( loc.where() == item_location::type::container ) { + if( item_is_in_container( loc ) ) { u.assign_activity( player_activity( rummage_activity_actor( loc, rummage_activity_actor::action::eat ) ) ); } else { From 5ed2438ef355b48255bf82c6b22acfb57e1dcbc5 Mon Sep 17 00:00:00 2001 From: NotGura Date: Tue, 23 Nov 2021 14:29:24 -0300 Subject: [PATCH 09/11] Astyle and Jsonlint --- data/json/player_activities.json | 4 ++-- src/activity_actor_definitions.h | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/data/json/player_activities.json b/data/json/player_activities.json index cc3b4c18e20fd..4301ab3d826e7 100644 --- a/data/json/player_activities.json +++ b/data/json/player_activities.json @@ -1077,9 +1077,9 @@ "interruptable": false, "suspendable": false, "interruptable_with_kb": false - }, + }, { - "id": "ACT_RUMMAGE_POCKET", + "id": "ACT_RUMMAGE_POCKET", "type": "activity_type", "activity_level": "NO_EXERCISE", "verb": "rummaging pocket", diff --git a/src/activity_actor_definitions.h b/src/activity_actor_definitions.h index 79b3744848a58..ac1cf9f49b674 100644 --- a/src/activity_actor_definitions.h +++ b/src/activity_actor_definitions.h @@ -1594,8 +1594,9 @@ class rummage_activity_actor : public activity_actor public: rummage_activity_actor() = default; - rummage_activity_actor( const item_location &i_loc, action act_kind, const tripoint &pnt = tripoint_zero ) - : item_loc( { std::make_pair( i_loc, i_loc->count() ) } ), kind( act_kind ), m_pnt(pnt) {} + rummage_activity_actor( const item_location &i_loc, action act_kind, + const tripoint &pnt = tripoint_zero ) + : item_loc( { std::make_pair( i_loc, i_loc->count() ) } ), kind( act_kind ), m_pnt( pnt ) {} rummage_activity_actor( const drop_locations &drop_loc, action act_kind, const tripoint &pnt = tripoint_zero ) : item_loc( drop_loc ), kind( act_kind ), m_pnt( pnt ) {} From 0cb37ee835ad15703606f7140d1d7542bc750195 Mon Sep 17 00:00:00 2001 From: NotGura Date: Wed, 24 Nov 2021 11:52:50 -0300 Subject: [PATCH 10/11] Fix build errors --- src/activity_actor.cpp | 13 ++++--------- src/game.cpp | 18 ++++++++---------- src/handle_action.cpp | 8 +++----- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index 436dc0b02c6af..3972129154a55 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -5196,18 +5196,13 @@ std::unique_ptr haircut_activity_actor::deserialize( JsonValue & return haircut_activity_actor().clone(); } -bool item_is_in_container( const item_location &item_loc ) -{ - return item_loc.where() == item_location::type::container; -} - void rummage_activity_actor::start( player_activity &act, Character &who ) { int moves = 0; if( kind == action::drop ) { - for( drop_location i_loc : item_loc ) { + for( const drop_location &i_loc : item_loc ) { //Only add the move cost for items inside a container - if( item_is_in_container( i_loc.first ) ) { + if( i_loc.first.where() == item_location::type::container ) { moves += i_loc.first.obtain_cost( who ); } } @@ -5218,7 +5213,7 @@ void rummage_activity_actor::start( player_activity &act, Character &who ) act.moves_left = moves; } -void rummage_activity_actor::do_turn( player_activity &act, Character &who ) +void rummage_activity_actor::do_turn( player_activity &/*act*/, Character & /*who*/ ) { } @@ -5324,7 +5319,7 @@ std::string enum_to_string( break; } debugmsg( "Invalid rummage_activity_actor::action" ); - abort(); + cata_fatal( "Invalid rummage_activity_actor::action" ); } } //namespace io diff --git a/src/game.cpp b/src/game.cpp index 4896dadc802bd..d3879a0d9ad9f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -284,8 +284,6 @@ static const trap_str_id tr_unfinished_construction( "tr_unfinished_construction static const zone_type_id zone_type_LOOT_CUSTOM( "LOOT_CUSTOM" ); static const zone_type_id zone_type_NO_AUTO_PICKUP( "NO_AUTO_PICKUP" ); -bool item_is_in_container( const item_location & ); - #if defined(TILES) #include "cata_tiles.h" #endif // TILES @@ -1889,7 +1887,7 @@ int game::inventory_item_menu( item_location locThisItem, !locThisItem.get_item()->item_has_uses_recursive( true ) ) { // Item has uses and none of its contents (if any) has uses. - if( item_is_in_container( locThisItem ) ) { + if( locThisItem.where() == item_location::type::container ) { u.assign_activity( player_activity( rummage_activity_actor( locThisItem, rummage_activity_actor::action::activate ) ) ); } else { @@ -1906,7 +1904,7 @@ int game::inventory_item_menu( item_location locThisItem, } case 'E': if( !locThisItem.get_item()->is_container() ) { - if( item_is_in_container( locThisItem ) ) { + if( locThisItem.where() == item_location::type::container ) { u.assign_activity( player_activity( rummage_activity_actor( locThisItem, rummage_activity_actor::action::eat ) ) ) ; @@ -1920,7 +1918,7 @@ int game::inventory_item_menu( item_location locThisItem, case 'W': { contents_change_handler handler; handler.unseal_pocket_containing( locThisItem ); - if( item_is_in_container( locThisItem ) ) { + if( locThisItem.where() == item_location::type::container ) { u.assign_activity( player_activity( rummage_activity_actor( locThisItem, rummage_activity_actor::action::wear ) ) ); } else { @@ -1933,7 +1931,7 @@ int game::inventory_item_menu( item_location locThisItem, if( u.can_wield( *locThisItem ).success() ) { contents_change_handler handler; handler.unseal_pocket_containing( locThisItem ); - if( item_is_in_container( locThisItem ) ) { + if( locThisItem.where() == item_location::type::container ) { u.assign_activity( player_activity( rummage_activity_actor( locThisItem, rummage_activity_actor::action::wield ) ) ); } else { @@ -1958,7 +1956,7 @@ int game::inventory_item_menu( item_location locThisItem, u.takeoff( locThisItem ); break; case 'd': { - if( item_is_in_container( locThisItem ) ) { + if( locThisItem.where() == item_location::type::container ) { u.assign_activity( player_activity( rummage_activity_actor( locThisItem, rummage_activity_actor::action::drop, u.pos() ) ) ); } else { @@ -1979,7 +1977,7 @@ int game::inventory_item_menu( item_location locThisItem, avatar_action::mend( u, locThisItem ); break; case 'R': { - if( item_is_in_container( locThisItem ) ) { + if( locThisItem.where() == item_location::type::container ) { u.assign_activity( player_activity( rummage_activity_actor( locThisItem, rummage_activity_actor::action::read ) ) ); } else { @@ -7929,8 +7927,8 @@ void game::unload_container() void game::drop_in_direction( const tripoint &pnt ) { drop_locations drop_loc = game_menus::inv::multidrop( u ); - for( drop_location d_loc : drop_loc ) { - if( item_is_in_container( d_loc.first ) ) { + for( const drop_location &d_loc : drop_loc ) { + if( d_loc.first.where() == item_location::type::container ) { u.assign_activity( player_activity( rummage_activity_actor( drop_loc, rummage_activity_actor::action::drop, pnt ) ) ); return; diff --git a/src/handle_action.cpp b/src/handle_action.cpp index a3873df727e0c..623f5f7566a17 100644 --- a/src/handle_action.cpp +++ b/src/handle_action.cpp @@ -148,8 +148,6 @@ static const zone_type_id zone_type_VEHICLE_DECONSTRUCT( "VEHICLE_DECONSTRUCT" ) static const zone_type_id zone_type_VEHICLE_REPAIR( "VEHICLE_REPAIR" ); static const zone_type_id zone_type_zone_disassemble( "zone_disassemble" ); -bool item_is_in_container( const item_location & ); - #define dbg(x) DebugLog((x),D_GAME) << __FILE__ << ":" << __LINE__ << ": " #if defined(__ANDROID__) @@ -1315,7 +1313,7 @@ static void wear() item_location loc = game_menus::inv::wear( player_character ); if( loc ) { - if( item_is_in_container( loc ) ) { + if( loc.where() == item_location::type::container ) { player_character.assign_activity( player_activity( rummage_activity_actor( loc, rummage_activity_actor::action::wear ) ) ); } else { @@ -1345,7 +1343,7 @@ static void read() item_location loc = game_menus::inv::read( player_character ); if( loc ) { - if( item_is_in_container( loc ) ) { + if( loc.where() == item_location::type::container ) { player_character.assign_activity( player_activity( rummage_activity_actor( loc, rummage_activity_actor::action::read ) ) ); @@ -2125,7 +2123,7 @@ bool game::do_regular_action( action_id &act, avatar &player_character, case ACTION_EAT: if( !avatar_action::eat_here( player_character ) ) { item_location loc = game_menus::inv::consume( player_character ); - if( item_is_in_container( loc ) ) { + if( loc.where() == item_location::type::container ) { u.assign_activity( player_activity( rummage_activity_actor( loc, rummage_activity_actor::action::eat ) ) ); } else { From 4bd5b2fc20c4b23b024362420e9cba4460b45217 Mon Sep 17 00:00:00 2001 From: NotGura Date: Mon, 29 Nov 2021 15:21:11 -0300 Subject: [PATCH 11/11] Blank