diff --git a/doc/fixes36.3 b/doc/fixes36.3 index fbac27988..4d853b695 100644 --- a/doc/fixes36.3 +++ b/doc/fixes36.3 @@ -314,6 +314,7 @@ NetHack Community Patches (or Variation) Included ------------------------------------------------- add a couple of engraving suggestions in pull request #79 chasonr's faster method to write characters to msdos VGA in pull request #220 +autopickup exception priority change in pull request #226 Code Cleanup and Reorganization diff --git a/include/decl.h b/include/decl.h index e030ce454..974af0f10 100644 --- a/include/decl.h +++ b/include/decl.h @@ -418,6 +418,7 @@ struct autopickup_exception { boolean grab; struct autopickup_exception *next; }; +E struct autopickup_exception *apelist; struct plinemsg_type { xchar msgtype; /* one of MSGTYP_foo */ diff --git a/include/flag.h b/include/flag.h index 090f6e1b0..8fe94339b 100644 --- a/include/flag.h +++ b/include/flag.h @@ -423,7 +423,6 @@ struct instance_flags { int wc2_statuslines; /* default = 2, curses can handle 3 */ int wc2_windowborders; /* display borders on NetHack windows */ int wc2_petattr; /* text attributes for pet */ - struct autopickup_exception *autopickup_exceptions; #ifdef WIN32 #define MAX_ALTKEYHANDLER 25 char altkeyhandler[MAX_ALTKEYHANDLER]; diff --git a/src/cmd.c b/src/cmd.c index a9b17bd86..e6c4049b1 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -2139,7 +2139,7 @@ int final; *ocl ? "'" : "", *ocl ? ocl : "all types", *ocl ? "'" : ""); if (flags.pickup_thrown && *ocl) /* *ocl: don't show if 'all types' */ Strcat(buf, " plus thrown"); - if (iflags.autopickup_exceptions) + if (apelist) Strcat(buf, ", with exceptions"); } else Strcpy(buf, "off"); diff --git a/src/decl.c b/src/decl.c index f81271b52..c6e6c6039 100644 --- a/src/decl.c +++ b/src/decl.c @@ -213,6 +213,8 @@ char preferred_pet; /* '\0', 'c', 'd', 'n' (none) */ NEARDATA struct monst *mydogs = (struct monst *) 0; /* monsters that are moving to another dungeon level */ NEARDATA struct monst *migrating_mons = (struct monst *) 0; +NEARDATA struct autopickup_exception *apelist = + (struct autopickup_exception *)0; NEARDATA struct mvitals mvitals[NUMMONS]; NEARDATA long domove_attempting = 0L; diff --git a/src/options.c b/src/options.c index 836e86d7a..bddc35102 100644 --- a/src/options.c +++ b/src/options.c @@ -4414,7 +4414,7 @@ int count_apes(VOID_ARGS) { int numapes = 0; - struct autopickup_exception *ape = iflags.autopickup_exceptions; + struct autopickup_exception *ape = apelist; while (ape) { numapes++; @@ -5327,7 +5327,7 @@ boolean setinitial, setfromfile; start_menu(tmpwin); if (numapes) { ape = (struct autopickup_exception *) - iflags.autopickup_exceptions; + apelist; any = zeroany; add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, "Always pickup '<'; never pickup '>'", @@ -5897,7 +5897,7 @@ dotogglepickup() if (flags.pickup) { oc_to_str(flags.pickup_types, ocl); Sprintf(buf, "ON, for %s objects%s", ocl[0] ? ocl : "all", - (iflags.autopickup_exceptions) + (apelist) ? ((count_apes() == 1) ? ", with one exception" : ", with some exceptions") @@ -5952,8 +5952,8 @@ const char *mapping; ape->pattern = dupstr(text); ape->grab = grab; - ape->next = (struct autopickup_exception *) iflags.autopickup_exceptions; - iflags.autopickup_exceptions = (struct autopickup_exception *) ape; + ape->next = (struct autopickup_exception *) apelist; + apelist = (struct autopickup_exception *) ape; return 1; } @@ -5963,14 +5963,14 @@ struct autopickup_exception *whichape; { struct autopickup_exception *ape, *freeape, *prev = 0; - for (ape = iflags.autopickup_exceptions; ape;) { + for (ape = apelist; ape;) { if (ape == whichape) { freeape = ape; ape = ape->next; if (prev) prev->next = ape; else - iflags.autopickup_exceptions = ape; + apelist = ape; regex_free(freeape->regex); free((genericptr_t) freeape->pattern); free((genericptr_t) freeape); @@ -5984,11 +5984,11 @@ struct autopickup_exception *whichape; void free_autopickup_exceptions() { - struct autopickup_exception *ape = iflags.autopickup_exceptions; - while ((ape = iflags.autopickup_exceptions) != 0) { + struct autopickup_exception *ape = apelist; + while ((ape = apelist) != 0) { regex_free(ape->regex); free((genericptr_t) ape->pattern); - iflags.autopickup_exceptions = ape->next; + apelist = ape->next; free((genericptr_t) ape); } } diff --git a/src/pickup.c b/src/pickup.c index c0ef2b0cf..ab8d5f069 100644 --- a/src/pickup.c +++ b/src/pickup.c @@ -718,11 +718,13 @@ struct obj *obj; /* * Does the text description of this match an exception? */ - struct autopickup_exception - *ape = iflags.autopickup_exceptions; + struct autopickup_exception *ape = apelist; + if (ape) { char *objdesc = makesingular(doname(obj)); - while (ape && !regex_match(objdesc, ape->regex)) ape = ape->next; + + while (ape && !regex_match(objdesc, ape->regex)) + ape = ape->next; } return ape; } @@ -732,6 +734,7 @@ autopick_testobj(otmp, calc_costly) struct obj *otmp; boolean calc_costly; { + struct autopickup_exception *ape; static boolean costly = FALSE; const char *otypes = flags.pickup_types; boolean pickit; @@ -748,9 +751,8 @@ boolean calc_costly; /* check for pickup_types */ pickit = (!*otypes || index(otypes, otmp->oclass)); - /* check for autopickup excpetions */ - struct autopickup_exception - *ape = check_autopickup_exceptions(otmp); + /* check for autopickup exceptions */ + ape = check_autopickup_exceptions(otmp); if (ape) pickit = ape->grab;