From: PatR Date: Tue, 31 May 2016 12:35:56 +0000 (-0700) Subject: wishing fix X-Git-Tag: NetHack-3.6.1_RC01~719 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c68dfe8f52d66e9c0de326f64c1505a59483192a;p=nethack wishing fix rnd_otyp_by_namedesc() had an off by one error when choosing which matching item to return, making it impossible to successfully wish for the Amulet of Yendor, always yielding the plastic imitation. n == 2, maxprob == 2 prob = rn2(maxprob); => 0 or 1 i = 0; while (i < n - 1 && (prob -= ... + 1) > 0) i++; always exited the loop on the first test of the condition because subtracting 1 from 0 or 1 never yielded a result greater than 0. It's still suboptimal: "amulet of yendor" should find an exact match and should never return "cheap plastic imitation of amulet of yendor" from the partial match. I think biasing the choice among multiple candidates based on their generation probabilities only makes sense when all the candidates are within the same class. If scroll of light occurred in 5% of scrolls and spellbook of light occurred in 10% of spellbooks (both percentages pulled out of thin air), having "light" get a 2 out 3 chance to be a spellbook doesn't seem right because scrolls are four times more likely than spellbooks (in most of the dungeon; books aren't randomly generated at all on the rogue level or in Gehennom). --- diff --git a/src/objnam.c b/src/objnam.c index 618d1b5d7..fe6b25795 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -2488,7 +2488,8 @@ char oclass; long prob = rn2(maxprob); i = 0; - while (i < n - 1 && (prob -= (objects[validobjs[i]].oc_prob + 1)) > 0) + while (i < n - 1 + && (prob -= (objects[validobjs[i]].oc_prob + 1)) >= 0) i++; return validobjs[i]; }