-/* NetHack 3.6 context.h $NHDT-Date: 1447653421 2015/11/16 05:57:01 $ $NHDT-Branch: master $:$NHDT-Revision: 1.28 $ */
+/* NetHack 3.6 context.h $NHDT-Date: 1455835579 2016/02/18 22:46:19 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.29 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
struct novel_tracking { /* for choosing random passage when reading novel */
unsigned id; /* novel oid from previous passage selection */
int count; /* number of passage indices available in pasg[] */
- xchar pasg[30]; /* pasg[0..count] are passage indices */
+ xchar pasg[20]; /* pasg[0..count-1] are passage indices */
+ /* tribute file is allowed to have more than 20 passages for a novel;
+ if it does, reading will first choose a random subset of 20 of them;
+ reading all 20 or switching to a different novel and then back again
+ will pick a new subset, independent of previous ones so might not
+ contain all--or even any--of the ones left out of the prior subset;
+ chatting with Death works the same as reading a novel except that
+ sometimes he delivers one of a few hardcoded messages rather than a
+ passage from the Death Quotes section of dat/tribute */
};
struct context_info {
-/* NetHack 3.6 files.c $NHDT-Date: 1454035130 2016/01/29 02:38:50 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.202 $ */
+/* NetHack 3.6 files.c $NHDT-Date: 1455835581 2016/02/18 22:46:21 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.204 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
#define TITLESCOPE 2
#define PASSAGESCOPE 3
-#define MAXPASSAGES SIZE(context.novel.pasg) /* 30 */
+#define MAXPASSAGES SIZE(context.novel.pasg) /* 20 */
static int FDECL(choose_passage, (int, unsigned));
been chosen, reset the tracking to make all passages available again */
static int
choose_passage(passagecnt, oid)
-int passagecnt; /* total of available passages, 1..MAXPASSAGES */
+int passagecnt; /* total of available passages */
unsigned oid; /* book.o_id, used to determine whether re-reading same book */
{
int idx, res;
if (passagecnt < 1)
return 0;
- if (passagecnt > MAXPASSAGES)
- passagecnt = MAXPASSAGES;
/* if a different book or we've used up all the passages already,
reset in order to have all 'passagecnt' passages available */
if (oid != context.novel.id || context.novel.count == 0) {
+ int i, range = passagecnt, limit = MAXPASSAGES;
+
context.novel.id = oid;
- context.novel.count = passagecnt;
- for (idx = 0; idx < MAXPASSAGES; idx++)
- context.novel.pasg[idx] = (xchar) ((idx < passagecnt) ? idx + 1
- : 0);
+ if (range <= limit) {
+ /* collect all of the N indices */
+ context.novel.count = passagecnt;
+ for (idx = 0; idx < MAXPASSAGES; idx++)
+ context.novel.pasg[idx] = (xchar) ((idx < passagecnt)
+ ? idx + 1 : 0);
+ } else {
+ /* collect MAXPASSAGES of the N indices */
+ context.novel.count = MAXPASSAGES;
+ for (idx = i = 0; i < passagecnt; ++i, --range)
+ if (range > 0 && rn2(range) < limit) {
+ context.novel.pasg[idx++] = (xchar) (i + 1);
+ --limit;
+ }
+ }
}
idx = rn2(context.novel.count);
if ((p2 = index(p1, ')')) != 0) {
*p2 = '\0';
passagecnt = atoi(p1);
- if (passagecnt > MAXPASSAGES)
- passagecnt = MAXPASSAGES;
scope = TITLESCOPE;
if (matchedsection && !strcmpi(st, tribtitle)) {
matchedtitle = TRUE;