1*77f90040Sop /* $OpenBSD: hack.bones.c,v 1.12 2023/06/03 15:19:38 op Exp $ */
2d0b779f3Sniklas
3df930be7Sderaadt /*
4d25013f2Scamield * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
5d25013f2Scamield * Amsterdam
6d25013f2Scamield * All rights reserved.
7d25013f2Scamield *
8d25013f2Scamield * Redistribution and use in source and binary forms, with or without
9d25013f2Scamield * modification, are permitted provided that the following conditions are
10d25013f2Scamield * met:
11d25013f2Scamield *
12d25013f2Scamield * - Redistributions of source code must retain the above copyright notice,
13d25013f2Scamield * this list of conditions and the following disclaimer.
14d25013f2Scamield *
15d25013f2Scamield * - Redistributions in binary form must reproduce the above copyright
16d25013f2Scamield * notice, this list of conditions and the following disclaimer in the
17d25013f2Scamield * documentation and/or other materials provided with the distribution.
18d25013f2Scamield *
19d25013f2Scamield * - Neither the name of the Stichting Centrum voor Wiskunde en
20d25013f2Scamield * Informatica, nor the names of its contributors may be used to endorse or
21d25013f2Scamield * promote products derived from this software without specific prior
22d25013f2Scamield * written permission.
23d25013f2Scamield *
24d25013f2Scamield * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25d25013f2Scamield * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26d25013f2Scamield * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27d25013f2Scamield * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28d25013f2Scamield * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29d25013f2Scamield * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30d25013f2Scamield * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31d25013f2Scamield * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32d25013f2Scamield * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33d25013f2Scamield * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34d25013f2Scamield * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35d25013f2Scamield */
36d25013f2Scamield
37d25013f2Scamield /*
38d25013f2Scamield * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
39d25013f2Scamield * All rights reserved.
40d25013f2Scamield *
41d25013f2Scamield * Redistribution and use in source and binary forms, with or without
42d25013f2Scamield * modification, are permitted provided that the following conditions
43d25013f2Scamield * are met:
44d25013f2Scamield * 1. Redistributions of source code must retain the above copyright
45d25013f2Scamield * notice, this list of conditions and the following disclaimer.
46d25013f2Scamield * 2. Redistributions in binary form must reproduce the above copyright
47d25013f2Scamield * notice, this list of conditions and the following disclaimer in the
48d25013f2Scamield * documentation and/or other materials provided with the distribution.
49d25013f2Scamield * 3. The name of the author may not be used to endorse or promote products
50d25013f2Scamield * derived from this software without specific prior written permission.
51d25013f2Scamield *
52d25013f2Scamield * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53d25013f2Scamield * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54d25013f2Scamield * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55d25013f2Scamield * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56d25013f2Scamield * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57d25013f2Scamield * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58d25013f2Scamield * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59d25013f2Scamield * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60d25013f2Scamield * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61d25013f2Scamield * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62df930be7Sderaadt */
63df930be7Sderaadt
644a5fbbc4Spjanzen #include <unistd.h>
65aed906e4Smestre
66df930be7Sderaadt #include "hack.h"
67aed906e4Smestre
68df930be7Sderaadt extern char plname[PL_NSIZ];
69df930be7Sderaadt extern struct permonst pm_ghost;
70df930be7Sderaadt
71df930be7Sderaadt char bones[] = "bones_xx";
72df930be7Sderaadt
73df930be7Sderaadt /* save bones and possessions of a deceased adventurer */
744a5fbbc4Spjanzen void
savebones(void)75aed906e4Smestre savebones(void)
764a5fbbc4Spjanzen {
774a5fbbc4Spjanzen int fd;
784a5fbbc4Spjanzen struct obj *otmp;
794a5fbbc4Spjanzen struct trap *ttmp;
804a5fbbc4Spjanzen struct monst *mtmp;
814a5fbbc4Spjanzen
82df930be7Sderaadt if(dlevel <= 0 || dlevel > MAXLEVEL) return;
83df930be7Sderaadt if(!rn2(1 + dlevel/2)) return; /* not so many ghosts on low levels */
84df930be7Sderaadt bones[6] = '0' + (dlevel/10);
85df930be7Sderaadt bones[7] = '0' + (dlevel%10);
866cd28e42Smillert if((fd = open(bones, O_RDONLY)) >= 0){
87df930be7Sderaadt (void) close(fd);
88df930be7Sderaadt return;
89df930be7Sderaadt }
90df930be7Sderaadt /* drop everything; the corpse's possessions are usually cursed */
91df930be7Sderaadt otmp = invent;
92df930be7Sderaadt while(otmp){
93df930be7Sderaadt otmp->ox = u.ux;
94df930be7Sderaadt otmp->oy = u.uy;
95df930be7Sderaadt otmp->age = 0; /* very long ago */
96df930be7Sderaadt otmp->owornmask = 0;
97df930be7Sderaadt if(rn2(5)) otmp->cursed = 1;
98df930be7Sderaadt if(!otmp->nobj){
99df930be7Sderaadt otmp->nobj = fobj;
100df930be7Sderaadt fobj = invent;
101df930be7Sderaadt invent = 0; /* superfluous */
102df930be7Sderaadt break;
103df930be7Sderaadt }
104df930be7Sderaadt otmp = otmp->nobj;
105df930be7Sderaadt }
106df930be7Sderaadt if(!(mtmp = makemon(PM_GHOST, u.ux, u.uy))) return;
107df930be7Sderaadt mtmp->mx = u.ux;
108df930be7Sderaadt mtmp->my = u.uy;
109df930be7Sderaadt mtmp->msleep = 1;
110846311fcStdeval (void) strlcpy((char *) mtmp->mextra, plname, mtmp->mxlth);
111df930be7Sderaadt mkgold(somegold() + d(dlevel,30), u.ux, u.uy);
112df930be7Sderaadt for(mtmp = fmon; mtmp; mtmp = mtmp->nmon){
113df930be7Sderaadt mtmp->m_id = 0;
114df930be7Sderaadt if(mtmp->mtame) {
115df930be7Sderaadt mtmp->mtame = 0;
116df930be7Sderaadt mtmp->mpeaceful = 0;
117df930be7Sderaadt }
118df930be7Sderaadt mtmp->mlstmv = 0;
119df930be7Sderaadt if(mtmp->mdispl) unpmon(mtmp);
120df930be7Sderaadt }
121df930be7Sderaadt for(ttmp = ftrap; ttmp; ttmp = ttmp->ntrap)
122df930be7Sderaadt ttmp->tseen = 0;
123df930be7Sderaadt for(otmp = fobj; otmp; otmp = otmp->nobj) {
124df930be7Sderaadt otmp->o_id = 0;
125df930be7Sderaadt /* otmp->o_cnt_id = 0; - superfluous */
126df930be7Sderaadt otmp->onamelth = 0;
127df930be7Sderaadt otmp->known = 0;
128df930be7Sderaadt otmp->invlet = 0;
129df930be7Sderaadt if(otmp->olet == AMULET_SYM && !otmp->spe) {
130df930be7Sderaadt otmp->spe = -1; /* no longer the actual amulet */
131df930be7Sderaadt otmp->cursed = 1; /* flag as gotten from a ghost */
132df930be7Sderaadt }
133df930be7Sderaadt }
134df69c215Sderaadt if((fd = open(bones, O_CREAT | O_TRUNC | O_WRONLY, FMASK)) == -1) return;
135df930be7Sderaadt savelev(fd,dlevel);
136df930be7Sderaadt (void) close(fd);
137df930be7Sderaadt }
138df930be7Sderaadt
1394a5fbbc4Spjanzen int
getbones(void)140aed906e4Smestre getbones(void)
1414a5fbbc4Spjanzen {
142*77f90040Sop int fd,x,y;
1434a5fbbc4Spjanzen
144df930be7Sderaadt if(rn2(3)) return(0); /* only once in three times do we find bones */
145df930be7Sderaadt bones[6] = '0' + dlevel/10;
146df930be7Sderaadt bones[7] = '0' + dlevel%10;
147df69c215Sderaadt if((fd = open(bones, O_RDONLY)) == -1) return(0);
148df930be7Sderaadt getlev(fd, 0, dlevel);
149df930be7Sderaadt for(x = 0; x < COLNO; x++) for(y = 0; y < ROWNO; y++)
150df930be7Sderaadt levl[x][y].seen = levl[x][y].new = 0;
151df930be7Sderaadt (void) close(fd);
152df930be7Sderaadt #ifdef WIZARD
153df930be7Sderaadt if(!wizard) /* duvel!frans: don't remove bones while debugging */
15454da88e4Spjanzen #endif /* WiZARD */
155df69c215Sderaadt if(unlink(bones) == -1){
156df930be7Sderaadt pline("Cannot unlink %s .", bones);
157df930be7Sderaadt return(0);
158df930be7Sderaadt }
159*77f90040Sop return(1);
160df930be7Sderaadt }
161