Пример #1
0
void
outoracle(boolean special, boolean delphi)
{
    char line[COLNO];
    char *endp;
    dlb *oracles;
    int oracle_idx;
    char xbuf[BUFSZ];

    if (oracle_flg < 0 ||       /* couldn't open ORACLEFILE */
        (oracle_flg > 0 && oracle_cnt == 0))    /* oracles already exhausted */
        return;

    oracles = dlb_fopen(ORACLEFILE, "r");

    if (oracles) {
        struct menulist menu;

        if (oracle_flg == 0) {  /* if this is the first outoracle() */
            init_oracles(oracles);
            oracle_flg = 1;
            if (oracle_cnt == 0)
                return;
        }
        /* 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) */
        oracle_idx = special ? 0 : rnd((int)oracle_cnt - 1);
        dlb_fseek(oracles, oracle_loc[oracle_idx], SEEK_SET);
        if (!special)
            oracle_loc[oracle_idx] = oracle_loc[--oracle_cnt];

        init_menulist(&menu);
        if (delphi)
            add_menutext(&menu,
                         special ?
                         "The Oracle scornfully takes all your money and says:"
                         :
                         "The Oracle meditates for a moment and then intones:");
        else
            add_menutext(&menu, "The message reads:");
        add_menutext(&menu, "");

        while (dlb_fgets(line, COLNO, oracles) && strcmp(line, "---\n")) {
            if ((endp = strchr(line, '\n')) != 0)
                *endp = 0;
            add_menutext(&menu, xcrypt(line, xbuf));
        }
        display_menu(menu.items, menu.icount, NULL, PICK_NONE, PLHINT_ANYWHERE,
                     NULL);
        free(menu.items);
        dlb_fclose(oracles);
    } else {
        pline("Can't open oracles file!");
        oracle_flg = -1;        /* don't try to open it again */
    }
}
Пример #2
0
void
outoracle(boolean special, boolean delphi)
{
    char line[COLNO];
    char *endp;
    dlb *oracles;
    int oracle_idx;

    if (oracle_flg < 0 ||       /* couldn't open ORACLEFILE */
        (oracle_flg > 0 && oracle_cnt == 0))    /* oracles already exhausted */
        return;

    oracles = dlb_fopen(ORACLEFILE, "r");

    if (oracles) {
        struct nh_menulist menu;

        if (oracle_flg == 0) {  /* if this is the first outoracle() */
            init_oracles(oracles);
            oracle_flg = 1;
            if (oracle_cnt == 0)
                return;
        }
        /* 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) */
        oracle_idx = special ? 0 : rnd((int)oracle_cnt - 1);
        dlb_fseek(oracles, oracle_loc[oracle_idx], SEEK_SET);
        if (!special)
            oracle_loc[oracle_idx] = oracle_loc[--oracle_cnt];

        init_menulist(&menu);

        if (delphi)
            add_menutext(
                &menu, special ?
                "Potter protests, but then takes your money and says:" :
                "Potter thinks for a second, and then announces in a gravelly voice:");
        else
            add_menutext(&menu, "The message reads:");
        add_menutext(&menu, "");

        while (dlb_fgets(line, COLNO, oracles) && strcmp(line, "---\n")) {
            if ((endp = strchr(line, '\n')) != 0)
                *endp = 0;
            char decrypted_line[strlen(line) + 1];
            add_menutext(&menu, xcrypt(line, decrypted_line));
        }

        display_menu(&menu, NULL, PICK_NONE, PLHINT_ANYWHERE,
                     NULL);
        dlb_fclose(oracles);
    } else {
        pline("Can't open oracles file!");
        oracle_flg = -1;        /* don't try to open it again */
    }
}
Пример #3
0
int
dohistory(const struct nh_cmd_arg *arg)
{
    struct nh_menulist menu;
    boolean over = program_state.gameover;
    boolean showall = over || wizard;
    int i;

    (void) arg;

    if (histcount < 2) {
        /* you get an automatic entry on turn 1 for being born. If it's the
           only one, there is nothing worth reporting */
        if (!over)
            pline(msgc_info, "History has not recorded anything about you.");
        return 0;
    }

    init_menulist(&menu);

    for (i = 0; i < histcount; i++) {
        if (histevents[i].hidden && !showall)
            continue;
        add_menutext(&menu, msgprintf("On T:%u you %s", histevents[i].when,
                                      histevents[i].what));
    }

    display_menu(&menu, "History has recorded:", PICK_NONE,
                 PLHINT_ANYWHERE, NULL);

    return 0;
}
Пример #4
0
static void
enlght_line(struct nh_menulist *menu, const char *start, const char *middle,
            const char *end)
{
    const char *buf;

    buf = msgprintf("%s%s%s.", start, middle, end);
    add_menutext(menu, buf);
}
Пример #5
0
/* display a list of discovered artifacts; return their count */
int disp_artifact_discoveries(
    struct menulist *menu /* supplied by dodiscover() */
    )
{
    int i, m, otyp;
    char buf[BUFSZ];

    for (i = 0; i < NROFARTIFACTS; i++) {
	if (artidisco[i] == 0) break;	/* empty slot implies end of list */
	if (i == 0)
	    add_menuheading(menu, "Artifacts");
	m = artidisco[i];
	otyp = artilist[m].otyp;
	sprintf(buf, "  %s [%s %s]", artiname(m),
		align_str(artilist[m].alignment), simple_typename(otyp));
	add_menutext(menu, buf);
    }
    return i;
}
Пример #6
0
int
wiz_light_sources(const struct nh_cmd_arg *arg)
{
    struct nh_menulist menu;
    const char *buf;
    light_source *ls;

    (void) arg;

    init_menulist(&menu);

    buf = msgprintf("Mobile light sources: hero @ (%2d,%2d)", u.ux, u.uy);
    add_menutext(&menu, buf);
    add_menutext(&menu, "");

    if (level->lev_lights) {
        add_menutext(&menu, "location range flags  type    id");
        add_menutext(&menu, "-------- ----- ------ ----  -------");
        for (ls = level->lev_lights; ls; ls = ls->next) {
            buf = msgprintf("  %2d,%2d   %2d   0x%04x  %s  %p",
                    ls->x, ls->y, ls->range, ls->flags,
                    (ls->type == LS_OBJECT ? "obj" :
                     ls->type == LS_MONSTER ? (
                       mon_is_local((struct monst *)ls->id) ? "mon" :
                       ((struct monst *)ls->id == &youmonst) ? "you" :
                       "<m>") : /* migrating monster */ "???"),
                    ls->id);
            add_menutext(&menu, buf);
        }
    } else
        add_menutext(&menu, "<none>");


    display_menu(&menu, NULL, PICK_NONE, PLHINT_ANYWHERE,
                 NULL);

    return 0;
}
Пример #7
0
int wiz_light_sources(void)
{
    struct menulist menu;
    char buf[BUFSZ];
    light_source *ls;

    init_menulist(&menu);

    sprintf(buf, "Mobile light sources: hero @ (%2d,%2d)", u.ux, u.uy);
    add_menutext(&menu, buf);
    add_menutext(&menu, "");

    if (level->lev_lights) {
	add_menutext(&menu, "location range flags  type    id");
	add_menutext(&menu, "-------- ----- ------ ----  -------");
	for (ls = level->lev_lights; ls; ls = ls->next) {
	    sprintf(buf, "  %2d,%2d   %2d   0x%04x  %s  %p",
		ls->x, ls->y, ls->range, ls->flags,
		(ls->type == LS_OBJECT ? "obj" :
		 ls->type == LS_MONSTER ?
		    (mon_is_local((struct monst *)ls->id) ? "mon" :
		     ((struct monst *)ls->id == &youmonst) ? "you" :
		     "<m>") :		/* migrating monster */
		 "???"),
		ls->id);
	    add_menutext(&menu, buf);
	}
    } else
	add_menutext(&menu, "<none>");


    display_menu(menu.items, menu.icount, NULL, PICK_NONE, NULL);
    free(menu.items);

    return 0;
}
Пример #8
0
/*
 * Look in the "data" file for more info.  Called if the user typed in the
 * whole name (user_typed_name == TRUE), or we've found a possible match
 * with a character/glyph.
 */
