Update minion.c

szy_
pmje2o5iu 1 year ago
parent cf18d840fa
commit c30b724d83

@ -16,22 +16,22 @@ static const int elementals[4] = {
void void
newemin(struct monst *mtmp) newemin(struct monst *mtmp)
{ {
if (!mtmp->mextra) if (!mtmp->mextra) // If the monster does not have an mextra structure
mtmp->mextra = newmextra(); mtmp->mextra = newmextra(); // Create a new mextra structure for the monster
if (!EMIN(mtmp)) { if (!EMIN(mtmp)) { // If the monster does not have an emin structure
EMIN(mtmp) = (struct emin *) alloc(sizeof(struct emin)); EMIN(mtmp) = (struct emin *) alloc(sizeof(struct emin)); // Allocate memory for the emin structure
(void) memset((genericptr_t) EMIN(mtmp), 0, sizeof(struct emin)); (void) memset((genericptr_t) EMIN(mtmp), 0, sizeof(struct emin)); // Initialize the emin structure with zeros
} }
} }
void void
free_emin(struct monst *mtmp) free_emin(struct monst *mtmp)
{ {
if (mtmp->mextra && EMIN(mtmp)) { if (mtmp->mextra && EMIN(mtmp)) { // If the monster has an mextra structure and an emin structure
free((genericptr_t) EMIN(mtmp)); free((genericptr_t) EMIN(mtmp)); // Free the memory allocated for the emin structure
EMIN(mtmp) = (struct emin *) 0; EMIN(mtmp) = (struct emin *) 0; // Set the emin pointer to null
} }
mtmp->isminion = 0; mtmp->isminion = 0; // Set the isminion flag to 0 to indicate that the monster is not a minion
} }
/* count the number of monsters on the level */ /* count the number of monsters on the level */
@ -42,15 +42,15 @@ monster_census(boolean spotted) /* seen|sensed vs all */
int count = 0; int count = 0;
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
if (DEADMONSTER(mtmp)) if (DEADMONSTER(mtmp)) // If the monster is dead, skip to the next monster
continue; continue;
if (mtmp->isgd && mtmp->mx == 0) if (mtmp->isgd && mtmp->mx == 0) // If the monster is a guardian and is not on the map, skip to the next monster
continue; continue;
if (spotted && !canspotmon(mtmp)) if (spotted && !canspotmon(mtmp)) // If spotted flag is true and the monster is not visible, skip to the next monster
continue; continue;
++count; ++count; // Increment the count
} }
return count; return count; // Return the final count
} }
/* mon summons a monster */ /* mon summons a monster */
@ -133,11 +133,11 @@ msummon(struct monst *mon)
* If this daemon is unique and being re-summoned (the only way we * If this daemon is unique and being re-summoned (the only way we
* could get this far with an extinct dtype), try another. * could get this far with an extinct dtype), try another.
*/ */
if ((gm.mvitals[dtype].mvflags & G_GONE) != 0) { if ((gm.mvitals[dtype].mvflags & G_GONE) != 0) { // Check if the monster type is flagged as gone
dtype = ndemon(atyp); dtype = ndemon(atyp); // Generate a new demon monster type
if (dtype == NON_PM) if (dtype == NON_PM) // If the generated type is not a valid monster type
return 0; return 0; // Return 0 to indicate failure
} }
/* some candidates can generate a group of monsters, so simple /* some candidates can generate a group of monsters, so simple
count of non-null makemon() result is not sufficient */ count of non-null makemon() result is not sufficient */
@ -426,12 +426,12 @@ lminion(void)
struct permonst *ptr; struct permonst *ptr;
for (tryct = 0; tryct < 20; tryct++) { for (tryct = 0; tryct < 20; tryct++) {
ptr = mkclass(S_ANGEL, 0); ptr = mkclass(S_ANGEL, 0); // Generate a random monster class of angels
if (ptr && !is_lord(ptr)) if (ptr && !is_lord(ptr)) // If a valid non-lord monster is generated
return monsndx(ptr); return monsndx(ptr); // Return the monster number
} }
return NON_PM; return NON_PM; // Return NON_PM if no valid non-lord monster can be generated after 20 tries
} }
int int

Loading…
Cancel
Save