shiny object probabilities
The wishing code uses 'oc_prob + 1' so that probability 0 (never random) objects are eligible to be selected if their name matches a wish; collecting 'shiny' objects shouldn't do that. (No effect on play since there aren't any shiny objects with 0% random chance.) rn2() takes int, and total oc_prob for entire objects[] array is 15000, so don't accumulate the target probability in a long.
This commit is contained in:
21
src/objnam.c
21
src/objnam.c
@@ -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, (char *, CHAR_P));
|
||||
STATIC_DCL short FDECL(rnd_otyp_by_namedesc, (const char *, CHAR_P));
|
||||
STATIC_DCL boolean FDECL(wishymatch, (const char *, const char *, BOOLEAN_P));
|
||||
STATIC_DCL char *NDECL(nextobuf);
|
||||
STATIC_DCL void FDECL(releaseobuf, (char *));
|
||||
@@ -2693,6 +2693,7 @@ schar skill;
|
||||
{
|
||||
int i, n = 0;
|
||||
short otyp = STRANGE_OBJECT;
|
||||
|
||||
for (i = bases[WEAPON_CLASS];
|
||||
i < NUM_OBJECTS && objects[i].oc_class == WEAPON_CLASS; i++)
|
||||
if (objects[i].oc_skill == skill) {
|
||||
@@ -2712,15 +2713,15 @@ schar skill;
|
||||
|
||||
STATIC_OVL short
|
||||
rnd_otyp_by_namedesc(name, oclass)
|
||||
char *name;
|
||||
const char *name;
|
||||
char oclass;
|
||||
{
|
||||
int i, n = 0;
|
||||
short validobjs[NUM_OBJECTS];
|
||||
register const char *zn;
|
||||
long maxprob = 0;
|
||||
int prob, maxprob = 0;
|
||||
|
||||
if (!name)
|
||||
if (!name || !*name)
|
||||
return STRANGE_OBJECT;
|
||||
|
||||
memset((genericptr_t) validobjs, 0, sizeof validobjs);
|
||||
@@ -2737,17 +2738,15 @@ char oclass;
|
||||
|| ((zn = objects[i].oc_uname) != 0
|
||||
&& wishymatch(name, zn, FALSE))) {
|
||||
validobjs[n++] = (short) i;
|
||||
maxprob += (objects[i].oc_prob + 1);
|
||||
maxprob += objects[i].oc_prob;
|
||||
}
|
||||
}
|
||||
|
||||
if (n > 0 && maxprob) {
|
||||
long prob = rn2(maxprob);
|
||||
|
||||
i = 0;
|
||||
while (i < n - 1
|
||||
&& (prob -= (objects[validobjs[i]].oc_prob + 1)) >= 0)
|
||||
i++;
|
||||
prob = rn2(maxprob);
|
||||
for (i = 0; i < n - 1; i++)
|
||||
if ((prob -= objects[validobjs[i]].oc_prob) < 0)
|
||||
break;
|
||||
return validobjs[i];
|
||||
}
|
||||
return STRANGE_OBJECT;
|
||||
|
||||
Reference in New Issue
Block a user