]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.save.c
2 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
6 static char rcsid
[] = "$NetBSD: hack.save.c,v 1.5 1995/03/23 08:31:27 cgd Exp $";
10 extern char genocided
[60]; /* defined in Decl.c */
11 extern char fut_geno
[60]; /* idem */
15 extern char SAVEF
[], nul
[];
16 extern char pl_character
[PL_CSIZ
];
17 extern struct obj
*restobjchn();
18 extern struct monst
*restmonchn();
22 settty("Be seeing you ...\n");
30 #ifndef NOSAVEONHANGUP
37 /* returns 1 if save successful */
40 int tmp
; /* not register ! */
42 (void) signal(SIGHUP
, SIG_IGN
);
43 (void) signal(SIGINT
, SIG_IGN
);
44 if((fd
= creat(SAVEF
, FMASK
)) < 0) {
45 if(!hu
) pline("Cannot open save file. (Continue or Quit)");
46 (void) unlink(SAVEF
); /* ab@unido */
49 if(flags
.moonphase
== FULL_MOON
) /* ut-sally!fletcher */
50 u
.uluck
--; /* and unido!ab */
52 saveobjchn(fd
, invent
);
53 saveobjchn(fd
, fcobj
);
54 savemonchn(fd
, fallen_down
);
56 bwrite(fd
, (char *) &tmp
, sizeof tmp
);
57 bwrite(fd
, (char *) &flags
, sizeof(struct flag
));
58 bwrite(fd
, (char *) &dlevel
, sizeof dlevel
);
59 bwrite(fd
, (char *) &maxdlevel
, sizeof maxdlevel
);
60 bwrite(fd
, (char *) &moves
, sizeof moves
);
61 bwrite(fd
, (char *) &u
, sizeof(struct you
));
63 bwrite(fd
, (char *) &(u
.ustuck
->m_id
), sizeof u
.ustuck
->m_id
);
64 bwrite(fd
, (char *) pl_character
, sizeof pl_character
);
65 bwrite(fd
, (char *) genocided
, sizeof genocided
);
66 bwrite(fd
, (char *) fut_geno
, sizeof fut_geno
);
68 for(tmp
= 1; tmp
<= maxdlevel
; tmp
++) {
70 extern boolean level_exists
[];
72 if(tmp
== dlevel
|| !level_exists
[tmp
]) continue;
74 if((ofd
= open(lock
, 0)) < 0) {
75 if(!hu
) pline("Error while saving: cannot read %s.", lock
);
78 if(!hu
) done("tricked");
81 getlev(ofd
, hackpid
, tmp
);
83 bwrite(fd
, (char *) &tmp
, sizeof tmp
); /* level number */
84 savelev(fd
,tmp
); /* actual level */
89 (void) unlink(lock
); /* get rid of current level --jgm */
99 int tmp
; /* not a register ! */
100 unsigned mid
; /* idem */
102 extern boolean restoring
;
106 invent
= restobjchn(fd
);
107 for(otmp
= invent
; otmp
; otmp
= otmp
->nobj
)
109 setworn(otmp
, otmp
->owornmask
);
110 fcobj
= restobjchn(fd
);
111 fallen_down
= restmonchn(fd
);
112 mread(fd
, (char *) &tmp
, sizeof tmp
);
113 if(tmp
!= getuid()) { /* strange ... */
115 (void) unlink(SAVEF
);
116 puts("Saved game was not yours.");
120 mread(fd
, (char *) &flags
, sizeof(struct flag
));
121 mread(fd
, (char *) &dlevel
, sizeof dlevel
);
122 mread(fd
, (char *) &maxdlevel
, sizeof maxdlevel
);
123 mread(fd
, (char *) &moves
, sizeof moves
);
124 mread(fd
, (char *) &u
, sizeof(struct you
));
126 mread(fd
, (char *) &mid
, sizeof mid
);
127 mread(fd
, (char *) pl_character
, sizeof pl_character
);
128 mread(fd
, (char *) genocided
, sizeof genocided
);
129 mread(fd
, (char *) fut_geno
, sizeof fut_geno
);
132 if(read(fd
, (char *) &tmp
, sizeof tmp
) != sizeof tmp
)
136 if((nfd
= creat(lock
, FMASK
)) < 0)
137 panic("Cannot open temp file %s!\n", lock
);
141 (void) lseek(fd
, (off_t
)0, 0);
144 (void) unlink(SAVEF
);
146 for(otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
147 if(otmp
->olet
== CHAIN_SYM
) goto chainfnd
;
148 panic("Cannot find the iron chain?");
152 for(otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
153 if(otmp
->olet
== BALL_SYM
&& otmp
->spe
)
155 panic("Cannot find the iron ball?");
161 register struct monst
*mtmp
;
163 for(mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
164 if(mtmp
->m_id
== mid
) goto monfnd
;
165 panic("Cannot find the monster ustuck.");
170 setsee(); /* only to recompute seelx etc. - these weren't saved */
181 register struct obj
*otmp
, *otmp2
;
182 register struct obj
*first
= 0;
185 /* suppress "used before set" warning from lint */
189 mread(fd
, (char *) &xl
, sizeof(xl
));
192 if(!first
) first
= otmp
;
193 else otmp2
->nobj
= otmp
;
194 mread(fd
, (char *) otmp
, (unsigned) xl
+ sizeof(struct obj
));
195 if(!otmp
->o_id
) otmp
->o_id
= flags
.ident
++;
198 if(first
&& otmp2
->nobj
){
199 impossible("Restobjchn: error reading objchn.");
209 register struct monst
*mtmp
, *mtmp2
;
210 register struct monst
*first
= 0;
213 struct permonst
*monbegin
;
216 mread(fd
, (char *)&monbegin
, sizeof(monbegin
));
217 differ
= (char *)(&mons
[0]) - (char *)(monbegin
);
220 /* suppress "used before set" warning from lint */
224 mread(fd
, (char *) &xl
, sizeof(xl
));
227 if(!first
) first
= mtmp
;
228 else mtmp2
->nmon
= mtmp
;
229 mread(fd
, (char *) mtmp
, (unsigned) xl
+ sizeof(struct monst
));
231 mtmp
->m_id
= flags
.ident
++;
232 mtmp
->data
= (struct permonst
*)
233 ((char *) mtmp
->data
+ differ
);
235 mtmp
->minvent
= restobjchn(fd
);
238 if(first
&& mtmp2
->nmon
){
239 impossible("Restmonchn: error reading monchn.");