From a0cdf82bf08528b9a8664aecb33622991752d6a6 Mon Sep 17 00:00:00 2001 From: David Seguin Date: Sun, 10 Oct 2021 13:28:07 -0400 Subject: [PATCH] Allow harvestable plants to be autoforaged (#52207) --- .../furniture-domestic_plants.json | 4 ++-- src/game.cpp | 6 ++++-- src/iexamine.cpp | 17 +++++++++++++---- src/iexamine.h | 3 ++- src/options.cpp | 4 ++-- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/data/json/furniture_and_terrain/furniture-domestic_plants.json b/data/json/furniture_and_terrain/furniture-domestic_plants.json index 37dede65583e7..e77b8d2a701b7 100644 --- a/data/json/furniture_and_terrain/furniture-domestic_plants.json +++ b/data/json/furniture_and_terrain/furniture-domestic_plants.json @@ -81,7 +81,7 @@ "move_cost_mod": 0, "required_str": -1, "flags": [ "PLANT", "SEALED", "TRANSPARENT", "CONTAINER", "NOITEM", "TINY", "DONT_REMOVE_ROTTEN", "GROWTH_HARVEST" ], - "examine_action": "aggie_plant", + "examine_action": "harvest_plant", "bash": { "str_min": 4, "str_max": 10, "sound": "crunch.", "sound_fail": "whish." }, "plant_data": { "transform": "f_null", "base": "f_null" } }, @@ -172,7 +172,7 @@ "move_cost_mod": 0, "required_str": -1, "flags": [ "PLANT", "SEALED", "TRANSPARENT", "CONTAINER", "NOITEM", "TINY", "DONT_REMOVE_ROTTEN", "GROWTH_HARVEST" ], - "examine_action": "aggie_plant", + "examine_action": "harvest_plant", "deconstruct": { "items": [ { "item": "2x4", "count": [ 11, 12 ] }, diff --git a/src/game.cpp b/src/game.cpp index b1076b25d59b6..b124576bc1b45 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -9332,9 +9332,10 @@ point game::place_player( const tripoint &dest_loc ) const auto forage = [&]( const tripoint & pos ) { const ter_t &xter_t = *m.ter( pos ); const furn_t &xfurn_t = *m.furn( pos ); - const bool forage_everything = forage_type == "both"; + const bool forage_everything = forage_type == "all"; const bool forage_bushes = forage_everything || forage_type == "bushes"; const bool forage_trees = forage_everything || forage_type == "trees"; + const bool forage_crops = forage_everything || forage_type == "crops"; if( !xter_t.can_examine( pos ) ) { return; } else if( ( forage_bushes && xter_t.has_examine( iexamine::shrub_marloss ) ) || @@ -9346,7 +9347,8 @@ point game::place_player( const tripoint &dest_loc ) ) { xter_t.examine( u, pos ); } else if( ( forage_everything && xfurn_t.has_examine( iexamine::harvest_furn ) ) || - ( forage_everything && xfurn_t.has_examine( iexamine::harvest_furn_nectar ) ) + ( forage_everything && xfurn_t.has_examine( iexamine::harvest_furn_nectar ) ) || + ( forage_crops && xfurn_t.has_examine( iexamine::harvest_plant ) ) ) { xfurn_t.examine( u, pos ); } diff --git a/src/iexamine.cpp b/src/iexamine.cpp index fec982d312ba4..6abc650880a55 100644 --- a/src/iexamine.cpp +++ b/src/iexamine.cpp @@ -2077,7 +2077,7 @@ void iexamine::harvest_furn_nectar( Character &you, const tripoint &examp ) void iexamine::harvest_furn( Character &you, const tripoint &examp ) { bool auto_forage = get_option( "AUTO_FEATURES" ) && - get_option( "AUTO_FORAGING" ) == "both"; + get_option( "AUTO_FORAGING" ) == "all"; if( !auto_forage && !query_pick( you, examp ) ) { return; } @@ -2087,7 +2087,7 @@ void iexamine::harvest_furn( Character &you, const tripoint &examp ) void iexamine::harvest_ter_nectar( Character &you, const tripoint &examp ) { bool auto_forage = get_option( "AUTO_FEATURES" ) && - ( get_option( "AUTO_FORAGING" ) == "both" || + ( get_option( "AUTO_FORAGING" ) == "all" || get_option( "AUTO_FORAGING" ) == "bushes" || get_option( "AUTO_FORAGING" ) == "trees" ); if( !auto_forage && !query_pick( you, examp ) ) { @@ -2099,7 +2099,7 @@ void iexamine::harvest_ter_nectar( Character &you, const tripoint &examp ) void iexamine::harvest_ter( Character &you, const tripoint &examp ) { bool auto_forage = get_option( "AUTO_FEATURES" ) && - ( get_option( "AUTO_FORAGING" ) == "both" || + ( get_option( "AUTO_FORAGING" ) == "all" || get_option( "AUTO_FORAGING" ) == "trees" ); if( !auto_forage && !query_pick( you, examp ) ) { return; @@ -2365,6 +2365,13 @@ std::list iexamine::get_harvest_items( const itype &type, const int plant_ return result; } +void iexamine::harvest_plant( Character &you, const tripoint &examp ) +{ + if( get_map().has_flag_furn( ter_furn_flag::TFLAG_GROWTH_HARVEST, examp ) ) { + harvest_plant( you, examp, false ); + } +} + /** * Actual harvesting of selected plant */ @@ -3523,7 +3530,7 @@ static void pick_plant( Character &you, const tripoint &examp, void iexamine::tree_hickory( Character &you, const tripoint &examp ) { bool auto_forage = get_option( "AUTO_FEATURES" ) && - ( get_option( "AUTO_FORAGING" ) == "both" || + ( get_option( "AUTO_FORAGING" ) == "all" || get_option( "AUTO_FORAGING" ) == "trees" ); bool digging_up = false; @@ -6267,6 +6274,7 @@ iexamine_functions iexamine_functions_from_string( const std::string &function_n { "harvest_furn", &iexamine::harvest_furn }, { "harvest_ter_nectar", &iexamine::harvest_ter_nectar }, { "harvest_ter", &iexamine::harvest_ter }, + { "harvest_plant", &iexamine::harvest_plant }, { "harvested_plant", &iexamine::harvested_plant }, { "shrub_marloss", &iexamine::shrub_marloss }, { "translocator", &iexamine::translocator }, @@ -6307,6 +6315,7 @@ iexamine_functions iexamine_functions_from_string( const std::string &function_n "harvest_furn", "harvest_ter_nectar", "harvest_ter", + "harvest_plant", }; auto iter = function_map.find( function_name ); diff --git a/src/iexamine.h b/src/iexamine.h index 71c9088b009dd..18235c6b4d94c 100644 --- a/src/iexamine.h +++ b/src/iexamine.h @@ -151,7 +151,8 @@ std::list get_harvest_items( const itype &type, int plant_count, std::vector get_seed_entries( const std::vector &seed_inv ); int query_seed( const std::vector &seed_entries ); void plant_seed( Character &you, const tripoint &examp, const itype_id &seed_id ); -void harvest_plant( Character &you, const tripoint &examp, bool from_activity = false ); +void harvest_plant( Character &you, const tripoint &examp ); +void harvest_plant( Character &you, const tripoint &examp, bool from_activity ); void fertilize_plant( Character &you, const tripoint &tile, const itype_id &fertilizer ); itype_id choose_fertilizer( Character &you, const std::string &pname, bool ask_player ); ret_val can_fertilize( Character &you, const tripoint &tile, const itype_id &fertilizer ); diff --git a/src/options.cpp b/src/options.cpp index 3cca62749d1ac..ac7aca301f1e2 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -1219,8 +1219,8 @@ void options_manager::add_options_general() get_option( "AUTO_MINING" ).setPrerequisite( "AUTO_FEATURES" ); add( "AUTO_FORAGING", "general", to_translation( "Auto foraging" ), - to_translation( "Action to perform when 'Auto foraging' is enabled. Bushes: Only forage bushes. - Trees: Only forage trees. - Everything: Forage bushes, trees, and everything else including flowers, cattails etc." ), - { { "off", to_translation( "options", "Disabled" ) }, { "bushes", to_translation( "Bushes" ) }, { "trees", to_translation( "Trees" ) }, { "both", to_translation( "Everything" ) } }, + to_translation( "Action to perform when 'Auto foraging' is enabled. Bushes: Only forage bushes. - Trees: Only forage trees. - Crops: Only forage crops. - Everything: Forage bushes, trees, crops, and everything else including flowers, cattails etc." ), + { { "off", to_translation( "options", "Disabled" ) }, { "bushes", to_translation( "Bushes" ) }, { "trees", to_translation( "Trees" ) }, { "crops", to_translation( "Crops" ) }, { "all", to_translation( "Everything" ) } }, "off" );