]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.save.c
2 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
6 static char rcsid
[] = "$Id: hack.save.c,v 1.4 1994/03/28 11:21:12 cgd Exp $";
10 extern char genocided
[60]; /* defined in Decl.c */
11 extern char fut_geno
[60]; /* idem */
14 extern char SAVEF
[], nul
[];
15 extern char pl_character
[PL_CSIZ
];
16 extern struct obj
*restobjchn();
17 extern struct monst
*restmonchn();
21 settty("Be seeing you ...\n");
29 #ifndef NOSAVEONHANGUP
36 /* returns 1 if save successful */
39 int tmp
; /* not register ! */
41 (void) signal(SIGHUP
, SIG_IGN
);
42 (void) signal(SIGINT
, SIG_IGN
);
43 if((fd
= creat(SAVEF
, FMASK
)) < 0) {
44 if(!hu
) pline("Cannot open save file. (Continue or Quit)");
45 (void) unlink(SAVEF
); /* ab@unido */
48 if(flags
.moonphase
== FULL_MOON
) /* ut-sally!fletcher */
49 u
.uluck
--; /* and unido!ab */
51 saveobjchn(fd
, invent
);
52 saveobjchn(fd
, fcobj
);
53 savemonchn(fd
, fallen_down
);
55 bwrite(fd
, (char *) &tmp
, sizeof tmp
);
56 bwrite(fd
, (char *) &flags
, sizeof(struct flag
));
57 bwrite(fd
, (char *) &dlevel
, sizeof dlevel
);
58 bwrite(fd
, (char *) &maxdlevel
, sizeof maxdlevel
);
59 bwrite(fd
, (char *) &moves
, sizeof moves
);
60 bwrite(fd
, (char *) &u
, sizeof(struct you
));
62 bwrite(fd
, (char *) &(u
.ustuck
->m_id
), sizeof u
.ustuck
->m_id
);
63 bwrite(fd
, (char *) pl_character
, sizeof pl_character
);
64 bwrite(fd
, (char *) genocided
, sizeof genocided
);
65 bwrite(fd
, (char *) fut_geno
, sizeof fut_geno
);
67 for(tmp
= 1; tmp
<= maxdlevel
; tmp
++) {
69 extern boolean level_exists
[];
71 if(tmp
== dlevel
|| !level_exists
[tmp
]) continue;
73 if((ofd
= open(lock
, 0)) < 0) {
74 if(!hu
) pline("Error while saving: cannot read %s.", lock
);
77 if(!hu
) done("tricked");
80 getlev(ofd
, hackpid
, tmp
);
82 bwrite(fd
, (char *) &tmp
, sizeof tmp
); /* level number */
83 savelev(fd
,tmp
); /* actual level */
88 (void) unlink(lock
); /* get rid of current level --jgm */
98 int tmp
; /* not a register ! */
99 unsigned mid
; /* idem */
101 extern boolean restoring
;
105 invent
= restobjchn(fd
);
106 for(otmp
= invent
; otmp
; otmp
= otmp
->nobj
)
108 setworn(otmp
, otmp
->owornmask
);
109 fcobj
= restobjchn(fd
);
110 fallen_down
= restmonchn(fd
);
111 mread(fd
, (char *) &tmp
, sizeof tmp
);
112 if(tmp
!= getuid()) { /* strange ... */
114 (void) unlink(SAVEF
);
115 puts("Saved game was not yours.");
119 mread(fd
, (char *) &flags
, sizeof(struct flag
));
120 mread(fd
, (char *) &dlevel
, sizeof dlevel
);
121 mread(fd
, (char *) &maxdlevel
, sizeof maxdlevel
);
122 mread(fd
, (char *) &moves
, sizeof moves
);
123 mread(fd
, (char *) &u
, sizeof(struct you
));
125 mread(fd
, (char *) &mid
, sizeof mid
);
126 mread(fd
, (char *) pl_character
, sizeof pl_character
);
127 mread(fd
, (char *) genocided
, sizeof genocided
);
128 mread(fd
, (char *) fut_geno
, sizeof fut_geno
);
131 if(read(fd
, (char *) &tmp
, sizeof tmp
) != sizeof tmp
)
135 if((nfd
= creat(lock
, FMASK
)) < 0)
136 panic("Cannot open temp file %s!\n", lock
);
140 (void) lseek(fd
, 0, 0);
143 (void) unlink(SAVEF
);
145 for(otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
146 if(otmp
->olet
== CHAIN_SYM
) goto chainfnd
;
147 panic("Cannot find the iron chain?");
151 for(otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
152 if(otmp
->olet
== BALL_SYM
&& otmp
->spe
)
154 panic("Cannot find the iron ball?");
160 register struct monst
*mtmp
;
162 for(mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
163 if(mtmp
->m_id
== mid
) goto monfnd
;
164 panic("Cannot find the monster ustuck.");
169 setsee(); /* only to recompute seelx etc. - these weren't saved */
180 register struct obj
*otmp
, *otmp2
;
181 register struct obj
*first
= 0;
184 /* suppress "used before set" warning from lint */
188 mread(fd
, (char *) &xl
, sizeof(xl
));
191 if(!first
) first
= otmp
;
192 else otmp2
->nobj
= otmp
;
193 mread(fd
, (char *) otmp
, (unsigned) xl
+ sizeof(struct obj
));
194 if(!otmp
->o_id
) otmp
->o_id
= flags
.ident
++;
197 if(first
&& otmp2
->nobj
){
198 impossible("Restobjchn: error reading objchn.");
208 register struct monst
*mtmp
, *mtmp2
;
209 register struct monst
*first
= 0;
212 struct permonst
*monbegin
;
215 mread(fd
, (char *)&monbegin
, sizeof(monbegin
));
216 differ
= (char *)(&mons
[0]) - (char *)(monbegin
);
219 /* suppress "used before set" warning from lint */
223 mread(fd
, (char *) &xl
, sizeof(xl
));
226 if(!first
) first
= mtmp
;
227 else mtmp2
->nmon
= mtmp
;
228 mread(fd
, (char *) mtmp
, (unsigned) xl
+ sizeof(struct monst
));
230 mtmp
->m_id
= flags
.ident
++;
231 mtmp
->data
= (struct permonst
*)
232 ((char *) mtmp
->data
+ differ
);
234 mtmp
->minvent
= restobjchn(fd
);
237 if(first
&& mtmp2
->nmon
){
238 impossible("Restmonchn: error reading monchn.");