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

Fix starting a fire with a firewood source #31256

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 22 additions & 1 deletion src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,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