From 7bd9888575b0c2b7c0c57fdca5264c755b4ebe4e Mon Sep 17 00:00:00 2001 From: Matt Hemsteger Date: Sun, 9 Jun 2019 03:07:53 -0700 Subject: [PATCH] Fix starting a fire with a firewood source (#31256) * Fix starting a fire with a firewood source --- src/activity_handlers.cpp | 23 ++++++++++++++++++++++- src/iuse_actor.cpp | 15 ++++++++------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/activity_handlers.cpp b/src/activity_handlers.cpp index b833d793953b1..51a129e803d81 100644 --- a/src/activity_handlers.cpp +++ b/src/activity_handlers.cpp @@ -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( 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(); } diff --git a/src/iuse_actor.cpp b/src/iuse_actor.cpp index 8c7f4c3e12f51..b8d58c48e156d 100644 --- a/src/iuse_actor.cpp +++ b/src/iuse_actor.cpp @@ -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 pnt_ = choose_adjacent( _( "Light where?" ) ) ) { pos = *pnt_; @@ -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." ) ); @@ -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 )