Mercurial > hg > early-roguelike
annotate rogue4/options.c @ 12:9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
| author | edwarj4 | 
|---|---|
| date | Sat, 24 Oct 2009 16:52:52 +0000 | 
| parents | |
| children | e7dc81b41168 | 
| rev | line source | 
|---|---|
| 12 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 1 /* | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 2 * This file has all the code for the option command. I would rather | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 3 * this command were not necessary, but it is the only way to keep the | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 4 * wolves off of my back. | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 5 * | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 6 * @(#)options.c 4.12 (Berkeley) 3/2/82 | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 7 * | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 8 * Rogue: Exploring the Dungeons of Doom | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 9 * Copyright (C) 1980, 1981, 1982 Michael Toy, Ken Arnold and Glenn Wichman | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 10 * All rights reserved. | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 11 * | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 12 * See the file LICENSE.TXT for full copyright and licensing information. | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 13 */ | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 14 | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 15 #include <curses.h> | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 16 #include <ctype.h> | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 17 #include <string.h> | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 18 #include "rogue.h" | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 19 | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 20 #define EQSTR(a, b, c) (strncmp(a, b, c) == 0) | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 21 | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 22 #define NUM_OPTS (sizeof optlist / sizeof (OPTION)) | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 23 | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 24 /* | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 25 * description of an option and what to do with it | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 26 */ | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 27 struct optstruct { | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 28 char *o_name; /* option name */ | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 29 char *o_prompt; /* prompt for interactive entry */ | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 30 int *o_opt; /* pointer to thing to set */ | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 31 int (*o_putfunc)(); /* function to print value */ | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 32 int (*o_getfunc)(); /* function to get value interactively */ | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 33 }; | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 34 | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 35 typedef struct optstruct OPTION; | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 36 | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 37 int put_bool(), get_bool(), put_str(), get_str(); | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 38 | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 39 OPTION optlist[] = { | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 40 {"terse", "Terse output: ", | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 41 (int *) &terse, put_bool, get_bool }, | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 42 {"flush", "Flush typeahead during battle: ", | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 43 (int *) &fight_flush, put_bool, get_bool }, | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 44 {"jump", "Show position only at end of run: ", | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 45 (int *) &jump, put_bool, get_bool }, | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 46 {"step", "Do inventories one line at a time: ", | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 47 (int *) &slow_invent, put_bool, get_bool }, | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 48 {"askme", "Ask me about unidentified things: ", | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 49 (int *) &askme, put_bool, get_bool }, | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 50 {"passgo", "Follow turnings in passageways: ", | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 51 (int *) &passgo, put_bool, get_bool }, | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 52 {"name", "Name: ", | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 53 (int *) whoami, put_str, get_str }, | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 54 {"fruit", "Fruit: ", | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 55 (int *) fruit, put_str, get_str }, | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 56 {"file", "Save file: ", | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 57 (int *) file_name, put_str, get_str } | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 58 }; | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 59 | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 60 /* | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 61 * option: | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 62 * Print and then set options from the terminal | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 63 */ | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 64 option() | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 65 { | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 66 register OPTION *op; | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 67 register int retval; | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 68 | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 69 wclear(hw); | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 70 /* | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 71 * Display current values of options | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 72 */ | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 73 for (op = optlist; op < &optlist[NUM_OPTS]; op++) | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 74 { | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 75 waddstr(hw, op->o_prompt); | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 76 (*op->o_putfunc)(op->o_opt); | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 77 waddch(hw, '\n'); | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 78 } | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 79 /* | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 80 * Set values | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 81 */ | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 82 wmove(hw, 0, 0); | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 83 for (op = optlist; op < &optlist[NUM_OPTS]; op++) | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 84 { | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 85 waddstr(hw, op->o_prompt); | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 86 if ((retval = (*op->o_getfunc)(op->o_opt, hw))) | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 87 if (retval == QUIT) | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 88 break; | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 89 else if (op > optlist) { /* MINUS */ | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 90 wmove(hw, (op - optlist) - 1, 0); | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 91 op -= 2; | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 92 } | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 93 else /* trying to back up beyond the top */ | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 94 { | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 95 putchar('\007'); | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 96 wmove(hw, 0, 0); | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 97 op--; | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 98 } | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 99 } | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 100 /* | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 101 * Switch back to original screen | 
| 
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
 edwarj4 parents: diff
changeset | 
