]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.lev.c
1 /* $NetBSD: hack.lev.c,v 1.4 1997/10/19 16:58:09 christos Exp $ */
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
9 __RCSID("$NetBSD: hack.lev.c,v 1.4 1997/10/19 16:58:09 christos Exp $");
16 #include "def.mkroom.h"
22 boolean level_exists
[MAXLEVEL
+ 1];
30 struct wseg
*wtmp
, *wtmp2
;
35 panic("Save on bad file!"); /* impossible */
36 if (lev
>= 0 && lev
<= MAXLEVEL
)
37 level_exists
[lev
] = TRUE
;
39 bwrite(fd
, (char *) &hackpid
, sizeof(hackpid
));
40 bwrite(fd
, (char *) &lev
, sizeof(lev
));
41 bwrite(fd
, (char *) levl
, sizeof(levl
));
42 bwrite(fd
, (char *) &moves
, sizeof(long));
43 bwrite(fd
, (char *) &xupstair
, sizeof(xupstair
));
44 bwrite(fd
, (char *) &yupstair
, sizeof(yupstair
));
45 bwrite(fd
, (char *) &xdnstair
, sizeof(xdnstair
));
46 bwrite(fd
, (char *) &ydnstair
, sizeof(ydnstair
));
48 savegoldchn(fd
, fgold
);
49 savetrapchn(fd
, ftrap
);
51 saveobjchn(fd
, billobjs
);
55 bwrite(fd
, (char *) rooms
, sizeof(rooms
));
56 bwrite(fd
, (char *) doors
, sizeof(doors
));
63 bwrite(fd
, (char *) wsegs
, sizeof(wsegs
));
64 for (tmp
= 1; tmp
< 32; tmp
++) {
65 for (wtmp
= wsegs
[tmp
]; wtmp
; wtmp
= wtmp2
) {
67 bwrite(fd
, (char *) wtmp
, sizeof(struct wseg
));
71 bwrite(fd
, (char *) wgrowtime
, sizeof(wgrowtime
));
81 /* lint wants the 3rd arg of write to be an int; lint -p an unsigned */
82 if (write(fd
, loc
, (int) num
) != num
)
83 panic("cannot write %u bytes to file #%d", num
, fd
);
98 bwrite(fd
, (char *) &xl
, sizeof(int));
99 bwrite(fd
, (char *) otmp
, xl
+ sizeof(struct obj
));
103 bwrite(fd
, (char *) &minusone
, sizeof(int));
114 struct permonst
*monbegin
= &mons
[0];
116 bwrite(fd
, (char *) &monbegin
, sizeof(monbegin
));
120 xl
= mtmp
->mxlth
+ mtmp
->mnamelth
;
121 bwrite(fd
, (char *) &xl
, sizeof(int));
122 bwrite(fd
, (char *) mtmp
, xl
+ sizeof(struct monst
));
124 saveobjchn(fd
, mtmp
->minvent
);
128 bwrite(fd
, (char *) &minusone
, sizeof(int));
132 savegoldchn(fd
, gold
)
139 bwrite(fd
, (char *) gold
, sizeof(struct gold
));
143 bwrite(fd
, nul
, sizeof(struct gold
));
147 savetrapchn(fd
, trap
)
154 bwrite(fd
, (char *) trap
, sizeof(struct trap
));
158 bwrite(fd
, nul
, sizeof(struct trap
));
176 /* First some sanity checks */
177 mread(fd
, (char *) &hpid
, sizeof(hpid
));
178 mread(fd
, (char *) &dlvl
, sizeof(dlvl
));
179 if ((pid
&& pid
!= hpid
) || (lev
&& dlvl
!= lev
)) {
180 pline("Strange, this map is not as I remember it.");
181 pline("Somebody is trying some trickery here ...");
182 pline("This game is void ...");
187 mread(fd
, (char *) levl
, sizeof(levl
));
188 mread(fd
, (char *) &omoves
, sizeof(omoves
));
189 mread(fd
, (char *) &xupstair
, sizeof(xupstair
));
190 mread(fd
, (char *) &yupstair
, sizeof(yupstair
));
191 mread(fd
, (char *) &xdnstair
, sizeof(xdnstair
));
192 mread(fd
, (char *) &ydnstair
, sizeof(ydnstair
));
194 fmon
= restmonchn(fd
);
196 /* regenerate animals while on another level */
198 long tmoves
= (moves
> omoves
) ? moves
- omoves
: 0;
199 struct monst
*mtmp
, *mtmp2
;
201 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp2
) {
202 long newhp
; /* tmoves may be very large */
205 if (strchr(genocided
, mtmp
->data
->mlet
)) {
209 if (mtmp
->mtame
&& tmoves
> 250) {
214 (strchr(MREGEN
, mtmp
->data
->mlet
) ? tmoves
: tmoves
/ 20);
215 if (newhp
> mtmp
->mhpmax
)
216 mtmp
->mhp
= mtmp
->mhpmax
;
224 mread(fd
, (char *) gold
, sizeof(struct gold
));
229 mread(fd
, (char *) gold
, sizeof(struct gold
));
233 mread(fd
, (char *) trap
, sizeof(struct trap
));
238 mread(fd
, (char *) trap
, sizeof(struct trap
));
241 fobj
= restobjchn(fd
);
242 billobjs
= restobjchn(fd
);
245 mread(fd
, (char *) rooms
, sizeof(rooms
));
246 mread(fd
, (char *) doors
, sizeof(doors
));
249 mread(fd
, (char *) wsegs
, sizeof(wsegs
));
250 for (tmp
= 1; tmp
< 32; tmp
++)
252 wheads
[tmp
] = wsegs
[tmp
] = wtmp
= newseg();
254 mread(fd
, (char *) wtmp
, sizeof(struct wseg
));
257 wheads
[tmp
]->nseg
= wtmp
= newseg();
261 mread(fd
, (char *) wgrowtime
, sizeof(wgrowtime
));
273 rlen
= read(fd
, buf
, (int) len
);
275 pline("Read %d instead of %u bytes.\n", rlen
, len
);
277 (void) unlink(SAVEF
);
278 error("Error restoring old game.");
280 panic("Error reading level file.");