OSDN Git Service

fix #39767
[jnethack/source.git] / src / bones.c
1 /* NetHack 3.6  bones.c $NHDT-Date: 1557092711 2019/05/05 21:45:11 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.75 $ */
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-2019            */
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 = (WINDOWPORT("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; /* monster if hero turned into one (other than ghost) */
223 struct obj *cont; /* container if hero is turned into a statue */
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         /* when turning into green slime, all gear remains held;
232            other types "arise from the dead" do aren't holding
233            equipment during their brief interval as a corpse */
234         if (!mtmp || is_undead(mtmp->data))
235             obj_no_longer_held(otmp);
236
237         otmp->owornmask = 0L;
238         /* lamps don't go out when dropped */
239         if ((cont || artifact_light(otmp)) && obj_is_burning(otmp))
240             end_burn(otmp, TRUE); /* smother in statue */
241
242         if (otmp->otyp == SLIME_MOLD)
243             goodfruit(otmp->spe);
244
245         if (rn2(5))
246             curse(otmp);
247         if (mtmp)
248             (void) add_to_minv(mtmp, otmp);
249         else if (cont)
250             (void) add_to_container(cont, otmp);
251         else
252             place_object(otmp, x, y);
253     }
254     if (cont)
255         cont->owt = weight(cont);
256 }
257
258 /* possibly restore oracle's room and/or put her back inside it; returns
259    False if she's on the wrong level and should be removed, True otherwise */
260 STATIC_OVL boolean
261 fixuporacle(oracle)
262 struct monst *oracle;
263 {
264     coord cc;
265     int ridx, o_ridx;
266
267     /* oracle doesn't move, but knight's joust or monk's staggering blow
268        could push her onto a hole in the floor; at present, traps don't
269        activate in such situation hence she won't fall to another level;
270        however, that could change so be prepared to cope with such things */
271     if (!Is_oracle_level(&u.uz))
272         return FALSE;
273
274     oracle->mpeaceful = 1;
275     o_ridx = levl[oracle->mx][oracle->my].roomno - ROOMOFFSET;
276     if (o_ridx >= 0 && rooms[o_ridx].rtype == DELPHI)
277         return TRUE; /* no fixup needed */
278
279     /*
280      * The Oracle isn't in DELPHI room.  Either hero entered her chamber
281      * and got the one-time welcome message, converting it into an
282      * ordinary room, or she got teleported out, or both.  Try to put
283      * her back inside her room, if necessary, and restore its type.
284      */
285
286     /* find original delphi chamber; should always succeed */
287     for (ridx = 0; ridx < SIZE(rooms); ++ridx)
288         if (rooms[ridx].orig_rtype == DELPHI)
289             break;
290
291     if (o_ridx != ridx && ridx < SIZE(rooms)) {
292         /* room found and she's not not in it, so try to move her there */
293         cc.x = (rooms[ridx].lx + rooms[ridx].hx) / 2;
294         cc.y = (rooms[ridx].ly + rooms[ridx].hy) / 2;
295         if (enexto(&cc, cc.x, cc.y, oracle->data)) {
296             rloc_to(oracle, cc.x, cc.y);
297             o_ridx = levl[oracle->mx][oracle->my].roomno - ROOMOFFSET;
298         }
299         /* [if her room is already full, she might end up outside;
300            that's ok, next hero just won't get any welcome message,
301            same as used to happen before this fixup was introduced] */
302     }
303     if (ridx == o_ridx) /* if she's in her room, mark it as such */
304         rooms[ridx].rtype = DELPHI;
305     return TRUE; /* keep oracle in new bones file */
306 }
307
308 /* check whether bones are feasible */
309 boolean
310 can_make_bones()
311 {
312     register struct trap *ttmp;
313
314     if (!flags.bones)
315         return FALSE;
316     if (ledger_no(&u.uz) <= 0 || ledger_no(&u.uz) > maxledgerno())
317         return FALSE;
318     if (no_bones_level(&u.uz))
319         return FALSE; /* no bones for specific levels */
320     if (u.uswallow) {
321         return FALSE; /* no bones when swallowed */
322     }
323     if (!Is_branchlev(&u.uz)) {
324         /* no bones on non-branches with portals */
325         for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap)
326             if (ttmp->ttyp == MAGIC_PORTAL)
327                 return FALSE;
328     }
329
330     if (depth(&u.uz) <= 0                 /* bulletproofing for endgame */
331         || (!rn2(1 + (depth(&u.uz) >> 2)) /* fewer ghosts on low levels */
332             && !wizard))
333         return FALSE;
334     /* don't let multiple restarts generate multiple copies of objects
335        in bones files */
336     if (discover)
337         return FALSE;
338     return TRUE;
339 }
340
341 /* save bones and possessions of a deceased adventurer */
342 void
343 savebones(how, when, corpse)
344 int how;
345 time_t when;
346 struct obj *corpse;
347 {
348     int fd, x, y;
349     struct trap *ttmp;
350     struct monst *mtmp;
351     struct permonst *mptr;
352     struct fruit *f;
353     struct cemetery *newbones;
354     char c, *bonesid;
355     char whynot[BUFSZ];
356
357     /* caller has already checked `can_make_bones()' */
358
359     clear_bypasses();
360     fd = open_bonesfile(&u.uz, &bonesid);
361     if (fd >= 0) {
362         (void) nhclose(fd);
363         if (wizard) {
364 /*JP
365             if (yn("Bones file already exists.  Replace it?") == 'y') {
366 */
367             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') {
368                 if (delete_bonesfile(&u.uz))
369                     goto make_bones;
370                 else
371 /*JP
372                     pline("Cannot unlink old bones.");
373 */
374                     pline("\8cÃ\82¢\8d\9c\82ð\8dí\8f\9c\82Å\82«\82È\82©\82Á\82½\81D");
375             }
376         }
377         /* compression can change the file's name, so must
378            wait until after any attempt to delete this file */
379         compress_bonesfile();
380         return;
381     }
382
383  make_bones:
384     unleash_all();
385     /* in case these characters are not in their home bases */
386     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
387         if (DEADMONSTER(mtmp))
388             continue;
389         mptr = mtmp->data;
390         if (mtmp->iswiz || mptr == &mons[PM_MEDUSA]
391             || mptr->msound == MS_NEMESIS || mptr->msound == MS_LEADER
392             || mptr == &mons[PM_VLAD_THE_IMPALER]
393             || (mptr == &mons[PM_ORACLE] && !fixuporacle(mtmp)))
394             mongone(mtmp);
395     }
396     if (u.usteed)
397         dismount_steed(DISMOUNT_BONES);
398     dmonsfree(); /* discard dead or gone monsters */
399
400     /* mark all fruits as nonexistent; when we come to them we'll mark
401      * them as existing (using goodfruit())
402      */
403     for (f = ffruit; f; f = f->nextf)
404         f->fid = -f->fid;
405
406     /* check iron balls separately--maybe they're not carrying it */
407     if (uball)
408         uball->owornmask = uchain->owornmask = 0L;
409
410     /* dispose of your possessions, usually cursed */
411     if (u.ugrave_arise == (NON_PM - 1)) {
412         struct obj *otmp;
413
414         /* embed your possessions in your statue */
415         otmp = mk_named_object(STATUE, &mons[u.umonnum], u.ux, u.uy, plname);
416
417         drop_upon_death((struct monst *) 0, otmp, u.ux, u.uy);
418         if (!otmp)
419             return; /* couldn't make statue */
420         mtmp = (struct monst *) 0;
421     } else if (u.ugrave_arise < LOW_PM) {
422         /* drop everything */
423         drop_upon_death((struct monst *) 0, (struct obj *) 0, u.ux, u.uy);
424         /* trick makemon() into allowing monster creation
425          * on your location
426          */
427         in_mklev = TRUE;
428         mtmp = makemon(&mons[PM_GHOST], u.ux, u.uy, MM_NONAME);
429         in_mklev = FALSE;
430         if (!mtmp)
431             return;
432         mtmp = christen_monst(mtmp, plname);
433         if (corpse)
434             (void) obj_attach_mid(corpse, mtmp->m_id);
435     } else {
436         /* give your possessions to the monster you become */
437         in_mklev = TRUE; /* use <u.ux,u.uy> as-is */
438         mtmp = makemon(&mons[u.ugrave_arise], u.ux, u.uy, NO_MINVENT);
439         in_mklev = FALSE;
440         if (!mtmp) { /* arise-type might have been genocided */
441             drop_upon_death((struct monst *) 0, (struct obj *) 0, u.ux, u.uy);
442             u.ugrave_arise = NON_PM; /* in case caller cares */
443             return;
444         }
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         /* 'mtmp' now has hero's inventory; if 'mtmp' is a mummy, give it
452            a wrapping unless already carrying one */
453         if (mtmp->data->mlet == S_MUMMY && !m_carrying(mtmp, MUMMY_WRAPPING))
454             (void) mongets(mtmp, MUMMY_WRAPPING);
455         m_dowear(mtmp, TRUE);
456     }
457     if (mtmp) {
458         mtmp->m_lev = (u.ulevel ? u.ulevel : 1);
459         mtmp->mhp = mtmp->mhpmax = u.uhpmax;
460         mtmp->female = flags.female;
461         mtmp->msleeping = 1;
462     }
463     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
464         resetobjs(mtmp->minvent, FALSE);
465         /* do not zero out m_ids for bones levels any more */
466         mtmp->mlstmv = 0L;
467         if (mtmp->mtame)
468             mtmp->mtame = mtmp->mpeaceful = 0;
469     }
470     for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) {
471         ttmp->madeby_u = 0;
472         ttmp->tseen = (ttmp->ttyp == HOLE);
473     }
474     resetobjs(fobj, FALSE);
475     resetobjs(level.buriedobjlist, FALSE);
476
477     /* Hero is no longer on the map. */
478     u.ux0 = u.ux, u.uy0 = u.uy;
479     u.ux = u.uy = 0;
480
481     /* Clear all memory from the level. */
482     for (x = 1; x < COLNO; x++)
483         for (y = 0; y < ROWNO; y++) {
484             levl[x][y].seenv = 0;
485             levl[x][y].waslit = 0;
486             levl[x][y].glyph = cmap_to_glyph(S_stone);
487             lastseentyp[x][y] = 0;
488         }
489
490     /* Attach bones info to the current level before saving. */
491     newbones = (struct cemetery *) alloc(sizeof *newbones);
492     /* entries are '\0' terminated but have fixed length allocations,
493        so pre-fill with spaces to initialize any excess room */
494     (void) memset((genericptr_t) newbones, ' ', sizeof *newbones);
495     /* format name+role,&c, death reason, and date+time;
496        gender and alignment reflect final values rather than what the
497        character started out as, same as topten and logfile entries */
498     Sprintf(newbones->who, "%s-%.3s-%.3s-%.3s-%.3s", plname, urole.filecode,
499             urace.filecode, genders[flags.female].filecode,
500             aligns[1 - u.ualign.type].filecode);
501     formatkiller(newbones->how, sizeof newbones->how, how, TRUE);
502     Strcpy(newbones->when, yyyymmddhhmmss(when));
503     /* final resting place, used to decide when bones are discovered */
504     newbones->frpx = u.ux0, newbones->frpy = u.uy0;
505     newbones->bonesknown = FALSE;
506     /* if current character died on a bones level, the cemetery list
507        will have multiple entries, most recent (this dead hero) first */
508     newbones->next = level.bonesinfo;
509     level.bonesinfo = newbones;
510     /* flag these bones if they are being created in wizard mode;
511        they might already be flagged as such, even when we're playing
512        in normal mode, if this level came from a previous bones file */
513     if (wizard)
514         level.flags.wizard_bones = 1;
515
516     fd = create_bonesfile(&u.uz, &bonesid, whynot);
517     if (fd < 0) {
518         if (wizard)
519             pline1(whynot);
520         /* bones file creation problems are silent to the player.
521          * Keep it that way, but place a clue into the paniclog.
522          */
523         paniclog("savebones", whynot);
524         return;
525     }
526     c = (char) (strlen(bonesid) + 1);
527
528 #ifdef MFLOPPY /* check whether there is room */
529     if (iflags.checkspace) {
530         savelev(fd, ledger_no(&u.uz), COUNT_SAVE);
531         /* savelev() initializes bytes_counted to 0, so it must come
532          * first here even though it does not in the real save.  the
533          * resulting extra bflush() at the end of savelev() may increase
534          * bytes_counted by a couple over what the real usage will be.
535          *
536          * note it is safe to call store_version() here only because
537          * bufon() is null for ZEROCOMP, which MFLOPPY uses -- otherwise
538          * this code would have to know the size of the version
539          * information itself.
540          */
541         store_version(fd);
542         store_savefileinfo(fd);
543         bwrite(fd, (genericptr_t) &c, sizeof c);
544         bwrite(fd, (genericptr_t) bonesid, (unsigned) c); /* DD.nnn */
545         savefruitchn(fd, COUNT_SAVE);
546         bflush(fd);
547         if (bytes_counted > freediskspace(bones)) { /* not enough room */
548             if (wizard)
549 /*JP
550                 pline("Insufficient space to create bones file.");
551 */
552                 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");
553             (void) nhclose(fd);
554             cancel_bonesfile();
555             return;
556         }
557         co_false(); /* make sure stuff before savelev() gets written */
558     }
559 #endif /* MFLOPPY */
560
561     store_version(fd);
562     store_savefileinfo(fd);
563     bwrite(fd, (genericptr_t) &c, sizeof c);
564     bwrite(fd, (genericptr_t) bonesid, (unsigned) c); /* DD.nnn */
565     savefruitchn(fd, WRITE_SAVE | FREE_SAVE);
566     update_mlstmv(); /* update monsters for eventual restoration */
567     savelev(fd, ledger_no(&u.uz), WRITE_SAVE | FREE_SAVE);
568     bclose(fd);
569     commit_bonesfile(&u.uz);
570     compress_bonesfile();
571 }
572
573 int
574 getbones()
575 {
576     register int fd;
577     register int ok;
578     char c, *bonesid, oldbonesid[40]; /* was [10]; more should be safer */
579
580     if (discover) /* save bones files for real games */
581         return 0;
582
583     if (!flags.bones)
584         return 0;
585     /* wizard check added by GAN 02/05/87 */
586     if (rn2(3) /* only once in three times do we find bones */
587         && !wizard)
588         return 0;
589     if (no_bones_level(&u.uz))
590         return 0;
591     fd = open_bonesfile(&u.uz, &bonesid);
592     if (fd < 0)
593         return 0;
594
595     if (validate(fd, bones) != 0) {
596         if (!wizard)
597 /*JP
598             pline("Discarding unuseable bones; no need to panic...");
599 */
600             pline("\8eg\82¦\82È\82¢\8d\9c\82ð\8eÌ\82Ä\82½\81D\8dQ\82Ä\82é\95K\97v\82Í\82È\82¢\81D\81D\81D");
601         ok = FALSE;
602     } else {
603         ok = TRUE;
604         if (wizard) {
605 /*JP
606             if (yn("Get bones?") == 'n') {
607 */
608             if (yn("\8d\9c\82ð\8fE\82¤\81H") == 'n') {
609                 (void) nhclose(fd);
610                 compress_bonesfile();
611                 return 0;
612             }
613         }
614         mread(fd, (genericptr_t) &c, sizeof c); /* length incl. '\0' */
615         mread(fd, (genericptr_t) oldbonesid, (unsigned) c); /* DD.nnn */
616         if (strcmp(bonesid, oldbonesid) != 0
617             /* from 3.3.0 through 3.6.0, bones in the quest branch stored
618                a bogus bonesid in the file; 3.6.1 fixed that, but for
619                3.6.0 bones to remain compatible, we need an extra test;
620                once compatibility with 3.6.x goes away, this can too
621                (we don't try to make this conditional upon the value of
622                VERSION_COMPATIBILITY because then we'd need patchlevel.h) */
623             && (strlen(bonesid) <= 2
624                 || strcmp(bonesid + 2, oldbonesid) != 0)) {
625             char errbuf[BUFSZ];
626
627 /*JP
628             Sprintf(errbuf, "This is bones level '%s', not '%s'!", oldbonesid,
629 */
630             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,
631                     bonesid);
632             if (wizard) {
633                 pline1(errbuf);
634                 ok = FALSE; /* won't die of trickery */
635             }
636             trickery(errbuf);
637         } else {
638             register struct monst *mtmp;
639
640             getlev(fd, 0, 0, TRUE);
641
642             /* Note that getlev() now keeps tabs on unique
643              * monsters such as demon lords, and tracks the
644              * birth counts of all species just as makemon()
645              * does.  If a bones monster is extinct or has been
646              * subject to genocide, their mhpmax will be
647              * set to the magic DEFUNCT_MONSTER cookie value.
648              */
649             for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
650                 if (has_mname(mtmp))
651                     sanitize_name(MNAME(mtmp));
652                 if (mtmp->mhpmax == DEFUNCT_MONSTER) {
653                     if (wizard) {
654                         debugpline1("Removing defunct monster %s from bones.",
655                                     mtmp->data->mname);
656                     }
657                     mongone(mtmp);
658                 } else
659                     /* to correctly reset named artifacts on the level */
660                     resetobjs(mtmp->minvent, TRUE);
661             }
662             resetobjs(fobj, TRUE);
663             resetobjs(level.buriedobjlist, TRUE);
664         }
665     }
666     (void) nhclose(fd);
667     sanitize_engravings();
668     u.uroleplay.numbones++;
669
670     if (wizard) {
671 /*JP
672         if (yn("Unlink bones?") == 'n') {
673 */
674         if (yn("\8d\9c\82ð\8fÁ\82·\81H") == 'n') {
675             compress_bonesfile();
676             return ok;
677         }
678     }
679     if (!delete_bonesfile(&u.uz)) {
680         /* When N games try to simultaneously restore the same
681          * bones file, N-1 of them will fail to delete it
682          * (the first N-1 under AmigaDOS, the last N-1 under UNIX).
683          * So no point in a mysterious message for a normal event
684          * -- just generate a new level for those N-1 games.
685          */
686         /* pline("Cannot unlink bones."); */
687         return 0;
688     }
689     return ok;
690 }
691
692 /*bones.c*/