]> granicus.if.org Git - nethack/commitdiff
I haven't been active in the past decade, but here's a small patch. Main
authorarromdee <arromdee>
Sun, 11 Dec 2011 18:11:29 +0000 (18:11 +0000)
committerarromdee <arromdee>
Sun, 11 Dec 2011 18:11:29 +0000 (18:11 +0000)
branch only.  This adds a check when setting a new fruit so that if no fruits
have been created since the last time the option has been set, the current
fruit is overwritten.  Result: the user cannot repeatedly set the fruit
option and overflow the maximum fruit number.

include/extern.h
include/flag.h
src/cmd.c
src/mkobj.c
src/options.c
src/restore.c

index b8173a5cca46314642d7c3ad75fa2a2a695e3a86..d58d1831486a85a87757f5f9b930f535a247c07a 100644 (file)
@@ -1610,7 +1610,7 @@ E int NDECL(doset);
 E int NDECL(dotogglepickup);
 E void NDECL(option_help);
 E void FDECL(next_opt, (winid,const char *));
-E int FDECL(fruitadd, (char *));
+E int FDECL(fruitadd, (char *,struct fruit *));
 E int FDECL(choose_classes_menu, (const char *,int,BOOLEAN_P,char *,char *));
 E void FDECL(add_menu_cmd_alias, (CHAR_P, CHAR_P));
 E char FDECL(map_menu_cmd, (CHAR_P));
