OSDN Git Service

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