Update minion.c

szy_
pmje2o5iu 1 year ago
parent cf18d840fa
commit c30b724d83

@ -16,22 +16,22 @@ static const int elementals[4] = {
void
newemin(struct monst *mtmp)
{
if (!mtmp->mextra)
mtmp->mextra = newmextra();
if (!EMIN(mtmp)) {
EMIN(mtmp) = (struct emin *) alloc(sizeof(struct emin));
(void) memset((genericptr_t) EMIN(mtmp), 0, sizeof(struct emin));
if (!mtmp->mextra) // If the monster does not have an mextra structure
mtmp->mextra = newmextra(); // Create a new mextra structure for the monster
if (!EMIN(mtmp)) { // If the monster does not have an emin structure
EMIN(mtmp) = (struct emin *) alloc(sizeof(struct emin)); // Allocate memory for the emin structure
(void) memset((genericptr_t) EMIN(mtmp), 0, sizeof(struct emin)); // Initialize the emin structure with zeros
}
}
void
free_emin(struct monst *mtmp)
{
if (mtmp->mextra && EMIN(mtmp)) {
free((genericptr_t) EMIN(mtmp));
EMIN(mtmp) = (struct emin *) 0;
if (mtmp->mextra && EMIN(mtmp)) { // If the monster has an mextra structure and an emin structure
free((genericptr_t) EMIN(mtmp)); // Free the memory allocated for the emin structure
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 */
@ -42,15 +42,15 @@ monster_census(boolean spotted) /* seen|sensed vs all */
int count = 0;
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
if (DEADMONSTER(mtmp))
if (DEADMONSTER(mtmp)) // If the monster is dead, skip to the next monster
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;
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;
++count;
++count; // Increment the count
}
return count;
return count; // Return the final count
}
/* 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
* could get this far with an extinct dtype), try another.
*/
if ((gm.mvitals[dtype].mvflags & G_GONE) != 0) {
dtype = ndemon(atyp);
if (dtype == NON_PM)
return 0;
}
if ((gm.mvitals[dtype].mvflags & G_GONE) != 0) { // Check if the monster type is flagged as gone
dtype = ndemon(atyp); // Generate a new demon monster type
if (dtype == NON_PM) // If the generated type is not a valid monster type
return 0; // Return 0 to indicate failure
}
/* some candidates can generate a group of monsters, so simple
count of non-null makemon() result is not sufficient */
@ -426,12 +426,12 @@ lminion(void)
struct permonst *ptr;
for (tryct = 0; tryct < 20; tryct++) {
ptr = mkclass(S_ANGEL, 0);
if (ptr && !is_lord(ptr))
return monsndx(ptr);
ptr = mkclass(S_ANGEL, 0); // Generate a random monster class of angels
if (ptr && !is_lord(ptr)) // If a valid non-lord monster is generated
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

Loading…
Cancel
Save