Skip to content

Commit

Permalink
Allow harvestable plants to be autoforaged (#52207)
Browse files Browse the repository at this point in the history
  • Loading branch information
dseguin authored Oct 10, 2021
1 parent 1060d48 commit a0cdf82
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
},
Expand Down Expand Up @@ -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 ] },
Expand Down
6 changes: 4 additions & 2 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) ||
Expand All @@ -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 );
}
Expand Down
17 changes: 13 additions & 4 deletions src/iexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>( "AUTO_FEATURES" ) &&
get_option<std::string>( "AUTO_FORAGING" ) == "both";
get_option<std::string>( "AUTO_FORAGING" ) == "all";
if( !auto_forage && !query_pick( you, examp ) ) {
return;
}
Expand All @@ -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<bool>( "AUTO_FEATURES" ) &&
( get_option<std::string>( "AUTO_FORAGING" ) == "both" ||
( get_option<std::string>( "AUTO_FORAGING" ) == "all" ||
get_option<std::string>( "AUTO_FORAGING" ) == "bushes" ||
get_option<std::string>( "AUTO_FORAGING" ) == "trees" );
if( !auto_forage && !query_pick( you, examp ) ) {
Expand All @@ -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<bool>( "AUTO_FEATURES" ) &&
( get_option<std::string>( "AUTO_FORAGING" ) == "both" ||
( get_option<std::string>( "AUTO_FORAGING" ) == "all" ||
get_option<std::string>( "AUTO_FORAGING" ) == "trees" );
if( !auto_forage && !query_pick( you, examp ) ) {
return;
Expand Down Expand Up @@ -2365,6 +2365,13 @@ std::list<item> 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
*/
Expand Down Expand Up @@ -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<bool>( "AUTO_FEATURES" ) &&
( get_option<std::string>( "AUTO_FORAGING" ) == "both" ||
( get_option<std::string>( "AUTO_FORAGING" ) == "all" ||
get_option<std::string>( "AUTO_FORAGING" ) == "trees" );

bool digging_up = false;
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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 );
Expand Down
3 changes: 2 additions & 1 deletion src/iexamine.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ std::list<item> get_harvest_items( const itype &type, int plant_count,
std::vector<seed_tuple> get_seed_entries( const std::vector<item *> &seed_inv );
int query_seed( const std::vector<seed_tuple> &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<bool> can_fertilize( Character &you, const tripoint &tile, const itype_id &fertilizer );
Expand Down
4 changes: 2 additions & 2 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);

Expand Down

0 comments on commit a0cdf82

Please sign in to comment.