Skip to content

Commit

Permalink
fixup! Hide plastic babies in slices of king cake
Browse files Browse the repository at this point in the history
  • Loading branch information
entrez committed Feb 4, 2022
1 parent 99e49b1 commit a8228c8
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 14 deletions.
5 changes: 5 additions & 0 deletions include/obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*
Expand Down
6 changes: 3 additions & 3 deletions src/bones.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/eat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/mkobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/objnam.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a8228c8

Please sign in to comment.