]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.save.c
1 /* $NetBSD: hack.save.c,v 1.7 2001/03/25 20:44:02 jsm Exp $ */
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
9 __RCSID("$NetBSD: hack.save.c,v 1.7 2001/03/25 20:44:02 jsm Exp $");
24 settty("Be seeing you ...\n");
30 #ifndef NOSAVEONHANGUP
33 int n
__attribute__((__unused__
));
38 #endif /* NOSAVEONHANGUP */
40 /* returns 1 if save successful */
48 (void) signal(SIGHUP
, SIG_IGN
);
49 (void) signal(SIGINT
, SIG_IGN
);
50 if ((fd
= creat(SAVEF
, FMASK
)) < 0) {
52 pline("Cannot open save file. (Continue or Quit)");
53 (void) unlink(SAVEF
); /* ab@unido */
56 if (flags
.moonphase
== FULL_MOON
) /* ut-sally!fletcher */
57 u
.uluck
--; /* and unido!ab */
59 saveobjchn(fd
, invent
);
60 saveobjchn(fd
, fcobj
);
61 savemonchn(fd
, fallen_down
);
63 bwrite(fd
, (char *) &tmp
, sizeof tmp
);
64 bwrite(fd
, (char *) &flags
, sizeof(struct flag
));
65 bwrite(fd
, (char *) &dlevel
, sizeof dlevel
);
66 bwrite(fd
, (char *) &maxdlevel
, sizeof maxdlevel
);
67 bwrite(fd
, (char *) &moves
, sizeof moves
);
68 bwrite(fd
, (char *) &u
, sizeof(struct you
));
70 bwrite(fd
, (char *) &(u
.ustuck
->m_id
), sizeof u
.ustuck
->m_id
);
71 bwrite(fd
, (char *) pl_character
, sizeof pl_character
);
72 bwrite(fd
, (char *) genocided
, sizeof genocided
);
73 bwrite(fd
, (char *) fut_geno
, sizeof fut_geno
);
75 for (tmp
= 1; tmp
<= maxdlevel
; tmp
++) {
77 if (tmp
== dlevel
|| !level_exists
[tmp
])
80 if ((ofd
= open(lock
, O_RDONLY
)) < 0) {
82 pline("Error while saving: cannot read %s.", lock
);
89 getlev(ofd
, hackpid
, tmp
);
91 bwrite(fd
, (char *) &tmp
, sizeof tmp
); /* level number */
92 savelev(fd
, tmp
); /* actual level */
97 (void) unlink(lock
); /* get rid of current level --jgm */
108 int tmp
; /* not a ! */
109 unsigned mid
; /* idem */
114 invent
= restobjchn(fd
);
115 for (otmp
= invent
; otmp
; otmp
= otmp
->nobj
)
117 setworn(otmp
, otmp
->owornmask
);
118 fcobj
= restobjchn(fd
);
119 fallen_down
= restmonchn(fd
);
120 mread(fd
, (char *) &tmp
, sizeof tmp
);
121 if (tmp
!= getuid()) { /* strange ... */
123 (void) unlink(SAVEF
);
124 puts("Saved game was not yours.");
128 mread(fd
, (char *) &flags
, sizeof(struct flag
));
129 mread(fd
, (char *) &dlevel
, sizeof dlevel
);
130 mread(fd
, (char *) &maxdlevel
, sizeof maxdlevel
);
131 mread(fd
, (char *) &moves
, sizeof moves
);
132 mread(fd
, (char *) &u
, sizeof(struct you
));
134 mread(fd
, (char *) &mid
, sizeof mid
);
135 mread(fd
, (char *) pl_character
, sizeof pl_character
);
136 mread(fd
, (char *) genocided
, sizeof genocided
);
137 mread(fd
, (char *) fut_geno
, sizeof fut_geno
);
140 if (read(fd
, (char *) &tmp
, sizeof tmp
) != sizeof tmp
)
144 if ((nfd
= creat(lock
, FMASK
)) < 0)
145 panic("Cannot open temp file %s!\n", lock
);
149 (void) lseek(fd
, (off_t
) 0, SEEK_SET
);
152 (void) unlink(SAVEF
);
154 for (otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
155 if (otmp
->olet
== CHAIN_SYM
)
157 panic("Cannot find the iron chain?");
161 for (otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
162 if (otmp
->olet
== BALL_SYM
&& otmp
->spe
)
164 panic("Cannot find the iron ball?");
172 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
173 if (mtmp
->m_id
== mid
)
175 panic("Cannot find the monster ustuck.");
180 setsee(); /* only to recompute seelx etc. - these
192 struct obj
*otmp
, *otmp2
= NULL
;
193 struct obj
*first
= 0;
196 mread(fd
, (char *) &xl
, sizeof(xl
));
204 mread(fd
, (char *) otmp
, (unsigned) xl
+ sizeof(struct obj
));
206 otmp
->o_id
= flags
.ident
++;
209 if (first
&& otmp2
->nobj
) {
210 impossible("Restobjchn: error reading objchn.");
220 struct monst
*mtmp
, *mtmp2
= NULL
;
221 struct monst
*first
= 0;
224 struct permonst
*monbegin
;
227 mread(fd
, (char *) &monbegin
, sizeof(monbegin
));
228 differ
= (const char *) (&mons
[0]) - (const char *) (monbegin
);
231 /* suppress "used before set" warning from lint */
235 mread(fd
, (char *) &xl
, sizeof(xl
));
243 mread(fd
, (char *) mtmp
, (unsigned) xl
+ sizeof(struct monst
));
245 mtmp
->m_id
= flags
.ident
++;
246 mtmp
->data
= (const struct permonst
*)
247 ((const char *) mtmp
->data
+ differ
);
249 mtmp
->minvent
= restobjchn(fd
);
252 if (first
&& mtmp2
->nmon
) {
253 impossible("Restmonchn: error reading monchn.");