>B1014 <Someone> [reported] change request - disclosure default

>
>	I'd like the default for "Would you like to see your <whatever>"
>	at the end of a game to be "y" instead of "n". I haven't asked
>	for full disclosure in order to have it skipped if I press the
>	space bar once too often by mistake.

This changes the way the flags.end_disclose array is used to
allow what this request is asking for.  It should be backward
compatible with previous "disclose" options.

The order that the end_disclore options are stored:
inventory, attribs, vanquished, genocided, conduct
There is an array in flags:
	end_disclose[NUM_DISCLOSURE_OPT];
with option settings for the each of the following:
iagvc [see disclosure_options in decl.c]:
Legal setting values in that array are:
	DISCLOSE_PROMPT_DEFAULT_YES  ask with default answer yes
	DISCLOSE_PROMPT_DEFAULT_NO   ask with default answer no
	DISCLOSE_YES_WITHOUT_PROMPT  always disclose and don't ask
	DISCLOSE_NO_WITHOUT_PROMPT   never disclose and don't ask

Those setting values can be used in the option
string as a prefix to each disclosure option
to get the desired behaviour for that option.

For backward compatibility, no prefix is actually required,
and the presence of a i,a,g,v, or c without a prefix sets
the corresponding value to DISCLOSE_YES_WITHOUT_PROMPT;

The actual prefixes used are controlled by the following in flag.h:
#define DISCLOSE_PROMPT_DEFAULT_YES	'y'
#define DISCLOSE_PROMPT_DEFAULT_NO	'n'
#define DISCLOSE_YES_WITHOUT_PROMPT	'+'
#define DISCLOSE_NO_WITHOUT_PROMPT	'-'

As far as the docs go, I don't know if I've got the *roff
stuff right.   The TeX stuff looks okay when I converted it to .pdf.

This increments EDITLEVEL.  If that is a problem, I can
add a routine to restore.c to perform a conversion of the old
values in flags. Let me know.
This commit is contained in:
nethack.allison
2002-01-27 01:26:59 +00:00
parent df9092ccb5
commit 8389fb1f29
9 changed files with 287 additions and 67 deletions

View File

@@ -73,6 +73,8 @@ const char ynaqchars[] = "ynaq";
const char ynNaqchars[] = "yn#aq";
NEARDATA long yn_number = 0L;
const char disclosure_options[] = "iavgc";
#ifdef MICRO
char hackdir[PATHLEN]; /* where rumors, help, record are */
char levels[PATHLEN]; /* where levels are */

108
src/end.c
View File

