Exemplo n.º 1
0
void
curses_free_nh_opts(struct nh_option_desc *opts)
{
    if (game_is_running) {
        if (opts == nh_options)
            curses_impossible("Freeing non-game options during a game!");
        else
            nhlib_free_optlist(opts);
    } else if (opts != nh_options) {
        curses_impossible("Freeing game options outside a game!");
        nhlib_free_optlist(opts);
    }
}
Exemplo n.º 2
0
nh_bool
read_nh_config(void)
{
    fnchar filename[BUFSZ];

    struct nh_option_desc *opts = nh_get_options();
    if (!opts)
        return FALSE;

    nhlib_free_optlist(nh_options);
    nh_options = opts;

    get_config_name(filename, FALSE);
    read_config_file(filename);

    return TRUE;
}
Exemplo n.º 3
0
boolean
set_option(const char *name, union nh_optvalue value,
           struct newgame_options *ngo)
{
    struct nh_option_desc *option = NULL, *options = new_opt_struct();
    boolean ret = FALSE;

    /* can't change options for other players */
    if (program_state.followmode != FM_PLAY)
        goto free;

    if (options)
        option = nhlib_find_option(options, name);

    if (!option || (option->birth_option && program_state.game_running))
        goto free;

    if (!nhlib_option_value_ok(option, value))
        goto free;

    nhlib_copy_option_value(option, value);

    if (option->type == OPTTYPE_BOOL) {
        boolean *bvar = nhlib_find_boolopt(boolopt_map, option->name);

        if (!bvar) {
            impossible("no boolean for option '%s'", option->name);
            goto free;
        }
        *bvar = option->value.b;

        ret = TRUE;
        goto free;
    } else if (!strcmp("disclose", option->name)) {
        flags.end_disclose = option->value.e;
    } else if (!strcmp("fruit", option->name)) {
        strncpy(gamestate.fruits.curname, option->value.s, PL_FSIZ-1);
        gamestate.fruits.curname[PL_FSIZ - 1] = '\0';
        if (objects)    /* don't do fruitadd before the game is running */
            fruitadd(gamestate.fruits.curname);
    } else if (!strcmp("menustyle", option->name)) {
        flags.menu_style = option->value.e;
    } else if (!strcmp("movecommand", option->name)) {
        flags.interaction_mode = option->value.e;
    } else if (!strcmp("packorder", option->name)) {
        if (!change_inv_order(option->value.s))
            goto free;
    } else if (!strcmp("pickup_burden", option->name)) {
        flags.pickup_burden = option->value.e;
    } else if (!strcmp("autopickup_rules", option->name)) {
        if (flags.ap_rules) {
            free(flags.ap_rules->rules);
            free(flags.ap_rules);
            flags.ap_rules = NULL;
        }
        flags.ap_rules = nhlib_copy_autopickup_rules(option->value.ar);
    }
    /* birth options */
    else if (!strcmp("mode", option->name)) {
        flags.debug = (option->value.e == MODE_WIZARD);
        flags.explore = (option->value.e == MODE_EXPLORE);
        flags.challenge = (option->value.e == MODE_CHALLENGE);
    } else if (!strcmp("align", option->name)) {
        u.initalign = option->value.e;
    } else if (!strcmp("gender", option->name)) {
        u.initgend = option->value.e;
    } else if (!strcmp("race", option->name)) {
        u.initrace = option->value.e;
    } else if (!strcmp("role", option->name)) {
        u.initrole = option->value.e;
    }

    else if (!strcmp("name", option->name)) {
        strncpy(u.uplname, option->value.s, PL_NSIZ-1);
        (u.uplname)[PL_NSIZ - 1] = '\0';
    } else if (!strcmp("seed", option->name)) {
        /* note: does not NUL-terminate a max-length string, this is
           intentional */
        strncpy(flags.setseed, option->value.s, RNG_SEED_SIZE_BASE64);
    } else if (!strcmp("catname", option->name)) {
        if (!ngo)
            panic("catname set outside newgame sequence");
        strncpy(ngo->catname, option->value.s, PL_PSIZ-1);
        ngo->catname[PL_PSIZ - 1] = '\0';
    } else if (!strcmp("dogname", option->name)) {
        if (!ngo)
            panic("dogname set outside newgame sequence");
        strncpy(ngo->dogname, option->value.s, PL_PSIZ-1);
        ngo->dogname[PL_PSIZ - 1] = '\0';
    } else if (!strcmp("horsename", option->name)) {
        if (!ngo)
            panic("horsename set outside newgame sequence");
        strncpy(ngo->horsename, option->value.s, PL_PSIZ-1);
        ngo->horsename[PL_PSIZ - 1] = '\0';
    } else if (!strcmp("pettype", option->name)) {
        if (!ngo)
            panic("preferred_pet set outside newgame sequence");
        ngo->preferred_pet = (char)option->value.e;
    } else if (!strcmp("timezone", option->name)) {
        flags.timezone = option->value.e;
    } else if (!strcmp("polyinit", option->name)) {
        flags.polyinit_mnum = option->value.e;
    }

    else
        /* unrecognized option */
        goto free;

    /* assume that any recognized option has been handled. */
    ret = TRUE;

free:
    nhlib_free_optlist(options);

    return ret;
}