From: PatR Date: Sun, 17 Jan 2016 01:36:48 +0000 (-0800) Subject: tribute streamlining X-Git-Tag: NetHack-3.6.1_RC01~1006 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=350dcf067b6085e6c044568e7f37183227ae60be;p=nethack 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). --- diff --git a/src/files.c b/src/files.c index 8836b2b90..c367e6d15 100644 --- a/src/files.c +++ b/src/files.c @@ -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. */ /* NetHack may be freely redistributed. See license for details. */ @@ -3519,6 +3519,9 @@ unsigned oid; /* book identifier */ boolean grasped = FALSE; boolean foundpassage = FALSE; + if (nowin_buf) + *nowin_buf = '\0'; + /* check for mandatories */ if (!tribsection || !tribtitle) { if (!nowin_buf) @@ -3562,12 +3565,12 @@ unsigned oid; /* book identifier */ (void) strip_newline(line); switch (line[0]) { case '%': - if (!strncmpi(&line[1], "section ", sizeof("section ") - 1)) { + if (!strncmpi(&line[1], "section ", sizeof "section " - 1)) { char *st = &line[9]; /* 9 from "%section " */ scope = SECTIONSCOPE; 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 *p1, *p2; @@ -3592,27 +3595,25 @@ unsigned oid; /* book identifier */ } } } else if (!strncmpi(&line[1], "passage ", - sizeof("passage ") - 1)) { + sizeof "passage " - 1)) { int passagenum = 0; char *st = &line[9]; /* 9 from "%passage " */ - while (*st == ' ' || *st == '\t') - st++; - if (*st && digit(*st) && (strlen(st) < 3)) - passagenum = atoi(st); - if (passagenum && (passagenum <= passagecnt)) { + mungspaces(st); + passagenum = atoi(st); + if (passagenum > 0 && passagenum <= passagecnt) { scope = PASSAGESCOPE; - if (matchedtitle && (passagenum == targetpassage)) { - if (!nowin_buf) + if (matchedtitle && passagenum == targetpassage) { + foundpassage = TRUE; + if (!nowin_buf) { tribwin = create_nhwindow(NHW_MENU); - else - foundpassage = TRUE; + if (tribwin == WIN_ERR) + goto cleanup; + } } } - } else if (!strncmpi(&line[1], "e ", sizeof("e ") - 1)) { - if (matchedtitle && scope == PASSAGESCOPE - && ((!nowin_buf && tribwin != WIN_ERR) - || (nowin_buf && foundpassage))) + } else if (!strncmpi(&line[1], "e ", sizeof "e " - 1)) { + if (foundpassage) goto cleanup; if (scope == TITLESCOPE) matchedtitle = FALSE; @@ -3629,13 +3630,16 @@ unsigned oid; /* book identifier */ /* comment only, next! */ break; default: - if (matchedtitle && scope == PASSAGESCOPE) { - if (!nowin_buf && tribwin != WIN_ERR) { + if (foundpassage) { + if (!nowin_buf) { + /* outputting multi-line passage to text window */ putstr(tribwin, 0, line); - Strcpy(lastline, line); - } else if (nowin_buf) { - if ((int) strlen(line) < bufsz - 1) - Strcpy(nowin_buf, line); + if (*line) + Strcpy(lastline, line); + } else { + /* 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: (void) dlb_fclose(fp); - if (!nowin_buf && tribwin != WIN_ERR) { - if (matchedtitle && scope == PASSAGESCOPE) { - 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); - } - destroy_nhwindow(tribwin); - tribwin = WIN_ERR; - grasped = TRUE; + if (nowin_buf) { + /* one-line buffer */ + grasped = *nowin_buf ? TRUE : FALSE; } else { - if (!nowin_buf) - pline("It seems to be %s of \"%s\"!", badtranslation, tribtitle); - else - if (foundpassage) + if (tribwin != WIN_ERR) { /* implies 'foundpassage' */ + /* multi-line window, normal case; + if lastline is empty, there were no non-empty lines between + "%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; + } + destroy_nhwindow(tribwin); + } + if (!grasped) + /* multi-line window, problem */ + pline("It seems to be %s of \"%s\"!", badtranslation, tribtitle); } return grasped; } diff --git a/src/sounds.c b/src/sounds.c index eaf36487d..05c6b8859 100644 --- a/src/sounds.c +++ b/src/sounds.c @@ -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 */ /* NetHack may be freely redistributed. See license for details. */ @@ -494,7 +494,7 @@ register struct monst *mtmp; char verbuf[BUFSZ]; register const char *pline_msg = 0, /* Monnam(mtmp) will be prepended */ *verbl_msg = 0, /* verbalize() */ - *verbl_msg_mcan = 0; /* verbalize() if cancelled */ + *verbl_msg_mcan = 0; /* verbalize() if cancelled */ struct permonst *ptr = mtmp->data; int msound = ptr->msound; @@ -824,6 +824,7 @@ register struct monst *mtmp; break; case MS_SEDUCE: { int swval; + if (SYSOPT_SEDUCE) { if (ptr->mlet != S_NYMPH && could_seduce(mtmp, &youmonst, (struct attack *) 0) == 1) { @@ -907,50 +908,46 @@ register struct monst *mtmp; : soldier_foe_msg[rn2(3)]; break; } - case MS_RIDER: - /* 3.6 tribute */ - if (ptr == &mons[PM_DEATH] - && !context.tribute.Deathnotice && u_have_novel()) { - struct obj *book = u_have_novel(); - const char *tribtitle = (char *)0; - - if (book) { - int novelidx = book->novelidx; - - tribtitle = noveltitle(&novelidx); - } - if (tribtitle) { + case MS_RIDER: { + const char *tribtitle; + struct obj *book = 0; + + /* 3.6.0 tribute */ + if (ptr == &mons[PM_DEATH] && !context.tribute.Deathnotice + && (book = u_have_novel()) != 0) { + if ((tribtitle = noveltitle(&book->novelidx)) != 0) { Sprintf(verbuf, "Ah, so you have a copy of /%s/.", tribtitle); /* no Death featured in these two, so exclude them */ - if (!(strcmpi(tribtitle, "Snuff") == 0 - || strcmpi(tribtitle, "The Wee Free Men") == 0)) - Strcat(verbuf, " I may have been misquoted there."); + if (!strcmpi(tribtitle, "Snuff") + || !strcmpi(tribtitle, "The Wee Free Men")) + Strcat(verbuf, " I may have been misquoted there."); verbl_msg = verbuf; - context.tribute.Deathnotice = 1; } - } else if (ptr == &mons[PM_DEATH] - && !rn2(2) && Death_quote(verbuf, BUFSZ)) { + context.tribute.Deathnotice = 1; + } else if (ptr == &mons[PM_DEATH] && rn2(3) + && Death_quote(verbuf, BUFSZ)) { verbl_msg = verbuf; - } + /* 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."; - else + } else verbl_msg = "Who do you think you are, War?"; break; - } + } /* MS_RIDER */ + } /* switch */ - if (pline_msg) + if (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); - else if (verbl_msg) { + } else if (verbl_msg) { if (ptr == &mons[PM_DEATH]) { /* Death talks in CAPITAL LETTERS and without quotation marks */ char tmpbuf[BUFSZ]; - Sprintf(tmpbuf, "%s", verbl_msg); - pline1(ucase(tmpbuf)); + + pline1(ucase(strcpy(tmpbuf, verbl_msg))); } else { verbalize1(verbl_msg); }