Skip to content

Commit

Permalink
Merge pull request #40025 from Qrox/fix-40001
Browse files Browse the repository at this point in the history
Fix a crash when npc tries to heal horse-mounted player
  • Loading branch information
ZhilkinSerg authored Apr 30, 2020
2 parents 70c9d8b + 27e7fbb commit 5130b68
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
18 changes: 12 additions & 6 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4710,16 +4710,22 @@ template const Creature *game::critter_at<Creature>( const tripoint &, bool ) co
template<typename T>
shared_ptr_fast<T> game::shared_from( const T &critter )
{
if( const shared_ptr_fast<monster> mon_ptr = critter_tracker->find( critter.pos() ) ) {
return std::dynamic_pointer_cast<T>( mon_ptr );
}
if( static_cast<const Creature *>( &critter ) == static_cast<const Creature *>( &u ) ) {
// u is not stored in a shared_ptr, but it won't go out of scope anyway
return std::dynamic_pointer_cast<T>( u_shared_ptr );
}
for( auto &cur_npc : active_npc ) {
if( static_cast<const Creature *>( cur_npc.get() ) == static_cast<const Creature *>( &critter ) ) {
return std::dynamic_pointer_cast<T>( cur_npc );
if( critter.is_monster() ) {
if( const shared_ptr_fast<monster> mon_ptr = critter_tracker->find( critter.pos() ) ) {
if( static_cast<const Creature *>( mon_ptr.get() ) == static_cast<const Creature *>( &critter ) ) {
return std::dynamic_pointer_cast<T>( mon_ptr );
}
}
}
if( critter.is_npc() ) {
for( auto &cur_npc : active_npc ) {
if( static_cast<const Creature *>( cur_npc.get() ) == static_cast<const Creature *>( &critter ) ) {
return std::dynamic_pointer_cast<T>( cur_npc );
}
}
}
return nullptr;
Expand Down
24 changes: 13 additions & 11 deletions src/npcmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<player *>( current_ally() );
if( action == npc_flee ) {
tar = good_escape_direction( false );
} else if( cur != nullptr ) {
Expand Down Expand Up @@ -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<player *>( 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<int>( path.size() ) <= follow_distance() &&
Expand Down

0 comments on commit 5130b68

Please sign in to comment.