]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.save.c
fe09e1e72e1e84d6735f293cbe99a4d9b18b1fbb
1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.save.c - version 1.0.3 */
5 extern char genocided
[60]; /* defined in Decl.c */
6 extern char fut_geno
[60]; /* idem */
9 extern char SAVEF
[], nul
[];
10 extern char pl_character
[PL_CSIZ
];
12 extern struct obj
*restobjchn();
13 extern struct monst
*restmonchn();
17 settty("Be seeing you ...\n");
25 #ifndef NOSAVEONHANGUP
32 /* returns 1 if save successful */
35 int tmp
; /* not register ! */
37 (void) signal(SIGHUP
, SIG_IGN
);
38 (void) signal(SIGINT
, SIG_IGN
);
39 if((fd
= creat(SAVEF
, FMASK
)) < 0) {
40 if(!hu
) pline("Cannot open save file. (Continue or Quit)");
41 (void) unlink(SAVEF
); /* ab@unido */
44 if(flags
.moonphase
== FULL_MOON
) /* ut-sally!fletcher */
45 u
.uluck
--; /* and unido!ab */
47 saveobjchn(fd
, invent
);
48 saveobjchn(fd
, fcobj
);
49 savemonchn(fd
, fallen_down
);
51 bwrite(fd
, (char *) &tmp
, sizeof tmp
);
52 bwrite(fd
, (char *) &flags
, sizeof(struct flag
));
53 bwrite(fd
, (char *) &dlevel
, sizeof dlevel
);
54 bwrite(fd
, (char *) &maxdlevel
, sizeof maxdlevel
);
55 bwrite(fd
, (char *) &moves
, sizeof moves
);
56 bwrite(fd
, (char *) &u
, sizeof(struct you
));
58 bwrite(fd
, (char *) &(u
.ustuck
->m_id
), sizeof u
.ustuck
->m_id
);
59 bwrite(fd
, (char *) pl_character
, sizeof pl_character
);
60 bwrite(fd
, (char *) genocided
, sizeof genocided
);
61 bwrite(fd
, (char *) fut_geno
, sizeof fut_geno
);
63 for(tmp
= 1; tmp
<= maxdlevel
; tmp
++) {
65 extern boolean level_exists
[];
67 if(tmp
== dlevel
|| !level_exists
[tmp
]) continue;
69 if((ofd
= open(lock
, 0)) < 0) {
70 if(!hu
) pline("Error while saving: cannot read %s.", lock
);
73 if(!hu
) done("tricked");
76 getlev(ofd
, hackpid
, tmp
);
78 bwrite(fd
, (char *) &tmp
, sizeof tmp
); /* level number */
79 savelev(fd
,tmp
); /* actual level */
84 (void) unlink(lock
); /* get rid of current level --jgm */
94 int tmp
; /* not a register ! */
95 unsigned mid
; /* idem */
97 extern boolean restoring
;
101 invent
= restobjchn(fd
);
102 for(otmp
= invent
; otmp
; otmp
= otmp
->nobj
)
104 setworn(otmp
, otmp
->owornmask
);
105 fcobj
= restobjchn(fd
);
106 fallen_down
= restmonchn(fd
);
107 mread(fd
, (char *) &tmp
, sizeof tmp
);
108 if(tmp
!= getuid()) { /* strange ... */
110 (void) unlink(SAVEF
);
111 puts("Saved game was not yours.");
115 mread(fd
, (char *) &flags
, sizeof(struct flag
));
116 mread(fd
, (char *) &dlevel
, sizeof dlevel
);
117 mread(fd
, (char *) &maxdlevel
, sizeof maxdlevel
);
118 mread(fd
, (char *) &moves
, sizeof moves
);
119 mread(fd
, (char *) &u
, sizeof(struct you
));
121 mread(fd
, (char *) &mid
, sizeof mid
);
122 mread(fd
, (char *) pl_character
, sizeof pl_character
);
123 mread(fd
, (char *) genocided
, sizeof genocided
);
124 mread(fd
, (char *) fut_geno
, sizeof fut_geno
);
127 if(read(fd
, (char *) &tmp
, sizeof tmp
) != sizeof tmp
)
131 if((nfd
= creat(lock
, FMASK
)) < 0)
132 panic("Cannot open temp file %s!\n", lock
);
136 (void) lseek(fd
, 0L, 0);
139 (void) unlink(SAVEF
);
141 for(otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
142 if(otmp
->olet
== CHAIN_SYM
) goto chainfnd
;
143 panic("Cannot find the iron chain?");
147 for(otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
148 if(otmp
->olet
== BALL_SYM
&& otmp
->spe
)
150 panic("Cannot find the iron ball?");
156 register struct monst
*mtmp
;
158 for(mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
159 if(mtmp
->m_id
== mid
) goto monfnd
;
160 panic("Cannot find the monster ustuck.");
165 setsee(); /* only to recompute seelx etc. - these weren't saved */
176 register struct obj
*otmp
, *otmp2
;
177 register struct obj
*first
= 0;
180 /* suppress "used before set" warning from lint */
184 mread(fd
, (char *) &xl
, sizeof(xl
));
187 if(!first
) first
= otmp
;
188 else otmp2
->nobj
= otmp
;
189 mread(fd
, (char *) otmp
, (unsigned) xl
+ sizeof(struct obj
));
190 if(!otmp
->o_id
) otmp
->o_id
= flags
.ident
++;
193 if(first
&& otmp2
->nobj
){
194 impossible("Restobjchn: error reading objchn.");
204 register struct monst
*mtmp
, *mtmp2
;
205 register struct monst
*first
= 0;
208 struct permonst
*monbegin
;
211 mread(fd
, (char *)&monbegin
, sizeof(monbegin
));
212 differ
= (char *)(&mons
[0]) - (char *)(monbegin
);
215 /* suppress "used before set" warning from lint */
219 mread(fd
, (char *) &xl
, sizeof(xl
));
222 if(!first
) first
= mtmp
;
223 else mtmp2
->nmon
= mtmp
;
224 mread(fd
, (char *) mtmp
, (unsigned) xl
+ sizeof(struct monst
));
226 mtmp
->m_id
= flags
.ident
++;
227 mtmp
->data
= (struct permonst
*)
228 ((char *) mtmp
->data
+ differ
);
230 mtmp
->minvent
= restobjchn(fd
);
233 if(first
&& mtmp2
->nmon
){
234 impossible("Restmonchn: error reading monchn.");