MCPcopy Create free account
hub / github.com/NetHack/NetHack / outoracle

Function outoracle

src/rumors.c:639–693  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

637
638#ifndef SFCTOOL
639void
640outoracle(boolean special, boolean delphi)
641{
642 winid tmpwin;
643 dlb *oracles;
644 int oracle_idx;
645 char *endp, line[COLNO], xbuf[BUFSZ];
646
647 /* early return if we couldn't open ORACLEFILE on previous attempt,
648 or if all the oracularities are already exhausted */
649 if (go.oracle_flg < 0 || (go.oracle_flg > 0 && svo.oracle_cnt == 0))
650 return;
651
652 oracles = dlb_fopen(ORACLEFILE, "r");
653
654 if (oracles) {
655 if (go.oracle_flg == 0) { /* if this is the first outoracle() */
656 init_oracles(oracles);
657 go.oracle_flg = 1;
658 if (svo.oracle_cnt == 0)
659 goto close_oracles;
660 }
661 /* oracle_loc[0] is the special oracle;
662 oracle_loc[1..oracle_cnt-1] are normal ones */
663 if (svo.oracle_cnt <= 1 && !special)
664 goto close_oracles; /*(shouldn't happen)*/
665 oracle_idx = special ? 0 : rnd((int) svo.oracle_cnt - 1);
666 (void) dlb_fseek(oracles, (long) svo.oracle_loc[oracle_idx], SEEK_SET);
667 if (!special) /* move offset of very last one into this slot */
668 svo.oracle_loc[oracle_idx] = svo.oracle_loc[--svo.oracle_cnt];
669
670 tmpwin = create_nhwindow(NHW_TEXT);
671 if (delphi)
672 putstr(tmpwin, 0,
673 special
674 ? "The Oracle scornfully takes all your gold and says:"
675 : "The Oracle meditates for a moment and then intones:");
676 else
677 putstr(tmpwin, 0, "The message reads:");
678 putstr(tmpwin, 0, "");
679
680 while (dlb_fgets(line, COLNO, oracles) && strcmp(line, "---\n")) {
681 if ((endp = strchr(line, '\n')) != 0)
682 *endp = 0;
683 putstr(tmpwin, 0, xcrypt(line, xbuf));
684 }
685 display_nhwindow(tmpwin, TRUE);
686 destroy_nhwindow(tmpwin);
687 close_oracles:
688 (void) dlb_fclose(oracles);
689 } else {
690 couldnt_open_file(ORACLEFILE);
691 go.oracle_flg = -1; /* don't try to open it again */
692 }
693}
694
695int
696doconsult(struct monst *oracl)

Callers 1

doconsultFunction · 0.85

Calls 8

dlb_fopenFunction · 0.85
init_oraclesFunction · 0.85
rndFunction · 0.85
dlb_fseekFunction · 0.85
dlb_fgetsFunction · 0.85
xcryptFunction · 0.85
dlb_fcloseFunction · 0.85
couldnt_open_fileFunction · 0.85

Tested by

no test coverage detected