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