]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.lev.c
2 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
6 static char rcsid
[] = "$NetBSD: hack.lev.c,v 1.3 1995/03/23 08:30:32 cgd Exp $";
10 #include "def.mkroom.h"
12 extern struct monst
*restmonchn();
13 extern struct obj
*restobjchn();
14 extern struct obj
*billobjs
;
23 extern struct wseg
*wsegs
[32], *wheads
[32];
24 extern long wgrowtime
[32];
27 boolean level_exists
[MAXLEVEL
+1];
34 register struct wseg
*wtmp
, *wtmp2
;
38 if(fd
< 0) panic("Save on bad file!"); /* impossible */
39 if(lev
>= 0 && lev
<= MAXLEVEL
)
40 level_exists
[lev
] = TRUE
;
42 bwrite(fd
,(char *) &hackpid
,sizeof(hackpid
));
43 bwrite(fd
,(char *) &lev
,sizeof(lev
));
44 bwrite(fd
,(char *) levl
,sizeof(levl
));
45 bwrite(fd
,(char *) &moves
,sizeof(long));
46 bwrite(fd
,(char *) &xupstair
,sizeof(xupstair
));
47 bwrite(fd
,(char *) &yupstair
,sizeof(yupstair
));
48 bwrite(fd
,(char *) &xdnstair
,sizeof(xdnstair
));
49 bwrite(fd
,(char *) &ydnstair
,sizeof(ydnstair
));
51 savegoldchn(fd
, fgold
);
52 savetrapchn(fd
, ftrap
);
54 saveobjchn(fd
, billobjs
);
58 bwrite(fd
,(char *) rooms
,sizeof(rooms
));
59 bwrite(fd
,(char *) doors
,sizeof(doors
));
66 bwrite(fd
,(char *) wsegs
,sizeof(wsegs
));
67 for(tmp
=1; tmp
<32; tmp
++){
68 for(wtmp
= wsegs
[tmp
]; wtmp
; wtmp
= wtmp2
){
70 bwrite(fd
,(char *) wtmp
,sizeof(struct wseg
));
74 bwrite(fd
,(char *) wgrowtime
,sizeof(wgrowtime
));
81 register unsigned num
;
83 /* lint wants the 3rd arg of write to be an int; lint -p an unsigned */
84 if(write(fd
, loc
, (int) num
) != num
)
85 panic("cannot write %u bytes to file #%d", num
, fd
);
90 register struct obj
*otmp
;
92 register struct obj
*otmp2
;
99 bwrite(fd
, (char *) &xl
, sizeof(int));
100 bwrite(fd
, (char *) otmp
, xl
+ sizeof(struct obj
));
104 bwrite(fd
, (char *) &minusone
, sizeof(int));
109 register struct monst
*mtmp
;
111 register struct monst
*mtmp2
;
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
));
123 if(mtmp
->minvent
) saveobjchn(fd
,mtmp
->minvent
);
127 bwrite(fd
, (char *) &minusone
, sizeof(int));
132 register struct gold
*gold
;
134 register struct gold
*gold2
;
137 bwrite(fd
, (char *) gold
, sizeof(struct gold
));
141 bwrite(fd
, nul
, sizeof(struct gold
));
146 register struct trap
*trap
;
148 register struct trap
*trap2
;
151 bwrite(fd
, (char *) trap
, sizeof(struct trap
));
155 bwrite(fd
, nul
, sizeof(struct trap
));
162 register struct gold
*gold
;
163 register struct trap
*trap
;
165 register struct wseg
*wtmp
;
172 /* First some sanity checks */
173 mread(fd
, (char *) &hpid
, sizeof(hpid
));
174 mread(fd
, (char *) &dlvl
, sizeof(dlvl
));
175 if((pid
&& pid
!= hpid
) || (lev
&& dlvl
!= lev
)) {
176 pline("Strange, this map is not as I remember it.");
177 pline("Somebody is trying some trickery here ...");
178 pline("This game is void ...");
184 mread(fd
, (char *) levl
, sizeof(levl
));
185 mread(fd
, (char *)&omoves
, sizeof(omoves
));
186 mread(fd
, (char *)&xupstair
, sizeof(xupstair
));
187 mread(fd
, (char *)&yupstair
, sizeof(yupstair
));
188 mread(fd
, (char *)&xdnstair
, sizeof(xdnstair
));
189 mread(fd
, (char *)&ydnstair
, sizeof(ydnstair
));
191 fmon
= restmonchn(fd
);
193 /* regenerate animals while on another level */
194 { long tmoves
= (moves
> omoves
) ? moves
-omoves
: 0;
195 register struct monst
*mtmp
, *mtmp2
;
196 extern char genocided
[];
198 for(mtmp
= fmon
; mtmp
; mtmp
= mtmp2
) {
199 long newhp
; /* tmoves may be very large */
202 if(index(genocided
, mtmp
->data
->mlet
)) {
207 if(mtmp
->mtame
&& tmoves
> 250) {
213 (index(MREGEN
, mtmp
->data
->mlet
) ? tmoves
: tmoves
/20);
214 if(newhp
> mtmp
->mhpmax
)
215 mtmp
->mhp
= mtmp
->mhpmax
;
223 mread(fd
, (char *)gold
, sizeof(struct gold
));
228 mread(fd
, (char *)gold
, sizeof(struct gold
));
232 mread(fd
, (char *)trap
, sizeof(struct trap
));
237 mread(fd
, (char *)trap
, sizeof(struct trap
));
240 fobj
= restobjchn(fd
);
241 billobjs
= restobjchn(fd
);
244 mread(fd
, (char *)rooms
, sizeof(rooms
));
245 mread(fd
, (char *)doors
, sizeof(doors
));
248 mread(fd
, (char *)wsegs
, sizeof(wsegs
));
249 for(tmp
= 1; tmp
< 32; tmp
++) if(wsegs
[tmp
]){
250 wheads
[tmp
] = wsegs
[tmp
] = wtmp
= newseg();
252 mread(fd
, (char *)wtmp
, sizeof(struct wseg
));
253 if(!wtmp
->nseg
) break;
254 wheads
[tmp
]->nseg
= wtmp
= newseg();
258 mread(fd
, (char *)wgrowtime
, sizeof(wgrowtime
));
265 register unsigned len
;
268 extern boolean restoring
;
270 rlen
= read(fd
, buf
, (int) len
);
272 pline("Read %d instead of %u bytes.\n", rlen
, len
);
274 (void) unlink(SAVEF
);
275 error("Error restoring old game.");
277 panic("Error reading level file.");
283 extern boolean in_mklev
;
285 if(getbones()) return;