tribute streamlining

Chatting with Death doesn't always deliver a tribute Death Quote but
when it does, it wasn't giving each of them once before reusing them
even though they should have been treated the same as passage
selections from a novel.  I'm still not sure why it wasn't working
as intended, but after some revision to the tribute parsing code, now
it is.  If you #chat with Death enough times to get 20 tribute quotes,
you will see each of the 20 quotes once (in random order), then
further chatting will give them again (in different random order).
This commit is contained in:
PatR
2016-01-16 17:36:48 -08:00
parent 06aedee513
commit 350dcf067b
2 changed files with 75 additions and 70 deletions
+49 -41
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 files.c $NHDT-Date: 1451697801 2016/01/02 01:23:21 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.199 $ */ /* NetHack 3.6 files.c $NHDT-Date: 1452992318 2016/01/17 00:58:38 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.201 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -3519,6 +3519,9 @@ unsigned oid; /* book identifier */
boolean grasped = FALSE; boolean grasped = FALSE;
boolean foundpassage = FALSE; boolean foundpassage = FALSE;
if (nowin_buf)
*nowin_buf = '\0';
/* check for mandatories */ /* check for mandatories */
if (!tribsection || !tribtitle) { if (!tribsection || !tribtitle) {
if (!nowin_buf) if (!nowin_buf)
@@ -3562,12 +3565,12 @@ unsigned oid; /* book identifier */
(void) strip_newline(line); (void) strip_newline(line);
switch (line[0]) { switch (line[0]) {
case '%': case '%':
if (!strncmpi(&line[1], "section ", sizeof("section ") - 1)) { if (!strncmpi(&line[1], "section ", sizeof "section " - 1)) {
char *st = &line[9]; /* 9 from "%section " */ char *st = &line[9]; /* 9 from "%section " */
scope = SECTIONSCOPE; scope = SECTIONSCOPE;
matchedsection = !strcmpi(st, tribsection) ? TRUE : FALSE; matchedsection = !strcmpi(st, tribsection) ? TRUE : FALSE;
} else if (!strncmpi(&line[1], "title ", sizeof("title ") - 1)) { } else if (!strncmpi(&line[1], "title ", sizeof "title " - 1)) {
char *st = &line[7]; /* 7 from "%title " */ char *st = &line[7]; /* 7 from "%title " */
char *p1, *p2; char *p1, *p2;
@@ -3592,27 +3595,25 @@ unsigned oid; /* book identifier */
} }
} }
} else if (!strncmpi(&line[1], "passage ", } else if (!strncmpi(&line[1], "passage ",
sizeof("passage ") - 1)) { sizeof "passage " - 1)) {
int passagenum = 0; int passagenum = 0;
char *st = &line[9]; /* 9 from "%passage " */ char *st = &line[9]; /* 9 from "%passage " */
while (*st == ' ' || *st == '\t') mungspaces(st);
st++; passagenum = atoi(st);
if (*st && digit(*st) && (strlen(st) < 3)) if (passagenum > 0 && passagenum <= passagecnt) {
passagenum = atoi(st);
if (passagenum && (passagenum <= passagecnt)) {
scope = PASSAGESCOPE; scope = PASSAGESCOPE;
if (matchedtitle && (passagenum == targetpassage)) { if (matchedtitle && passagenum == targetpassage) {
if (!nowin_buf) foundpassage = TRUE;
if (!nowin_buf) {
tribwin = create_nhwindow(NHW_MENU); tribwin = create_nhwindow(NHW_MENU);
else if (tribwin == WIN_ERR)
foundpassage = TRUE; goto cleanup;
}
} }
} }
} else if (!strncmpi(&line[1], "e ", sizeof("e ") - 1)) { } else if (!strncmpi(&line[1], "e ", sizeof "e " - 1)) {
if (matchedtitle && scope == PASSAGESCOPE if (foundpassage)
&& ((!nowin_buf && tribwin != WIN_ERR)
|| (nowin_buf && foundpassage)))
goto cleanup; goto cleanup;
if (scope == TITLESCOPE) if (scope == TITLESCOPE)
matchedtitle = FALSE; matchedtitle = FALSE;
@@ -3629,13 +3630,16 @@ unsigned oid; /* book identifier */
/* comment only, next! */ /* comment only, next! */
break; break;
default: default:
if (matchedtitle && scope == PASSAGESCOPE) { if (foundpassage) {
if (!nowin_buf && tribwin != WIN_ERR) { if (!nowin_buf) {
/* outputting multi-line passage to text window */
putstr(tribwin, 0, line); putstr(tribwin, 0, line);
Strcpy(lastline, line); if (*line)
} else if (nowin_buf) { Strcpy(lastline, line);
if ((int) strlen(line) < bufsz - 1) } else {
Strcpy(nowin_buf, line); /* fetching one-line passage into buffer */
copynchars(nowin_buf, line, bufsz - 1);
goto cleanup; /* don't wait for "%e passage" */
} }
} }
} }
@@ -3643,26 +3647,30 @@ unsigned oid; /* book identifier */
cleanup: cleanup:
(void) dlb_fclose(fp); (void) dlb_fclose(fp);
if (!nowin_buf && tribwin != WIN_ERR) { if (nowin_buf) {
if (matchedtitle && scope == PASSAGESCOPE) { /* one-line buffer */
display_nhwindow(tribwin, FALSE); grasped = *nowin_buf ? TRUE : FALSE;
/* put the final attribution line into message history,
analogous to the summary line from long quest messages */
if (index(lastline, '['))
mungspaces(lastline); /* to remove leading spaces */
else /* construct one if necessary */
Sprintf(lastline, "[%s, by Terry Pratchett]", tribtitle);
putmsghistory(lastline, FALSE);
}
destroy_nhwindow(tribwin);
tribwin = WIN_ERR;
grasped = TRUE;
} else { } else {
if (!nowin_buf) if (tribwin != WIN_ERR) { /* implies 'foundpassage' */
pline("It seems to be %s of \"%s\"!", badtranslation, tribtitle); /* multi-line window, normal case;
else if lastline is empty, there were no non-empty lines between
if (foundpassage) "%passage n" and "%e passage" so we leave 'grasped' False */
if (*lastline) {
display_nhwindow(tribwin, FALSE);
/* put the final attribution line into message history,
analogous to the summary line from long quest messages */
if (index(lastline, '['))
mungspaces(lastline); /* to remove leading spaces */
else /* construct one if necessary */
Sprintf(lastline, "[%s, by Terry Pratchett]", tribtitle);
putmsghistory(lastline, FALSE);
grasped = TRUE; grasped = TRUE;
}
destroy_nhwindow(tribwin);
}
if (!grasped)
/* multi-line window, problem */
pline("It seems to be %s of \"%s\"!", badtranslation, tribtitle);
} }
return grasped; return grasped;
} }
+26 -29
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 sounds.c $NHDT-Date: 1450461632 2015/12/18 18:00:32 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.77 $ */ /* NetHack 3.6 sounds.c $NHDT-Date: 1452992329 2016/01/17 00:58:49 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.78 $ */
/* Copyright (c) 1989 Janet Walz, Mike Threepoint */ /* Copyright (c) 1989 Janet Walz, Mike Threepoint */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -494,7 +494,7 @@ register struct monst *mtmp;
char verbuf[BUFSZ]; char verbuf[BUFSZ];
register const char *pline_msg = 0, /* Monnam(mtmp) will be prepended */ register const char *pline_msg = 0, /* Monnam(mtmp) will be prepended */
*verbl_msg = 0, /* verbalize() */ *verbl_msg = 0, /* verbalize() */
*verbl_msg_mcan = 0; /* verbalize() if cancelled */ *verbl_msg_mcan = 0; /* verbalize() if cancelled */
struct permonst *ptr = mtmp->data; struct permonst *ptr = mtmp->data;
int msound = ptr->msound; int msound = ptr->msound;
@@ -824,6 +824,7 @@ register struct monst *mtmp;
break; break;
case MS_SEDUCE: { case MS_SEDUCE: {
int swval; int swval;
if (SYSOPT_SEDUCE) { if (SYSOPT_SEDUCE) {
if (ptr->mlet != S_NYMPH if (ptr->mlet != S_NYMPH
&& could_seduce(mtmp, &youmonst, (struct attack *) 0) == 1) { && could_seduce(mtmp, &youmonst, (struct attack *) 0) == 1) {
@@ -907,50 +908,46 @@ register struct monst *mtmp;
: soldier_foe_msg[rn2(3)]; : soldier_foe_msg[rn2(3)];
break; break;
} }
case MS_RIDER: case MS_RIDER: {
/* 3.6 tribute */ const char *tribtitle;
if (ptr == &mons[PM_DEATH] struct obj *book = 0;
&& !context.tribute.Deathnotice && u_have_novel()) {
struct obj *book = u_have_novel();
const char *tribtitle = (char *)0;
if (book) { /* 3.6.0 tribute */
int novelidx = book->novelidx; if (ptr == &mons[PM_DEATH] && !context.tribute.Deathnotice
&& (book = u_have_novel()) != 0) {
tribtitle = noveltitle(&novelidx); if ((tribtitle = noveltitle(&book->novelidx)) != 0) {
}
if (tribtitle) {
Sprintf(verbuf, "Ah, so you have a copy of /%s/.", tribtitle); Sprintf(verbuf, "Ah, so you have a copy of /%s/.", tribtitle);
/* no Death featured in these two, so exclude them */ /* no Death featured in these two, so exclude them */
if (!(strcmpi(tribtitle, "Snuff") == 0 if (!strcmpi(tribtitle, "Snuff")
|| strcmpi(tribtitle, "The Wee Free Men") == 0)) || !strcmpi(tribtitle, "The Wee Free Men"))
Strcat(verbuf, " I may have been misquoted there."); Strcat(verbuf, " I may have been misquoted there.");
verbl_msg = verbuf; verbl_msg = verbuf;
context.tribute.Deathnotice = 1;
} }
} else if (ptr == &mons[PM_DEATH] context.tribute.Deathnotice = 1;
&& !rn2(2) && Death_quote(verbuf, BUFSZ)) { } else if (ptr == &mons[PM_DEATH] && rn2(3)
&& Death_quote(verbuf, BUFSZ)) {
verbl_msg = verbuf; verbl_msg = verbuf;
}
/* end of tribute addition */ /* end of tribute addition */
else if (ptr == &mons[PM_DEATH] && !rn2(10)) } else if (ptr == &mons[PM_DEATH] && !rn2(10)) {
pline_msg = "is busy reading a copy of Sandman #8."; pline_msg = "is busy reading a copy of Sandman #8.";
else } else
verbl_msg = "Who do you think you are, War?"; verbl_msg = "Who do you think you are, War?";
break; break;
} } /* MS_RIDER */
} /* switch */
if (pline_msg) if (pline_msg) {
pline("%s %s", Monnam(mtmp), pline_msg); pline("%s %s", Monnam(mtmp), pline_msg);
else if (mtmp->mcan && verbl_msg_mcan) } else if (mtmp->mcan && verbl_msg_mcan) {
verbalize1(verbl_msg_mcan); verbalize1(verbl_msg_mcan);
else if (verbl_msg) { } else if (verbl_msg) {
if (ptr == &mons[PM_DEATH]) { if (ptr == &mons[PM_DEATH]) {
/* Death talks in CAPITAL LETTERS /* Death talks in CAPITAL LETTERS
and without quotation marks */ and without quotation marks */
char tmpbuf[BUFSZ]; char tmpbuf[BUFSZ];
Sprintf(tmpbuf, "%s", verbl_msg);
pline1(ucase(tmpbuf)); pline1(ucase(strcpy(tmpbuf, verbl_msg)));
} else { } else {
verbalize1(verbl_msg); verbalize1(verbl_msg);
} }