-/* 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. */
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 *));
}
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];
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) {
|| ((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];
}
shiny_obj(oclass)
char oclass;
{
- return (int) rnd_otyp_by_namedesc("shiny", oclass);
+ return (int) rnd_otyp_by_namedesc("shiny", oclass, 0);
}
/*
}
}
- 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;