Skip to content

Commit

Permalink
Allow allies to spear attack over the player (#650)
Browse files Browse the repository at this point in the history
  • Loading branch information
zenzombie authored Jan 22, 2024
1 parent 0d525ca commit ec2e49d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions changes/allow-ally-spear-attacks-over-player.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allows allies to spear attack over the player
25 changes: 21 additions & 4 deletions src/brogue/Monsters.c
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,14 @@ boolean monsterAvoids(creature *monst, pos p) {
return false;
}

/// @brief Attempts to utilize a monster's turn by either initiating movement or launching an attack.
/// Aims to shift the monster one space closer to the destination by evaluating the feasibility
/// of moves in different directions. If the destination is occupied by an accessible enemy within
/// melee range (including whip/spear), the monster will attack instead of moving.
/// @param monst the monster
/// @param targetLoc the destination
/// @param willingToAttackPlayer
/// @return true if a turn-consuming action was performed
boolean moveMonsterPassivelyTowards(creature *monst, pos targetLoc, boolean willingToAttackPlayer) {
const int x = monst->loc.x;
const int y = monst->loc.y;
Expand Down Expand Up @@ -2924,6 +2932,9 @@ void monsterMillAbout(creature *monst, short movementChance) {
}
}

/// @brief Handles the given allied monster's turn under normal circumstances
/// e.g. not discordant, fleeing, paralyzed or entranced
/// @param monst the allied monster
void moveAlly(creature *monst) {
creature *closestMonster = NULL;
short i, j, x, y, dir, shortestDistance, leashLength;
Expand Down Expand Up @@ -3091,7 +3102,7 @@ void moveAlly(creature *monst) {
}

targetLoc = closestMonster->loc;
moveMonsterPassivelyTowards(monst, targetLoc, false);
moveMonsterPassivelyTowards(monst, targetLoc, true);
} else if (isPosInMap(monst->targetCorpseLoc)
&& !monst->status[STATUS_POISONED]
&& (!monst->status[STATUS_BURNING] || monst->status[STATUS_IMMUNE_TO_FIRE])) { // Going to start eating a corpse.
Expand Down Expand Up @@ -3586,9 +3597,15 @@ void setMonsterLocation(creature *monst, pos newLoc) {
}
}

// Tries to move the given monster in the given vector; returns true if the move was legal
// (including attacking player, vomiting or struggling in vain)
// Be sure that dx, dy are both in the range [-1, 1] or the move will sometimes fail due to the diagonal check.
/// @brief Tries to move a monster one space or perform a melee attack in the given direction.
/// Handles confused movement, turn-consuming non-movement actions like vomiting, and unique
/// attack patterns (axe-like, whip, spear). Fast-moving monsters get 2 turns, moving one
/// space each time.
/// @param monst the monster
/// @param dx the x axis component of the direction [-1, 0, 1]
/// @param dy the y axis component of the direction [-1, 0, 1]
/// @return true if a turn-consuming action was performed. otherwise false (e.g. monster is
/// unwilling to attack or blocked by terrain)
boolean moveMonster(creature *monst, short dx, short dy) {
short x = monst->loc.x, y = monst->loc.y;
short newX, newY;
Expand Down

0 comments on commit ec2e49d

Please sign in to comment.