Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "construction_partial.h"
#include "craft_command.h"
#include "crafting.h"
#include "crafting_quality.h"
#include "creature.h"
#include "damage.h"
#include "debug.h"
Expand Down Expand Up @@ -113,6 +114,10 @@
static const activity_id ACT_CONSUME_MEDS_MENU( "ACT_CONSUME_MEDS_MENU" );
static const activity_id ACT_CRACKING( "ACT_CRACKING" );
static const activity_id ACT_CRAFT( "ACT_CRAFT" );
static constexpr auto craft_is_long_idx = 0;
static constexpr auto craft_bench_type_idx = 1;
static constexpr auto craft_tools_mult_percent_idx = 2;
static constexpr auto craft_tools_mult_next_refresh_idx = 3;
static const activity_id ACT_DISMEMBER( "ACT_DISMEMBER" );
static const activity_id ACT_DISSECT( "ACT_DISSECT" );
static const activity_id ACT_EAT_MENU( "ACT_EAT_MENU" );
Expand Down Expand Up @@ -207,7 +212,7 @@
static const itype_id itype_splinter( "splinter" );
static const itype_id itype_stick_long( "stick_long" );
static const itype_id itype_vine_30( "vine_30" );
static const itype_id itype_welder( "welder" );

Check warning on line 215 in src/activity_handlers.cpp

View workflow job for this annotation

GitHub Actions / build

Variable 'itype_welder' declared but not used. [cata-unused-statics]
static const itype_id itype_wool_staple( "wool_staple" );

static const zone_type_id zone_type_FARM_PLOT( "FARM_PLOT" );
Expand Down Expand Up @@ -3800,18 +3805,28 @@
return;
}

if( !p->can_continue_craft( *craft ) ) {
p->cancel_activity();
return;
}

const recipe &rec = craft->get_making();
const tripoint bench_pos = act->coords.front();
// Ugly
bench_type bench_t = bench_type( act->values[1] );
const float crafting_speed = crafting_speed_multiplier( *p, *craft, bench_location{bench_t, bench_pos} );
bench_type bench_t = bench_type( act->values[craft_bench_type_idx] );

while( act->values.size() <= craft_tools_mult_next_refresh_idx ) {
act->values.push_back( 0 );
}

const auto now_turn = to_turn<int>( calendar::turn );
if( now_turn >= act->values[craft_tools_mult_next_refresh_idx] ) {
const auto tools_mult = crafting_tools_speed_multiplier( *p, rec );
act->values[craft_tools_mult_percent_idx] = std::round( tools_mult * 100.0f );
act->values[craft_tools_mult_next_refresh_idx] = INT_MAX;
}

const auto tools_mult_cached = static_cast<float>( act->values[craft_tools_mult_percent_idx] ) /
100.0f;
const float crafting_speed = crafting_speed_multiplier( *p, *craft, bench_location{bench_t, bench_pos},
tools_mult_cached );
const int assistants = p->available_assistant_count( craft->get_making() );
const bool is_long = act->values[0];
const bool is_long = act->values[craft_is_long_idx];

