diff --git a/src/game.cpp b/src/game.cpp index 32d40f2b13d2e..1ee510101830e 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -4710,16 +4710,22 @@ template const Creature *game::critter_at( const tripoint &, bool ) co template shared_ptr_fast game::shared_from( const T &critter ) { - if( const shared_ptr_fast mon_ptr = critter_tracker->find( critter.pos() ) ) { - return std::dynamic_pointer_cast( mon_ptr ); - } if( static_cast( &critter ) == static_cast( &u ) ) { // u is not stored in a shared_ptr, but it won't go out of scope anyway return std::dynamic_pointer_cast( u_shared_ptr ); } - for( auto &cur_npc : active_npc ) { - if( static_cast( cur_npc.get() ) == static_cast( &critter ) ) { - return std::dynamic_pointer_cast( cur_npc ); + if( critter.is_monster() ) { + if( const shared_ptr_fast mon_ptr = critter_tracker->find( critter.pos() ) ) { + if( static_cast( mon_ptr.get() ) == static_cast( &critter ) ) { + return std::dynamic_pointer_cast( mon_ptr ); + } + } + } + if( critter.is_npc() ) { + for( auto &cur_npc : active_npc ) { + if( static_cast( cur_npc.get() ) == static_cast( &critter ) ) { + return std::dynamic_pointer_cast( cur_npc ); + } } } return nullptr; diff --git a/src/npcmove.cpp b/src/npcmove.cpp index 22a60a947c494..e69cf42ae171b 100644 --- a/src/npcmove.cpp +++ b/src/npcmove.cpp @@ -912,7 +912,6 @@ void npc::execute_action( npc_action action ) int oldmoves = moves; tripoint tar = pos(); Creature *cur = current_target(); - player *patient = dynamic_cast( current_ally() ); if( action == npc_flee ) { tar = good_escape_direction( false ); } else if( cur != nullptr ) { @@ -1079,18 +1078,21 @@ void npc::execute_action( npc_action action ) } break; - case npc_heal_player: - update_path( patient->pos() ); - if( path.size() == 1 ) { // We're adjacent to u, and thus can heal u - heal_player( *patient ); - } else if( !path.empty() ) { - say( _( "Hold still %s, I'm coming to help you." ), patient->disp_name() ); - move_to_next(); - } else { - move_pause(); + case npc_heal_player: { + player *patient = dynamic_cast( current_ally() ); + if( patient ) { + update_path( patient->pos() ); + if( path.size() == 1 ) { // We're adjacent to u, and thus can heal u + heal_player( *patient ); + } else if( !path.empty() ) { + say( _( "Hold still %s, I'm coming to help you." ), patient->disp_name() ); + move_to_next(); + } else { + move_pause(); + } } break; - + } case npc_follow_player: update_path( g->u.pos() ); if( static_cast( path.size() ) <= follow_distance() &&