Skip to content

Commit

Permalink
Prevent spear and whip attacks around corners (#649)
Browse files Browse the repository at this point in the history
  • Loading branch information
zenzombie authored Jan 23, 2024
1 parent 888f86f commit d47925c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions changes/prevent-spear-attacks-around-corners.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent monsters with a spear or whip attack from attacking around corners
14 changes: 14 additions & 0 deletions src/brogue/Movement.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,13 @@ boolean handleWhipAttacks(creature *attacker, enum directions dir, boolean *abor
}
pos originLoc = attacker->loc;
pos targetLoc = posNeighborInDirection(attacker->loc, dir);

// The neighboring position in the attack direction must not be diagonally blocked.
// Generally speaking, the attacker must be able to move one tile in the attack direction.
if (diagonalBlocked(originLoc.x, originLoc.y, targetLoc.x, targetLoc.y, attacker == &player)) {
return false;
}

pos strikeLoc;
getImpactLoc(&strikeLoc, originLoc, targetLoc, 5, false, &boltCatalog[BOLT_WHIP]);

Expand Down Expand Up @@ -631,6 +638,13 @@ boolean handleSpearAttacks(creature *attacker, enum directions dir, boolean *abo
return false;
}

// The neighboring position in the attack direction must not be diagonally blocked
// Generally speaking, the attacker must be able to move one tile in the attack direction.
pos neighborLoc = posNeighborInDirection(attacker->loc, dir);
if (diagonalBlocked(attacker->loc.x, attacker->loc.y, neighborLoc.x, neighborLoc.y, attacker == &player)) {
return false;
}

for (i = 0; i < range; i++) {
const pos targetLoc = (pos) {
attacker->loc.x + (1 + i) * nbDirs[dir][0],
Expand Down

0 comments on commit d47925c

Please sign in to comment.