comparison arogue5/options.c @ 63:0ed67132cf10

Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
author elwin
date Thu, 09 Aug 2012 22:58:48 +0000
parents
children c56f672244f4
comparison
equal deleted inserted replaced
62:0ef99244acb8 63:0ed67132cf10
1 /*
2 * This file has all the code for the option command.
3 * I would rather this command were not necessary, but
4 * it is the only way to keep the wolves off of my back.
5 *
6 * Advanced Rogue
7 * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T
8 * All rights reserved.
9 *
10 * Based on "Rogue: Exploring the Dungeons of Doom"
11 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
12 * All rights reserved.
13 *
14 * See the file LICENSE.TXT for full copyright and licensing information.
15 */
16
17 #include "curses.h"
18 #include <ctype.h>
19 #include "rogue.h"
20
21 #define NUM_OPTS (sizeof optlist / sizeof (OPTION))
22
23
24 /*
25 * description of an option and what to do with it
26 */
27 struct optstruct {
28 char *o_name; /* option name */
29 char *o_prompt; /* prompt for interactive entry */
30 int *o_opt; /* pointer to thing to set */
31 int (*o_putfunc)(); /* function to print value */
32 int (*o_getfunc)(); /* function to get value interactively */
33 };
34
35 typedef struct optstruct OPTION;
36
37 int put_bool(),
38 get_bool(),
39 put_str(),
40 get_str(),
41 put_abil(),
42 get_abil(),
43 get_quest(),
44 put_quest();
45
46 OPTION optlist[] = {
47 {"terse", "Terse output: ",
48 (int *) &terse, put_bool, get_bool },
49 {"flush", "Flush typeahead during battle: ",
50 (int *) &fight_flush, put_bool, get_bool },
51 {"jump", "Show position only at end of run: ",
52 (int *) &jump, put_bool, get_bool },
53 {"step", "Do inventories one line at a time: ",
54 (int *) &slow_invent, put_bool, get_bool },
55 {"askme", "Ask me about unidentified things: ",
56 (int *) &askme, put_bool, get_bool },
57 {"pickup", "Pick things up automatically: ",
58 (int *) &auto_pickup, put_bool, get_bool },
59 {"name", "Name: ",
60 (int *) whoami, put_str, get_str },
61 {"fruit", "Fruit: ",
62 (int *) fruit, put_str, get_str },
63 {"file", "Save file: ",
64 (int *) file_name, put_str, get_str },
65 {"score", "Score file: ",
66 (int *) score_file, put_str, get_str },
67 {"class", "Character class: ",
68 (int *)&char_type, put_abil, get_abil },
69 {"quest", "Quest item: ",
70 (int *) &quest_item, put_quest, get_quest }
71 };
72
73 /*
74 * The ability field is read-only
75 */
76 get_abil(abil, win)
77 int *abil;
78 WINDOW *win;
79 {
80 register int oy, ox;
81
82 getyx(win, oy, ox);
83 put_abil(abil, win);
84 get_ro(win, oy, ox);
85 }
86
87 /*
88 * The quest field is read-only
89 */
90 get_quest(quest, win)
91 int *quest;
92 WINDOW *win;
93 {
94 register int oy, ox;
95
96 getyx(win, oy, ox);
97 waddstr(win, rel_magic[*quest].mi_name);
98 get_ro(win, oy, ox);
99 }
100
101 /*
102 * get_ro:
103 * "Get" a read-only value.
104 */
105
106 get_ro(win, oy, ox)
107 WINDOW *win;
108 register int oy, ox;
109 {
110 register int ny, nx;
111 register bool op_bad;
112
113 op_bad = TRUE;
114 getyx(win, ny, nx);
115 while(op_bad)
116 {
117 wmove(win, oy, ox);
118 draw(win);
119 switch (wgetch(win))
120 {
121 case '\n':
122 case '\r':
123 op_bad = FALSE;
124 break;
125 case '\033':
126 case '\007':
127 return QUIT;
128 case '-':
129 return MINUS;
130 default:
131 mvwaddstr(win, ny, nx + 5, "(no change allowed)");
132 }
133 }
134 wmove(win, ny, nx + 5);
135 wclrtoeol(win);
136 wmove(win, ny, nx);
137 waddch(win, '\n');
138 return NORM;
139 }
140
141 /*
142 * allow changing a boolean option and print it out
143 */
144
145 get_bool(bp, win)
146 bool *bp;
147 WINDOW *win;
148 {
149 register int oy, ox;
150 register bool op_bad;
151
152 op_bad = TRUE;
153 getyx(win, oy, ox);
154 waddstr(win, *bp ? "True" : "False");
155 while(op_bad)
156 {
157 wmove(win, oy, ox);
158 draw(win);
159 switch (wgetch(win))
160 {
161 case 't':
162 case 'T':
163 *bp = TRUE;
164 op_bad = FALSE;
165 break;
166 case 'f':
167 case 'F':
168 *bp = FALSE;
169 op_bad = FALSE;
170 break;
171 case '\n':
172 case '\r':
173 op_bad = FALSE;
174 break;
175 case '\033':
176 case '\007':
177 return QUIT;
178 case '-':
179 return MINUS;
180