From d7ff4513015393a7cac4e3febb1bc064811e3558 Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 21 Mar 2015 10:33:59 -0400 Subject: [PATCH] More book tribute integration --- dat/tribute | 184 +++++++++++++++++++++++------------------ include/context.h | 3 - include/extern.h | 2 +- src/allmain.c | 1 - src/files.c | 142 +++++++++++++++++++++++++++++++ src/mkobj.c | 5 ++ src/read.c | 131 ----------------------------- src/shknam.c | 11 +-- src/spell.c | 6 +- sys/winnt/Makefile.msc | 4 +- 10 files changed, 259 insertions(+), 230 deletions(-) diff --git a/dat/tribute b/dat/tribute index 922cbd5d3..2a10ba038 100644 --- a/dat/tribute +++ b/dat/tribute @@ -1,8 +1,15 @@ +# NetHack 3.6.0 tribute to: +# +# Sir Terence David John "Terry" Pratchett +# April 28, 1948 - March 12, 2015 +# ("or until the ripples he caused in the world die away...") +# +# %section books # # # -%book The Colour of Magic(1) +%title The Colour of Magic (1) %passage 1 The Colour of Magic, by Terry Pratchett @@ -11,395 +18,412 @@ bbbbbbbbbbb bbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbbbbb CC cc ddd eee ff %e passage -%e book +%e title # # # -%book The Light Fantastic(1) +%title The Light Fantastic (1) %passage 1 The Light Fantastic, by Terry Pratchett %e passage -%e book +%e title # # # -%book Equal Rites(1) +%title Equal Rites (1) %passage 1 Equal Rites, by Terry Pratchett %e passage -%e book +%e title # # # -%book Mort(1) +%title Mort (1) %passage 1 Mort, by Terry Pratchett %e passage -%e book +%e title # # # -%book Sourcery(1) +%title Sourcery (1) %passage 1 Sourcery, by Terry Pratchett %e passage -%e book +%e title # # # -%book Wyrd Sisters(1) +%title Wyrd Sisters (1) %passage 1 Wyrd Sisters, by Terry Pratchett %e passage -%e book +%e title # # # -%book Pyramids(1) +%title Pyramids (1) %passage 1 Pyramids, by Terry Pratchett %e passage -%e book +%e title # # # -%book Guards! Guards!(1) +%title Guards! Guards! (1) %passage 1 Guards! Guards!, by Terry Pratchett %e passage -%e book +%e title # # # -%book Eric(1) +%title Eric (1) %passage 1 Eric, by Terry Pratchett %e passage -%e book +%e title # # # -%book Moving Pictures(1) +%title Moving Pictures (1) %passage 1 Moving Pictures, by Terry Pratchett %e passage -%e book +%e title # # # -%book Reaper Man(1) +%title Reaper Man (1) %passage 1 Reaper Man, by Terry Pratchett %e passage -%e book +%e title # # # -%book Witches Abroad(1) +%title Witches Abroad (1) %passage 1 Witches Abroad, by Terry Pratchett %e passage -%e book +%e title # # # -%book Small Gods(1) +%title Small Gods (1) %passage 1 Small Gods, by Terry Pratchett %e passage -%e book +%e title # # # -%book Lords and Ladies(1) +%title Lords and Ladies (1) %passage 1 Lords and Ladies, by Terry Pratchett %e passage -%e book +%e title # # # -%book Men at Arms(1) +%title Men at Arms (1) %passage 1 Men at Arms, by Terry Pratchett %e passage -%e book +%e title # # # -%book Soul Music(1) +%title Soul Music (1) %passage 1 Soul Music, by Terry Pratchett %e passage -%e book +%e title # # # -%book Interesting Times(1) +%title Interesting Times (1) %passage 1 Interesting Times, by Terry Pratchett %e passage -%e book +%e title # # # -%book Maskerade(1) +%title Maskerade (1) %passage 1 Maskerade, by Terry Pratchett %e passage -%e book +%e title # # # -%book Feet of Clay(1) +%title Feet of Clay (1) %passage 1 Feet of Clay, by Terry Pratchett %e passage -%e book +%e title # # # -%book Hogfather(1) +%title Hogfather (1) %passage 1 Hogfather, by Terry Pratchett %e passage -%e book +%e title # # # -%book Jingo(1) +%title Jingo (1) %passage 1 Jingo, by Terry Pratchett %e passage -%e book +%e title # # # -%book The Last Continent(1) +%title The Last Continent (1) %passage 1 The Last Continent, by Terry Pratchett %e passage -%e book +%e title # # # -%book Carpe Jugulum(1) +%title Carpe Jugulum (1) %passage 1 Carpe Jugulum, by Terry Pratchett %e passage -%e book +%e title # # # -%book The Fifth Elephant(1) +%title The Fifth Elephant (1) %passage 1 The Fifth Elephant, by Terry Pratchett %e passage -%e book +%e title # # # -%book The Truth(1) +%title The Truth (1) %passage 1 The Truth, by Terry Pratchett %e passage -%e book +%e title # # # -%book Thief of Time(1) +%title Thief of Time (1) %passage 1 Thief of Time, by Terry Pratchett %e passage -%e book +%e title # # # -%book The Last Hero(1) +%title The Last Hero (1) %passage 1 The Last Hero, by Terry Pratchett %e passage -%e book +%e title # # # -%book The Amazing Maurice and his Educated Rodents(1) +%title The Amazing Maurice and his Educated Rodents (1) %passage 1 The Amazing Maurice and his Educated Rodents, by Terry Pratchett %e passage -%e book +%e title # # # -%book Night Watch(1) +%title Night Watch (1) %passage 1 Night Watch, by Terry Pratchett %e passage -%e book +%e title # # # -%book The Wee Free Men(1) +%title The Wee Free Men (1) %passage 1 The Wee Free Men, by Terry Pratchett %e passage -%e book +%e title # # # -%book Monstrous Regiment(1) +%title Monstrous Regiment (1) %passage 1 Monstrous Regiment, by Terry Pratchett %e passage -%e book +%e title # # # -%book A Hat Full of Sky(1) +%title A Hat Full of Sky (1) %passage 1 A Hat Full of Sky, by Terry Pratchett %e passage -%e book +%e title # # # -%book Going Postal(1) +%title Going Postal (1) %passage 1 Going Postal, by Terry Pratchett %e passage -%e book +%e title # # # -%book Thud!(1) +%title Thud! (1) %passage 1 Thud!, by Terry Pratchett %e passage -%e book +%e title # # # -%book Wintersmith(1) +%title Wintersmith (1) %passage 1 Wintersmith, by Terry Pratchett %e passage -%e book +%e title # # # -%book Making Money(1) +%title Making Money (1) %passage 1 Making Money, by Terry Pratchett %e passage -%e book +%e title # # # -%book Unseen Academicals(1) +%title Unseen Academicals (1) %passage 1 Unseen Academicals, by Terry Pratchett %e passage -%e book +%e title # # # -%book I Shall Wear Midnight(1) +%title I Shall Wear Midnight (1) %passage 1 I Shall Wear Midnight, by Terry Pratchett %e passage -%e book +%e title # # # -%book Snuff(1) +%title Snuff (1) %passage 1 Snuff, by Terry Pratchett %e passage -%e book +%e title # # # -%book Raising Steam(1) +%title Raising Steam (1) %passage 1 Raising Steam, by Terry Pratchett %e passage -%e book +%e title %e section +#----------------------------------------------------- +# Currently this section is not used. It is added +# to illustrate how these could be added and adapted +# should they be useful for something +# +%section Death +%title Death Quotes (2) +%passage 1 +WHERE THE FIRST PRIMAL CELL WAS, THERE WAS I ALSO. WHERE MAN IS, THERE AM I. +WHEN THE LAST LIFE CRAWLS UNDER FREEZING STARS, THERE WILL I BE. +%e passage +%passage 2 +I AM DEATH, NOT TAXES. *I* TURN UP ONLY ONCE. +%e passage +%e title +%e section + diff --git a/include/context.h b/include/context.h index 772df192f..fad18f827 100644 --- a/include/context.h +++ b/include/context.h @@ -79,9 +79,6 @@ struct tribute_info { Bitfield(bookstock,1); /* Have we stocked the book? */ /* Markers for other tributes can go here */ /* 31 free bits */ - int bookidx; /* Index of book in list of book titles */ - int passagecnt; /* Number of passages for this book avail */ - int passagenum; /* Passage last read */ }; struct context_info { diff --git a/include/extern.h b/include/extern.h index f382f8ca2..76d5737fd 100644 --- a/include/extern.h +++ b/include/extern.h @@ -746,6 +746,7 @@ E void NDECL(really_close); #ifdef DEBUG E boolean FDECL(showdebug, (const char *)); #endif +E void FDECL(read_tribute, (const char *,const char *,int)); /* ### fountain.c ### */ @@ -1839,7 +1840,6 @@ E void FDECL(punish, (struct obj *)); E void NDECL(unpunish); E boolean FDECL(cant_revive, (int *,BOOLEAN_P,struct obj *)); E boolean NDECL(create_particular); -E void FDECL(read_tribbook, (const char *, struct obj *)); /* ### rect.c ### */ diff --git a/src/allmain.c b/src/allmain.c index 7224dd284..44c61d146 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -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; diff --git a/src/files.c b/src/files.c index a6f17b906..471f5acb4 100644 --- a/src/files.c +++ b/src/files.c @@ -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*/ diff --git a/src/mkobj.c b/src/mkobj.c index 77c39ce7a..0f67aed13 100644 --- a/src/mkobj.c +++ b/src/mkobj.c @@ -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; } diff --git a/src/read.c b/src/read.c index ef46903c3..9be9f9390 100644 --- a/src/read.c +++ b/src/read.c @@ -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*/ diff --git a/src/shknam.c b/src/shknam.c index 88b983c8d..a8e08c0f0 100644 --- a/src/shknam.c +++ b/src/shknam.c @@ -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) { diff --git a/src/spell.c b/src/spell.c index cf847c089..e5e208046 100644 --- a/src/spell.c +++ b/src/spell.c @@ -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); } diff --git a/sys/winnt/Makefile.msc b/sys/winnt/Makefile.msc index 070ecd80d..789cdfe87 100644 --- a/sys/winnt/Makefile.msc +++ b/sys/winnt/Makefile.msc @@ -1093,8 +1093,7 @@ $(DAT)\porthelp: $(NTSYS)\porthelp nhdat: $(U)dlb_main.exe $(DAT)\data $(DAT)\oracles $(OPTIONS_FILE) \ $(DAT)\quest.dat $(DAT)\rumors $(DAT)\help $(DAT)\hh $(DAT)\cmdhelp \ $(DAT)\history $(DAT)\opthelp $(DAT)\wizhelp $(DAT)\dungeon $(DAT)\porthelp \ - $(DAT)\license $(DAT)\engrave $(DAT)\epitaph $(DAT)\bogusmon \ - $(DAT)\tribute $(O)sp_lev.tag + $(DAT)\license $(DAT)\engrave $(DAT)\epitaph $(DAT)\bogusmon $(DAT)\tribute $(O)sp_lev.tag cd $(DAT) echo data >dlb.lst echo oracles >>dlb.lst @@ -1107,7 +1106,6 @@ nhdat: $(U)dlb_main.exe $(DAT)\data $(DAT)\oracles $(OPTIONS_FILE) \ echo engrave >>dlb.lst echo epitaph >>dlb.lst echo bogusmon >>dlb.lst - echo tribute >>dlb.lst echo help >>dlb.lst echo hh >>dlb.lst echo cmdhelp >>dlb.lst