diff --git a/src/teleport.cpp b/src/teleport.cpp index d461b1a5f3fdc..287021146810c 100644 --- a/src/teleport.cpp +++ b/src/teleport.cpp @@ -95,12 +95,17 @@ bool teleport::teleport_to_point( Creature &critter, tripoint_bub_ms target, boo //handles teleporting into solids. if( dest->impassable( dest_target ) ) { if( force ) { - const std::optional nt = - random_point( points_in_radius( dest_target, 5 ), - [dest]( const tripoint_bub_ms & el ) { - return dest->passable( el ); - } ); - dest_target = nt ? *nt : dest_target; + std::vector nearest_points = closest_points_first( dest_target, 5 ); + nearest_points.erase( nearest_points.begin() ); + //TODO: Swap for this once #75961 merges + //std::vector nearest_points = closest_points_first( dest_target, 1, 5 ); + for( tripoint_bub_ms p : nearest_points ) { + if( dest->passable( p ) ) { + dest_target = p; + break; + } + } + } else { if( safe ) { if( c_is_u && display_message ) { @@ -184,13 +189,14 @@ bool teleport::teleport_to_point( Creature &critter, tripoint_bub_ms target, boo for( const effect &grab : poor_soul->get_effects_with_flag( json_flag_GRAB ) ) { poor_soul->remove_effect( grab.get_id() ); } - //apply a bunch of damage to it, similar to a tear in reality - poor_soul->apply_damage( nullptr, bodypart_id( "arm_l" ), rng( 5, 10 ) ); - poor_soul->apply_damage( nullptr, bodypart_id( "arm_r" ), rng( 5, 10 ) ); - poor_soul->apply_damage( nullptr, bodypart_id( "leg_l" ), rng( 7, 12 ) ); - poor_soul->apply_damage( nullptr, bodypart_id( "leg_r" ), rng( 7, 12 ) ); - poor_soul->apply_damage( nullptr, bodypart_id( "torso" ), rng( 5, 15 ) ); - poor_soul->apply_damage( nullptr, bodypart_id( "head" ), rng( 2, 8 ) ); + //apply a bunch of damage to it + std::vector target_bdpts = poor_soul->get_all_body_parts( + get_body_part_flags::only_main ); + for( const bodypart_id &bp_id : target_bdpts ) { + const float damage_to_deal = + static_cast( poor_soul->get_part_hp_max( bp_id ) ) / static_cast( rng( 6, 12 ) ); + poor_soul->apply_damage( nullptr, bp_id, damage_to_deal ); + } poor_soul->check_dead_state(); } } @@ -201,12 +207,13 @@ bool teleport::teleport_to_point( Creature &critter, tripoint_bub_ms target, boo //throw the thing that teleported in the opposite direction as the thing it teleported into. g->fling_creature( &critter, units::from_degrees( collision_angle - 180 ), 40, false, true ); //do a bunch of damage to it too. - critter.apply_damage( nullptr, bodypart_id( "arm_l" ), rng( 5, 10 ) ); - critter.apply_damage( nullptr, bodypart_id( "arm_r" ), rng( 5, 10 ) ); - critter.apply_damage( nullptr, bodypart_id( "leg_l" ), rng( 7, 12 ) ); - critter.apply_damage( nullptr, bodypart_id( "leg_r" ), rng( 7, 12 ) ); - critter.apply_damage( nullptr, bodypart_id( "torso" ), rng( 5, 15 ) ); - critter.apply_damage( nullptr, bodypart_id( "head" ), rng( 2, 8 ) ); + std::vector target_bdpts = critter.get_all_body_parts( + get_body_part_flags::only_main ); + for( const bodypart_id &bp_id : target_bdpts ) { + float damage_to_deal = + static_cast( critter.get_part_hp_max( bp_id ) ) / static_cast( rng( 6, 12 ) ); + critter.apply_damage( nullptr, bp_id, damage_to_deal ); + } critter.check_dead_state(); } //player and npc exclusive teleporting effects