Skip to content

Commit

Permalink
Fix starting a fire with a firewood source (#31256)
Browse files Browse the repository at this point in the history
* Fix starting a fire with a firewood source
  • Loading branch information
matthemsteger authored and ZhilkinSerg committed Jun 9, 2019
1 parent 5cb3b27 commit 7bd9888
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
23 changes: 22 additions & 1 deletion src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1841,7 +1841,28 @@ void activity_handlers::reload_finish( player_activity *act, player *p )

void activity_handlers::start_fire_finish( player_activity *act, player *p )
{
firestarter_actor::resolve_firestarter_use( *p, act->placement );
static const std::string iuse_name_string( "firestarter" );

item &it = p->i_at( act->position );
item *used_tool = it.get_usable_item( iuse_name_string );
if( used_tool == nullptr ) {
debugmsg( "Lost tool used for starting fire" );
act->set_to_null();
return;
}

const auto use_fun = used_tool->get_use( iuse_name_string );
const auto *actor = dynamic_cast<const firestarter_actor *>( use_fun->get_actor_ptr() );
if( actor == nullptr ) {
debugmsg( "iuse_actor type descriptor and actual type mismatch" );
act->set_to_null();
return;
}

p->consume_charges( it, it.type->charges_to_use() );
p->practice( skill_survival, act->index, 5 );

actor->resolve_firestarter_use( *p, act->placement );
act->set_to_null();
}

Expand Down
15 changes: 8 additions & 7 deletions src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,7 @@ iuse_actor *firestarter_actor::clone() const

bool firestarter_actor::prep_firestarter_use( const player &p, tripoint &pos )
{
// checks for fuel are handled by use and the activity, not here
if( pos == p.pos() ) {
if( const cata::optional<tripoint> pnt_ = choose_adjacent( _( "Light where?" ) ) ) {
pos = *pnt_;
Expand All @@ -1130,10 +1131,6 @@ bool firestarter_actor::prep_firestarter_use( const player &p, tripoint &pos )
return false;
}
}
if( !g->m.is_flammable( pos ) ) {
p.add_msg_if_player( m_info, _( "There's nothing to light there." ) );
return false;
}
if( pos == p.pos() ) {
p.add_msg_if_player( m_info, _( "You would set yourself on fire." ) );
p.add_msg_if_player( _( "But you're already smokin' hot." ) );
Expand Down Expand Up @@ -1256,12 +1253,16 @@ int firestarter_actor::use( player &p, item &it, bool t, const tripoint &spos )
p.mod_moves( -moves );
return it.type->charges_to_use();
}
p.assign_activity( activity_id( "ACT_START_FIRE" ), moves, -1, p.get_item_position( &it ),

// skill gains are handled by the activity, but stored here in the index field
const int potential_skill_gain = moves_modifier + moves_cost_fast / 100 + 2;
p.assign_activity( activity_id( "ACT_START_FIRE" ), moves, potential_skill_gain,
p.get_item_position( &it ),
it.tname() );
p.activity.values.push_back( g->natural_light_level( pos.z ) );
p.activity.placement = pos;
p.practice( skill_survival, moves_modifier + moves_cost_fast / 100 + 2, 5 );
return it.type->charges_to_use();
// charges to use are handled by the activity
return 0;
}

void salvage_actor::load( JsonObject &obj )
Expand Down

0 comments on commit 7bd9888

Please sign in to comment.