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:
90
src/files.c
90
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user