static void
checkfile(const char *inp, struct permonst *pm, boolean user_typed_name,
          boolean without_asking)
{
    dlb *fp;
    char buf[BUFSZ], newstr[BUFSZ];
    char *ep, *dbase_str;
    long txt_offset = 0;
    int chk_skip;
    boolean found_in_file = FALSE, skipping_entry = FALSE;

    fp = dlb_fopen(DATAFILE, "r");
    if (!fp) {
        pline("Cannot open data file!");
        return;
    }

    /* To prevent the need for entries in data.base like *ngel to account for
       Angel and angel, make the lookup string the same for both
       user_typed_name and picked name. */
    if (pm != NULL && !user_typed_name)
        dbase_str = strcpy(newstr, pm->mname);
    else
        dbase_str = strcpy(newstr, inp);

    for (ep = dbase_str; *ep; ep++)
        *ep = lowc(*ep);

    if (!strncmp(dbase_str, "interior of ", 12))
        dbase_str += 12;
    if (!strncmp(dbase_str, "a ", 2))
        dbase_str += 2;
    else if (!strncmp(dbase_str, "an ", 3))
        dbase_str += 3;
    else if (!strncmp(dbase_str, "the ", 4))
        dbase_str += 4;
    if (!strncmp(dbase_str, "tame ", 5))
        dbase_str += 5;
    else if (!strncmp(dbase_str, "peaceful ", 9))
        dbase_str += 9;
    if (!strncmp(dbase_str, "invisible ", 10))
        dbase_str += 10;
    if (!strncmp(dbase_str, "statue of ", 10))
        dbase_str[6] = '\0';
    else if (!strncmp(dbase_str, "figurine of ", 12))
        dbase_str[8] = '\0';

    /* Make sure the name is non-empty. */
    if (*dbase_str) {
        /* adjust the input to remove " [seen" and "named " and convert to
           lower case */
        const char *alt = 0;  /* alternate description */

        if ((ep = strstri_mutable(dbase_str, " [seen")) != 0)
            *ep = '\0';

        if ((ep = strstri_mutable(dbase_str, " named ")) != 0)
            alt = ep + 7;
        else
            ep = strstri_mutable(dbase_str, " called ");
        if (!ep)
            ep = strstri_mutable(dbase_str, ", ");
        if (ep && ep > dbase_str)
            *ep = '\0';

        /* 
         * If the object is named, then the name is the alternate description;
         * otherwise, the result of makesingular() applied to the name is. This
         * isn't strictly optimal, but named objects of interest to the user
         * will usually be found under their name, rather than under their
         * object type, so looking for a singular form is pointless.
         */

        if (!alt)
            alt = makesingular(dbase_str);
        else if (user_typed_name)
            alt = msglowercase(alt);

        /* skip first record; read second */
        txt_offset = 0L;
        if (!dlb_fgets(buf, BUFSZ, fp) || !dlb_fgets(buf, BUFSZ, fp)) {
            impossible("can't read 'data' file");
            dlb_fclose(fp);
            return;
        } else if (sscanf(buf, "%8lx\n", &txt_offset) < 1 || txt_offset <= 0)
            goto bad_data_file;

        /* look for the appropriate entry */
        while (dlb_fgets(buf, BUFSZ, fp)) {
            if (*buf == '.')
                break;  /* we passed last entry without success */

            if (digit(*buf)) {
                /* a number indicates the end of current entry */
                skipping_entry = FALSE;
            } else if (!skipping_entry) {
                if (!(ep = strchr(buf, '\n')))
                    goto bad_data_file;
                *ep = 0;
                /* if we match a key that begins with "~", skip this entry */
                chk_skip = (*buf == '~') ? 1 : 0;
                if (pmatch(&buf[chk_skip], dbase_str) ||
                    (alt && pmatch(&buf[chk_skip], alt))) {
                    if (chk_skip) {
                        skipping_entry = TRUE;
                        continue;
                    } else {
                        found_in_file = TRUE;
                        break;
                    }
                }
            }
        }
    }

    if (found_in_file) {
        long entry_offset;
        int entry_count;
        int i;

        /* skip over other possible matches for the info */
        do {
            if (!dlb_fgets(buf, BUFSZ, fp))
                goto bad_data_file;
        } while (!digit(*buf));

        if (sscanf(buf, "%ld,%d\n", &entry_offset, &entry_count) < 2) {
        bad_data_file:impossible("'data' file in wrong format");
            dlb_fclose(fp);
            return;
        }

        if (user_typed_name || without_asking || yn("More info?") == 'y') {
            struct nh_menulist menu;

            if (dlb_fseek(fp, txt_offset + entry_offset, SEEK_SET) < 0) {
                pline("? Seek error on 'data' file!");
                dlb_fclose(fp);
                return;
            }

            init_menulist(&menu);

            for (i = 0; i < entry_count; i++) {
                if (!dlb_fgets(buf, BUFSZ, fp))
                    goto bad_data_file;
                if ((ep = strchr(buf, '\n')) != 0)
                    *ep = 0;
                if (strchr(buf + 1, '\t') != 0)
                    tabexpand(buf + 1);
                add_menutext(&menu, buf + 1);
            }

            display_menu(&menu, NULL, FALSE, PLHINT_ANYWHERE,
                         NULL);
        }
    } else if (user_typed_name)
        pline("I don't have any information on those things.");

    dlb_fclose(fp);
}