Merge branch 'vendor/GDB' into gdb7
[dragonfly.git] / games / hack / hack.bones.c
CommitLineData
984263bc
MD
1/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2/* hack.bones.c - version 1.0.3 */
3/* $FreeBSD: src/games/hack/hack.bones.c,v 1.4 1999/11/16 10:26:35 marcel Exp $ */
c7106d58 4/* $DragonFly: src/games/hack/hack.bones.c,v 1.4 2006/08/21 19:45:32 pavalos Exp $ */
984263bc
MD
5
6#include "hack.h"
984263bc
MD
7
8char bones[] = "bones_xx";
9
10/* save bones and possessions of a deceased adventurer */
c7106d58
PA
11void
12savebones(void)
13{
984263bc
MD
14int fd;
15struct obj *otmp;
16struct trap *ttmp;
17struct monst *mtmp;
18 if(dlevel <= 0 || dlevel > MAXLEVEL) return;
19 if(!rn2(1 + dlevel/2)) return; /* not so many ghosts on low levels */
20 bones[6] = '0' + (dlevel/10);
21 bones[7] = '0' + (dlevel%10);
22 if((fd = open(bones,0)) >= 0){
c7106d58 23 close(fd);
984263bc
MD
24 return;
25 }
26 /* drop everything; the corpse's possessions are usually cursed */
27 otmp = invent;
28 while(otmp){
29 otmp->ox = u.ux;
30 otmp->oy = u.uy;
31 otmp->age = 0; /* very long ago */
32 otmp->owornmask = 0;
33 if(rn2(5)) otmp->cursed = 1;
34 if(!otmp->nobj){
35 otmp->nobj = fobj;
36 fobj = invent;
37 invent = 0; /* superfluous */
38 break;
39 }
40 otmp = otmp->nobj;
41 }
42 if(!(mtmp = makemon(PM_GHOST, u.ux, u.uy))) return;
43 mtmp->mx = u.ux;
44 mtmp->my = u.uy;
45 mtmp->msleep = 1;
c7106d58 46 strcpy((char *) mtmp->mextra, plname);
984263bc
MD
47 mkgold(somegold() + d(dlevel,30), u.ux, u.uy);
48 for(mtmp = fmon; mtmp; mtmp = mtmp->nmon){
49 mtmp->m_id = 0;
50 if(mtmp->mtame) {
51 mtmp->mtame = 0;
52 mtmp->mpeaceful = 0;
53 }
54 mtmp->mlstmv = 0;
55 if(mtmp->mdispl) unpmon(mtmp);
56 }
57 for(ttmp = ftrap; ttmp; ttmp = ttmp->ntrap)
58 ttmp->tseen = 0;
59 for(otmp = fobj; otmp; otmp = otmp->nobj) {
60 otmp->o_id = 0;
61 /* otmp->o_cnt_id = 0; - superfluous */
62 otmp->onamelth = 0;
63 otmp->known = 0;
64 otmp->invlet = 0;
65 if(otmp->olet == AMULET_SYM && !otmp->spe) {
66 otmp->spe = -1; /* no longer the actual amulet */
67 otmp->cursed = 1; /* flag as gotten from a ghost */
68 }
69 }
70 if((fd = creat(bones, FMASK)) < 0) return;
71 savelev(fd,dlevel);
c7106d58 72 close(fd);
984263bc
MD
73}
74
c7106d58
PA
75int
76getbones(void)
77{
984263bc
MD
78int fd,x,y,ok;
79 if(rn2(3)) return(0); /* only once in three times do we find bones */
80 bones[6] = '0' + dlevel/10;
81 bones[7] = '0' + dlevel%10;
82 if((fd = open(bones, 0)) < 0) return(0);
83 if((ok = uptodate(fd)) != 0){
84 getlev(fd, 0, dlevel);
85 for(x = 0; x < COLNO; x++) for(y = 0; y < ROWNO; y++)
86 levl[x][y].seen = levl[x][y].new = 0;
87 }
c7106d58 88 close(fd);
984263bc
MD
89#ifdef WIZARD
90 if(!wizard) /* duvel!frans: don't remove bones while debugging */
304d60d9 91#endif /* WiZARD */
984263bc
MD
92 if(unlink(bones) < 0){
93 pline("Cannot unlink %s .", bones);
94 return(0);
95 }
96 return(ok);
97}