Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require player to have the recipe at all stages in crafting #29949

Merged
merged 1 commit into from
Apr 26, 2019
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
5 changes: 5 additions & 0 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2716,6 +2716,11 @@ void activity_handlers::craft_do_turn( player_activity *act, player *p )
return;
}

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

const recipe &rec = craft->get_making();
const tripoint loc = act->targets.front().where() == item_location::type::character ?
tripoint_zero : act->targets.front().position();
Expand Down
26 changes: 26 additions & 0 deletions src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,11 @@ void player::start_craft( craft_command &command, const tripoint &loc )

void player::complete_craft( item &craft, const tripoint &loc )
{
if( !craft.is_craft() ) {
debugmsg( "complete_craft() called on non-craft '%s.' Aborting.", craft.tname() );
return;
}

const recipe &making = craft.get_making(); // Which recipe is it?
const int batch_size = craft.charges;

Expand Down Expand Up @@ -1085,6 +1090,27 @@ void player::complete_craft( item &craft, const tripoint &loc )
inv.restack( *this );
}

bool player::can_continue_craft( const item &craft )
{
if( !craft.is_craft() ) {
debugmsg( "complete_craft() called on non-craft '%s.' Aborting.", craft.tname() );
return false;
}

const recipe &rec = craft.get_making();
if( has_recipe( &rec, crafting_inventory(), get_crafting_helpers() ) == -1 ) {
add_msg_player_or_npc(
string_format( _( "You don't know the recipe for the %s and can't continue crafting." ),
rec.result_name() ),
string_format( _( "<npcname> doesn't know the recipe for the %s and can't continue crafting." ),
rec.result_name() )
);
return false;
}

return true;
}

/* selection of component if a recipe requirement has multiple options (e.g. 'duct tap' or 'welder') */
comp_selection<item_comp> player::select_item_component( const std::vector<item_comp> &components,
int batch, inventory &map_inv, bool can_cancel,
Expand Down
4 changes: 4 additions & 0 deletions src/iexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4723,6 +4723,10 @@ void iexamine::workbench_internal( player &p, const tripoint &examp,

const item *selected_craft = crafts[amenu2.ret].get_item();

if( !p.can_continue_craft( *selected_craft ) ) {
break;
}

p.add_msg_player_or_npc(
string_format( pgettext( "in progress craft", "You start working on the %s." ),
selected_craft->tname() ),
Expand Down
4 changes: 4 additions & 0 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8121,6 +8121,10 @@ int iuse::craft( player *p, item *it, bool, const tripoint & )
return 0;
}

if( !p->can_continue_craft( p->weapon ) ) {
return 0;
}

p->add_msg_player_or_npc(
string_format( pgettext( "in progress craft", "You start working on the %s." ), craft_name ),
string_format( pgettext( "in progress craft", "<npcname> starts working on the %s." ),
Expand Down
7 changes: 7 additions & 0 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,13 @@ class player : public Character
/** consume components and create an active, in progress craft containing them */
void start_craft( craft_command &command, const tripoint &loc );
void complete_craft( item &craft, const tripoint &loc = tripoint_zero );
/**
* Check if the player meets the requirements to continue the in progress craft and if
* unable to continue print messages explaining the reason.
* @param craft the currently in progress craft
* @return if the craft can be continued
*/
bool can_continue_craft( const item &craft );
/** Returns nearby NPCs ready and willing to help with crafting. */
std::vector<npc *> get_crafting_helpers() const;
int get_num_crafting_helpers( int max ) const;
Expand Down