@@ -40,8 +40,9 @@ STATIC_DCL void FDECL(sort_valuables, (struct valuable_data *,int));
STATIC_DCL void FDECL(add_artifact_score, (struct obj *));
STATIC_DCL void FDECL(display_artifact_score, (struct obj *,winid));
STATIC_DCL void FDECL(savelife, (int));
STATIC_DCL void NDECL(list_vanquished);
STATIC_DCL void NDECL(list_genocided);
STATIC_DCL void FDECL(list_vanquished, (int));
STATIC_DCL void FDECL(list_genocided, (int));
STATIC_DCL boolean FDECL(should_query_disclose_option, (int, int*));
#if defined(__BEOS__) || defined(MICRO) || defined(WIN32) || defined(OS2)
extern void FDECL(nethack_exit,(int));
@@ -286,6 +287,41 @@ panic VA_DECL(const char *, str)
done(PANICKED);
}
STATIC_OVL boolean
should_query_disclose_option(category, defquery)
int category;
int *defquery;
{
int idx;
char *dop = index(disclosure_options, category);
if (dop && defquery) {
idx = (dop - disclosure_options) / sizeof(char);
if (idx < 0 || idx > (NUM_DISCLOSURE_OPTIONS - 1)) {
impossible(
"should_query_disclose_option: bad disclosure index %d %c",
idx, category);
*defquery = DISCLOSE_PROMPT_DEFAULT_YES;
return TRUE;
}
if (flags.end_disclose[idx] == DISCLOSE_YES_WITHOUT_PROMPT) {
*defquery = 'q';
return FALSE;
} else if (flags.end_disclose[idx] == DISCLOSE_NO_WITHOUT_PROMPT) {
*defquery = 'q';
return FALSE;
} else if (flags.end_disclose[idx] == DISCLOSE_PROMPT_DEFAULT_YES) {
*defquery = 'y';
return TRUE;
} else if (flags.end_disclose[idx] == DISCLOSE_PROMPT_DEFAULT_NO) {
*defquery = 'n';
return TRUE;
}
}
if (defquery)impossible("should_query_disclose_option: bad category %c", category);
else impossible("should_query_disclose_option: null defquery");
return TRUE;
}
STATIC_OVL void
disclose(how,taken)
int how;
@@ -293,48 +329,44 @@ boolean taken;
{
char c;
char qbuf[QBUFSZ];
int defquery;
if (invent && !done_stopprint &&
(!flags.end_disclose[0] || index(flags.end_disclose, 'i'))) {
if(taken)
Sprintf(qbuf,"Do you want to see what you had when you %s?",
(how == QUIT) ? "quit" : "died");
else
Strcpy(qbuf,"Do you want your possessions identified?");
if ((c = yn_function(qbuf, ynqchars, 'y')) == 'y') {
/* New dump format by maartenj@cs.vu.nl */
struct obj *obj;
for (obj = invent; obj; obj = obj->nobj) {
makeknown(obj->otyp);
obj->known = obj->bknown = obj->dknown = obj->rknown = 1;
if (invent && !done_stopprint) {
if (should_query_disclose_option('i', &defquery)) {
if(taken)
Sprintf(qbuf,"Do you want to see what you had when you %s?",
(how == QUIT) ? "quit" : "died");
else
Strcpy(qbuf,"Do you want your possessions identified?");
if ((c = yn_function(qbuf, ynqchars, defquery)) == 'y') {
/* New dump format by maartenj@cs.vu.nl */
struct obj *obj;
for (obj = invent; obj; obj = obj->nobj) {
makeknown(obj->otyp);
obj->known = obj->bknown = obj->dknown = obj->rknown = 1;
}
(void) display_inventory((char *)0, TRUE);
container_contents(invent, TRUE, TRUE);
}
(void) display_inventory((char *)0, TRUE);
container_contents(invent, TRUE, TRUE);
if (c == 'q') done_stopprint++;
}
if (c == 'q') done_stopprint++;
}
if (!done_stopprint &&
(!flags.end_disclose[0] || index(flags.end_disclose, 'a'))) {
c = yn_function("Do you want to see your attributes?",ynqchars,'y');
if (!done_stopprint && should_query_disclose_option('a', &defquery)) {
c = yn_function("Do you want to see your attributes?",ynqchars, defquery);
if (c == 'y') enlightenment(how >= PANICKED ? 1 : 2); /* final */
if (c == 'q') done_stopprint++;
}
if (!done_stopprint &&
(!flags.end_disclose[0] || index(flags.end_disclose, 'v'))) {
list_vanquished();
}
if (!done_stopprint && should_query_disclose_option('v', &defquery))
list_vanquished(defquery);
if (!done_stopprint &&
(!flags.end_disclose[0] || index(flags.end_disclose, 'g'))) {
list_genocided();
}
if (!done_stopprint && should_query_disclose_option('g', &defquery))
list_genocided(defquery);
if (!done_stopprint &&
(!flags.end_disclose[0] || index(flags.end_disclose, 'c'))) {
c = yn_function("Do you want to see your conduct?",ynqchars,'y');
if (!done_stopprint && should_query_disclose_option('c', &defquery)) {
c = yn_function("Do you want to see your conduct?",ynqchars,defquery);
if (c == 'y') show_conduct(how >= PANICKED ? 1 : 2);
if (c == 'q') done_stopprint++;
}
@@ -896,7 +928,8 @@ int status;
}
STATIC_OVL void
list_vanquished()
list_vanquished(defquery)
int defquery;
{
register int i, lev;
int ntypes = 0, max_lev = 0, nkilled;
@@ -917,7 +950,7 @@ list_vanquished()
*/
if (ntypes != 0) {
c = yn_function("Do you want an account of creatures vanquished?",
ynqchars, 'n');
ynqchars, defquery);
if (c == 'q') done_stopprint++;
if (c == 'y') {
klwin = create_nhwindow(NHW_MENU);
@@ -980,7 +1013,8 @@ num_genocides()
}
STATIC_OVL void
list_genocided()
list_genocided(defquery)
int defquery;
{
register int i;
int ngenocided;
@@ -993,7 +1027,7 @@ list_genocided()
/* genocided species list */
if (ngenocided != 0) {
c = yn_function("Do you want a list of species genocided?",
ynqchars, 'n');
ynqchars, defquery);
if (c == 'q') done_stopprint++;
if (c == 'y') {
klwin = create_nhwindow(NHW_MENU);

View File

@@ -214,7 +214,7 @@ static struct Comp_Opt
{ "catname", "the name of your (first) cat (e.g., catname:Tabby)",
PL_PSIZ, DISP_IN_GAME },
{ "disclose", "the kinds of information to disclose at end of game",
sizeof(flags.end_disclose),
sizeof(flags.end_disclose) * 2,
SET_IN_GAME },
{ "dogname", "the name of your (first) dog (e.g., dogname:Fang)",
PL_PSIZ, DISP_IN_GAME },
@@ -499,6 +499,8 @@ initoptions()
flags.pickup_types[0] = '\0';
flags.pickup_burden = MOD_ENCUMBER;
for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++)
flags.end_disclose[i] = DISCLOSE_PROMPT_DEFAULT_NO;
switch_graphics(ASCII_GRAPHICS); /* set default characters */
#if defined(UNIX) && defined(TTY_GRAPHICS)
/*
@@ -1554,7 +1556,28 @@ goodfruit:
/* things to disclose at end of game */
if (match_optname(opts, "disclose", 4, TRUE)) {
flags.end_disclose[0] = '\0'; /* all */
/*
* The order that the end_disclore options are stored:
* inventory, attribs, vanquished, genocided, conduct
* There is an array in flags:
* end_disclose[NUM_DISCLOSURE_OPT];
* with option settings for the each of the following:
* iagvc [see disclosure_options in decl.c]:
* Legal setting values in that array are:
* DISCLOSE_PROMPT_DEFAULT_YES ask with default answer yes
* DISCLOSE_PROMPT_DEFAULT_NO ask with default answer no
* DISCLOSE_YES_WITHOUT_PROMPT always disclose and don't ask
* DISCLOSE_NO_WITHOUT_PROMPT never disclose and don't ask
*
* Those setting values can be used in the option
* string as a prefix to get the desired behaviour.
*
* For backward compatibility, no prefix is required,
* and the presence of a i,a,g,v, or c without a
* prefix sets the corresponding value to DISCLOSE_YES_WITHOUT_PROMPT;
*/
boolean badopt = FALSE;
int idx, prefix_val;
if (!(op = string_for_opt(opts, TRUE))) {
/* for backwards compatibility, "disclose" without a
* value means all (was inventory and attributes,
@@ -1562,7 +1585,11 @@ goodfruit:
* it means "none"
* (note "none" contains none of "iavkgc")
*/
if (negated) Strcpy(flags.end_disclose, "none");
for (num = 0; num < NUM_DISCLOSURE_OPTIONS; num++) {
if (negated)
flags.end_disclose[num] = DISCLOSE_NO_WITHOUT_PROMPT;
else flags.end_disclose[num] = DISCLOSE_PROMPT_DEFAULT_YES;
}
return;
}
if (negated) {
@@ -1570,16 +1597,37 @@ goodfruit:
return;
}
num = 0;
prefix_val = -1;
while (*op && num < sizeof flags.end_disclose - 1) {
register char c;
register char c, *dop;
char valid_settings[] = {
DISCLOSE_PROMPT_DEFAULT_YES,
DISCLOSE_PROMPT_DEFAULT_NO,
DISCLOSE_YES_WITHOUT_PROMPT,
DISCLOSE_NO_WITHOUT_PROMPT
};
c = lowc(*op);
if (c == 'k') c = 'v'; /* killed -> vanquished */
if (!index(flags.end_disclose, c)) {
flags.end_disclose[num++] = c;
flags.end_disclose[num] = '\0'; /* for index */
}
dop = index(disclosure_options, c);
if (dop) {
idx = dop - disclosure_options;
if (idx < 0 || idx > NUM_DISCLOSURE_OPTIONS - 1) {
impossible("bad disclosure index %d %c",
idx, c);
continue;
}
if (prefix_val != -1) {
flags.end_disclose[idx] = prefix_val;
prefix_val = -1;
} else
flags.end_disclose[idx] = DISCLOSE_YES_WITHOUT_PROMPT;
} else if (index(valid_settings, c)) {
prefix_val = c;
} else
badopt = TRUE;
op++;
}
if (badopt) badoption(opts);
return;
}
@@ -2188,7 +2236,7 @@ boolean setinitial,setfromfile;
char buf[BUFSZ];
boolean retval = FALSE;
/* Special handling of menustyle, pickup_burden, and pickup_types. */
/* Special handling of menustyle, pickup_burden, and pickup_types, disclose options. */
if (!strcmp("menustyle", optname)) {
const char *style_name;
menu_item *style_pick = (menu_item *)0;
@@ -2231,6 +2279,71 @@ boolean setinitial,setfromfile;
/* parseoptions will prompt for the list of types */
parseoptions(strcpy(buf, "pickup_types"), setinitial, setfromfile);
retval = TRUE;
} else if (!strcmp("disclose", optname)) {
int pick_cnt, pick_idx, opt_idx;
winid tmpwin;
menu_item *disclosure_category_pick = (menu_item *)0;
/*
* The order of disclose_names[]
* must correspond to disclosure_options in decl.h
*/
const char *disclosure_names[] = {
"inventory", "attributes", "vanquished", "genocides", "conduct"
};
int disc_cat[NUM_DISCLOSURE_OPTIONS];
const char *disclosure_name;
tmpwin = create_nhwindow(NHW_MENU);
start_menu(tmpwin);
for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++) {
disclosure_name = disclosure_names[i];
any.a_int = i + 1;
add_menu(tmpwin, NO_GLYPH, &any, disclosure_options[i], 0,
ATR_NONE, disclosure_name, MENU_UNSELECTED);
disc_cat[i] = 0;
}
end_menu(tmpwin, "Change which disclosure options categories:");
if ((pick_cnt = select_menu(tmpwin, PICK_ANY, &disclosure_category_pick)) > 0) {
for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx) {
opt_idx = disclosure_category_pick[pick_idx].item.a_int - 1;
disc_cat[opt_idx] = 1;
}
free((genericptr_t)disclosure_category_pick);
disclosure_category_pick = (menu_item *)0;
}
destroy_nhwindow(tmpwin);
for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++) {
if (disc_cat[i]) {
char dbuf[BUFSZ];
menu_item *disclosure_option_pick = (menu_item *)0;
Sprintf(dbuf, "Disclosure options for %s:", disclosure_names[i]);
tmpwin = create_nhwindow(NHW_MENU);
start_menu(tmpwin);
any.a_char = DISCLOSE_NO_WITHOUT_PROMPT;
add_menu(tmpwin, NO_GLYPH, &any, 'a', 0,
ATR_NONE,"Never disclose and don't prompt", MENU_UNSELECTED);
any.a_void = 0;
any.a_char = DISCLOSE_YES_WITHOUT_PROMPT;
add_menu(tmpwin, NO_GLYPH, &any, 'b', 0,
ATR_NONE,"Always disclose and don't prompt", MENU_UNSELECTED);
any.a_void = 0;
any.a_char = DISCLOSE_PROMPT_DEFAULT_NO;
add_menu(tmpwin, NO_GLYPH, &any, 'c', 0,
ATR_NONE,"Prompt and default answer to \"No\"", MENU_UNSELECTED);
any.a_void = 0;
any.a_char = DISCLOSE_PROMPT_DEFAULT_YES;
add_menu(tmpwin, NO_GLYPH, &any, 'd', 0,
ATR_NONE,"Prompt and default answer to \"Yes\"", MENU_UNSELECTED);
end_menu(tmpwin, dbuf);
if (select_menu(tmpwin, PICK_ONE, &disclosure_option_pick) > 0) {
flags.end_disclose[i] = disclosure_option_pick->item.a_char;
free((genericptr_t)disclosure_option_pick);
}
destroy_nhwindow(tmpwin);
}
}
retval = TRUE;
}
return retval;
}
@@ -2248,9 +2361,7 @@ char *buf;
char ocl[MAXOCLASSES+1];
static const char none[] = "(none)", randomrole[] = "random",
to_be_done[] = "(to be done)";
#ifdef PREFIXES_IN_USE
int i;
#endif
buf[0] = '\0';
if (!strcmp(optname,"align"))
@@ -2260,9 +2371,17 @@ char *buf;
iflags.bouldersym : oc_syms[(int)objects[BOULDER].oc_class]);
else if (!strcmp(optname, "catname"))
Sprintf(buf, "%s", catname[0] ? catname : none );
else if (!strcmp(optname, "disclose"))
Sprintf(buf, "%s",
flags.end_disclose[0] ? flags.end_disclose : "all" );
else if (!strcmp(optname, "disclose")) {
boolean all = TRUE, dnone = TRUE;
for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++) {
char topt[2];
topt[1] = '\0';
topt[0] = flags.end_disclose[i];
Strcat(buf, topt);
topt[0] = disclosure_options[i];
Strcat(buf, topt);
}
}
else if (!strcmp(optname, "dogname"))
Sprintf(buf, "%s", dogname[0] ? dogname : none );
else if (!strcmp(optname, "dungeon"))