3131#include " construction_partial.h"
3232#include " craft_command.h"
3333#include " crafting.h"
34+ #include " crafting_quality.h"
3435#include " creature.h"
3536#include " damage.h"
3637#include " debug.h"
@@ -113,6 +114,10 @@ static const activity_id ACT_CONSUME_FOOD_MENU( "ACT_CONSUME_FOOD_MENU" );
113114static const activity_id ACT_CONSUME_MEDS_MENU ( " ACT_CONSUME_MEDS_MENU" );
114115static const activity_id ACT_CRACKING ( " ACT_CRACKING" );
115116static const activity_id ACT_CRAFT ( " ACT_CRAFT" );
117+ static constexpr auto craft_is_long_idx = 0 ;
118+ static constexpr auto craft_bench_type_idx = 1 ;
119+ static constexpr auto craft_tools_mult_percent_idx = 2 ;
120+ static constexpr auto craft_tools_mult_next_refresh_idx = 3 ;
116121static const activity_id ACT_DISMEMBER ( " ACT_DISMEMBER" );
117122static const activity_id ACT_DISSECT ( " ACT_DISSECT" );
118123static const activity_id ACT_EAT_MENU ( " ACT_EAT_MENU" );
@@ -3800,18 +3805,28 @@ void activity_handlers::craft_do_turn( player_activity *act, player *p )
38003805 return ;
38013806 }
38023807
3803- if ( !p->can_continue_craft ( *craft ) ) {
3804- p->cancel_activity ();
3805- return ;
3806- }
3807-
38083808 const recipe &rec = craft->get_making ();
38093809 const tripoint bench_pos = act->coords .front ();
38103810 // Ugly
3811- bench_type bench_t = bench_type ( act->values [1 ] );
3812- const float crafting_speed = crafting_speed_multiplier ( *p, *craft, bench_location{bench_t , bench_pos} );
3811+ bench_type bench_t = bench_type ( act->values [craft_bench_type_idx] );
3812+
3813+ while ( act->values .size () <= craft_tools_mult_next_refresh_idx ) {
3814+ act->values .push_back ( 0 );
3815+ }
3816+
3817+ const auto now_turn = to_turn<int >( calendar::turn );
3818+ if ( now_turn >= act->values [craft_tools_mult_next_refresh_idx] ) {
3819+ const auto tools_mult = crafting_tools_speed_multiplier ( *p, rec );
3820+ act->values [craft_tools_mult_percent_idx] = std::round ( tools_mult * 100 .0f );
3821+ act->values [craft_tools_mult_next_refresh_idx] = INT_MAX;
3822+ }
3823+
3824+ const auto tools_mult_cached = static_cast <float >( act->values [craft_tools_mult_percent_idx] ) /
3825+ 100 .0f ;
3826+ const float crafting_speed = crafting_speed_multiplier ( *p, *craft, bench_location{bench_t , bench_pos},
3827+ tools_mult_cached );
38133828 const int assistants = p->available_assistant_count ( craft->get_making () );
3814- const bool is_long = act->values [0 ];
3829+ const bool is_long = act->values [craft_is_long_idx ];
38153830
38163831 if ( crafting_speed <= 0 .0f ) {
38173832 p->cancel_activity ();
@@ -3838,30 +3853,15 @@ void activity_handlers::craft_do_turn( player_activity *act, player *p )
38383853 const auto new_counter_f = current_progress / base_total_moves * 10'000'000.0 ;
38393854 // This is to ensure we don't over count skill steps
38403855 const auto new_counter = std::min ( static_cast <int >( std::round ( new_counter_f ) ), 10'000'000 );
3856+ auto five_percent_steps = new_counter / 500'000 - old_counter / 500'000 ;
38413857 craft->set_counter ( new_counter );
38423858
38433859 p->set_moves ( 0 );
38443860
3845- // Skill and tools are gained/consumed after every 5% progress
3846- int five_percent_steps = craft->get_counter () / 500'000 - old_counter / 500'000 ;
38473861 if ( five_percent_steps > 0 ) {
38483862 p->craft_skill_gain ( *craft, five_percent_steps );
38493863 }
38503864
3851- // Unlike skill, tools are consumed once at the start and should not be consumed at the end
3852- if ( craft->get_counter () >= 10'000'000 ) {
3853- --five_percent_steps;
3854- }
3855-
3856- if ( five_percent_steps > 0 ) {
3857- if ( !p->craft_consume_tools ( *craft, five_percent_steps, false ) ) {
3858- // So we don't skip over any tool comsuption
3859- craft->set_counter ( craft->get_counter () - ( craft->get_counter () % 500'000 + 1 ) );
3860- p->cancel_activity ();
3861- return ;
3862- }
3863- }
3864-
38653865 // if item_counter has reached 100% or more
38663866 if ( craft->get_counter () >= 10'000'000 ) {
38673867 // TODO!: CHEEKY check
0 commit comments