symset restrictions attribute (trunk only)

Pat Rankin wrote:
> I was about to also suggest that there
> be a rogue/non-rogue (with perhaps a third choice meaning "both")
> attribute.  That way we could keep the rogue choices from being
> listed in the "symset" menu and the non-rogue choices from the
> "roguesymset" menu.  Players who deliberately wanted to switch
> over would need to modify the attribute, possibly on a cloned set.
> Or perhaps they could just explicitly set their desired choices
> via NETHACKOPTIONS or .nethackrc and not use the 'O' menues--the
> new attribute doesn't necessary have to block which sets get used
> where, just filter menu entries to display the most applicable
> candidates.
This commit is contained in:
nethack.allison
2006-10-03 02:38:40 +00:00
parent 084dce82d0
commit 0ce424b71a
5 changed files with 111 additions and 21 deletions
+3
View File
@@ -160,6 +160,7 @@ finish
start: RogueIBM start: RogueIBM
Handling: IBM Handling: IBM
Restrictions: rogue
S_weapon: \x29 S_weapon: \x29
S_amulet: \x2c S_amulet: \x2c
S_food: \x3a S_food: \x3a
@@ -190,6 +191,7 @@ finish
start: RogueEpyx start: RogueEpyx
Description: Rogue level color symbol set like Epyx Rogue Description: Rogue level color symbol set like Epyx Rogue
Restrictions: rogue
Handling: IBM Handling: IBM
Color: Yes Color: Yes
S_weapon: \x18 # up arrow S_weapon: \x18 # up arrow
@@ -267,6 +269,7 @@ start: RogueEpyx
finish finish
start: RogueWindows start: RogueWindows
Restrictions: rogue
Handling: IBM Handling: IBM
S_weapon: \x29 S_weapon: \x29
S_amulet: \x2c S_amulet: \x2c
+12 -10
View File
@@ -241,21 +241,23 @@ struct symparse {
/* linked list of symsets and their characteristics */ /* linked list of symsets and their characteristics */
struct symsetentry { struct symsetentry {
struct symsetentry *next; /* next in list */ struct symsetentry *next; /* next in list */
char *name; /* ptr to symset name */ char *name; /* ptr to symset name */
char *desc; /* ptr to description */ char *desc; /* ptr to description */
int idx; /* an index value */ int idx; /* an index value */
int handling; /* known handlers value */ int handling; /* known handlers value */
Bitfield(nocolor,1); /* don't use color if set */ Bitfield(nocolor,1); /* don't use color if set */
/* 7 free bits */ Bitfield(primary,1); /* restricted for use as primary set */
Bitfield(rogue,1); /* restricted for use as rogue lev set */
/* 5 free bits */
}; };
/* /*
* Graphics sets for display symbols * Graphics sets for display symbols
*/ */
#define DEFAULT_GRAPHICS 0 /* regular characters: '-', '+', &c */ #define DEFAULT_GRAPHICS 0 /* regular characters: '-', '+', &c */
#define PRIMARY 0 /* primary graphics */ #define PRIMARY 0 /* primary graphics set */
#define ROGUESET 1 /* rogue graphics */ #define ROGUESET 1 /* rogue graphics set */
#define NUM_GRAPHICS 2 #define NUM_GRAPHICS 2
/* /*
@@ -269,11 +271,11 @@ struct symsetentry {
extern const struct symdef defsyms[MAXPCHARS]; /* defaults */ extern const struct symdef defsyms[MAXPCHARS]; /* defaults */
extern const struct symdef def_warnsyms[WARNCOUNT]; extern const struct symdef def_warnsyms[WARNCOUNT];
extern struct symsetentry symset[NUM_GRAPHICS]; /* from drawing.c */
extern int currentgraphics; /* from drawing.c */ extern int currentgraphics; /* from drawing.c */
extern uchar showsyms[]; extern uchar showsyms[];
#ifdef LOADSYMSETS #ifdef LOADSYMSETS
extern struct symsetentry symset[NUM_GRAPHICS]; /* from drawing.c */
#define SYMHANDLING(ht) (symset[currentgraphics].handling == (ht)) #define SYMHANDLING(ht) (symset[currentgraphics].handling == (ht))
#else #else
#define SYMHANDLING(ht) ((ht) == H_UNK) #define SYMHANDLING(ht) ((ht) == H_UNK)
+25
View File
@@ -541,6 +541,11 @@ boolean name_too;
symset[which_set].nocolor = 0; symset[which_set].nocolor = 0;
symset[which_set].handling = H_UNK; symset[which_set].handling = H_UNK;
symset[which_set].desc = (char *)0;
symset[which_set].nocolor = 0;
/* initialize restriction bits */
symset[which_set].primary = 0;
symset[which_set].rogue = 0;
if (name_too) { if (name_too) {
if (symset[which_set].name) if (symset[which_set].name)
@@ -562,6 +567,25 @@ const char *known_handling[] = {
(const char *)0, (const char *)0,
}; };
/*
* Accepted keywords for symset restrictions.
* These can be virtually anything that you want to
* be able to test in the code someplace.
* Be sure to:
* - add a corresponding Bitfield to the symsetentry struct in rm.h
* - initialize the field to zero in parse_sym_line in the SYM_CONTROL
* case 0 section of the idx switch. The location is prefaced with
* with a comment stating "initialize restriction bits".
* - set the value appropriately based on the index of your keyword
* under the case 5 sections of the same SYM_CONTROL idx switches.
* - add the field to clear_symsetentry()
*/
const char *known_restrictions[] = {
"primary",
"rogue",
(const char *)0,
};
struct symparse loadsyms[] = { struct symparse loadsyms[] = {
{SYM_CONTROL, 0, "start"}, {SYM_CONTROL, 0, "start"},
{SYM_CONTROL, 0, "begin"}, {SYM_CONTROL, 0, "begin"},
@@ -570,6 +594,7 @@ struct symparse loadsyms[] = {
{SYM_CONTROL, 3, "description"}, {SYM_CONTROL, 3, "description"},
{SYM_CONTROL, 4, "color"}, {SYM_CONTROL, 4, "color"},
{SYM_CONTROL, 4, "colour"}, {SYM_CONTROL, 4, "colour"},
{SYM_CONTROL, 5, "restrictions"},
{SYM_PCHAR, S_stone, "S_stone"}, {SYM_PCHAR, S_stone, "S_stone"},
{SYM_PCHAR, S_vwall, "S_vwall"}, {SYM_PCHAR, S_vwall, "S_vwall"},
{SYM_PCHAR, S_hwall, "S_hwall"}, {SYM_PCHAR, S_hwall, "S_hwall"},
+39 -4
View File
@@ -2426,9 +2426,10 @@ read_wizkit()
#endif /*WIZARD*/ #endif /*WIZARD*/
#ifdef LOADSYMSETS #ifdef LOADSYMSETS
extern struct symsetentry *symset_list; /* options.c */ extern struct symsetentry *symset_list; /* options.c */
extern struct symparse loadsyms[]; /* drawing.c */ extern struct symparse loadsyms[]; /* drawing.c */
extern const char *known_handling[]; /* drawing.c */ extern const char *known_handling[]; /* drawing.c */
extern const char *known_restrictions[]; /* drawing.c */
static int symset_count = 0; /* for pick-list building only */ static int symset_count = 0; /* for pick-list building only */
static boolean chosen_symset_start = FALSE, chosen_symset_end = FALSE; static boolean chosen_symset_start = FALSE, chosen_symset_end = FALSE;
@@ -2481,7 +2482,7 @@ parse_sym_line(buf, which_set)
char *buf; char *buf;
int which_set; int which_set;
{ {
int val; int i, val;
struct symparse *symp = (struct symparse *)0; struct symparse *symp = (struct symparse *)0;
char *bufp, *commentp, *altp; char *bufp, *commentp, *altp;
@@ -2553,6 +2554,9 @@ int which_set;
Strcpy(tmpsp->name, bufp); Strcpy(tmpsp->name, bufp);
tmpsp->desc = (char *)0; tmpsp->desc = (char *)0;
tmpsp->nocolor = 0; tmpsp->nocolor = 0;
/* initialize restriction bits */
tmpsp->primary = 0;
tmpsp->rogue = 0;
break; break;
case 3: /* description:something */ case 3: /* description:something */
tmpsp = symset_list; /* most recent symset */ tmpsp = symset_list; /* most recent symset */
@@ -2561,6 +2565,21 @@ int which_set;
Strcpy(tmpsp->desc, bufp); Strcpy(tmpsp->desc, bufp);
} }
break; break;
case 5:
/* restrictions: xxxx*/
tmpsp = symset_list; /* most recent symset */
i = 0;
while (known_restrictions[i]) {
if (!strcmpi(known_restrictions[i], bufp)) {
switch(i) {
case 0: tmpsp->primary = 1; break;
case 1: tmpsp->rogue = 1; break;
}
break; /* while loop */
}
i++;
}
break;
} }
} }
return 1; return 1;
@@ -2573,6 +2592,7 @@ int which_set;
if (!strcmpi(bufp, symset[which_set].name)) { if (!strcmpi(bufp, symset[which_set].name)) {
/* matches desired one */ /* matches desired one */
chosen_symset_start = TRUE; chosen_symset_start = TRUE;
/* these init_*() functions clear symset fields too */
# ifdef REINCARNATION # ifdef REINCARNATION
if (which_set == ROGUESET) init_r_symbols(); if (which_set == ROGUESET) init_r_symbols();
# endif # endif
@@ -2605,6 +2625,21 @@ int which_set;
} }
} }
break; break;
case 5: /* restrictions: xxxx*/
i = 0;
while (known_restrictions[i]) {
if (!strcmpi(known_restrictions[i], bufp)) {
switch(i) {
case 0: symset[which_set].primary = 1;
break;
case 1: symset[which_set].rogue = 1;
break;
}
break; /* while loop */
}
i++;
}
break;
} }
} else { /* !SYM_CONTROL */ } else { /* !SYM_CONTROL */
val = sym_val(bufp); val = sym_val(bufp);
+31 -6
View File
@@ -3155,11 +3155,15 @@ boolean setinitial,setfromfile;
} else if (!strcmp("symset", optname) || } else if (!strcmp("symset", optname) ||
!strcmp("roguesymset", optname)) { !strcmp("roguesymset", optname)) {
menu_item *symset_pick = (menu_item *)0; menu_item *symset_pick = (menu_item *)0;
boolean rogueflag = (*optname == 'r'); boolean primaryflag = (*optname == 's'),
rogueflag = (*optname == 'r'),
ready_to_switch = FALSE,
nothing_to_do = FALSE;
#ifdef LOADSYMSETS #ifdef LOADSYMSETS
int res; int res;
char *symset_name, fmtstr[20]; char *symset_name, fmtstr[20];
struct symsetentry *sl; struct symsetentry *sl;
int setcount = 0;
#endif #endif
int chosen = -2, which_set = int chosen = -2, which_set =
#ifdef REINCARNATION #ifdef REINCARNATION
@@ -3179,22 +3183,43 @@ boolean setinitial,setfromfile;
if (res && symset_list) { if (res && symset_list) {
char symsetchoice[BUFSZ]; char symsetchoice[BUFSZ];
int let = 'a', biggest = 0, thissize = 0; int let = 'a', biggest = 0, thissize = 0;
tmpwin = create_nhwindow(NHW_MENU);
start_menu(tmpwin);
any.a_int = 1;
add_menu(tmpwin, NO_GLYPH, &any, let++, 0,
ATR_NONE, "Default Symbols", MENU_UNSELECTED);
sl = symset_list; sl = symset_list;
while (sl) { while (sl) {
/* check restrictions */
if ((!rogueflag && sl->rogue) ||
(!primaryflag && sl->primary)) {
sl = sl->next;
continue;
}
setcount++;
/* find biggest name */ /* find biggest name */
if (sl->name) thissize = strlen(sl->name); if (sl->name) thissize = strlen(sl->name);
if (thissize > biggest) biggest = thissize; if (thissize > biggest) biggest = thissize;
sl = sl->next; sl = sl->next;
} }
if (!setcount) {
pline("There are no appropriate %ssymbol sets available.",
(rogueflag) ? "rogue level " :
(primaryflag) ? "primary " :
"");
return TRUE;
}
Sprintf(fmtstr,"%%-%ds %%s", biggest + 5); Sprintf(fmtstr,"%%-%ds %%s", biggest + 5);
tmpwin = create_nhwindow(NHW_MENU);
start_menu(tmpwin);
any.a_int = 1;
add_menu(tmpwin, NO_GLYPH, &any, let++, 0,
ATR_NONE, "Default Symbols", MENU_UNSELECTED);
sl = symset_list; sl = symset_list;
while (sl) { while (sl) {
/* check restrictions */
if ((!rogueflag && sl->rogue) ||
(!primaryflag && sl->primary)) {
sl = sl->next;
continue;
}
if (sl->name) { if (sl->name) {
any.a_int = sl->idx + 2; any.a_int = sl->idx + 2;
Sprintf(symsetchoice, fmtstr, sl->name, Sprintf(symsetchoice, fmtstr, sl->name,