More book tribute integration

This commit is contained in:
nhmall
2015-03-21 10:33:59 -04:00
parent b342beea2b
commit d7ff451301
10 changed files with 259 additions and 230 deletions

View File

@@ -489,7 +489,6 @@ newgame()
context.next_attrib_check = 600L; /* arbitrary first setting */
context.tribute.enabled = TRUE; /* turn on 3.6 tributes */
context.tribute.tributesz = sizeof(struct tribute_info);
context.tribute.bookidx = 0;
for (i = 0; i < NUMMONS; i++)
mvitals[i].mvflags = mons[i].geno & G_NOCORPSE;

View File

@@ -3263,4 +3263,146 @@ const char *filename;
}
#endif /*DEBUG*/
/* ---------- BEGIN TRIBUTE ----------- */
/* 3.6 tribute code */
#define SECTIONSCOPE 1
#define TITLESCOPE 2
#define PASSAGESCOPE 3
void
read_tribute(tribsection, tribtitle, tribpassage, text, maxtextlines)
char *tribsection, *tribtitle;
int tribpassage;
{
dlb *fp;
char *endp;
char line[BUFSZ];
int scopes[4] = {0, SECTIONSCOPE, TITLESCOPE, PASSAGESCOPE};
int scope = 0, section = 0, passage = 0, book = 0;
int linect = 0, passagecnt = 0, targetpassage = 0, textcnt = 0;
char *sectionnm = "", *booknm = "";
boolean matchedsection = FALSE, matchedtitle = FALSE;
winid tribwin = WIN_ERR;
/* check for mandatories */
if (!tribsection || !tribtitle) {
pline("It's an incomprehensible foreign translation of \"%s\"!",
tribtitle);
return;
}
debugpline3("read_tribute %s, %s, %d.", tribsection, tribtitle, tribpassage);
fp = dlb_fopen(TRIBUTEFILE, "r");
if (!fp) {
/* this is actually an error - cannot open tribute file! */
pline("You feel too overwhelmed to continue!");
return;
}
/*
* Syntax (not case-sensitive):
* %section books
*
* In the books section:
* %title booktitle(n)
* where booktitle=book title
* (n)= total number of passages present for this title
* %passage n
* where n=sequential passage number
*
* %e ends the passage/book/section
* If in a passage, it marks the end of that passage.
* If in a book, it marks the end of that book.
* If in a section, it marks the end of that section.
*
* %section death
*/
while (dlb_fgets(line, sizeof line, fp) != 0) {
linect++;
if ((endp = index(line, '\n')) != 0) *endp = 0;
switch (line[0]) {
case '%':
if (!strncmpi(&line[1], "section ", sizeof("section ")-1)) {
char *st = &line[9]; /* 9 from "%section " */
scope = SECTIONSCOPE;
if (!strcmpi(st, tribsection))
matchedsection = TRUE;
else
matchedsection = FALSE;
} else if (!strncmpi(&line[1], "title ", sizeof("title ")-1)) {
char *st = &line[7]; /* 7 from "%title " */
char *p1, *p2;
if ((p1 = index(st, '(')) != 0) {
*p1++ = '\0';
(void)mungspaces(st);
if ((p2 = index(p1, ')')) != 0) {
*p2 = '\0';
passagecnt = atoi(p1);
/* sanity check here caps #passages at 50 */
if ((passagecnt > 0) && (passagecnt < 50)) {
scope = TITLESCOPE;
if (matchedsection && !strcmpi(st, tribtitle)) {
matchedtitle = TRUE;
if (!tribpassage) {
targetpassage = rnd(passagecnt);
} else {
if (tribpassage <= passagecnt)
targetpassage = tribpassage;
else
targetpassage = 0;
}
} else {
matchedtitle = FALSE;
}
}
}
}
} else if (!strncmpi(&line[1], "passage ", 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)) {
scope = PASSAGESCOPE;
if (matchedtitle && (passagenum == targetpassage))
tribwin = create_nhwindow(NHW_MENU);
}
} else if (!strncmpi(&line[1], "e ", sizeof("e ")-1)) {
if (matchedtitle && (scope == PASSAGESCOPE) && tribwin != WIN_ERR)
goto cleanup;
if (scope == TITLESCOPE) matchedtitle = FALSE;
if (scope == SECTIONSCOPE) matchedsection = FALSE;
if (scope) --scope;
} else {
debugpline1("tribute file error: bad %% command, line %d.",
linect);
}
break;
case '#':
/* comment only, next! */
break;
default:
if (matchedtitle && (scope == PASSAGESCOPE) && tribwin != WIN_ERR)
putstr(tribwin, 0, line);
}
}
cleanup:
(void) dlb_fclose(fp);
if (tribwin != WIN_ERR) {
if (matchedtitle && (scope == PASSAGESCOPE))
display_nhwindow(tribwin, FALSE);
destroy_nhwindow(tribwin);
tribwin = WIN_ERR;
}
return;
}
/* ---------- END TRIBUTE ----------- */
/*files.c*/

View File

@@ -862,6 +862,11 @@ boolean artif;
set_corpsenm(otmp, otmp->corpsenm);
break;
case SPE_NOVEL:
{
int novidx = -1;
otmp = oname(otmp, noveltitle(&novidx));
otmp->novelidx = novidx;
}
break;
}

View File

