Mercurial > hg > early-roguelike
comparison rogue5/options.c @ 33:f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
| author | elwin |
|---|---|
| date | Mon, 24 May 2010 20:10:59 +0000 |
| parents | |
| children | 655c317b6237 |
comparison
equal
deleted
inserted
replaced
| 32:2dcd75e6a736 | 33:f502bf60e6e4 |
|---|---|
| 1 /* | |
| 2 * This file has all the code for the option command. I would rather | |
| 3 * this command were not necessary, but it is the only way to keep the | |
| 4 * wolves off of my back. | |
| 5 * | |
| 6 * @(#)options.c 4.24 (Berkeley) 05/10/83 | |
| 7 * | |
| 8 * Rogue: Exploring the Dungeons of Doom | |
| 9 * Copyright (C) 1980-1983, 1985, 1999 Michael Toy, Ken Arnold and Glenn Wichman | |
| 10 * All rights reserved. | |
| 11 * | |
| 12 * See the file LICENSE.TXT for full copyright and licensing information. | |
| 13 */ | |
| 14 | |
| 15 #include <stdlib.h> | |
| 16 #include <curses.h> | |
| 17 #include <ctype.h> | |
| 18 #include <string.h> | |
| 19 #include "rogue.h" | |
| 20 | |
| 21 #define EQSTR(a, b, c) (strncmp(a, b, c) == 0) | |
| 22 | |
| 23 #define NUM_OPTS (sizeof optlist / sizeof (OPTION)) | |
| 24 | |
| 25 /* | |
| 26 * description of an option and what to do with it | |
| 27 */ | |
| 28 struct optstruct { | |
| 29 char *o_name; /* option name */ | |
| 30 char *o_prompt; /* prompt for interactive entry */ | |
| 31 void *o_opt; /* pointer to thing to set */ | |
| 32 /* function to print value */ | |
| 33 void (*o_putfunc)(void *opt); | |
| 34 /* function to get value interactively */ | |
| 35 int (*o_getfunc)(void *opt, WINDOW *win); | |
| 36 }; | |
| 37 | |
| 38 typedef struct optstruct OPTION; | |
| 39 | |
| 40 void pr_optname(const OPTION *op); | |
| 41 | |
| 42 static const OPTION optlist[] = { | |
| 43 {"terse", "Terse output", | |
| 44 &terse, put_bool, get_bool }, | |
| 45 {"flush", "Flush typeahead during battle", | |
| 46 &fight_flush, put_bool, get_bool }, | |
| 47 {"jump", "Show position only at end of run", | |
| 48 &jump, put_bool, get_bool }, | |
| 49 {"seefloor", "Show the lamp-illuminated floor", | |
| 50 &see_floor, put_bool, get_sf }, | |
| 51 {"passgo", "Follow turnings in passageways", | |
| 52 &passgo, put_bool, get_bool }, | |
| 53 {"tombstone", "Print out tombstone when killed", | |
| 54 &tombstone, put_bool, get_bool }, | |
| 55 {"inven", "Inventory style", | |
| 56 &inv_type, put_inv_t, get_inv_t }, | |
| 57 {"name", "Name", | |
| 58 whoami, put_str, get_str }, | |
| 59 {"fruit", "Fruit", | |
| 60 fruit, put_str, get_str }, | |
| 61 {"file", "Save file", | |
| 62 file_name, put_str, get_str } | |
| 63 }; | |
| 64 | |
| 65 /* | |
| 66 * option: | |
| 67 * Print and then set options from the terminal | |
| 68 */ | |
| 69 | |
| 70 void | |
| 71 option(void) | |
| 72 { | |
| 73 const OPTION *op; | |
| 74 int retval; | |
| 75 | |
| 76 wclear(hw); | |
| 77 /* | |
| 78 * Display current values of options | |
| 79 */ | |
| 80 for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++) | |
| 81 { | |
| 82 pr_optname(op); | |
| 83 (*op->o_putfunc)(op->o_opt); | |
| 84 waddch(hw, '\n'); | |
| 85 } | |
| 86 /* | |
| 87 * Set values | |
| 88 */ | |
| 89 wmove(hw, 0, 0); | |
| 90 for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++) | |
| 91 { | |
| 92 pr_optname(op); | |
| 93 retval = (*op->o_getfunc)(op->o_opt, hw); | |
| 94 if (retval) | |
| 95 { | |
| 96 if (retval == QUIT) | |
| 97 break; | |
| 98 else if (op > optlist) { /* MINUS */ | |
| 99 wmove(hw, (int)(op - optlist) - 1, 0); | |
| 100 op -= 2; | |
| 101 } | |
| 102 else /* trying to back up beyond the top */ | |
| 103 { | |
| 104 putchar('\007'); | |
| 105 wmove(hw, 0, 0); | |
| 106 op--; | |
| 107 } | |
| 108 } | |
| 109 } | |
| 110 /* | |
| 111 * Switch back to original screen | |
| 112 */ | |
| 113 wmove(hw, LINES - 1, 0); | |
| 114 waddstr(hw, "--Press space to continue--"); | |
| 115 wrefresh(hw); | |
| 116 wait_for(hw, ' '); | |
| 117 clearok(curscr, TRUE); | |
| 118 touchwin(stdscr); | |
| 119 after = FALSE; | |
| 120 } | |
| 121 | |
| 122 /* | |
| 123 * pr_optname: | |
| 124 * Print out the option name prompt | |
| 125 */ | |
| 126 | |
| 127 void | |
| 128 pr_optname(const OPTION *op) | |
| 129 { | |
| 130 wprintw(hw, "%s (\"%s\"): ", op->o_prompt, op->o_name); | |
| 131 } | |
| 132 | |
| 133 /* | |
| 134 * put_bool | |
| 135 * Put out a boolean | |
| 136 */ | |
| 137 | |
| 138 void | |
| 139 put_bool(void *b) | |
| 140 { | |
| 141 waddstr(hw, *(int *) b ? "True" : "False"); | |
| 142 } | |
| 143 | |
| 144 /* | |
| 145 * put_str: | |
| 146 * Put out a string | |
| 147 */ | |
| 148 | |
| 149 void | |
| 150 put_str(void *str) | |
| 151 { | |
| 152 waddstr(hw, (char *) str); | |
| 153 } | |
| 154 | |
| 155 /* | |
| 156 * put_inv_t: | |
| 157 * Put out an inventory type | |
| 158 */ | |
| 159 | |
| 160 void | |
| 161 put_inv_t(void *ip) | |
| 162 { | |
| 163 waddstr(hw, inv_t_name[*(int *) ip]); | |
| 164 } | |
| 165 | |
| 166 /* | |
| 167 * get_bool: | |
| 168 * Allow changing a boolean option and print it out | |
| 169 */ | |
| 170 int | |
| 171 get_bool(void *vp, WINDOW *win) | |
| 172 { | |
| 173 int *bp = (int *) vp; | |
| 174 int oy, ox; | |
| 175 int op_bad; | |
| 176 | |
| 177 op_bad = TRUE; | |
| 178 getyx(win, oy, ox); | |
| 179 waddstr(win, *bp ? "True" : "False"); | |
| 180 while (op_bad) | |
