Skip to content

Commit b45a3bb

Browse files
committed
Hide plastic babies in slices of king cake
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.
1 parent 98e210f commit b45a3bb

File tree

5 files changed

+45
-7
lines changed

5 files changed

+45
-7
lines changed

src/bones.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ no_bones_level(d_level *lev)
3838
static void
3939
goodfruit(int id)
4040
{
41-
struct fruit *f = fruit_from_indx(-id);
41+
struct fruit *f = fruit_from_indx(id);
4242

4343
if (f)
44-
f->fid = id;
44+
f->fid = abs(id);
4545
}
4646

4747
static void

src/eat.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,6 +2350,34 @@ fpostfx(struct obj *otmp)
23502350
if (!u.uconduct.literate++)
23512351
livelog_write_string(LL_CONDUCT, "became literate by reading the fortune inside a cookie");
23522352
break;
2353+
case SLIME_MOLD:
2354+
if (otmp->spe < 0) { /* holiday food, not user-defined fruitname */
2355+
struct fruit *f = fruit_from_indx(otmp->spe);
2356+
if (!rn2(30) && f && !strcmp("slice of king cake", f->fname)) {
2357+
const int babies[] = {
2358+
PM_BABY_CROCODILE,
2359+
PM_BABY_LONG_WORM,
2360+
PM_BABY_PURPLE_WORM,
2361+
PM_BABY_GRAY_DRAGON,
2362+
PM_BABY_GOLD_DRAGON,
2363+
PM_BABY_SILVER_DRAGON,
2364+
PM_BABY_RED_DRAGON,
2365+
PM_BABY_WHITE_DRAGON,
2366+
PM_BABY_ORANGE_DRAGON,
2367+
PM_BABY_BLACK_DRAGON,
2368+
PM_BABY_BLUE_DRAGON,
2369+
PM_BABY_GREEN_DRAGON,
2370+
PM_BABY_YELLOW_DRAGON,
2371+
};
2372+
struct obj *feve = mksobj(FIGURINE, TRUE, FALSE);
2373+
set_corpsenm(feve, babies[rn2(SIZE(babies))]);
2374+
set_material(feve, PLASTIC);
2375+
There("is a plastic baby inside the slice of king cake!");
2376+
hold_another_object(feve, "It falls to the floor.",
2377+
(const char *) 0, (const char *) 0);
2378+
}
2379+
}
2380+
break;
23532381
case LUMP_OF_ROYAL_JELLY: {
23542382
/* This stuff seems to be VERY healthy! */
23552383
gainstr(otmp, 1, TRUE); /* will -1 if cursed */

src/mkobj.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ mksobj(int otyp, boolean init, boolean artif)
946946
/* fruitadd requires a modifiable string */
947947
char foodbuf[BUFSZ];
948948
Strcpy(foodbuf, foods[rn2(idx)]);
949-
otmp->spe = fruitadd(foodbuf, NULL);
949+
otmp->spe = -fruitadd(foodbuf, NULL);
950950
}
951951
}
952952
flags.made_fruit = TRUE;

src/objnam.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,13 @@ fruit_from_indx(int indx)
302302
{
303303
struct fruit *f;
304304

305+
/* Negative spe is used to distinguish between user-defined fruits
306+
and those created as holiday food; a negative fid in the g.ffruit
307+
list is used when saving bones. */
308+
indx = abs(indx);
309+
305310
for (f = g.ffruit; f; f = f->nextf)
306-
if (f->fid == indx)
311+
if (abs(f->fid) == indx)
307312
break;
308313
return f;
309314
}

src/restore.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,13 +508,18 @@ ghostfruit(register struct obj* otmp)
508508
register struct fruit *oldf;
509509

510510
for (oldf = g.oldfruit; oldf; oldf = oldf->nextf)
511-
if (oldf->fid == otmp->spe)
511+
if (oldf->fid == abs(otmp->spe))
512512
break;
513513

514-
if (!oldf)
514+
if (!oldf) {
515515
impossible("no old fruit?");
516-
else
516+
} else {
517+
boolean holiday_food = (otmp->spe < 0);
517518
otmp->spe = fruitadd(oldf->fname, (struct fruit *) 0);
519+
if (holiday_food) {
520+
otmp->spe = -(otmp->spe);
521+
}
522+
}
518523
}
519524

520525
#ifdef SYSCF

0 commit comments

Comments
 (0)