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.
52 KiB
52 KiB