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