adopt github pull request #286 - rndmonst()
Eliminate the cache that was supporting rndmonst() and pick a random monster in a single pass through mons[] via "weighted reservoir sampling", a term I'm not familiar with. It had a couple of bugs: if the first monster examined happened to be given a weighting of 0, rn2() would divide by 0. I didn't try to figure out how to trigger that. But the second one was easy to trigger: if all eligible monsters were extinct or genocided, it would issue a warning even though the situation isn't impossible. Aside from fixing those, the rest is mostly as-is. I included a bit of formatting in decl.c, moved some declarations to not require C99, and changed a couple of macros to not hide and duplicate a call to level_difficulty(). Fixes #286
This commit is contained in:
@@ -2107,7 +2107,6 @@ do_class_genocide()
|
||||
* have G_GENOD or !G_GENO.
|
||||
*/
|
||||
g.mvitals[i].mvflags |= (G_GENOD | G_NOCORPSE);
|
||||
reset_rndmonst(i);
|
||||
kill_genocided_monsters();
|
||||
update_inventory(); /* eggs & tins */
|
||||
pline("Wiped out all %s.", nam);
|
||||
@@ -2324,7 +2323,6 @@ int how;
|
||||
} else if (ptr == g.youmonst.data) {
|
||||
rehumanize();
|
||||
}
|
||||
reset_rndmonst(mndx);
|
||||
kill_genocided_monsters();
|
||||
update_inventory(); /* in case identified eggs were affected */
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user