autopickup_exceptions enhancement
An enhancement to the original to allow
two types of exceptions:
always pickup
never pickup
To specify "never pickup", begin the pattern string with '>'
which is NetHack's down direction symbol (for "leave it down")
To specify "always pickup", begin the pattern string with '<'
which is NetHack's up direction symbol.
For example, to pick up all arrows, regardless of the pickup_
types setting:
autopickup_exception = "<*arrows"
This commit is contained in:
+2
-1
@@ -372,10 +372,11 @@ E char *fqn_prefix_names[PREFIX_COUNT];
|
|||||||
#ifdef AUTOPICKUP_EXCEPTIONS
|
#ifdef AUTOPICKUP_EXCEPTIONS
|
||||||
struct autopickup_exception {
|
struct autopickup_exception {
|
||||||
char *pattern;
|
char *pattern;
|
||||||
|
boolean grab;
|
||||||
struct autopickup_exception *next;
|
struct autopickup_exception *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* AUTOPICKUP_EXCEPTIONS */
|
#endif /* AUTOPICKUP_EXCEPTIONS */
|
||||||
|
|
||||||
#undef E
|
#undef E
|
||||||
|
|
||||||
#endif /* DECL_H */
|
#endif /* DECL_H */
|
||||||
|
|||||||
@@ -1513,6 +1513,7 @@ E int FDECL(loot_mon, (struct monst *,int *,boolean *));
|
|||||||
E int NDECL(dotip);
|
E int NDECL(dotip);
|
||||||
E const char *FDECL(safe_qbuf, (const char *,unsigned,
|
E const char *FDECL(safe_qbuf, (const char *,unsigned,
|
||||||
const char *,const char *,const char *));
|
const char *,const char *,const char *));
|
||||||
|
E boolean FDECL(is_autopickup_exception, (struct obj *, BOOLEAN_P));
|
||||||
|
|
||||||
/* ### pline.c ### */
|
/* ### pline.c ### */
|
||||||
|
|
||||||
|
|||||||
+19
-6
@@ -2846,8 +2846,10 @@ boolean setinitial,setfromfile;
|
|||||||
tmpwin = create_nhwindow(NHW_TEXT);
|
tmpwin = create_nhwindow(NHW_TEXT);
|
||||||
ape = iflags.autopickup_exceptions;
|
ape = iflags.autopickup_exceptions;
|
||||||
for (i = 0; i < numapes && ape; i++) {
|
for (i = 0; i < numapes && ape; i++) {
|
||||||
Sprintf(apebuf, "\"%s\"", ape->pattern);
|
Sprintf(apebuf, "\"%s\" (%s)",
|
||||||
putstr(tmpwin, 0, ape->pattern);
|
ape->pattern,
|
||||||
|
ape->grab ? "always pickup" : "never pickup");
|
||||||
|
putstr(tmpwin, 0, apebuf);
|
||||||
ape = ape->next;
|
ape = ape->next;
|
||||||
}
|
}
|
||||||
display_nhwindow(tmpwin, FALSE);
|
display_nhwindow(tmpwin, FALSE);
|
||||||
@@ -3172,18 +3174,28 @@ add_autopickup_exception_mapping(mapping)
|
|||||||
const char *mapping;
|
const char *mapping;
|
||||||
{
|
{
|
||||||
struct autopickup_exception *newape, *ape;
|
struct autopickup_exception *newape, *ape;
|
||||||
char text[256];
|
char text[256], *text2;
|
||||||
static int allocsize = 0;
|
static int allocsize = 0;
|
||||||
int textsize = 0;
|
int textsize = 0;
|
||||||
|
boolean grab = FALSE;
|
||||||
|
|
||||||
if (sscanf(mapping, "\"%255[^\"]\"", text) == 1) {
|
if (sscanf(mapping, "\"%255[^\"]\"", text) == 1) {
|
||||||
textsize = strlen(text);
|
text2 = &text[0];
|
||||||
|
if (*text2 == '<') { /* force autopickup */
|
||||||
|
grab = TRUE;
|
||||||
|
++text2;
|
||||||
|
} else if (*text2 == '>') { /* default - Do not pickup */
|
||||||
|
grab = FALSE;
|
||||||
|
++text2;
|
||||||
|
}
|
||||||
|
textsize = strlen(text2);
|
||||||
if (!iflags.autopickup_exceptions) {
|
if (!iflags.autopickup_exceptions) {
|
||||||
iflags.autopickup_exceptions = (struct autopickup_exception *)
|
iflags.autopickup_exceptions = (struct autopickup_exception *)
|
||||||
alloc(sizeof(struct autopickup_exception));
|
alloc(sizeof(struct autopickup_exception));
|
||||||
iflags.autopickup_exceptions->pattern = (char *)
|
iflags.autopickup_exceptions->pattern = (char *)
|
||||||
alloc(textsize+1);
|
alloc(textsize+1);
|
||||||
Strcpy(iflags.autopickup_exceptions->pattern, text);
|
Strcpy(iflags.autopickup_exceptions->pattern, text2);
|
||||||
|
iflags.autopickup_exceptions->grab = grab;
|
||||||
iflags.autopickup_exceptions->next =
|
iflags.autopickup_exceptions->next =
|
||||||
(struct autopickup_exception *)0;
|
(struct autopickup_exception *)0;
|
||||||
} else {
|
} else {
|
||||||
@@ -3191,7 +3203,8 @@ const char *mapping;
|
|||||||
newape = (struct autopickup_exception *)alloc(
|
newape = (struct autopickup_exception *)alloc(
|
||||||
sizeof(struct autopickup_exception));
|
sizeof(struct autopickup_exception));
|
||||||
newape->pattern = (char *)alloc(textsize+1);
|
newape->pattern = (char *)alloc(textsize+1);
|
||||||
Strcpy(newape->pattern, text);
|
Strcpy(newape->pattern, text2);
|
||||||
|
newape->grab = grab;
|
||||||
newape->next = iflags.autopickup_exceptions;
|
newape->next = iflags.autopickup_exceptions;
|
||||||
iflags.autopickup_exceptions = newape;
|
iflags.autopickup_exceptions = newape;
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-10
@@ -598,8 +598,9 @@ end_query:
|
|||||||
|
|
||||||
#ifdef AUTOPICKUP_EXCEPTIONS
|
#ifdef AUTOPICKUP_EXCEPTIONS
|
||||||
boolean
|
boolean
|
||||||
is_autopickup_exception(obj)
|
is_autopickup_exception(obj, grab)
|
||||||
struct obj *obj;
|
struct obj *obj;
|
||||||
|
boolean grab; /* forced pickup, rather than forced leave behind? */
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Does the text description of this match an exception?
|
* Does the text description of this match an exception?
|
||||||
@@ -607,7 +608,8 @@ struct obj *obj;
|
|||||||
char *objdesc = makesingular(xname(obj));
|
char *objdesc = makesingular(xname(obj));
|
||||||
struct autopickup_exception *ape = iflags.autopickup_exceptions;
|
struct autopickup_exception *ape = iflags.autopickup_exceptions;
|
||||||
while (ape) {
|
while (ape) {
|
||||||
if (pmatch(ape->pattern, objdesc)) return TRUE;
|
if (pmatch(ape->pattern, objdesc) &&
|
||||||
|
((grab && ape->grab) || (!grab && !ape->grab))) return TRUE;
|
||||||
ape = ape->next;
|
ape = ape->next;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -635,21 +637,26 @@ menu_item **pick_list; /* list of objects and counts to pick up */
|
|||||||
/* first count the number of eligible items */
|
/* first count the number of eligible items */
|
||||||
for (n = 0, curr = olist; curr; curr = FOLLOW(curr, follow))
|
for (n = 0, curr = olist; curr; curr = FOLLOW(curr, follow))
|
||||||
|
|
||||||
if ((!*otypes || index(otypes, curr->oclass))
|
|
||||||
#ifdef AUTOPICKUP_EXCEPTIONS
|
#ifndef AUTOPICKUP_EXCEPTIONS
|
||||||
&& !is_autopickup_exception(curr)
|
if (!*otypes || index(otypes, curr->oclass))
|
||||||
|
#else
|
||||||
|
if ((!*otypes || index(otypes, curr->oclass) ||
|
||||||
|
is_autopickup_exception(curr, TRUE)) &&
|
||||||
|
!is_autopickup_exception(curr, FALSE))
|
||||||
#endif
|
#endif
|
||||||
);
|
|
||||||
n++;
|
n++;
|
||||||
|
|
||||||
if (n) {
|
if (n) {
|
||||||
*pick_list = pi = (menu_item *) alloc(sizeof(menu_item) * n);
|
*pick_list = pi = (menu_item *) alloc(sizeof(menu_item) * n);
|
||||||
for (n = 0, curr = olist; curr; curr = FOLLOW(curr, follow))
|
for (n = 0, curr = olist; curr; curr = FOLLOW(curr, follow))
|
||||||
if ((!*otypes || index(otypes, curr->oclass))
|
#ifndef AUTOPICKUP_EXCEPTIONS
|
||||||
#ifdef AUTOPICKUP_EXCEPTIONS
|
if (!*otypes || index(otypes, curr->oclass)) {
|
||||||
&& !is_autopickup_exception(curr)
|
#else
|
||||||
|
if ((!*otypes || index(otypes, curr->oclass) ||
|
||||||
|
is_autopickup_exception(curr, TRUE)) &&
|
||||||
|
!is_autopickup_exception(curr, FALSE)) {
|
||||||
#endif
|
#endif
|
||||||
) {
|
|
||||||
pi[n].item.a_obj = curr;
|
pi[n].item.a_obj = curr;
|
||||||
pi[n].count = curr->quan;
|
pi[n].count = curr->quan;
|
||||||
n++;
|
n++;
|
||||||
|
|||||||
Reference in New Issue
Block a user