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 a crash when npc tries to heal horse-mounted player #40025

Merged
merged 1 commit into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
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