wishing fix
commitc68dfe8f52d66e9c0de326f64c1505a59483192a
authorPatR <rankin@nethack.org>
Tue, 31 May 2016 12:35:56 +0000 (31 05:35 -0700)
committerPatR <rankin@nethack.org>
Tue, 31 May 2016 12:35:56 +0000 (31 05:35 -0700)
treee31c3736ff13084913c7110b8e5a48831c1ce850
parent30855febad4818ddc24034f3cfaff36abd4751a3
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