From a8228c845e999bc91db30029ba18eba6f5a243b7 Mon Sep 17 00:00:00 2001 From: Michael Meyer Date: Fri, 4 Feb 2022 16:27:16 -0500 Subject: [PATCH] fixup! Hide plastic babies in slices of king cake --- include/obj.h | 5 +++++ src/bones.c | 6 +++--- src/eat.c | 4 ++-- src/mkobj.c | 1 + src/objnam.c | 7 +------ src/options.c | 2 +- src/restore.c | 4 ++-- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/obj.h b/include/obj.h index 9c98f6f79..ccd4c403b 100644 --- a/include/obj.h +++ b/include/obj.h @@ -460,6 +460,11 @@ struct obj { #define thiefstone_ledger_valid(stone) \ ((stone)->keyed_ledger > 0 && (stone)->keyed_ledger <= maxledgerno()) +/* special holiday fruits are differentiated from user-defined fruits by + * negative spe */ +#define is_holiday_fruit(obj) ((obj)->otyp == SLIME_MOLD && (obj)->spe < 0) +#define fruit_id(obj) (abs((obj)->spe)) + /* * Notes for adding new oextra structures: * diff --git a/src/bones.c b/src/bones.c index 82161fa13..b2d2ebafd 100644 --- a/src/bones.c +++ b/src/bones.c @@ -41,7 +41,7 @@ goodfruit(int id) struct fruit *f = fruit_from_indx(id); if (f) - f->fid = abs(id); + f->fid = id; } static void @@ -137,7 +137,7 @@ resetobjs(struct obj *ochain, boolean restore) } if (otmp->otyp == SLIME_MOLD) { - goodfruit(otmp->spe); + goodfruit(fruit_id(otmp)); #ifdef MAIL_STRUCTURES } else if (otmp->otyp == SCR_MAIL) { /* 0: delivered in-game via external event; @@ -318,7 +318,7 @@ drop_upon_death(struct monst *mtmp, /* monster if hero turned into one (other th otmp->owt = weight(otmp); if (otmp->otyp == SLIME_MOLD) - goodfruit(otmp->spe); + goodfruit(fruit_id(otmp)); if (rn2(5)) curse(otmp); diff --git a/src/eat.c b/src/eat.c index 346acf94a..be3e75a4f 100644 --- a/src/eat.c +++ b/src/eat.c @@ -2351,8 +2351,8 @@ fpostfx(struct obj *otmp) livelog_write_string(LL_CONDUCT, "became literate by reading the fortune inside a cookie"); break; case SLIME_MOLD: - if (otmp->spe < 0) { /* holiday food, not user-defined fruitname */ - struct fruit *f = fruit_from_indx(otmp->spe); + if (is_holiday_fruit(otmp)) { + struct fruit *f = fruit_from_indx(fruit_id(otmp)); if (!rn2(15) && f && !strcmp("slice of king cake", f->fname)) { const int babies[] = { PM_BABY_CROCODILE, diff --git a/src/mkobj.c b/src/mkobj.c index 9532671d6..5b6668c24 100644 --- a/src/mkobj.c +++ b/src/mkobj.c @@ -946,6 +946,7 @@ mksobj(int otyp, boolean init, boolean artif) /* fruitadd requires a modifiable string */ char foodbuf[BUFSZ]; Strcpy(foodbuf, foods[rn2(idx)]); + /* holiday fruits have negative spe */ otmp->spe = -fruitadd(foodbuf, NULL); } } diff --git a/src/objnam.c b/src/objnam.c index 10d790f4d..129d7318c 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -302,11 +302,6 @@ fruit_from_indx(int indx) { struct fruit *f; - /* Negative spe is used to distinguish between user-defined fruits - and those created as holiday food; a negative fid in the g.ffruit - list is used when saving bones. */ - indx = abs(indx); - for (f = g.ffruit; f; f = f->nextf) if (abs(f->fid) == indx) break; @@ -598,7 +593,7 @@ xname_flags( break; case FOOD_CLASS: if (typ == SLIME_MOLD) { - struct fruit *f = fruit_from_indx(obj->spe); + struct fruit *f = fruit_from_indx(fruit_id(obj)); if (!f) { impossible("Bad fruit #%d?", obj->spe); diff --git a/src/options.c b/src/options.c index 90086b358..a0becfec3 100644 --- a/src/options.c +++ b/src/options.c @@ -6885,7 +6885,7 @@ fruitadd(char *str, struct fruit *replace_fruit) char buf[PL_FSIZ], altname[PL_FSIZ]; boolean user_specified = (str == g.pl_fruit); /* if not user-specified, then it's a fruit name for a fruit on - * a bones level or from orctown raider's loot... + * a bones level, a holiday food, or from orctown raider's loot... */ /* Note: every fruit has an id (kept in obj->spe) of at least 1; diff --git a/src/restore.c b/src/restore.c index 52122a436..8dae52b66 100644 --- a/src/restore.c +++ b/src/restore.c @@ -508,13 +508,13 @@ ghostfruit(register struct obj* otmp) register struct fruit *oldf; for (oldf = g.oldfruit; oldf; oldf = oldf->nextf) - if (oldf->fid == abs(otmp->spe)) + if (oldf->fid == fruit_id(otmp)) break; if (!oldf) { impossible("no old fruit?"); } else { - boolean holiday_food = (otmp->spe < 0); + boolean holiday_food = is_holiday_fruit(otmp); otmp->spe = fruitadd(oldf->fname, (struct fruit *) 0); if (holiday_food) { otmp->spe = -(otmp->spe);