OSDN Git Service

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