From c68dfe8f52d66e9c0de326f64c1505a59483192a Mon Sep 17 00:00:00 2001 From: PatR Date: Tue, 31 May 2016 05:35:56 -0700 Subject: [PATCH] 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). --- src/objnam.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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]; } -- 2.40.0