if( crafting_speed <= 0.0f ) {
p->cancel_activity();
Expand All @@ -3838,30 +3853,15 @@
const auto new_counter_f = current_progress / base_total_moves * 10'000'000.0;
// This is to ensure we don't over count skill steps
const auto new_counter = std::min( static_cast<int>( std::round( new_counter_f ) ), 10'000'000 );
auto five_percent_steps = new_counter / 500'000 - old_counter / 500'000;
craft->set_counter( new_counter );

p->set_moves( 0 );

// Skill and tools are gained/consumed after every 5% progress
int five_percent_steps = craft->get_counter() / 500'000 - old_counter / 500'000;
if( five_percent_steps > 0 ) {
p->craft_skill_gain( *craft, five_percent_steps );
}

// Unlike skill, tools are consumed once at the start and should not be consumed at the end
if( craft->get_counter() >= 10'000'000 ) {
--five_percent_steps;
}

if( five_percent_steps > 0 ) {
if( !p->craft_consume_tools( *craft, five_percent_steps, false ) ) {
// So we don't skip over any tool comsuption
craft->set_counter( craft->get_counter() - ( craft->get_counter() % 500'000 + 1 ) );
p->cancel_activity();
return;
}
}

// if item_counter has reached 100% or more
if( craft->get_counter() >= 10'000'000 ) {
//TODO!: CHEEKY check
Expand Down
61 changes: 59 additions & 2 deletions src/craft_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,65 @@ detached_ptr<item> craft_command::create_in_progress_craft()

new_craft->set_cached_tool_selections( tool_selections );
new_craft->set_tools_to_continue( true );
// Pass true to indicate that we are starting the craft and the remainder should be consumed as well
crafter->craft_consume_tools( *new_craft, 1, true );

for( const comp_selection<tool_comp> &tool_sel : tool_selections ) {
const auto type = tool_sel.comp.type;
if( tool_sel.comp.count > 0 ) {
const auto full_cost = tool_sel.comp.count * batch_size;
switch( tool_sel.use_from ) {
case usage_from::player:
if( !crafter->has_charges( type, full_cost ) ) {
return detached_ptr<item>();
}
break;
case usage_from::map:
if( !map_inv.has_charges( type, full_cost ) ) {
return detached_ptr<item>();
}
break;
case usage_from::both:
if( crafter->charges_of( type ) + map_inv.charges_of( type ) < full_cost ) {
return detached_ptr<item>();
}
break;
case usage_from::none:
case usage_from::cancel:
case usage_from::num_usages_from:
break;
}
} else {
switch( tool_sel.use_from ) {
case usage_from::player:
if( !crafter->has_amount( type, 1 ) ) {
return detached_ptr<item>();
}
break;
case usage_from::map:
if( !map_inv.has_tools( type, 1 ) ) {
return detached_ptr<item>();
}
break;
case usage_from::both:
if( crafter->amount_of( type ) + map_inv.amount_of( type ) < 1 ) {
return detached_ptr<item>();
}
break;
case usage_from::none:
case usage_from::cancel:
case usage_from::num_usages_from:
break;
}
}
}
for( const comp_selection<tool_comp> &tool : tool_selections ) {
if( tool.comp.count <= 0 ) {
continue;
}
auto to_consume = tool;
to_consume.comp.count *= batch_size;
crafter->consume_tools( to_consume, 1 );
}
new_craft->set_var( "craft_tools_fully_prepaid", 1 );
new_craft->set_next_failure_point( *crafter );

return new_craft;
Expand Down
15 changes: 10 additions & 5 deletions src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@
}

float crafting_speed_multiplier( const Character &who, const item &craft,
const bench_location &bench )
const bench_location &bench,
const std::optional<float> tools_multi_override )
{
if( !craft.is_craft() ) {
debugmsg( "Can't calculate crafting speed multiplier of non-craft '%s'", craft.tname() );
Expand All @@ -273,7 +274,9 @@
const float light_multi = lighting_crafting_speed_multiplier( who, rec );
const float bench_multi = workbench_crafting_speed_multiplier( craft, bench );
const float morale_multi = morale_crafting_speed_multiplier( who, rec );
const auto tools_multi = crafting_tools_speed_multiplier( who, rec );
const auto tools_multi = tools_multi_override
? *tools_multi_override
: crafting_tools_speed_multiplier( who, rec );
const float mutation_multi = who.mutation_value( "crafting_speed_modifier" );
const float game_opt_multi = get_option<int>( "CRAFTING_SPEED_MULT" ) == 0 ? 9999 :
100.0f / get_option<int>( "CRAFTING_SPEED_MULT" );
Expand Down Expand Up @@ -547,9 +550,9 @@
if( src_pos == tripoint_zero ) {
inv_pos = pos();
}
if( cached_moves == moves
&& cached_time == calendar::turn
&& cached_position == inv_pos ) {
const auto cache_hit = cached_time == calendar::turn
&& cached_position == inv_pos;
if( cache_hit ) {
return cached_crafting_inventory;
}
cached_crafting_inventory.form_from_map( inv_pos, radius, this, false, clear_path );
Expand Down Expand Up @@ -682,7 +685,7 @@
pgettext( "furniture, item", "Not enough space on the %s. <npcname> drops the %s on the ground." ),
vp->part().name(), newit->tname() );

return set_item_map( loc, std::move( newit ) );

Check warning on line 688 in src/crafting.cpp

View workflow job for this annotation

GitHub Actions / build

return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value]

} else {
if( here.has_furn( loc ) ) {
Expand All @@ -697,7 +700,7 @@
pgettext( "item", "<npcname> puts the %s on the ground." ),
newit->tname() );
}
return set_item_map( loc, std::move( newit ) );

Check warning on line 703 in src/crafting.cpp

View workflow job for this annotation

GitHub Actions / build

return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value]
}
}

