From 22a03424dd571d66a9f6a2c30032dc105da01fe2 Mon Sep 17 00:00:00 2001 From: "nethack.rankin" Date: Tue, 22 Jul 2008 21:11:39 +0000 Subject: [PATCH] more fruitadd() (trunk only) Each time save and restore is performed, the ffruit list gets reversed. Since additions can be made when it is in backwards order or in original order depending upon whether an odd or even number of save/ restore cycles have taken place, the numeric sequence of its entries is ultimately arbitrary. So there's no point using extra code to force new ones to be added at the end of the list; just put them at the beginning. --- src/options.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/options.c b/src/options.c index e4fe0d9bc..94e872846 100644 --- a/src/options.c +++ b/src/options.c @@ -4045,7 +4045,6 @@ char *str; { register int i; register struct fruit *f; - struct fruit *lastf = 0; int highest_fruit_id = 0; char buf[PL_FSIZ], altname[PL_FSIZ]; boolean user_specified = (str == pl_fruit); @@ -4103,7 +4102,6 @@ char *str; sanitize_name(altname); } for(f=ffruit; f; f = f->nextf) { - lastf = f; if(f->fid > highest_fruit_id) highest_fruit_id = f->fid; if (!strncmp(str, f->fname, PL_FSIZ-1) || (*altname && !strcmp(altname, f->fname))) @@ -4113,13 +4111,14 @@ char *str; fruit instead... we've got a lot to choose from. current_fruit remains as is. */ if (highest_fruit_id >= 127) return rnd(127); - highest_fruit_id++; + f = newfruit(); - if (ffruit) lastf->nextf = f; - else ffruit = f; copynchars(f->fname, *altname ? altname : str, PL_FSIZ-1); - f->fid = highest_fruit_id; - f->nextf = 0; + f->fid = ++highest_fruit_id; + /* we used to go out of our way to add it at the end of the list, + but the order is arbitrary so use simpler insertion at start */ + f->nextf = ffruit; + ffruit = f; nonew: if (user_specified) context.current_fruit = f->fid; return f->fid;