From 18d56724f91f3014269cf8b20eae83b9726bb3d9 Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 22 Sep 2018 16:46:27 -0700 Subject: [PATCH] 'unbreak' wishing probabilities Fixing rnd_otyp_by_namedesc() for use by get_shiny() broke its use by readobjnam(). Make the chance for 0% generation objects to have non-zero chance of being selected be a parameter. --- src/objnam.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/objnam.c b/src/objnam.c index a232d7860..46fc3d493 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 objnam.c $NHDT-Date: 1537313446 2018/09/18 23:30:46 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.208 $ */ +/* NetHack 3.6 objnam.c $NHDT-Date: 1537659941 2018/09/22 23:45:41 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.212 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2011. */ /* NetHack may be freely redistributed. See license for details. */ @@ -12,7 +12,7 @@ STATIC_DCL char *FDECL(strprepend, (char *, const char *)); STATIC_DCL short FDECL(rnd_otyp_by_wpnskill, (SCHAR_P)); -STATIC_DCL short FDECL(rnd_otyp_by_namedesc, (const char *, CHAR_P)); +STATIC_DCL short FDECL(rnd_otyp_by_namedesc, (const char *, CHAR_P, int)); STATIC_DCL boolean FDECL(wishymatch, (const char *, const char *, BOOLEAN_P)); STATIC_DCL char *NDECL(nextobuf); STATIC_DCL void FDECL(releaseobuf, (char *)); @@ -2712,9 +2712,10 @@ schar skill; } STATIC_OVL short -rnd_otyp_by_namedesc(name, oclass) +rnd_otyp_by_namedesc(name, oclass, xtra_prob) const char *name; char oclass; +int xtra_prob; /* to force 0% random generation items to also be considered */ { int i, n = 0; short validobjs[NUM_OBJECTS]; @@ -2726,6 +2727,14 @@ char oclass; memset((genericptr_t) validobjs, 0, sizeof validobjs); + /* FIXME: + * When this spans classes (the !oclass case), the item + * probabilities are not very useful because they don't take + * the class generation probability into account. [If 10% + * of spellbooks were blank and 1% of scrolls were blank, + * "blank" would have 10/11 chance to yield a blook even though + * scrolls are supposed to be much more common than books.] + */ for (i = oclass ? bases[(int) oclass] : STRANGE_OBJECT + 1; i < NUM_OBJECTS && (!oclass || objects[i].oc_class == oclass); ++i) { @@ -2738,14 +2747,14 @@ char oclass; || ((zn = objects[i].oc_uname) != 0 && wishymatch(name, zn, FALSE))) { validobjs[n++] = (short) i; - maxprob += objects[i].oc_prob; + maxprob += (objects[i].oc_prob + xtra_prob); } } if (n > 0 && maxprob) { prob = rn2(maxprob); for (i = 0; i < n - 1; i++) - if ((prob -= objects[validobjs[i]].oc_prob) < 0) + if ((prob -= (objects[validobjs[i]].oc_prob + xtra_prob)) < 0) break; return validobjs[i]; } @@ -2756,7 +2765,7 @@ int shiny_obj(oclass) char oclass; { - return (int) rnd_otyp_by_namedesc("shiny", oclass); + return (int) rnd_otyp_by_namedesc("shiny", oclass, 0); } /* @@ -3389,10 +3398,10 @@ srch: } } - if (((typ = rnd_otyp_by_namedesc(actualn, oclass)) != STRANGE_OBJECT) - || ((typ = rnd_otyp_by_namedesc(dn, oclass)) != STRANGE_OBJECT) - || ((typ = rnd_otyp_by_namedesc(un, oclass)) != STRANGE_OBJECT) - || ((typ = rnd_otyp_by_namedesc(origbp, oclass)) != STRANGE_OBJECT)) + if (((typ = rnd_otyp_by_namedesc(actualn, oclass, 1)) != STRANGE_OBJECT) + || ((typ = rnd_otyp_by_namedesc(dn, oclass, 1)) != STRANGE_OBJECT) + || ((typ = rnd_otyp_by_namedesc(un, oclass, 1)) != STRANGE_OBJECT) + || ((typ = rnd_otyp_by_namedesc(origbp, oclass, 1)) != STRANGE_OBJECT)) goto typfnd; typ = 0; -- 2.40.0