Skip to content

Fix reach attacks through ceiling #81772

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 13 additions & 3 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10643,11 +10643,21 @@
return g->get_creatures_if( [this, range, melee, &here]( const Creature & critter ) -> bool {
//the call to map.sees is to make sure that even if we can see it through walls
//via a mutation or cbm we only attack targets with a line of sight
bool can_see = ( ( sees( here, critter ) || sees_with_specials( critter ) ) && here.sees( pos_bub( here ), critter.pos_bub( here ), 100 ) );
tripoint_bub_ms you_pos = pos_bub( here );
tripoint_bub_ms critter_pos = critter.pos_bub( here );
bool can_see = ( ( sees( here, critter ) || sees_with_specials( critter ) ) && here.sees( you_pos, critter_pos, 100 ) );

Check failure on line 10648 in src/character.cpp

View workflow job for this annotation

GitHub Actions / run-clang-tidy (directly-changed)

Redundant parentheses. [cata-redundant-parentheses,-warnings-as-errors]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool can_see = ( ( sees( here, critter ) || sees_with_specials( critter ) ) && here.sees( you_pos, critter_pos, 100 ) );
bool can_see = ( sees( here, critter ) || sees_with_specials( critter ) ) && here.sees( you_pos, critter_pos, 100 );

if( can_see && melee ) //handles the case where we can see something with glass in the way for melee attacks
{
std::vector<tripoint_bub_ms> path = here.find_clear_path( pos_bub( here ),
critter.pos_bub( here ) );
if( you_pos.z() > critter_pos.z() && ( !here.has_floor( you_pos ) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting aside the thing that clang-tidy is complaining about (which is that doing the same thing (returning false) in two different branches of an if/else is considered bug-prone), I'm not sure the logic is correct.
Assume the player is above the target, we need one of "has_floor() == false" or "has_flag( GOES_DOWN ) == true" for the target to be a valid candidate, but we're also checking for GOES_UP?

BTW I think you can make clang happy by just breaking the "else" relation and have it be two separate if clauses, I don't think trying to refactor it into a single clause is a good idea.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handling it this way seems to make blind shots in the dark impossible which they physically are not, so maybe just check for obstacles?

!here.has_flag( ter_furn_flag::TFLAG_GOES_UP, you_pos ) &&
!here.has_flag( ter_furn_flag::TFLAG_GOES_DOWN, you_pos ) ) ) {

Check failure on line 10653 in src/character.cpp

View workflow job for this annotation

GitHub Actions / run-clang-tidy (directly-changed)

repeated branch body in conditional chain [bugprone-branch-clone,-warnings-as-errors]
return false;
} else if( you_pos.z() < critter_pos.z() && ( !here.has_floor( critter_pos ) &&
!here.has_flag( ter_furn_flag::TFLAG_GOES_UP, critter_pos ) &&
!here.has_flag( ter_furn_flag::TFLAG_GOES_DOWN, critter_pos ) ) ) {
return false;
}
std::vector<tripoint_bub_ms> path = here.find_clear_path( you_pos, critter_pos );
for( const tripoint_bub_ms &point : path ) {
if( here.impassable( point ) &&
!( weapon.has_flag( flag_SPEAR ) && // Fences etc. Spears can stab through those
Expand Down
Loading