Skip to content

Commit

Permalink
Butchering use best tool in crafting radius (CleverRaven#48930)
Browse files Browse the repository at this point in the history
* max_quality with radius
* butchering get best tool
* use max_quality visitable function
  • Loading branch information
Saicchi committed Jul 19, 2021
1 parent 3c14227 commit fa71f58
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/action.cpp
Expand Up @@ -599,8 +599,8 @@ bool can_butcher_at( const tripoint &p )
{
Character &player_character = get_player_character();
// TODO: unify this with game::butcher
const int factor = player_character.max_quality( qual_BUTCHER );
const int factorD = player_character.max_quality( qual_CUT_FINE );
const int factor = player_character.max_quality( qual_BUTCHER, PICKUP_RANGE );
const int factorD = player_character.max_quality( qual_CUT_FINE, PICKUP_RANGE );
map_stack items = get_map().i_at( p );
bool has_item = false;
bool has_corpse = false;
Expand Down
12 changes: 7 additions & 5 deletions src/activity_handlers.cpp
Expand Up @@ -484,7 +484,8 @@ static void butcher_cbm_group(

static void set_up_butchery( player_activity &act, player &u, butcher_type action )
{
const int factor = u.max_quality( action == butcher_type::DISSECT ? qual_CUT_FINE : qual_BUTCHER );
const int factor = u.max_quality( action == butcher_type::DISSECT ? qual_CUT_FINE : qual_BUTCHER,
PICKUP_RANGE );

const item &corpse_item = *act.targets.back();
const mtype &corpse = *corpse_item.get_mtype();
Expand Down Expand Up @@ -638,10 +639,11 @@ static void set_up_butchery( player_activity &act, player &u, butcher_type actio
act.index = false;
}

int butcher_time_to_cut( const player &u, const item &corpse_item, const butcher_type action )
int butcher_time_to_cut( player &u, const item &corpse_item, const butcher_type action )
{
const mtype &corpse = *corpse_item.get_mtype();
const int factor = u.max_quality( action == butcher_type::DISSECT ? qual_CUT_FINE : qual_BUTCHER );
const int factor = u.max_quality( action == butcher_type::DISSECT ? qual_CUT_FINE : qual_BUTCHER,
PICKUP_RANGE );

int time_to_cut;
switch( corpse.size ) {
Expand Down Expand Up @@ -1168,12 +1170,12 @@ void activity_handlers::butcher_finish( player_activity *act, player *p )

int skill_level = p->get_skill_level( skill_survival );
int factor = p->max_quality( action == butcher_type::DISSECT ? qual_CUT_FINE :
qual_BUTCHER );
qual_BUTCHER, PICKUP_RANGE );

// DISSECT has special case factor calculation and results.
if( action == butcher_type::DISSECT ) {
skill_level = p->get_skill_level( skill_firstaid );
skill_level += p->max_quality( qual_CUT_FINE );
skill_level += p->max_quality( qual_CUT_FINE, PICKUP_RANGE );
skill_level += p->get_skill_level( skill_electronics ) / 2;
add_msg_debug( debugmode::DF_ACT_BUTCHER, "Skill: %s", skill_level );
}
Expand Down
2 changes: 1 addition & 1 deletion src/activity_handlers.h
Expand Up @@ -97,7 +97,7 @@ struct activity_reason_info {
}
};

int butcher_time_to_cut( const player &u, const item &corpse_item, butcher_type action );
int butcher_time_to_cut( player &u, const item &corpse_item, butcher_type action );

// activity_item_handling.cpp
void activity_on_turn_drop();
Expand Down
1 change: 1 addition & 0 deletions src/character.h
Expand Up @@ -2742,6 +2742,7 @@ class Character : public Creature, public visitable
// inherited from visitable
bool has_quality( const quality_id &qual, int level = 1, int qty = 1 ) const override;
int max_quality( const quality_id &qual ) const override;
int max_quality( const quality_id &qual, int radius );
VisitResponse visit_items( const std::function<VisitResponse( item *, item * )> &func ) const
override;
std::list<item> remove_items_with( const std::function<bool( const item & )> &filter,
Expand Down
11 changes: 6 additions & 5 deletions src/game.cpp
Expand Up @@ -8722,12 +8722,12 @@ static void butcher_submenu( const std::vector<map_stack::iterator> &corpses, in
};
const bool enough_light = player_character.fine_detail_vision_mod() <= 4;

const int factor = player_character.max_quality( quality_id( "BUTCHER" ) );
const int factor = player_character.max_quality( quality_id( "BUTCHER" ), PICKUP_RANGE );
const std::string msgFactor = factor > INT_MIN
? string_format( _( "Your best tool has <color_cyan>%d butchering</color>." ), factor )
: _( "You have no butchering tool." );

const int factorD = player_character.max_quality( quality_id( "CUT_FINE" ) );
const int factorD = player_character.max_quality( quality_id( "CUT_FINE" ), PICKUP_RANGE );
const std::string msgFactorD = factorD > INT_MIN
? string_format( _( "Your best tool has <color_cyan>%d fine cutting</color>." ), factorD )
: _( "You have no fine cutting tool." );
Expand Down Expand Up @@ -8882,8 +8882,8 @@ void game::butcher()
return;
}

const int factor = u.max_quality( quality_id( "BUTCHER" ) );
const int factorD = u.max_quality( quality_id( "CUT_FINE" ) );
const int factor = u.max_quality( quality_id( "BUTCHER" ), PICKUP_RANGE );
const int factorD = u.max_quality( quality_id( "CUT_FINE" ), PICKUP_RANGE );
const std::string no_knife_msg = _( "You don't have a butchering tool." );
const std::string no_corpse_msg = _( "There are no corpses here to butcher." );

Expand Down Expand Up @@ -10155,7 +10155,8 @@ point game::place_player( const tripoint &dest_loc )
}

const std::string pulp_butcher = get_option<std::string>( "AUTO_PULP_BUTCHER" );
if( pulp_butcher == "butcher" && u.max_quality( quality_id( "BUTCHER" ) ) > INT_MIN ) {
if( pulp_butcher == "butcher" &&
u.max_quality( quality_id( "BUTCHER" ), PICKUP_RANGE ) > INT_MIN ) {
std::vector<item *> corpses;

for( item &it : m.i_at( u.pos() ) ) {
Expand Down
13 changes: 13 additions & 0 deletions src/visitable.cpp
Expand Up @@ -277,6 +277,19 @@ int Character::max_quality( const quality_id &qual ) const
return std::max( res, max_quality_internal( *this, qual ) );
}

int Character::max_quality( const quality_id &qual, int radius )
{
int res = max_quality( qual );

if( radius > 0 ) {
res = std::max( res,
crafting_inventory( tripoint_zero, radius, true )
.max_quality( qual ) );
}

return res;
}

/** @relates visitable */
int vehicle_cursor::max_quality( const quality_id &qual ) const
{
Expand Down

0 comments on commit fa71f58

Please sign in to comment.