]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.save.c
1 /* $NetBSD: hack.save.c,v 1.8 2003/04/02 18:36:40 jsm Exp $ */
4 * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * - Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * - Neither the name of the Stichting Centrum voor Wiskunde en
20 * Informatica, nor the names of its contributors may be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
39 * All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. The name of the author may not be used to endorse or promote products
50 * derived from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 #include <sys/cdefs.h>
66 __RCSID("$NetBSD: hack.save.c,v 1.8 2003/04/02 18:36:40 jsm Exp $");
81 settty("Be seeing you ...\n");
87 #ifndef NOSAVEONHANGUP
90 int n
__attribute__((__unused__
));
95 #endif /* NOSAVEONHANGUP */
97 /* returns 1 if save successful */
105 (void) signal(SIGHUP
, SIG_IGN
);
106 (void) signal(SIGINT
, SIG_IGN
);
107 if ((fd
= creat(SAVEF
, FMASK
)) < 0) {
109 pline("Cannot open save file. (Continue or Quit)");
110 (void) unlink(SAVEF
); /* ab@unido */
113 if (flags
.moonphase
== FULL_MOON
) /* ut-sally!fletcher */
114 u
.uluck
--; /* and unido!ab */
116 saveobjchn(fd
, invent
);
117 saveobjchn(fd
, fcobj
);
118 savemonchn(fd
, fallen_down
);
120 bwrite(fd
, (char *) &tmp
, sizeof tmp
);
121 bwrite(fd
, (char *) &flags
, sizeof(struct flag
));
122 bwrite(fd
, (char *) &dlevel
, sizeof dlevel
);
123 bwrite(fd
, (char *) &maxdlevel
, sizeof maxdlevel
);
124 bwrite(fd
, (char *) &moves
, sizeof moves
);
125 bwrite(fd
, (char *) &u
, sizeof(struct you
));
127 bwrite(fd
, (char *) &(u
.ustuck
->m_id
), sizeof u
.ustuck
->m_id
);
128 bwrite(fd
, (char *) pl_character
, sizeof pl_character
);
129 bwrite(fd
, (char *) genocided
, sizeof genocided
);
130 bwrite(fd
, (char *) fut_geno
, sizeof fut_geno
);
132 for (tmp
= 1; tmp
<= maxdlevel
; tmp
++) {
134 if (tmp
== dlevel
|| !level_exists
[tmp
])
137 if ((ofd
= open(lock
, O_RDONLY
)) < 0) {
139 pline("Error while saving: cannot read %s.", lock
);
141 (void) unlink(SAVEF
);
146 getlev(ofd
, hackpid
, tmp
);
148 bwrite(fd
, (char *) &tmp
, sizeof tmp
); /* level number */
149 savelev(fd
, tmp
); /* actual level */
154 (void) unlink(lock
); /* get rid of current level --jgm */
165 int tmp
; /* not a ! */
166 unsigned mid
; /* idem */
171 invent
= restobjchn(fd
);
172 for (otmp
= invent
; otmp
; otmp
= otmp
->nobj
)
174 setworn(otmp
, otmp
->owornmask
);
175 fcobj
= restobjchn(fd
);
176 fallen_down
= restmonchn(fd
);
177 mread(fd
, (char *) &tmp
, sizeof tmp
);
178 if (tmp
!= getuid()) { /* strange ... */
180 (void) unlink(SAVEF
);
181 puts("Saved game was not yours.");
185 mread(fd
, (char *) &flags
, sizeof(struct flag
));
186 mread(fd
, (char *) &dlevel
, sizeof dlevel
);
187 mread(fd
, (char *) &maxdlevel
, sizeof maxdlevel
);
188 mread(fd
, (char *) &moves
, sizeof moves
);
189 mread(fd
, (char *) &u
, sizeof(struct you
));
191 mread(fd
, (char *) &mid
, sizeof mid
);
192 mread(fd
, (char *) pl_character
, sizeof pl_character
);
193 mread(fd
, (char *) genocided
, sizeof genocided
);
194 mread(fd
, (char *) fut_geno
, sizeof fut_geno
);
197 if (read(fd
, (char *) &tmp
, sizeof tmp
) != sizeof tmp
)
201 if ((nfd
= creat(lock
, FMASK
)) < 0)
202 panic("Cannot open temp file %s!\n", lock
);
206 (void) lseek(fd
, (off_t
) 0, SEEK_SET
);
209 (void) unlink(SAVEF
);
211 for (otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
212 if (otmp
->olet
== CHAIN_SYM
)
214 panic("Cannot find the iron chain?");
218 for (otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
219 if (otmp
->olet
== BALL_SYM
&& otmp
->spe
)
221 panic("Cannot find the iron ball?");
229 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
230 if (mtmp
->m_id
== mid
)
232 panic("Cannot find the monster ustuck.");
237 setsee(); /* only to recompute seelx etc. - these
249 struct obj
*otmp
, *otmp2
= NULL
;
250 struct obj
*first
= 0;
253 mread(fd
, (char *) &xl
, sizeof(xl
));
261 mread(fd
, (char *) otmp
, (unsigned) xl
+ sizeof(struct obj
));
263 otmp
->o_id
= flags
.ident
++;
266 if (first
&& otmp2
->nobj
) {
267 impossible("Restobjchn: error reading objchn.");
277 struct monst
*mtmp
, *mtmp2
= NULL
;
278 struct monst
*first
= 0;
281 struct permonst
*monbegin
;
284 mread(fd
, (char *) &monbegin
, sizeof(monbegin
));
285 differ
= (const char *) (&mons
[0]) - (const char *) (monbegin
);
288 /* suppress "used before set" warning from lint */
292 mread(fd
, (char *) &xl
, sizeof(xl
));
300 mread(fd
, (char *) mtmp
, (unsigned) xl
+ sizeof(struct monst
));
302 mtmp
->m_id
= flags
.ident
++;
303 mtmp
->data
= (const struct permonst
*)
304 ((const char *) mtmp
->data
+ differ
);
306 mtmp
->minvent
= restobjchn(fd
);
309 if (first
&& mtmp2
->nmon
) {
310 impossible("Restmonchn: error reading monchn.");