]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.lev.c
1 /* $NetBSD: hack.lev.c,v 1.7 2008/01/28 06:55:41 dholland 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.lev.c,v 1.7 2008/01/28 06:55:41 dholland Exp $");
73 #include "def.mkroom.h"
79 boolean level_exists
[MAXLEVEL
+ 1];
87 struct wseg
*wtmp
, *wtmp2
;
92 panic("Save on bad file!"); /* impossible */
93 if (lev
>= 0 && lev
<= MAXLEVEL
)
94 level_exists
[lev
] = TRUE
;
96 bwrite(fd
, (char *) &hackpid
, sizeof(hackpid
));
97 bwrite(fd
, (char *) &lev
, sizeof(lev
));
98 bwrite(fd
, (char *) levl
, sizeof(levl
));
99 bwrite(fd
, (char *) &moves
, sizeof(long));
100 bwrite(fd
, (char *) &xupstair
, sizeof(xupstair
));
101 bwrite(fd
, (char *) &yupstair
, sizeof(yupstair
));
102 bwrite(fd
, (char *) &xdnstair
, sizeof(xdnstair
));
103 bwrite(fd
, (char *) &ydnstair
, sizeof(ydnstair
));
104 savemonchn(fd
, fmon
);
105 savegoldchn(fd
, fgold
);
106 savetrapchn(fd
, ftrap
);
107 saveobjchn(fd
, fobj
);
108 saveobjchn(fd
, billobjs
);
112 bwrite(fd
, (char *) rooms
, sizeof(rooms
));
113 bwrite(fd
, (char *) doors
, sizeof(doors
));
120 bwrite(fd
, (char *) wsegs
, sizeof(wsegs
));
121 for (tmp
= 1; tmp
< 32; tmp
++) {
122 for (wtmp
= wsegs
[tmp
]; wtmp
; wtmp
= wtmp2
) {
124 bwrite(fd
, (char *) wtmp
, sizeof(struct wseg
));
128 bwrite(fd
, (char *) wgrowtime
, sizeof(wgrowtime
));
138 /* lint wants the 3rd arg of write to be an int; lint -p an unsigned */
139 if (write(fd
, loc
, (int) num
) != num
)
140 panic("cannot write %u bytes to file #%d", num
, fd
);
155 bwrite(fd
, (char *) &xl
, sizeof(int));
156 bwrite(fd
, (char *) otmp
, xl
+ sizeof(struct obj
));
160 bwrite(fd
, (char *) &minusone
, sizeof(int));
171 const struct permonst
*monbegin
= &mons
[0];
173 bwrite(fd
, &monbegin
, sizeof(monbegin
));
177 xl
= mtmp
->mxlth
+ mtmp
->mnamelth
;
178 bwrite(fd
, (char *) &xl
, sizeof(int));
179 bwrite(fd
, (char *) mtmp
, xl
+ sizeof(struct monst
));
181 saveobjchn(fd
, mtmp
->minvent
);
185 bwrite(fd
, (char *) &minusone
, sizeof(int));
189 savegoldchn(fd
, gold
)
196 bwrite(fd
, (char *) gold
, sizeof(struct gold
));
200 bwrite(fd
, nul
, sizeof(struct gold
));
204 savetrapchn(fd
, trap
)
211 bwrite(fd
, (char *) trap
, sizeof(struct trap
));
215 bwrite(fd
, nul
, sizeof(struct trap
));
233 /* First some sanity checks */
234 mread(fd
, (char *) &hpid
, sizeof(hpid
));
235 mread(fd
, (char *) &dlvl
, sizeof(dlvl
));
236 if ((pid
&& pid
!= hpid
) || (lev
&& dlvl
!= lev
)) {
237 pline("Strange, this map is not as I remember it.");
238 pline("Somebody is trying some trickery here ...");
239 pline("This game is void ...");
244 mread(fd
, (char *) levl
, sizeof(levl
));
245 mread(fd
, (char *) &omoves
, sizeof(omoves
));
246 mread(fd
, (char *) &xupstair
, sizeof(xupstair
));
247 mread(fd
, (char *) &yupstair
, sizeof(yupstair
));
248 mread(fd
, (char *) &xdnstair
, sizeof(xdnstair
));
249 mread(fd
, (char *) &ydnstair
, sizeof(ydnstair
));
251 fmon
= restmonchn(fd
);
253 /* regenerate animals while on another level */
255 long tmoves
= (moves
> omoves
) ? moves
- omoves
: 0;
256 struct monst
*mtmp
, *mtmp2
;
258 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp2
) {
259 long newhp
; /* tmoves may be very large */
262 if (strchr(genocided
, mtmp
->data
->mlet
)) {
266 if (mtmp
->mtame
&& tmoves
> 250) {
271 (strchr(MREGEN
, mtmp
->data
->mlet
) ? tmoves
: tmoves
/ 20);
272 if (newhp
> mtmp
->mhpmax
)
273 mtmp
->mhp
= mtmp
->mhpmax
;
281 mread(fd
, (char *) gold
, sizeof(struct gold
));
286 mread(fd
, (char *) gold
, sizeof(struct gold
));
290 mread(fd
, (char *) trap
, sizeof(struct trap
));
295 mread(fd
, (char *) trap
, sizeof(struct trap
));
298 fobj
= restobjchn(fd
);
299 billobjs
= restobjchn(fd
);
302 mread(fd
, (char *) rooms
, sizeof(rooms
));
303 mread(fd
, (char *) doors
, sizeof(doors
));
306 mread(fd
, (char *) wsegs
, sizeof(wsegs
));
307 for (tmp
= 1; tmp
< 32; tmp
++)
309 wheads
[tmp
] = wsegs
[tmp
] = wtmp
= newseg();
311 mread(fd
, (char *) wtmp
, sizeof(struct wseg
));
314 wheads
[tmp
]->nseg
= wtmp
= newseg();
318 mread(fd
, (char *) wgrowtime
, sizeof(wgrowtime
));
330 rlen
= read(fd
, buf
, len
);
331 if (rlen
< 0 || (size_t)rlen
!= len
) {
332 pline("Read %d instead of %u bytes.\n", rlen
, len
);
334 (void) unlink(SAVEF
);
335 error("Error restoring old game.");
337 panic("Error reading level file.");