I've tried to understand monster generation and believe the attached patch creates a functionally equivalent (minus the MONS_PROGRAM_BUG's) implementation of monplace.cc:pick_random_monster.
This should be a lot more efficient than the current version, though it's still quite suboptimal, traversing all monster types twice. The same change could be applied to abyss monster generation, and possibly elsewhere. In that case, the "algorithm" should probably be factored out into stuff.cc (some general "chose one among many with varying weights").
I'm pretty sure the current behaviour is to some extent accidental, but I guess it works well enough. Probably best to make the code clearer first and adapt afterwards.
Log in to post a comment.