Add missing .Sh LIBRARY.
[dragonfly.git] / games / hack / hack.bones.c
blobf8d633443a8536d0b4c026041ff8ddf5258cac19
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 $ */
4 /* $DragonFly: src/games/hack/hack.bones.c,v 1.4 2006/08/21 19:45:32 pavalos Exp $ */
6 #include "hack.h"
8 char bones[] = "bones_xx";
10 /* save bones and possessions of a deceased adventurer */
11 void
12 savebones(void)
14 int fd;
15 struct obj *otmp;
16 struct trap *ttmp;
17 struct 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){
23 close(fd);
24 return;
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;
40 otmp = otmp->nobj;
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;
46 strcpy((char *) mtmp->mextra, plname);
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;
54 mtmp->mlstmv = 0;
55 if(mtmp->mdispl) unpmon(mtmp);
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 */
70 if((fd = creat(bones, FMASK)) < 0) return;
71 savelev(fd,dlevel);
72 close(fd);
75 int
76 getbones(void)
78 int 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;
88 close(fd);
89 #ifdef WIZARD
90 if(!wizard) /* duvel!frans: don't remove bones while debugging */
91 #endif /* WiZARD */
92 if(unlink(bones) < 0){
93 pline("Cannot unlink %s .", bones);
94 return(0);
96 return(ok);