Skip to content

Commit ae8d652

Browse files
authored
Document monster movement and visibility functions (#652)
1 parent 1bd85d9 commit ae8d652

File tree

1 file changed

+47
-4
lines changed

1 file changed

+47
-4
lines changed

src/brogue/Monsters.c

+47-4
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ creature *generateMonster(short monsterID, boolean itemPossible, boolean mutatio
163163
return monst;
164164
}
165165

166+
/// @brief Checks if the player knows a monster's location via telepathy or entrancement.
167+
/// @param monst the monster
168+
/// @return true if the monster is either entranced or revealed by telepathy
166169
boolean monsterRevealed(creature *monst) {
167170
if (monst == &player) {
168171
return false;
@@ -191,6 +194,15 @@ boolean monsterHiddenBySubmersion(const creature *monst, const creature *observe
191194
return false;
192195
}
193196

197+
/// @brief Checks if a creature is in a state that hides it from an observer.
198+
/// A creature is hidden if it's dormant, invisible (and not exposed by gas), or submerged (and the observer isn't).
199+
/// However, leader/followers and player/allies are never hidden from each other.
200+
/// Ignores line of sight, stealth, lighting, clairvoyance, telepathy, and terrain (except deep water).
201+
/// Used for bolt targeting/paths (player & monsters), whip/spear attacks (player & monsters).
202+
/// Called by canSeeMonster and canDirectlySeeMonster. A bit of a misnomer since monst can be the player.
203+
/// @param monst the creature
204+
/// @param observer the observer
205+
/// @return true if the creature is hidden from the observer
194206
boolean monsterIsHidden(const creature *monst, const creature *observer) {
195207
if (monst->bookkeepingFlags & MB_IS_DORMANT) {
196208
return true;
@@ -209,6 +221,14 @@ boolean monsterIsHidden(const creature *monst, const creature *observer) {
209221
return false;
210222
}
211223

224+
/// @brief Checks if the player has full knowledge about a creature,
225+
/// i.e. they know where it is, and what kind it is. Ignores hallucination.
226+
/// Equivalent to the monster being not hidden and either on a visible cell or revealed.
227+
/// Some notable uses include: auto-targeting (staffs, wands, etc.), determining which monsters
228+
/// display in the sidebar, auto-id of unidentified items (staffs, wands, runics, etc.), and the
229+
/// verbiage used in combat/dungeon messages (or whether a message appears at all).
230+
/// @param monst the monster
231+
/// @return true if the monster is not hidden and the player knows its location
212232
boolean canSeeMonster(creature *monst) {
213233
if (monst == &player) {
214234
return true;
@@ -220,7 +240,11 @@ boolean canSeeMonster(creature *monst) {
220240
return false;
221241
}
222242

223-
// This is different from canSeeMonster() in that it counts only physical sight -- not clairvoyance or telepathy.
243+
/// @brief Checks if the player can physically see a monster (i.e. line of sight and adequate lighting).
244+
/// Ignores telepathy, but invisible allies are treated as visible. Clairvoyant lighting is ignored, but
245+
/// darkening is a factor because it affects a cell's VISIBLE flag.
246+
/// @param monst the monster
247+
/// @return true if the player can physically see the monster
224248
boolean canDirectlySeeMonster(creature *monst) {
225249
if (monst == &player) {
226250
return true;
@@ -1478,6 +1502,14 @@ boolean monsterAvoids(creature *monst, pos p) {
14781502
return false;
14791503
}
14801504

1505+
/// @brief Attempts to utilize a monster's turn by either initiating movement or launching an attack.
1506+
/// Aims to shift the monster one space closer to the destination by evaluating the feasibility
1507+
/// of moves in different directions. If the destination is occupied by an accessible enemy within
1508+
/// melee range (including whip/spear), the monster will attack instead of moving.
1509+
/// @param monst the monster
1510+
/// @param targetLoc the destination
1511+
/// @param willingToAttackPlayer
1512+
/// @return true if a turn-consuming action was performed
14811513
static boolean moveMonsterPassivelyTowards(creature *monst, pos targetLoc, boolean willingToAttackPlayer) {
14821514
const int x = monst->loc.x;
14831515
const int y = monst->loc.y;
@@ -2430,6 +2462,7 @@ boolean monsterSummons(creature *monst, boolean alwaysUse) {
24302462

24312463
// Some monsters never make good targets irrespective of what bolt we're contemplating.
24322464
// Return false for those. Otherwise, return true.
2465+
// Used for monster-cast bolts only.
24332466
static boolean generallyValidBoltTarget(creature *caster, creature *target) {
24342467
if (caster == target) {
24352468
// Can't target yourself; that's the fundamental theorem of Brogue bolts.
@@ -2482,6 +2515,7 @@ static boolean targetEligibleForCombatBuff(creature *caster, creature *target) {
24822515

24832516
// Make a decision as to whether the given caster should fire the given bolt at the given target.
24842517
// Assumes that the conditions in generallyValidBoltTarget have already been satisfied.
2518+
// Used for monster-cast bolts only.
24852519
static boolean specificallyValidBoltTarget(creature *caster, creature *target, enum boltType theBoltType) {
24862520

24872521
if ((boltCatalog[theBoltType].flags & BF_TARGET_ALLIES)
@@ -2924,6 +2958,9 @@ static void monsterMillAbout(creature *monst, short movementChance) {
29242958
}
29252959
}
29262960

2961+
/// @brief Handles the given allied monster's turn under normal circumstances
2962+
/// e.g. not discordant, fleeing, paralyzed or entranced
2963+
/// @param monst the allied monster
29272964
static void moveAlly(creature *monst) {
29282965
creature *closestMonster = NULL;
29292966
short i, j, x, y, dir, shortestDistance, leashLength;
@@ -3586,9 +3623,15 @@ void setMonsterLocation(creature *monst, pos newLoc) {
35863623
}
35873624
}
35883625

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

0 commit comments

Comments
 (0)