-/* NetHack 3.6 rumors.c $NHDT-Date: 1446713640 2015/11/05 08:54:00 $ $NHDT-Branch: master $:$NHDT-Revision: 1.27 $ */
+/* NetHack 3.6 rumors.c $NHDT-Date: 1583445339 2020/03/05 21:55:39 $ $NHDT-Branch: NetHack-3.6-Mar2020 $:$NHDT-Revision: 1.38 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
+/*-Copyright (c) Robert Patrick Rankin, 2012. */
/* NetHack may be freely redistributed. See license for details. */
+/* JNetHack Copyright */
+/* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000 */
+/* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2020 */
+/* JNetHack may be freely redistributed. See license for details. */
+
#include "hack.h"
#include "lev.h"
#include "dlb.h"
STATIC_DCL void FDECL(init_rumors, (dlb *));
STATIC_DCL void FDECL(init_oracles, (dlb *));
+STATIC_DCL void FDECL(couldnt_open_file, (const char *));
/* rumor size variables are signed so that value -1 can be used as a flag */
static long true_rumor_size = 0L, false_rumor_size;
case 2: /*(might let a bogus input arg sneak thru)*/
case 1:
beginning = (long) true_rumor_start;
- tidbit = Rand() % true_rumor_size;
+ tidbit = rn2(true_rumor_size);
break;
case 0: /* once here, 0 => false rather than "either"*/
case -1:
beginning = (long) false_rumor_start;
- tidbit = Rand() % false_rumor_size;
+ tidbit = rn2(false_rumor_size);
break;
default:
impossible("strange truth value for rumor");
Strcat(rumor_buf, xcrypt(line, xbuf));
} while (
count++ < 50 && exclude_cookie
+#if 0 /*JP*/
&& (strstri(rumor_buf, "fortune") || strstri(rumor_buf, "pity")));
+#else
+ && (strstri(rumor_buf, "\90è") || strstri(rumor_buf, "\82È\82ñ\82Ä\82±\82Æ\82¾")));
+#endif
(void) dlb_fclose(rumors);
if (count >= 50)
impossible("Can't find non-cookie rumor?");
else if (!in_mklev) /* avoid exercizing wisdom for graffiti */
exercise(A_WIS, (adjtruth > 0));
} else {
- pline("Can't open rumors file!");
+ couldnt_open_file(RUMORFILE);
true_rumor_size = -1; /* don't try to open it again */
}
-/* this is safe either way, so do it always since we can't get the definition
- * out of makedefs.c
- */
+
+ /* this is safe either way, so do it always since we can't get the
+ * definition out of makedefs.c
+ */
#define PAD_RUMORS_TO
#ifdef PAD_RUMORS_TO
/* remove padding */
void
rumor_check()
{
- dlb *rumors;
+ dlb *rumors = 0;
winid tmpwin;
char *endp, line[BUFSZ], xbuf[BUFSZ], rumor_buf[BUFSZ];
if (true_rumor_size < 0L) { /* we couldn't open RUMORFILE */
- no_rumors:
+ no_rumors:
pline("rumors not accessible.");
return;
}
rumor_buf[0] = '\0';
if (true_rumor_size == 0L) { /* if this is 1st outrumor() */
init_rumors(rumors);
- if (true_rumor_size < 0L)
+ if (true_rumor_size < 0L) {
+ rumors = (dlb *) 0; /* init_rumors() closes it upon failure */
goto no_rumors; /* init failed */
+ }
}
tmpwin = create_nhwindow(NHW_TEXT);
/*
* reveal the values.
*/
-
- Sprintf(
- rumor_buf,
- "T start=%06ld (%06lx), end=%06ld (%06lx), size=%06ld (%06lx)",
- (long) true_rumor_start, true_rumor_start, true_rumor_end,
- (unsigned long) true_rumor_end, true_rumor_size,
- (unsigned long) true_rumor_size);
+ Sprintf(rumor_buf,
+ "T start=%06ld (%06lx), end=%06ld (%06lx), size=%06ld (%06lx)",
+ (long) true_rumor_start, true_rumor_start,
+ true_rumor_end, (unsigned long) true_rumor_end,
+ true_rumor_size, (unsigned long) true_rumor_size);
putstr(tmpwin, 0, rumor_buf);
-
- Sprintf(
- rumor_buf,
- "F start=%06ld (%06lx), end=%06ld (%06lx), size=%06ld (%06lx)",
- (long) false_rumor_start, false_rumor_start, false_rumor_end,
- (unsigned long) false_rumor_end, false_rumor_size,
- (unsigned long) false_rumor_size);
+ Sprintf(rumor_buf,
+ "F start=%06ld (%06lx), end=%06ld (%06lx), size=%06ld (%06lx)",
+ (long) false_rumor_start, false_rumor_start,
+ false_rumor_end, (unsigned long) false_rumor_end,
+ false_rumor_size, (unsigned long) false_rumor_size);
putstr(tmpwin, 0, rumor_buf);
/*
display_nhwindow(tmpwin, TRUE);
destroy_nhwindow(tmpwin);
} else {
- impossible("Can't open rumors file!");
+ couldnt_open_file(RUMORFILE);
true_rumor_size = -1; /* don't try to open it again */
}
}
-/* Gets a random line of text from file 'fname', and returns it. */
+/* Gets a random line of text from file 'fname', and returns it.
+ rng is the random number generator to use, and should act like rn2 does. */
char *
-get_rnd_text(fname, buf)
+get_rnd_text(fname, buf, rng)
const char *fname;
char *buf;
+int FDECL((*rng), (int));
{
dlb *fh;
buf[0] = '\0';
-
fh = dlb_fopen(fname, "r");
-
if (fh) {
- /* TODO: cache sizetxt, starttxt, endtxt. maybe cache file contents?
- */
- long sizetxt = 0, starttxt = 0, endtxt = 0, tidbit = 0;
+ /* TODO: cache sizetxt, starttxt, endtxt. maybe cache file contents? */
+ long sizetxt = 0L, starttxt = 0L, endtxt = 0L, tidbit = 0L;
char *endp, line[BUFSZ], xbuf[BUFSZ];
- (void) dlb_fgets(line, sizeof line,
- fh); /* skip "don't edit" comment */
+
+ /* skip "don't edit" comment */
+ (void) dlb_fgets(line, sizeof line, fh);
(void) dlb_fseek(fh, 0L, SEEK_CUR);
starttxt = dlb_ftell(fh);
(void) dlb_fseek(fh, 0L, SEEK_END);
endtxt = dlb_ftell(fh);
sizetxt = endtxt - starttxt;
- tidbit = Rand() % sizetxt;
+ /* might be zero (only if file is empty); should complain in that
+ case but if could happen over and over, also the suggestion
+ that save and restore might fix the problem wouldn't be useful */
+ if (sizetxt < 1L)
+ return buf;
+ tidbit = (*rng)(sizetxt);
(void) dlb_fseek(fh, starttxt + tidbit, SEEK_SET);
(void) dlb_fgets(line, sizeof line, fh);
*endp = 0;
Strcat(buf, xcrypt(line, xbuf));
(void) dlb_fclose(fh);
- } else
- impossible("Can't open file %s!", fname);
+ } else {
+ couldnt_open_file(fname);
+ }
+
return buf;
}
int mechanism;
{
static const char fortune_msg[] =
+/*JP
"This cookie has a scrap of paper inside.";
+*/
+ "\82±\82Ì\83N\83b\83L\81[\82É\82Í\8e\86\90Ø\82ª\93ü\82Á\82Ä\82¢\82é\81D";
const char *line;
char buf[BUFSZ];
boolean reading = (mechanism == BY_COOKIE || mechanism == BY_PAPER);
else if (Blind) {
if (mechanism == BY_COOKIE)
pline(fortune_msg);
+/*JP
pline("What a pity that you cannot read it!");
+*/
+ pline("\82»\82ê\82ð\93Ç\82ß\82È\82¢\82È\82ñ\82Ä\8bC\82Ì\93Å\82È\81I");
return;
}
}
line = getrumor(truth, buf, reading ? FALSE : TRUE);
if (!*line)
+/*JP
line = "NetHack rumors file closed for renovation.";
+*/
+ line = "\89\\82Ì\90^\91\8a\82Í\8dü\90V\82Ì\82½\82ß\8bx\8a§\82µ\82Ä\82¢\82é\81D";
switch (mechanism) {
case BY_ORACLE:
/* Oracle delivers the rumor */
+#if 0 /*JP:T*/
pline("True to her word, the Oracle %ssays: ",
(!rn2(4) ? "offhandedly "
: (!rn2(3) ? "casually "
: (rn2(2) ? "nonchalantly " : ""))));
+#else
+ pline("\96ñ\91©\82Ç\82¨\82è\82É\81C\8c«\8eÒ\82Í%s\8fq\82×\82½:",
+ (!rn2(4) ? "\96³\91¢\8dì\82É"
+ : (!rn2(3) ? "\89½\8bC\82È\82"
+ : (rn2(2) ? "\96³\93Ú\92\85\82É" : ""))));
+#endif
verbalize1(line);
/* [WIS exercized by getrumor()] */
return;
pline(fortune_msg);
/* FALLTHRU */
case BY_PAPER:
+/*JP
pline("It reads:");
+*/
+ pline("\82»\82ê\82ð\93Ç\82ñ\82¾:");
break;
}
pline1(line);
if (perform_bwrite(mode)) {
bwrite(fd, (genericptr_t) &oracle_cnt, sizeof oracle_cnt);
if (oracle_cnt)
- bwrite(fd, (genericptr_t) oracle_loc, oracle_cnt * sizeof(long));
+ bwrite(fd, (genericptr_t) oracle_loc,
+ oracle_cnt * sizeof(long));
}
if (release_data(mode)) {
if (oracle_cnt) {
boolean special;
boolean delphi;
{
- char line[COLNO];
- char *endp;
+ winid tmpwin;
dlb *oracles;
int oracle_idx;
- char xbuf[BUFSZ];
+ char *endp, line[COLNO], xbuf[BUFSZ];
/* early return if we couldn't open ORACLEFILE on previous attempt,
or if all the oracularities are already exhausted */
oracles = dlb_fopen(ORACLEFILE, "r");
if (oracles) {
- winid tmpwin;
if (oracle_flg == 0) { /* if this is the first outoracle() */
init_oracles(oracles);
oracle_flg = 1;
if (oracle_cnt == 0)
- return;
+ goto close_oracles;
}
/* oracle_loc[0] is the special oracle;
oracle_loc[1..oracle_cnt-1] are normal ones */
if (oracle_cnt <= 1 && !special)
- return; /*(shouldn't happen)*/
+ goto close_oracles; /*(shouldn't happen)*/
oracle_idx = special ? 0 : rnd((int) oracle_cnt - 1);
(void) dlb_fseek(oracles, (long) oracle_loc[oracle_idx], SEEK_SET);
if (!special) /* move offset of very last one into this slot */
if (delphi)
putstr(tmpwin, 0,
special
+/*JP
? "The Oracle scornfully takes all your money and says:"
+*/
+ ? "\8c«\8eÒ\82Í\8cy\95Ì\82µ\82½\82æ\82¤\82É\82 \82È\82½\82Ì\91S\82Ä\82Ì\82¨\8bà\82ð\8eó\82¯\82Æ\82è\81C\8fq\82×\82½\81F"
+/*JP
: "The Oracle meditates for a moment and then intones:");
+*/
+ : "\8c«\8eÒ\82Í\82µ\82Î\82ç\82áÒ\91z\82µ\81C\89Ì\82¤\82æ\82¤\82É\98b\82µ\82½\81F");
else
+/*JP
putstr(tmpwin, 0, "The message reads:");
+*/
+ putstr(tmpwin, 0, "\83\81\83b\83Z\81[\83W:");
putstr(tmpwin, 0, "");
while (dlb_fgets(line, COLNO, oracles) && strcmp(line, "---\n")) {
}
display_nhwindow(tmpwin, TRUE);
destroy_nhwindow(tmpwin);
+ close_oracles:
(void) dlb_fclose(oracles);
} else {
- pline("Can't open oracles file!");
+ couldnt_open_file(ORACLEFILE);
oracle_flg = -1; /* don't try to open it again */
}
}
umoney = money_cnt(invent);
if (!oracl) {
+/*JP
There("is no one here to consult.");
+*/
+ pline("\82±\82±\82É\82Í\90_\91õ\82ð\8fq\82×\82é\90l\82Í\82¢\82È\82¢\81D");
return 0;
} else if (!oracl->mpeaceful) {
+/*JP
pline("%s is in no mood for consultations.", Monnam(oracl));
+*/
+ pline("\8c«\8eÒ\82Í\90_\91õ\82ð\8d\90\82°\82Ä\82\82ê\82é\95µ\88Í\8bC\82Å\82Í\82È\82¢\81D");
return 0;
} else if (!umoney) {
+/*JP
You("have no money.");
+*/
+ You("\82¨\8bà\82ª\82È\82¢\81D");
return 0;
}
+/*JP
Sprintf(qbuf, "\"Wilt thou settle for a minor consultation?\" (%d %s)",
+*/
+ Sprintf(qbuf, "\81u\93ð\81C\92á\88Ê\82Ì\90_\91õ\82ð\8eó\82¯\82é\82©\81H\81v(%d%s)",
minor_cost, currency((long) minor_cost));
switch (ynq(qbuf)) {
default:
return 0;
case 'y':
if (umoney < (long) minor_cost) {
+/*JP
You("don't even have enough money for that!");
+*/
+ You("\82±\82ê\82É\95¥\82¦\82é\82¾\82¯\82Ì\82¨\8bà\82·\82ç\8e\9d\82Á\82Ä\82¢\82È\82¢\81I");
return 0;
}
u_pay = minor_cost;
if (umoney <= (long) minor_cost /* don't even ask */
|| (oracle_cnt == 1 || oracle_flg < 0))
return 0;
+/*JP
Sprintf(qbuf, "\"Then dost thou desire a major one?\" (%d %s)",
+*/
+ Sprintf(qbuf, "\81u\82È\82ç\82Î\93ð\81C\8d\82\88Ê\82Ì\90_\91õ\82ð\8eó\82¯\82é\82©\81H\81v(%d%s)",
major_cost, currency((long) major_cost));
if (yn(qbuf) != 'y')
return 0;
return 1;
}
+STATIC_OVL void
+couldnt_open_file(filename)
+const char *filename;
+{
+ int save_something = program_state.something_worth_saving;
+
+ /* most likely the file is missing, so suppress impossible()'s
+ "saving and restoring might fix this" (unless the fuzzer,
+ which escalates impossible to panic, is running) */
+ if (!iflags.debug_fuzzer)
+ program_state.something_worth_saving = 0;
+
+/*JP
+ impossible("Can't open '%s' file.", filename);
+*/
+ impossible("'%s'\83t\83@\83C\83\8b\82ª\8aJ\82¯\82È\82¢\81D", filename);
+ program_state.something_worth_saving = save_something;
+}
+
/*rumors.c*/