Skip to content

Commit

Permalink
Hide plastic babies in slices of king cake
Browse files Browse the repository at this point in the history
Sometimes the hero will find a plastic baby inside a piece of king cake,
just like in real life.

In order to make this apply to 'real' king cake created during Mardi
Gras, and not to user-defined fruit with an identical name, change
holiday fruits to use a negative fruit ID as their spe. Update
fruit_from_indx to use abs() when comparing fruit IDs to enable this.

Negative fruit IDs are already used when saving bones, to mark fruits
which don't exist on the current level and therefore don't need to be
included in the bones file, but those are negative fids in the g.ffruit
linked list, not negative spe on individual items.  These changes
shouldn't interfere with that process as long as the possible negative
spe is taken into consideration when saving and loading bones, which it
now should be.
  • Loading branch information
entrez committed Jan 19, 2022
1 parent 98e210f commit b45a3bb
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/bones.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ no_bones_level(d_level *lev)
static void
goodfruit(int id)
{
struct fruit *f = fruit_from_indx(-id);
struct fruit *f = fruit_from_indx(id);

if (f)
f->fid = id;
f->fid = abs(id);
}

static void
Expand Down
28 changes: 28 additions & 0 deletions src/eat.c
Original file line number Diff line number Diff line change
Expand Up @@ -2350,6 +2350,34 @@ fpostfx(struct obj *otmp)
if (!u.uconduct.literate++)
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 (!rn2(30) && f && !strcmp("slice of king cake", f->fname)) {
const int babies[] = {
PM_BABY_CROCODILE,
PM_BABY_LONG_WORM,
PM_BABY_PURPLE_WORM,
PM_BABY_GRAY_DRAGON,
PM_BABY_GOLD_DRAGON,
PM_BABY_SILVER_DRAGON,
PM_BABY_RED_DRAGON,
PM_BABY_WHITE_DRAGON,
PM_BABY_ORANGE_DRAGON,
PM_BABY_BLACK_DRAGON,
PM_BABY_BLUE_DRAGON,
PM_BABY_GREEN_DRAGON,
PM_BABY_YELLOW_DRAGON,
};
struct obj *feve = mksobj(FIGURINE, TRUE, FALSE);
set_corpsenm(feve, babies[rn2(SIZE(babies))]);
set_material(feve, PLASTIC);
There("is a plastic baby inside the slice of king cake!");
hold_another_object(feve, "It falls to the floor.",
(const char *) 0, (const char *) 0);
}
}
break;
case LUMP_OF_ROYAL_JELLY: {
/* This stuff seems to be VERY healthy! */
gainstr(otmp, 1, TRUE); /* will -1 if cursed */
Expand Down
2 changes: 1 addition & 1 deletion src/mkobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ mksobj(int otyp, boolean init, boolean artif)
/* fruitadd requires a modifiable string */
char foodbuf[BUFSZ];
Strcpy(foodbuf, foods[rn2(idx)]);
otmp->spe = fruitadd(foodbuf, NULL);
otmp->spe = -fruitadd(foodbuf, NULL);
}
}
flags.made_fruit = TRUE;
Expand Down
7 changes: 6 additions & 1 deletion src/objnam.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,13 @@ 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 (f->fid == indx)
if (abs(f->fid) == indx)
break;
return f;
}
Expand Down
11 changes: 8 additions & 3 deletions src/restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,13 +508,18 @@ ghostfruit(register struct obj* otmp)
register struct fruit *oldf;

for (oldf = g.oldfruit; oldf; oldf = oldf->nextf)
if (oldf->fid == otmp->spe)
if (oldf->fid == abs(otmp->spe))
break;

if (!oldf)
if (!oldf) {
impossible("no old fruit?");
else
} else {
boolean holiday_food = (otmp->spe < 0);
otmp->spe = fruitadd(oldf->fname, (struct fruit *) 0);
if (holiday_food) {
otmp->spe = -(otmp->spe);
}
}
}

#ifdef SYSCF
Expand Down

0 comments on commit b45a3bb

Please sign in to comment.