Skip to content

Commit

Permalink
Apply fixes and cleanup
Browse files Browse the repository at this point in the history
Including:
-Activity cleanup from code review
-Make can_eat() return false for crafts
-Make get_comestible return type a const reference like it should have been
  • Loading branch information
ifreund committed Apr 5, 2019
1 parent 8e14b36 commit 00e9a6a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
11 changes: 4 additions & 7 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2634,27 +2634,27 @@ void activity_handlers::craft_do_turn( player_activity *act, player *p )

if( !craft->is_craft() ) {
debugmsg( "ACT_CRAFT target '%s' is not a craft. Aborting ACT_CRAFT.", craft->tname() );
act->set_to_null();
p->cancel_activity();
return;
}
if( !p->has_item( *craft ) ) {
p->add_msg_if_player( "%s no longer has the target '%s.' Aborting ACT_CRAFT.",
p->disp_name(), craft->tname() );
act->set_to_null();
p->cancel_activity();
return;
}

const recipe &rec = craft->get_making();
const float crafting_speed = p->crafting_speed_multiplier( rec, true );
const bool is_long = act->values[0];
act->set_to_null();

if( crafting_speed <= 0.0f ) {
if( p->lighting_craft_speed_multiplier( rec ) <= 0.0f ) {
p->add_msg_if_player( m_bad, _( "You can no longer see well enough to keep crafting." ) );
} else {
p->add_msg_if_player( m_bad, _( "You are too frustrated to continue and just give up." ) );
}
p->cancel_activity();
return;
}
if( calendar::once_every( 1_hours ) && crafting_speed < 0.75f ) {
Expand All @@ -2666,17 +2666,14 @@ void activity_handlers::craft_do_turn( player_activity *act, player *p )
p->set_moves( 0 );

if( craft->item_counter >= rec.time ) {
p->cancel_activity();
item craft_copy = p->i_rem( craft );
p->complete_craft( craft_copy );
if( is_long ) {
if( p->making_would_work( p->lastrecipe, craft_copy.charges ) ) {
p->last_craft->execute();
}
}
} else {
p->assign_activity( activity_id( "ACT_CRAFT" ) );
p->activity.targets.push_back( item_location( *p, craft ) );
p->activity.values.push_back( is_long );
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/consumption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,10 @@ ret_val<edible_rating> player::can_eat( const item &food ) const
return ret_val<edible_rating>::make_failure( _( "That doesn't look edible." ) );
}

if( food.is_craft() ) {
return ret_val<edible_rating>::make_failure( _( "That doesn't look edible in its current form." ) );
}

if( food.item_tags.count( "DIRTY" ) ) {
return ret_val<edible_rating>::make_failure(
_( "This is full of dirt after being on the ground." ) );
Expand Down
3 changes: 2 additions & 1 deletion src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,8 @@ class comestible_inventory_preset : public inventory_selector_preset

const islot_comestible &get_edible_comestible( const item &it ) const {
if( it.is_comestible() && p.can_eat( it ).success() ) {
return *it.get_comestible();
// Ok since can_eat() returns false if is_craft() is true
return *it.type->comestible;
}
static const islot_comestible dummy {};
return dummy;
Expand Down
2 changes: 1 addition & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7854,7 +7854,7 @@ const recipe &item::get_making() const
return *making;
}

cata::optional<islot_comestible> item::get_comestible() const
const cata::optional<islot_comestible> &item::get_comestible() const
{
return is_craft() ? find_type( making->result() )->comestible :
type->comestible;
Expand Down
2 changes: 1 addition & 1 deletion src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -1814,7 +1814,7 @@ class item : public visitable<item>

const recipe &get_making() const;

cata::optional<islot_comestible> get_comestible() const;
const cata::optional<islot_comestible> &get_comestible() const;

private:
/**
Expand Down

0 comments on commit 00e9a6a

Please sign in to comment.