-/* 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: 1545132266 2018/12/18 11:24:26 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.34 $ */
/* 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-2019 */
+/* 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");
else if (!in_mklev) /* avoid exercizing wisdom for graffiti */
exercise(A_WIS, (adjtruth > 0));
} else {
-/*JP
- pline("Can't open rumors file!");
-*/
- pline("rumors\83t\83@\83C\83\8b\82ª\8aJ\82¯\82È\82¢\81I");
+ 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
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:
pline("rumors not accessible.");
+ if (rumors)
+ (void) dlb_fclose(rumors);
return;
}
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;
(void) dlb_fseek(fh, 0L, SEEK_END);
endtxt = dlb_ftell(fh);
sizetxt = endtxt - starttxt;
- tidbit = Rand() % sizetxt;
+ 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;
}
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 */
/*JP
: "The Oracle meditates for a moment and then intones:");
*/
- : "\8c«\8eÒ\82Í\82µ\82Î\82ç\82\96»\91z\82µ\81C\89Ì\82¤\82æ\82¤\82É\98b\82µ\82½\81F");
+ : "\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:");
}
display_nhwindow(tmpwin, TRUE);
destroy_nhwindow(tmpwin);
+ close_oracles:
(void) dlb_fclose(oracles);
} else {
-/*JP
- pline("Can't open oracles file!");
-*/
- pline("oracles\83t\83@\83C\83\8b\82ð\8aJ\82¯\82È\82¢\81I");
+ couldnt_open_file(ORACLEFILE);
oracle_flg = -1; /* don't try to open it again */
}
}
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 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*/