@@ -4,7 +4,6 @@
/* NetHack may be freely redistributed. See license for details. */
#include "hack.h"
#include "dlb.h"
#define Your_Own_Role(mndx) \
((mndx) == urole.malenum || \
@@ -2120,134 +2119,4 @@ create_particular()
return madeany;
}
/* 3.6 tribute code */
#define SECTIONSCOPE 1
#define BOOKSCOPE 2
#define PASSAGESCOPE 3
void
read_tribbook(tribtitle, bookobj)
char *tribtitle;
struct obj *bookobj;
{
dlb *fp;
char *endp;
char line[BUFSZ];
int scopes[4] = {0, SECTIONSCOPE, BOOKSCOPE, PASSAGESCOPE};
int scope = 0, section = 0, passage = 0, book = 0;
int linect = 0, passagecnt = 0, rndpassage = 0;
char *sectionnm = "", *booknm = "";
boolean matched = FALSE;
winid tribwin = WIN_ERR;
if (!tribtitle || !bookobj) {
pline("It is an incomprehensible foreign translation of \"%s\"",
tribtitle);
return;
}
debugpline2("Reading %s, a %s.", tribtitle, xname(bookobj));
fp = dlb_fopen(TRIBUTEFILE, "r");
if (!fp) {
/* this is actually an error - cannot open tribute file! */
pline("Overcome with fond memories, you snap \"%s\" shut!",
tribtitle);
return;
}
/*
* Syntax (not case-sensitive):
* %section books
* %section death
*
* In the books section:
* %book title(n)
* where title=book title
* (n)= total number of passages present for this book
* %passage n
* where n=sequential passage number
*
* %e ends the passage/book/section
* If in a passage, it marks the end of that passage.
* If in a book, it marks the end of that book.
* If in a section, it marks the end of that section.
*/
while (dlb_fgets(line, sizeof line, fp) != 0) {
linect++;
if ((endp = index(line, '\n')) != 0) *endp = 0;
switch (line[0]) {
case '%':
if (!strncmpi(&line[1], "section ", sizeof("section ")-1)) {
} else if (!strncmpi(&line[1], "book ", sizeof("book ")-1)) {
char *st = &line[6], *p1, *p2;
if ((p1 = index(st, '(')) != 0) {
*p1++ = '\0';
if ((p2 = index(p1, ')')) != 0) {
*p2 = '\0';
passagecnt = atoi(p1);
/* sanity check here caps #passages at 50 */
if ((passagecnt > 0) && (passagecnt < 50)) {
scope = BOOKSCOPE;
if (!strcmpi(st, tribtitle)) {
matched = TRUE;
rndpassage = rnd(passagecnt);
context.tribute.passagecnt = passagecnt;
context.tribute.passagenum = rndpassage;
} else {
matched = FALSE;
rndpassage = 0;
context.tribute.passagecnt = 0;
context.tribute.passagenum = 0;
/* this should not happen, but compensate */
if (tribwin != WIN_ERR)
destroy_nhwindow(tribwin);
}
}
}
}
} else if (!strncmpi(&line[1], "passage ", sizeof("passage ")-1)) {
int passagenum = 0;
char *st = &line[9];
while(*st == ' ' || *st == '\t') st++;
if (*st && digit(*st) && (strlen(st) < 3))
passagenum = atoi(st);
if (passagenum && (passagenum <= passagecnt)) {
scope = PASSAGESCOPE;
if (passagenum == rndpassage)
tribwin = create_nhwindow(NHW_MENU);
}
} else if (!strncmpi(&line[1], "e ", sizeof("e ")-1)) {
if (matched && (scope == PASSAGESCOPE) && tribwin != WIN_ERR)
goto cleanup;
} else {
pline("tribute file error: bad %%e command, line %d.",
linect);
}
break;
case '#':
/* comment only, next! */
break;
default:
if (matched && (scope == PASSAGESCOPE) && tribwin != WIN_ERR) {
putstr(tribwin, 0, line);
}
}
}
cleanup:
if (tribwin != WIN_ERR) {
if (matched && (scope == PASSAGESCOPE))
display_nhwindow(tribwin, FALSE);
destroy_nhwindow(tribwin);
tribwin = WIN_ERR;
}
(void) dlb_fclose(fp);
return;
}
/*read.c*/

View File

@@ -367,18 +367,13 @@ boolean mkspecl;
int atype;
struct permonst *ptr;
/* 3.6 tribute */
/* 3.6.0 tribute */
if (mkspecl && !strcmp(shp->name, "rare books")) {
int novidx = -1; /* -1 triggers random noveltitle() */
struct obj *novel=mksobj_at(SPE_NOVEL, sx, sy, FALSE, FALSE);
if (novel) novel = oname(novel, noveltitle(&novidx));
context.tribute.bookidx = novidx;
context.tribute.passagecnt = 0;
context.tribute.passagenum = 0;
context.tribute.bookstock = TRUE;
if (novel) context.tribute.bookstock = TRUE;
return;
}
if (rn2(100) < depth(&u.uz) &&
!MON_AT(sx, sy) && (ptr = mkclass(S_MIMIC,0)) &&
(mtmp = makemon(ptr,sx,sy,NO_MM_FLAGS)) != 0) {

View File

@@ -450,12 +450,12 @@ register struct obj *spellbook;
return(1);
}
/* 3.6 tribute */
/* 3.6.0 tribute */
if (booktype == SPE_NOVEL) {
/* Obtain current Terry Pratchett book
title for the current game. */
const char *tribtitle = noveltitle(&context.tribute.bookidx);
read_tribbook(tribtitle, spellbook);
const char *tribtitle = noveltitle(&spellbook->novelidx);
read_tribute("books", tribtitle, 0);
return(1);
}