index a4e53408d0e769ba010713c9035a7307f871c0c4..dc26b5bf3f9773e17e0a2272b97004259910fbe3 100644 (file)
@@ -76,6 +76,7 @@ struct flag {
        char     end_disclose[NUM_DISCLOSURE_OPTIONS + 1];  /* disclose various info
                                                                upon exit */
        char     menu_style;    /* User interface style setting */
+       boolean  made_fruit; /* don't easily let the user overflow the number of fruits */
 
        /* KMH, role patch -- Variables used during startup.
         *
index 67193ff787fc3a101bdf05e953618401c3b3a21d..312cd7ac3cc04e0ee87b68482b7bacf57efa0c0b 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -2053,6 +2053,20 @@ int final;
            if (wizard) Sprintf(eos(buf), " (%d)", u.ublesscnt);
 #endif
            you_can(buf,"");
+           if (wizard) {
+               int fcount = 0;
+               struct fruit *f;
+               char buf2[BUFSZ];
+               for(f=ffruit; f; f = f->nextf)
+               {
+                   Sprintf(buf, "Fruit %d ", ++fcount);
+                   Sprintf(buf2, "%s (id %d)", f->fname, f->fid);
+                   enl_msg(buf, "is ", "was ", buf2, "");
+               }
+               enl_msg("The current fruit ", "is ", "was ", pl_fruit, "");
+               Sprintf(buf, "%d", flags.made_fruit);
+               enl_msg("The made fruit flag ", "is ", "was ", buf, "");
+           }
        }
 
     {
index 4fba48b591c002791bb39a4d1f8a84ef4cba325e..c470809d7336e1cd84eafc787c0abd887a6e1f71 100644 (file)
@@ -680,6 +680,7 @@ boolean artif;
                break;
            case SLIME_MOLD:
                otmp->spe = context.current_fruit;
+               flags.made_fruit = TRUE;
                break;
            case KELP_FROND:
                otmp->quan = (long) rnd(2);
index ba3f67113ae5cafa88da92dc7973fcdc7d690a72..d806fa1d71645071084a6ecf4a14aecd4744978b 100644 (file)
@@ -721,7 +721,7 @@ initoptions_finish()
 #endif
                read_config_file((char *)0, SET_IN_FILE);
 
-       (void)fruitadd(pl_fruit);
+       (void)fruitadd(pl_fruit, (struct fruit *)0);
        /* Remove "slime mold" from list of object names; this will     */
        /* prevent it from being wished unless it's actually present    */
        /* as a named (or default) fruit.  Wishing for "fruit" will     */
@@ -1673,6 +1673,8 @@ boolean tinitial, tfrom_file;
 #endif /* CHANGE_COLOR */
 
        if (match_optname(opts, "fruit", 2, TRUE)) {
+               struct fruit *forig = 0;
+
                char empty_str = '\0';
                if (duplicate) complain_about_duplicate(opts,1);
                op = string_for_opt(opts, negated);
@@ -1690,13 +1692,22 @@ boolean tinitial, tfrom_file;
 
                    num = 0;
                    for(f=ffruit; f; f=f->nextf) {
-                       if (!strcmp(op, f->fname)) goto goodfruit;
+                       if (!strcmp(op, f->fname))
+                           break;
                        num++;
                    }
                    if (num >= 100) {
                        pline("Doing that so many times isn't very fruitful.");
                        return;
                    }
+                   if (!flags.made_fruit) {
+                       for(forig=ffruit; forig; forig=forig->nextf) {
+                           if (!strcmp(pl_fruit, forig->fname)) {
+                               break;
+                           }
+                       }
+                       
+                   }
                }
 goodfruit:
                nmcpy(pl_fruit, op, PL_FSIZ);
@@ -1704,7 +1715,7 @@ goodfruit:
                if (!*pl_fruit)
                    nmcpy(pl_fruit, "slime mold", PL_FSIZ);
                if (!initial) {
-                   (void)fruitadd(pl_fruit);
+                   (void)fruitadd(pl_fruit, forig);
                    pline("Fruit is now \"%s\".", pl_fruit);
                }
                /* If initial, then initoptions is allowed to do it instead
@@ -4218,10 +4229,13 @@ const char *str;
 /* Returns the fid of the fruit type; if that type already exists, it
  * returns the fid of that one; if it does not exist, it adds a new fruit
  * type to the chain and returns the new one.
+ * If replace_fruit is sent in, replace the fruit in the chain rather than
+ * adding a new entry--for user specified fruits only.
  */
 int
-fruitadd(str)
+fruitadd(str, replace_fruit)
 char *str;
+struct fruit *replace_fruit;
 {
        register int i;
        register struct fruit *f;
@@ -4282,10 +4296,27 @@ char *str;
                                nmcpy(pl_fruit+8, buf, PL_FSIZ-8);
                }
                *altname = '\0';
+               /* This flag indicates that a fruit has been made since the
+                * last time the user set the fruit.  If it hasn't, we can
+                * safely overwrite the current fruit, preventing the user from
+                * setting many fruits in a row and overflowing.
+                * Possible expansion: check for specific fruit IDs, not for
+                * any fruit.
+                */
+               flags.made_fruit = FALSE;
+               if (replace_fruit) {
+                   for(f=ffruit; f; f = f->nextf) {
+                       if (f == replace_fruit) {
+                           copynchars(f->fname, str, PL_FSIZ-1);
+                           goto nonew;
+                       }
+                   }
+               }
        } else {
                /* not user_supplied, so assumed to be from bones */
                copynchars(altname, str, PL_FSIZ-1);
                sanitize_name(altname);
+               flags.made_fruit = TRUE; /* for safety.  Any fruit name added from a bones level should exist anyway. */
        }
        for(f=ffruit; f; f = f->nextf) {
                if(f->fid > highest_fruit_id) highest_fruit_id = f->fid;
index 4d5136f7a1d92a074bf02429e12f18de8fce9fb1..ef7e192dc1c05a0608398169b62578bd68eda4a7 100644 (file)
@@ -508,7 +508,7 @@ register struct obj *otmp;
                if (oldf->fid == otmp->spe) break;
 
        if (!oldf) impossible("no old fruit?");
-       else otmp->spe = fruitadd(oldf->fname);
+       else otmp->spe = fruitadd(oldf->fname, (struct fruit *)0);
 }
 
 STATIC_OVL