From 95f89eb6f80ac18819233a9008f28707fa9f8626 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Tue, 5 Nov 2024 17:43:45 +0000 Subject: [PATCH 1/3] Remove hardcoded bp id usages --- src/teleport.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/teleport.cpp b/src/teleport.cpp index d461b1a5f3fdc..ee7d38a0ae949 100644 --- a/src/teleport.cpp +++ b/src/teleport.cpp @@ -26,6 +26,8 @@ #include "viewer.h" #include "map_iterator.h" +static const damage_type_id damage_pure( "pure" ); + static const efftype_id effect_teleglow( "teleglow" ); static const flag_id json_flag_DIMENSIONAL_ANCHOR( "DIMENSIONAL_ANCHOR" ); @@ -185,12 +187,14 @@ bool teleport::teleport_to_point( Creature &critter, tripoint_bub_ms target, boo 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 ) ); + std::vector target_bdpts = poor_soul->get_all_body_parts( + get_body_part_flags::only_main ); + for( bodypart_id bp_id : target_bdpts ) { + damage_instance bp_damage( damage_pure, + poor_soul->get_part_hp_max( bp_id ) / static_cast( rng( 6, + 12 ) ) ); + poor_soul->deal_damage( nullptr, bp_id, bp_damage ); + } poor_soul->check_dead_state(); } } @@ -201,12 +205,14 @@ 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( bodypart_id bp_id : target_bdpts ) { + damage_instance bp_damage( damage_pure, + critter.get_part_hp_max( bp_id ) / static_cast( rng( 6, + 12 ) ) ); + critter.deal_damage( nullptr, bp_id, bp_damage ); + } critter.check_dead_state(); } //player and npc exclusive teleporting effects From 28e9167edd73e92341385c70807de8ebd7640cd2 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Tue, 5 Nov 2024 17:44:43 +0000 Subject: [PATCH 2/3] Make force teleporting to impassable tiles redirect to nearest passable one rather than randomly --- src/teleport.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/teleport.cpp b/src/teleport.cpp index ee7d38a0ae949..1ca2b307effd0 100644 --- a/src/teleport.cpp +++ b/src/teleport.cpp @@ -97,12 +97,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 ) { From 6cf68d4694aebca44ac18f80d8759e4e9b0b4e20 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Tue, 5 Nov 2024 17:59:31 +0000 Subject: [PATCH 3/3] Simplify damage --- src/teleport.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/teleport.cpp b/src/teleport.cpp index 1ca2b307effd0..287021146810c 100644 --- a/src/teleport.cpp +++ b/src/teleport.cpp @@ -26,8 +26,6 @@ #include "viewer.h" #include "map_iterator.h" -static const damage_type_id damage_pure( "pure" ); - static const efftype_id effect_teleglow( "teleglow" ); static const flag_id json_flag_DIMENSIONAL_ANCHOR( "DIMENSIONAL_ANCHOR" ); @@ -191,14 +189,13 @@ 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 + //apply a bunch of damage to it std::vector target_bdpts = poor_soul->get_all_body_parts( get_body_part_flags::only_main ); - for( bodypart_id bp_id : target_bdpts ) { - damage_instance bp_damage( damage_pure, - poor_soul->get_part_hp_max( bp_id ) / static_cast( rng( 6, - 12 ) ) ); - poor_soul->deal_damage( nullptr, bp_id, bp_damage ); + 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(); } @@ -212,11 +209,10 @@ bool teleport::teleport_to_point( Creature &critter, tripoint_bub_ms target, boo //do a bunch of damage to it too. std::vector target_bdpts = critter.get_all_body_parts( get_body_part_flags::only_main ); - for( bodypart_id bp_id : target_bdpts ) { - damage_instance bp_damage( damage_pure, - critter.get_part_hp_max( bp_id ) / static_cast( rng( 6, - 12 ) ) ); - critter.deal_damage( nullptr, bp_id, bp_damage ); + 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(); }