OSDN Git Service

patch src/
[jnethack/source.git] / src / bones.c
1 /* NetHack 3.6  bones.c $NHDT-Date: 1449269914 2015/12/04 22:58:34 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.66 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985,1993. */
3 /* NetHack may be freely redistributed.  See license for details. */
4
5 #include "hack.h"
6 #include "lev.h"
7
8 extern char bones[]; /* from files.c */
9 #ifdef MFLOPPY
10 extern long bytes_counted;
11 #endif
12
13 STATIC_DCL boolean FDECL(no_bones_level, (d_level *));
14 STATIC_DCL void FDECL(goodfruit, (int));
15 STATIC_DCL void FDECL(resetobjs, (struct obj *, BOOLEAN_P));
16 STATIC_DCL boolean FDECL(fixuporacle, (struct monst *));
17
18 STATIC_OVL boolean
19 no_bones_level(lev)
20 d_level *lev;
21 {
22     extern d_level save_dlevel; /* in do.c */
23     s_level *sptr;
24
25     if (ledger_no(&save_dlevel))
26         assign_level(lev, &save_dlevel);
27
28     return (boolean) (((sptr = Is_special(lev)) != 0 && !sptr->boneid)
29                       || !dungeons[lev->dnum].boneid
30                       /* no bones on the last or multiway branch levels
31                          in any dungeon (level 1 isn't multiway) */
32                       || Is_botlevel(lev)
33                       || (Is_branchlev(lev) && lev->dlevel > 1)
34                       /* no bones in the invocation level */
35                       || (In_hell(lev)
36                           && lev->dlevel == dunlevs_in_dungeon(lev) - 1));
37 }
38
39 /* Call this function for each fruit object saved in the bones level: it marks
40  * that particular type of fruit as existing (the marker is that that type's
41  * ID is positive instead of negative).  This way, when we later save the
42  * chain of fruit types, we know to only save the types that exist.
43  */
44 STATIC_OVL void
45 goodfruit(id)
46 int id;
47 {
48     register struct fruit *f;
49
50     for (f = ffruit; f; f = f->nextf) {
51         if (f->fid == -id) {
52             f->fid = id;
53             return;
54         }
55     }
56 }
57
58 STATIC_OVL void
59 resetobjs(ochain, restore)
60 struct obj *ochain;
61 boolean restore;
62 {
63     struct obj *otmp, *nobj;
64
65     for (otmp = ochain; otmp; otmp = nobj) {
66         nobj = otmp->nobj;
67         if (otmp->cobj)
68             resetobjs(otmp->cobj, restore);
69         if (otmp->in_use) {
70             obj_extract_self(otmp);
71             dealloc_obj(otmp);
72             continue;
73         }
74
75         if (restore) {
76             /* artifact bookkeeping needs to be done during
77                restore; other fixups are done while saving */
78             if (otmp->oartifact) {
79                 if (exist_artifact(otmp->otyp, safe_oname(otmp))
80                     || is_quest_artifact(otmp)) {
81                     /* prevent duplicate--revert to ordinary obj */
82                     otmp->oartifact = 0;
83                     if (has_oname(otmp))
84                         free_oname(otmp);
85                 } else {
86                     artifact_exists(otmp, safe_oname(otmp), TRUE);
87                 }
88             } else if (has_oname(otmp)) {
89                 sanitize_name(ONAME(otmp));
90             }
91         } else { /* saving */
92             /* do not zero out o_ids for ghost levels anymore */
93
94             if (objects[otmp->otyp].oc_uses_known)
95                 otmp->known = 0;
96             otmp->dknown = otmp->bknown = 0;
97             otmp->rknown = 0;
98             otmp->lknown = 0;
99             otmp->cknown = 0;
100             otmp->invlet = 0;
101             otmp->no_charge = 0;
102             otmp->was_thrown = 0;
103
104             /* strip user-supplied names */
105             /* Statue and some corpse names are left intact,
106                presumably in case they came from score file.
107                [TODO: this ought to be done differently--names
108                which came from such a source or came from any
109                stoned or killed monster should be flagged in
110                some manner; then we could just check the flag
111                here and keep "real" names (dead pets, &c) while
112                discarding player notes attached to statues.] */
113             if (has_oname(otmp)
114                 && !(otmp->oartifact || otmp->otyp == STATUE
115                      || otmp->otyp == SPE_NOVEL
116                      || (otmp->otyp == CORPSE
117                          && otmp->corpsenm >= SPECIAL_PM))) {
118                 free_oname(otmp);
119             }
120
121             if (otmp->otyp == SLIME_MOLD)
122                 goodfruit(otmp->spe);
123 #ifdef MAIL
124             else if (otmp->otyp == SCR_MAIL)
125                 otmp->spe = 1;
126 #endif
127             else if (otmp->otyp == EGG)
128                 otmp->spe = 0;
129             else if (otmp->otyp == TIN) {
130                 /* make tins of unique monster's meat be empty */
131                 if (otmp->corpsenm >= LOW_PM
132                     && unique_corpstat(&mons[otmp->corpsenm]))
133                     otmp->corpsenm = NON_PM;
134             } else if (otmp->otyp == CORPSE || otmp->otyp == STATUE) {
135                 int mnum = otmp->corpsenm;
136
137                 /* Discard incarnation details of unique
138                    monsters (by passing null instead of otmp
139                    for object), shopkeepers (by passing false
140                    for revival flag), temple priests, and
141                    vault guards in order to prevent corpse
142                    revival or statue reanimation. */
143                 if (has_omonst(otmp)
144                     && cant_revive(&mnum, FALSE, (struct obj *) 0)) {
145                     free_omonst(otmp);
146                     /* mnum is now either human_zombie or
147                        doppelganger; for corpses of uniques,
148                        we need to force the transformation
149                        now rather than wait until a revival
150                        attempt, otherwise eating this corpse
151                        would behave as if it remains unique */
152                     if (mnum == PM_DOPPELGANGER && otmp->otyp == CORPSE)
153                         set_corpsenm(otmp, mnum);
154                 }
155             } else if (otmp->otyp == AMULET_OF_YENDOR) {
156                 /* no longer the real Amulet */
157                 otmp->otyp = FAKE_AMULET_OF_YENDOR;
158                 curse(otmp);
159             } else if (otmp->otyp == CANDELABRUM_OF_INVOCATION) {
160                 if (otmp->lamplit)
161                     end_burn(otmp, TRUE);
162                 otmp->otyp = WAX_CANDLE;
163                 otmp->age = 50L; /* assume used */
164                 if (otmp->spe > 0)
165                     otmp->quan = (long) otmp->spe;
166                 otmp->spe = 0;
167                 otmp->owt = weight(otmp);
168                 curse(otmp);
169             } else if (otmp->otyp == BELL_OF_OPENING) {
170                 otmp->otyp = BELL;
171                 curse(otmp);
172             } else if (otmp->otyp == SPE_BOOK_OF_THE_DEAD) {
173                 otmp->otyp = SPE_BLANK_PAPER;
174                 curse(otmp);
175             }
176         }
177     }
178 }
179
180 /* while loading bones, strip out text possibly supplied by old player
181    that might accidentally or maliciously disrupt new player's display */
182 void
183 sanitize_name(namebuf)
184 char *namebuf;
185 {
186     int c;
187     boolean strip_8th_bit =
188         !strcmp(windowprocs.name, "tty") && !iflags.wc_eight_bit_input;
189
190     /* it's tempting to skip this for single-user platforms, since
191        only the current player could have left these bones--except
192        things like "hearse" and other bones exchange schemes make
193        that assumption false */
194     while (*namebuf) {
195         c = *namebuf & 0177;
196         if (c < ' ' || c == '\177') {
197             /* non-printable or undesirable */
198             *namebuf = '.';
199         } else if (c != *namebuf) {
200             /* expected to be printable if user wants such things */
201             if (strip_8th_bit)
202                 *namebuf = '_';
203         }
204         ++namebuf;
205     }
206 }
207
208 /* called by savebones(); also by finish_paybill(shk.c) */
209 void
210 drop_upon_death(mtmp, cont, x, y)
211 struct monst *mtmp;
212 struct obj *cont;
213 int x, y;
214 {
215     struct obj *otmp;
216
217     u.twoweap = 0; /* ensure curse() won't cause swapwep to drop twice */
218     while ((otmp = invent) != 0) {
219         obj_extract_self(otmp);
220         obj_no_longer_held(otmp);
221
222         otmp->owornmask = 0;
223         /* lamps don't go out when dropped */
224         if ((cont || artifact_light(otmp)) && obj_is_burning(otmp))
225             end_burn(otmp, TRUE); /* smother in statue */
226
227         if (otmp->otyp == SLIME_MOLD)
228             goodfruit(otmp->spe);
229
230         if (rn2(5))
231             curse(otmp);
232         if (mtmp)
233             (void) add_to_minv(mtmp, otmp);
234         else if (cont)
235             (void) add_to_container(cont, otmp);
236         else
237             place_object(otmp, x, y);
238     }
239     if (cont)
240         cont->owt = weight(cont);
241 }
242
243 /* possibly restore oracle's room and/or put her back inside it; returns
244    False if she's on the wrong level and should be removed, True otherwise */
245 STATIC_OVL boolean
246 fixuporacle(oracle)
247 struct monst *oracle;
248 {
249     coord cc;
250     int ridx, o_ridx;
251
252     /* oracle doesn't move, but knight's joust or monk's staggering blow
253        could push her onto a hole in the floor; at present, traps don't
254        activate in such situation hence she won't fall to another level;
255        however, that could change so be prepared to cope with such things */
256     if (!Is_oracle_level(&u.uz))
257         return FALSE;
258
259     oracle->mpeaceful = 1;
260     o_ridx = levl[oracle->mx][oracle->my].roomno - ROOMOFFSET;
261     if (o_ridx >= 0 && rooms[o_ridx].rtype == DELPHI)
262         return TRUE; /* no fixup needed */
263
264     /*
265      * The Oracle isn't in DELPHI room.  Either hero entered her chamber
266      * and got the one-time welcome message, converting it into an
267      * ordinary room, or she got teleported out, or both.  Try to put
268      * her back inside her room, if necessary, and restore its type.
269      */
270
271     /* find original delphi chamber; should always succeed */
272     for (ridx = 0; ridx < SIZE(rooms); ++ridx)
273         if (rooms[ridx].orig_rtype == DELPHI)
274             break;
275
276     if (o_ridx != ridx && ridx < SIZE(rooms)) {
277         /* room found and she's not not in it, so try to move her there */
278         cc.x = (rooms[ridx].lx + rooms[ridx].hx) / 2;
279         cc.y = (rooms[ridx].ly + rooms[ridx].hy) / 2;
280         if (enexto(&cc, cc.x, cc.y, oracle->data)) {
281             rloc_to(oracle, cc.x, cc.y);
282             o_ridx = levl[oracle->mx][oracle->my].roomno - ROOMOFFSET;
283         }
284         /* [if her room is already full, she might end up outside;
285            that's ok, next hero just won't get any welcome message,
286            same as used to happen before this fixup was introduced] */
287     }
288     if (ridx == o_ridx) /* if she's in her room, mark it as such */
289         rooms[ridx].rtype = DELPHI;
290     return TRUE; /* keep oracle in new bones file */
291 }
292
293 /* check whether bones are feasible */
294 boolean
295 can_make_bones()
296 {
297     register struct trap *ttmp;
298
299     if (!flags.bones)
300         return FALSE;
301     if (ledger_no(&u.uz) <= 0 || ledger_no(&u.uz) > maxledgerno())
302         return FALSE;
303     if (no_bones_level(&u.uz))
304         return FALSE; /* no bones for specific levels */
305     if (u.uswallow) {
306         return FALSE; /* no bones when swallowed */
307     }
308     if (!Is_branchlev(&u.uz)) {
309         /* no bones on non-branches with portals */
310         for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap)
311             if (ttmp->ttyp == MAGIC_PORTAL)
312                 return FALSE;
313     }
314
315     if (depth(&u.uz) <= 0                 /* bulletproofing for endgame */
316         || (!rn2(1 + (depth(&u.uz) >> 2)) /* fewer ghosts on low levels */
317             && !wizard))
318         return FALSE;
319     /* don't let multiple restarts generate multiple copies of objects
320        in bones files */
321     if (discover)
322         return FALSE;
323     return TRUE;
324 }
325
326 /* save bones and possessions of a deceased adventurer */
327 void
328 savebones(how, when, corpse)
329 int how;
330 time_t when;
331 struct obj *corpse;
332 {
333     int fd, x, y;
334     struct trap *ttmp;
335     struct monst *mtmp;
336     struct permonst *mptr;
337     struct fruit *f;
338     struct cemetery *newbones;
339     char c, *bonesid;
340     char whynot[BUFSZ];
341
342     /* caller has already checked `can_make_bones()' */
343
344     clear_bypasses();
345     fd = open_bonesfile(&u.uz, &bonesid);
346     if (fd >= 0) {
347         (void) nhclose(fd);
348         if (wizard) {
349 /*JP
350             if (yn("Bones file already exists.  Replace it?") == 'y') {
351 */
352             if (yn("\8d\9c\83t\83@\83C\83\8b\82ª\8aù\82É\91\8dÝ\82µ\82Ä\82é\82æ\81D  \92u\82«\8a·\82¦\82é\81H") == 'y') {
353                 if (delete_bonesfile(&u.uz))
354                     goto make_bones;
355                 else
356 /*JP
357                     pline("Cannot unlink old bones.");
358 */
359                     pline("\8cÃ\82¢\8d\9c\82ð\8dí\8f\9c\82Å\82«\82È\82©\82Á\82½\81D");
360             }
361         }
362         /* compression can change the file's name, so must
363            wait until after any attempt to delete this file */
364         compress_bonesfile();
365         return;
366     }
367
368 make_bones:
369     unleash_all();
370     /* in case these characters are not in their home bases */
371     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
372         if (DEADMONSTER(mtmp))
373             continue;
374         mptr = mtmp->data;
375         if (mtmp->iswiz || mptr == &mons[PM_MEDUSA]
376             || mptr->msound == MS_NEMESIS || mptr->msound == MS_LEADER
377             || mptr == &mons[PM_VLAD_THE_IMPALER]
378             || (mptr == &mons[PM_ORACLE] && !fixuporacle(mtmp)))
379             mongone(mtmp);
380     }
381     if (u.usteed)
382         dismount_steed(DISMOUNT_BONES);
383     dmonsfree(); /* discard dead or gone monsters */
384
385     /* mark all fruits as nonexistent; when we come to them we'll mark
386      * them as existing (using goodfruit())
387      */
388     for (f = ffruit; f; f = f->nextf)
389         f->fid = -f->fid;
390
391     /* check iron balls separately--maybe they're not carrying it */
392     if (uball)
393         uball->owornmask = uchain->owornmask = 0;
394
395     /* dispose of your possessions, usually cursed */
396     if (u.ugrave_arise == (NON_PM - 1)) {
397         struct obj *otmp;
398
399         /* embed your possessions in your statue */
400         otmp = mk_named_object(STATUE, &mons[u.umonnum], u.ux, u.uy, plname);
401
402         drop_upon_death((struct monst *) 0, otmp, u.ux, u.uy);
403         if (!otmp)
404             return; /* couldn't make statue */
405         mtmp = (struct monst *) 0;
406     } else if (u.ugrave_arise < LOW_PM) {
407         /* drop everything */
408         drop_upon_death((struct monst *) 0, (struct obj *) 0, u.ux, u.uy);
409         /* trick makemon() into allowing monster creation
410          * on your location
411          */
412         in_mklev = TRUE;
413         mtmp = makemon(&mons[PM_GHOST], u.ux, u.uy, MM_NONAME);
414         in_mklev = FALSE;
415         if (!mtmp)
416             return;
417         mtmp = christen_monst(mtmp, plname);
418         if (corpse)
419             (void) obj_attach_mid(corpse, mtmp->m_id);
420     } else {
421         /* give your possessions to the monster you become */
422         in_mklev = TRUE; /* use <u.ux,u.uy> as-is */
423         mtmp = makemon(&mons[u.ugrave_arise], u.ux, u.uy, NO_MINVENT);
424         in_mklev = FALSE;
425         if (!mtmp) {
426             drop_upon_death((struct monst *) 0, (struct obj *) 0, u.ux, u.uy);
427             u.ugrave_arise = NON_PM; /* in case caller cares */
428             return;
429         }
430         /* give mummy-from-hero a wrapping unless hero already
431            carries one; don't bother forcing it to become worn */
432         if (mtmp->data->mlet == S_MUMMY && !carrying(MUMMY_WRAPPING))
433             (void) mongets(mtmp, MUMMY_WRAPPING);
434         mtmp = christen_monst(mtmp, plname);
435         newsym(u.ux, u.uy);
436         /* ["Your body rises from the dead as an <mname>..." used
437            to be given here, but it has been moved to done() so that
438            it gets delivered even when savebones() isn't called] */
439         drop_upon_death(mtmp, (struct obj *) 0, u.ux, u.uy);
440         m_dowear(mtmp, TRUE);
441     }
442     if (mtmp) {
443         mtmp->m_lev = (u.ulevel ? u.ulevel : 1);
444         mtmp->mhp = mtmp->mhpmax = u.uhpmax;
445         mtmp->female = flags.female;
446         mtmp->msleeping = 1;
447     }
448     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
449         resetobjs(mtmp->minvent, FALSE);
450         /* do not zero out m_ids for bones levels any more */
451         mtmp->mlstmv = 0L;
452         if (mtmp->mtame)
453             mtmp->mtame = mtmp->mpeaceful = 0;
454     }
455     for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) {
456         ttmp->madeby_u = 0;
457         ttmp->tseen = (ttmp->ttyp == HOLE);
458     }
459     resetobjs(fobj, FALSE);
460     resetobjs(level.buriedobjlist, FALSE);
461
462     /* Hero is no longer on the map. */
463     u.ux = u.uy = 0;
464
465     /* Clear all memory from the level. */
466     for (x = 1; x < COLNO; x++)
467         for (y = 0; y < ROWNO; y++) {
468             levl[x][y].seenv = 0;
469             levl[x][y].waslit = 0;
470             levl[x][y].glyph = cmap_to_glyph(S_stone);
471             lastseentyp[x][y] = 0;
472         }
473
474     /* Attach bones info to the current level before saving. */
475     newbones = (struct cemetery *) alloc(sizeof *newbones);
476     /* entries are '\0' terminated but have fixed length allocations,
477        so pre-fill with spaces to initialize any excess room */
478     (void) memset((genericptr_t) newbones, ' ', sizeof *newbones);
479     /* format name+role,&c, death reason, and date+time;
480        gender and alignment reflect final values rather than what the
481        character started out as, same as topten and logfile entries */
482     Sprintf(newbones->who, "%s-%.3s-%.3s-%.3s-%.3s", plname, urole.filecode,
483             urace.filecode, genders[flags.female].filecode,
484             aligns[1 - u.ualign.type].filecode);
485     formatkiller(newbones->how, sizeof newbones->how, how);
486     Strcpy(newbones->when, yyyymmddhhmmss(when));
487     /* final resting place, used to decide when bones are discovered */
488     newbones->frpx = u.ux, newbones->frpy = u.uy;
489     newbones->bonesknown = FALSE;
490     /* if current character died on a bones level, the cemetery list
491        will have multiple entries, most recent (this dead hero) first */
492     newbones->next = level.bonesinfo;
493     level.bonesinfo = newbones;
494     /* flag these bones if they are being created in wizard mode;
495        they might already be flagged as such, even when we're playing
496        in normal mode, if this level came from a previous bones file */
497     if (wizard)
498         level.flags.wizard_bones = 1;
499
500     fd = create_bonesfile(&u.uz, &bonesid, whynot);
501     if (fd < 0) {
502         if (wizard)
503             pline1(whynot);
504         /* bones file creation problems are silent to the player.
505          * Keep it that way, but place a clue into the paniclog.
506          */
507         paniclog("savebones", whynot);
508         return;
509     }
510     c = (char) (strlen(bonesid) + 1);
511
512 #ifdef MFLOPPY /* check whether there is room */
513     if (iflags.checkspace) {
514         savelev(fd, ledger_no(&u.uz), COUNT_SAVE);
515         /* savelev() initializes bytes_counted to 0, so it must come
516          * first here even though it does not in the real save.  the
517          * resulting extra bflush() at the end of savelev() may increase
518          * bytes_counted by a couple over what the real usage will be.
519          *
520          * note it is safe to call store_version() here only because
521          * bufon() is null for ZEROCOMP, which MFLOPPY uses -- otherwise
522          * this code would have to know the size of the version
523          * information itself.
524          */
525         store_version(fd);
526         store_savefileinfo(fd);
527         bwrite(fd, (genericptr_t) &c, sizeof c);
528         bwrite(fd, (genericptr_t) bonesid, (unsigned) c); /* DD.nnn */
529         savefruitchn(fd, COUNT_SAVE);
530         bflush(fd);
531         if (bytes_counted > freediskspace(bones)) { /* not enough room */
532             if (wizard)
533 /*JP
534                 pline("Insufficient space to create bones file.");
535 */
536                 pline("\8d\9c\83t\83@\83C\83\8b\82ð\90\90¬\82·\82é\82½\82ß\82Ì\8f[\95ª\82È\97Ì\88æ\82ª\82È\82¢\81D");
537             (void) nhclose(fd);
538             cancel_bonesfile();
539             return;
540         }
541         co_false(); /* make sure stuff before savelev() gets written */
542     }
543 #endif /* MFLOPPY */
544
545     store_version(fd);
546     store_savefileinfo(fd);
547     bwrite(fd, (genericptr_t) &c, sizeof c);
548     bwrite(fd, (genericptr_t) bonesid, (unsigned) c); /* DD.nnn */
549     savefruitchn(fd, WRITE_SAVE | FREE_SAVE);
550     update_mlstmv(); /* update monsters for eventual restoration */
551     savelev(fd, ledger_no(&u.uz), WRITE_SAVE | FREE_SAVE);
552     bclose(fd);
553     commit_bonesfile(&u.uz);
554     compress_bonesfile();
555 }
556
557 int
558 getbones()
559 {
560     register int fd;
561     register int ok;
562     char c, *bonesid, oldbonesid[10];
563
564     if (discover) /* save bones files for real games */
565         return 0;
566
567     if (!flags.bones)
568         return 0;
569     /* wizard check added by GAN 02/05/87 */
570     if (rn2(3) /* only once in three times do we find bones */
571         && !wizard)
572         return 0;
573     if (no_bones_level(&u.uz))
574         return 0;
575     fd = open_bonesfile(&u.uz, &bonesid);
576     if (fd < 0)
577         return 0;
578
579     if (validate(fd, bones) != 0) {
580         if (!wizard)
581 /*JP
582             pline("Discarding unuseable bones; no need to panic...");
583 */
584             pline("\8eg\82¦\82È\82¢\8d\9c\82ð\8eÌ\82Ä\82½\81D\8dQ\82Ä\82é\95K\97v\82Í\82È\82¢\81D\81D\81D");
585         ok = FALSE;
586     } else {
587         ok = TRUE;
588         if (wizard) {
589 /*JP
590             if (yn("Get bones?") == 'n') {
591 */
592             if (yn("\8d\9c\82ð\8fE\82¤\81H") == 'n') {
593                 (void) nhclose(fd);
594                 compress_bonesfile();
595                 return 0;
596             }
597         }
598         mread(fd, (genericptr_t) &c, sizeof c); /* length incl. '\0' */
599         mread(fd, (genericptr_t) oldbonesid, (unsigned) c); /* DD.nnn */
600         if (strcmp(bonesid, oldbonesid) != 0) {
601             char errbuf[BUFSZ];
602
603 /*JP
604             Sprintf(errbuf, "This is bones level '%s', not '%s'!", oldbonesid,
605 */
606             Sprintf(errbuf, "\82±\82Ì\8d\9c\82Ì\83\8c\83x\83\8b\82Í'%s'\82Å\82 \82Á\82Ä\81A'%s'\82Å\82Í\82È\82¢\81I", oldbonesid,
607                     bonesid);
608             if (wizard) {
609                 pline1(errbuf);
610                 ok = FALSE; /* won't die of trickery */
611             }
612             trickery(errbuf);
613         } else {
614             register struct monst *mtmp;
615
616             getlev(fd, 0, 0, TRUE);
617
618             /* Note that getlev() now keeps tabs on unique
619              * monsters such as demon lords, and tracks the
620              * birth counts of all species just as makemon()
621              * does.  If a bones monster is extinct or has been
622              * subject to genocide, their mhpmax will be
623              * set to the magic DEFUNCT_MONSTER cookie value.
624              */
625             for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
626                 if (has_mname(mtmp))
627                     sanitize_name(MNAME(mtmp));
628                 if (mtmp->mhpmax == DEFUNCT_MONSTER) {
629                     if (wizard) {
630                         debugpline1("Removing defunct monster %s from bones.",
631                                     mtmp->data->mname);
632                     }
633                     mongone(mtmp);
634                 } else
635                     /* to correctly reset named artifacts on the level */
636                     resetobjs(mtmp->minvent, TRUE);
637             }
638             resetobjs(fobj, TRUE);
639             resetobjs(level.buriedobjlist, TRUE);
640         }
641     }
642     (void) nhclose(fd);
643     sanitize_engravings();
644     u.uroleplay.numbones++;
645
646     if (wizard) {
647 /*JP
648         if (yn("Unlink bones?") == 'n') {
649 */
650         if (yn("\8d\9c\82ð\8fÁ\82·\81H") == 'n') {
651             compress_bonesfile();
652             return ok;
653         }
654     }
655     if (!delete_bonesfile(&u.uz)) {
656         /* When N games try to simultaneously restore the same
657          * bones file, N-1 of them will fail to delete it
658          * (the first N-1 under AmigaDOS, the last N-1 under UNIX).
659          * So no point in a mysterious message for a normal event
660          * -- just generate a new level for those N-1 games.
661          */
662         /* pline("Cannot unlink bones."); */
663         return 0;
664     }
665     return ok;
666 }
667
668 /*bones.c*/