Expand All @@ -713,7 +716,7 @@
return;
}

return set_item_map_or_vehicle( who, who.pos(), std::move( newit ) );

Check warning on line 719 in src/crafting.cpp

View workflow job for this annotation

GitHub Actions / build

return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value]
}

item *Character::start_craft( craft_command &command, const tripoint & )
Expand Down Expand Up @@ -753,6 +756,8 @@
activity->values.push_back( command.is_long() );
// Ugly
activity->values.push_back( static_cast<int>( bench.type ) );
activity->values.push_back( 100 );
activity->values.push_back( 0 );

add_msg_player_or_npc(
pgettext( "in progress craft", "You start working on the %s." ),
Expand Down Expand Up @@ -2348,7 +2353,7 @@
bench_type best_type = bench_here.first;
float best_bench_multi = bench_here.second;
tripoint best_loc = who.pos();
std::vector<tripoint> reachable( PICKUP_RANGE * PICKUP_RANGE );

Check warning on line 2356 in src/crafting.cpp

View workflow job for this annotation

GitHub Actions / build

performing an implicit widening conversion to type 'size_type' (aka 'unsigned long') of a multiplication performed in type 'int' [bugprone-implicit-widening-of-multiplication-result]
g->m.reachable_flood_steps( reachable, who.pos(), PICKUP_RANGE, 1, 100 );
for( const tripoint &adj : reachable ) {
if( const cata::value_ptr<furn_workbench_info> &wb = g->m.furn( adj )->workbench ) {
Expand Down
4 changes: 3 additions & 1 deletion src/crafting.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <list>
#include <optional>
#include <set>
#include <vector>

Expand Down Expand Up @@ -45,7 +46,8 @@ float morale_crafting_speed_multiplier( const Character &who, const recipe &rec
float lighting_crafting_speed_multiplier( const Character &who, const recipe &rec );
float crafting_speed_multiplier( const Character &who, const recipe &rec, bool );
float crafting_speed_multiplier( const Character &who, const item &craft,
const bench_location &bench );
const bench_location &bench,
std::optional<float> tools_multi_override = std::nullopt );
void complete_craft( Character &who, item &craft );

namespace crafting
Expand Down
6 changes: 6 additions & 0 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8669,6 +8669,10 @@ int iuse::craft( player *p, item *it, bool, const tripoint &pos )
return 0;
}

if( it->get_var( "craft_tools_fully_prepaid", 0 ) == 0 ) {
it->set_var( "craft_tools_fully_prepaid", 1 );
}

bench_location best_bench = find_best_bench( *p, *it );
p->add_msg_player_or_npc(
pgettext( "in progress craft", "You start working on the %s." ),
Expand Down Expand Up @@ -8700,6 +8704,8 @@ int iuse::craft( player *p, item *it, bool, const tripoint &pos )
p->activity->values.push_back( 0 ); // Not a long craft
// Ugly
p->activity->values.push_back( static_cast<int>( best_bench.type ) );
p->activity->values.push_back( 100 );
p->activity->values.push_back( 0 );

return 0;
}
Expand Down
8 changes: 6 additions & 2 deletions src/player_activity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
static const activity_id ACT_CONSUME_FOOD_MENU( "ACT_CONSUME_FOOD_MENU" );
static const activity_id ACT_CONSUME_MEDS_MENU( "ACT_CONSUME_MEDS_MENU" );
static const activity_id ACT_CRAFT( "ACT_CRAFT" );
static constexpr auto craft_bench_type_idx = 1;
static constexpr auto craft_tools_mult_percent_idx = 2;
static const activity_id ACT_DIG( "ACT_DIG" );
static const activity_id ACT_DIG_CHANNEL( "ACT_DIG_CHANNEL" );
static const activity_id ACT_EAT_MENU( "ACT_EAT_MENU" );
Expand Down Expand Up @@ -164,7 +166,7 @@
}
int n = 0;
return g->get_npcs_if( [&]( const npc & guy ) {
if( n >= max ) {

Check warning on line 169 in src/player_activity.cpp

View workflow job for this annotation

GitHub Actions / build

comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
return false;
}
// NPCs can help craft if awake, taking orders, within pickup range and have clear path
Expand Down Expand Up @@ -207,14 +209,16 @@
const recipe &rec = craft->get_making();
const tripoint bench_pos = act.coords.front();
// Ugly
bench_type bench_t = bench_type( act.values[1] );
const auto bench_t = bench_type( act.values[craft_bench_type_idx] );

const bench_location bench{ bench_t, bench_pos };

const float light_mult = lighting_crafting_speed_multiplier( u, rec );
const float bench_mult = workbench_crafting_speed_multiplier( *craft, bench );
const float morale_mult = morale_crafting_speed_multiplier( u, rec );
const auto tools_mult = crafting_tools_speed_multiplier( u, rec );
const auto tools_mult = ( act.values.size() > craft_tools_mult_percent_idx )
? static_cast<float>( act.values[craft_tools_mult_percent_idx] ) / 100.0f
: crafting_tools_speed_multiplier( u, rec );
const int assistants = u.available_assistant_count( craft->get_making() );
const float base_total_moves = std::max( 1, rec.batch_time( craft->charges, 1.0f, 0 ) );
const float assist_total_moves = std::max( 1, rec.batch_time( craft->charges, 1.0f, assistants ) );
Expand Down Expand Up @@ -272,7 +276,7 @@
nc_color col = percent == 100
? c_white
: percent > 100 ? c_green : c_red;
std::string spaces = "";

Check warning on line 279 in src/player_activity.cpp

View workflow job for this annotation

GitHub Actions / build

redundant string initialization [readability-redundant-string-init]
std::string colorized = colorize( std::to_string( percent ) + '%', col );
return string_format( _( " %s- %s: %s\n" ), spaces.insert( 0, indent, ' ' ), name, colorized );
}
Expand All @@ -287,7 +291,7 @@
/*
* Progress block
*/
std::string target = "";

Check warning on line 294 in src/player_activity.cpp

View workflow job for this annotation

GitHub Actions / build

redundant string initialization [readability-redundant-string-init]
std::string progress_desc = "Progress: ";

/*
Expand Down Expand Up @@ -371,7 +375,7 @@
act_progress_message msg = actor->get_progress_message( *this, u );
if( msg.implemented ) {
if( msg.msg_full ) {
return *msg.msg_full;

Check warning on line 378 in src/player_activity.cpp

View workflow job for this annotation

GitHub Actions / build

conversion from 'std::optional<std::basic_string<char>>' into 'std::basic_string<char>' and back into 'std::optional<std::basic_string<char>>', remove potentially error-prone optional dereference [bugprone-optional-value-conversion]
} else if( msg.msg_extra_info ) {
return string_format( _( "%s: %s" ), get_verb().translated(), *msg.msg_extra_info );
} else {
Expand Down Expand Up @@ -626,7 +630,7 @@
}

template <typename T>
bool containers_equal( const T &left, const T &right )

Check warning on line 633 in src/player_activity.cpp

View workflow job for this annotation

GitHub Actions / build

function 'containers_equal' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]
{
if( left.size() != right.size() ) {
return false;
Expand Down
Loading