Fix makemon() trying to generate a monster on top of another monster

When makemon was called with all-zero arguments (e.g. for random
monster generation over time), ptr==NULL means "a random monster".
This was being forwarded to mon==NULL in makemon_rnd_goodpos, and
then mtmp==NULL in goodpos, which means "an object, not a monster".
Because objects can be generated under monsters, this meant that an
attempt to create a random monster could end up choosing a location
that already had a monster, which would then cause the monster
generation to fail.

This mostly wasn't noticeable in normal play: it effectively
reduced the monster generation rate depending on how many locations
outside LOS happened to contain a monster. Normally that's a very
small proportion, so the bug had no obvious effects: but when there
are very few locations outside LOS (i.e. the player can see almost
every location on the level), the bug effectively caused monster
generation to stop once those locations became occupied by
non-moving (e.g. hiding) monsters, something that became observable
in games where the player decided to dig out and light almost an
entire level.

This commit fixes the problem by adding a new flag to goodpos that
requests that it not choose a position that already has a monster.

This bug was diagnosed, and this fix committed, by ais523; but
nhmall wrote almost all of the code implementing the fix.
This commit is contained in:
nhmall
2024-02-27 19:04:35 +00:00
committed by Alex Smith
parent 1d26f80ccf
commit 334535e7b0
4 changed files with 38 additions and 28 deletions

View File

@@ -1073,33 +1073,36 @@ typedef uint32_t mmflags_nht; /* makemon MM_ flags */
/* flags to control makemon(); goodpos() uses some plus has some of its own*/
#define NO_MM_FLAGS 0x000000L /* use this rather than plain 0 */
#define NO_MINVENT 0x000001L /* suppress minvent when creating mon */
#define MM_NOWAIT 0x000002L /* don't set STRAT_WAITMASK flags */
#define MM_NOCOUNTBIRTH 0x0004L /* don't increment born count (for revival) */
#define MM_IGNOREWATER 0x0008L /* ignore water when positioning */
#define MM_ADJACENTOK 0x0010L /* acceptable to use adjacent coordinates */
#define MM_ANGRY 0x000020L /* monster is created angry */
#define MM_NONAME 0x000040L /* monster is not christened */
#define MM_EGD 0x000100L /* add egd structure */
#define MM_EPRI 0x000200L /* add epri structure */
#define MM_ESHK 0x000400L /* add eshk structure */
#define MM_EMIN 0x000800L /* add emin structure */
#define MM_EDOG 0x001000L /* add edog structure */
#define MM_ASLEEP 0x002000L /* monsters should be generated asleep */
#define MM_NOGRP 0x004000L /* suppress creation of monster groups */
#define MM_NOTAIL 0x008000L /* if a long worm, don't give it a tail */
#define MM_MALE 0x010000L /* male variation */
#define MM_FEMALE 0x020000L /* female variation */
#define MM_NOMSG 0x040000L /* no appear message */
#define NO_MM_FLAGS 0x00000000L /* use this rather than plain 0 */
#define NO_MINVENT 0x00000001L /* suppress minvent when creating mon */
#define MM_NOWAIT 0x00000002L /* don't set STRAT_WAITMASK flags */
#define MM_NOCOUNTBIRTH 0x00000004L /* don't incr born count (for revival) */
#define MM_IGNOREWATER 0x00000008L /* ignore water when positioning */
#define MM_ADJACENTOK 0x00000010L /* ok to use adjacent coordinates */
#define MM_ANGRY 0x00000020L /* monster is created angry */
#define MM_NONAME 0x00000040L /* monster is not christened */
#define MM_EGD 0x00000080L /* add egd structure */
#define MM_EPRI 0x00000100L /* add epri structure */
#define MM_ESHK 0x00000200L /* add eshk structure */
#define MM_EMIN 0x00000400L /* add emin structure */
#define MM_EDOG 0x00000800L /* add edog structure */
#define MM_ASLEEP 0x00001000L /* monsters should be generated asleep */
#define MM_NOGRP 0x00002000L /* suppress creation of monster groups */
#define MM_NOTAIL 0x00004000L /* if a long worm, don't give it a tail */
#define MM_MALE 0x00008000L /* male variation */
#define MM_FEMALE 0x00010000L /* female variation */
#define MM_NOMSG 0x00020000L /* no appear message */
#define MM_NOEXCLAM 0x00040000L /* more sedate "<mon> appears."
* mesg for ^G */
#define MM_IGNORELAVA 0x00080000L /* ignore lava when positioning */
#define MM_MINVIS 0x00100000L /* for ^G/create_particular */
/* if more MM_ flag masks are added, skip or renumber the GP_ one(s) */
#define GP_ALLOW_XY 0x080000L /* [actually used by enexto() to decide
* whether to make extra call to goodpos()] */
#define GP_ALLOW_U 0x100000L /* don't reject hero's location */
#define GP_CHECKSCARY 0x200000L /* check monster for onscary() */
#define MM_NOEXCLAM 0x400000L /* more sedate "<mon> appears." mesg for ^G */
#define MM_IGNORELAVA 0x800000L /* ignore lava when positioning */
#define MM_MINVIS 0x01000000L /* for ^G/create_particular */
#define GP_ALLOW_XY 0x00200000L /* [actually used by enexto() to decide
* whether to make extra call to goodpos()] */
#define GP_ALLOW_U 0x00400000L /* don't reject hero's location */
#define GP_CHECKSCARY 0x00800000L /* check monster for onscary() */
#define GP_AVOID_MONPOS 0x01000000L /* don't accept existing mon location */
/* 25 bits used */
/* flags for make_corpse() and mkcorpstat(); 0..7 are recorded in obj->spe */
#define CORPSTAT_NONE 0x00