1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.save.c - version 1.0.3 */
6 extern char genocided[60]; /* defined in Decl.c */
7 extern char fut_geno[60]; /* idem */
11 extern char SAVEF[], nul[];
12 extern char pl_character[PL_CSIZ];
13 extern struct obj *restobjchn();
14 extern struct monst *restmonchn();
18 settty("Be seeing you ...\n");
26 #ifndef NOSAVEONHANGUP
33 /* returns 1 if save successful */
38 (void) signal(SIGHUP, SIG_IGN);
39 (void) signal(SIGINT, SIG_IGN);
40 if((fd = creat(SAVEF, FMASK)) < 0) {
41 if(!hu) pline("Cannot open save file. (Continue or Quit)");
42 (void) unlink(SAVEF); /* ab@unido */
45 if(flags.moonphase == FULL_MOON) /* ut-sally!fletcher */
46 u.uluck--; /* and unido!ab */
48 saveobjchn(fd, invent);
49 saveobjchn(fd, fcobj);
50 savemonchn(fd, fallen_down);
52 bwrite(fd, (char *) &tmp, sizeof tmp);
53 bwrite(fd, (char *) &flags, sizeof(struct flag));
54 bwrite(fd, (char *) &dlevel, sizeof dlevel);
55 bwrite(fd, (char *) &maxdlevel, sizeof maxdlevel);
56 bwrite(fd, (char *) &moves, sizeof moves);
57 bwrite(fd, (char *) &u, sizeof(struct you));
59 bwrite(fd, (char *) &(u.ustuck->m_id), sizeof u.ustuck->m_id);
60 bwrite(fd, (char *) pl_character, sizeof pl_character);
61 bwrite(fd, (char *) genocided, sizeof genocided);
62 bwrite(fd, (char *) fut_geno, sizeof fut_geno);
64 for(tmp = 1; tmp <= maxdlevel; tmp++) {
66 extern boolean level_exists[];
68 if(tmp == dlevel || !level_exists[tmp]) continue;
70 if((ofd = open(lock, 0)) < 0) {
71 if(!hu) pline("Error while saving: cannot read %s.", lock);
74 if(!hu) done("tricked");
77 getlev(ofd, hackpid, tmp);
79 bwrite(fd, (char *) &tmp, sizeof tmp); /* level number */
80 savelev(fd,tmp); /* actual level */
85 (void) unlink(lock); /* get rid of current level --jgm */
95 int tmp; /* not a ! */
96 unsigned mid; /* idem */
98 extern boolean restoring;
102 invent = restobjchn(fd);
103 for(otmp = invent; otmp; otmp = otmp->nobj)
105 setworn(otmp, otmp->owornmask);
106 fcobj = restobjchn(fd);
107 fallen_down = restmonchn(fd);
108 mread(fd, (char *) &tmp, sizeof tmp);
109 if(tmp != getuid()) { /* strange ... */
111 (void) unlink(SAVEF);
112 puts("Saved game was not yours.");
116 mread(fd, (char *) &flags, sizeof(struct flag));
117 mread(fd, (char *) &dlevel, sizeof dlevel);
118 mread(fd, (char *) &maxdlevel, sizeof maxdlevel);
119 mread(fd, (char *) &moves, sizeof moves);
120 mread(fd, (char *) &u, sizeof(struct you));
122 mread(fd, (char *) &mid, sizeof mid);
123 mread(fd, (char *) pl_character, sizeof pl_character);
124 mread(fd, (char *) genocided, sizeof genocided);
125 mread(fd, (char *) fut_geno, sizeof fut_geno);
128 if(read(fd, (char *) &tmp, sizeof tmp) != sizeof tmp)
132 if((nfd = creat(lock, FMASK)) < 0)
133 panic("Cannot open temp file %s!\n", lock);
137 (void) lseek(fd, (off_t)0, 0);
140 (void) unlink(SAVEF);
142 for(otmp = fobj; otmp; otmp = otmp->nobj)
143 if(otmp->olet == CHAIN_SYM) goto chainfnd;
144 panic("Cannot find the iron chain?");
148 for(otmp = fobj; otmp; otmp = otmp->nobj)
149 if(otmp->olet == BALL_SYM && otmp->spe)
151 panic("Cannot find the iron ball?");
159 for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
160 if(mtmp->m_id == mid) goto monfnd;
161 panic("Cannot find the monster ustuck.");
166 setsee(); /* only to recompute seelx etc. - these weren't saved */
177 struct obj *otmp, *otmp2;
178 struct obj *first = 0;
181 /* suppress "used before set" warning from lint */
185 mread(fd, (char *) &xl, sizeof(xl));
188 if(!first) first = otmp;
189 else otmp2->nobj = otmp;
190 mread(fd, (char *) otmp, (unsigned) xl + sizeof(struct obj));
191 if(!otmp->o_id) otmp->o_id = flags.ident++;
194 if(first && otmp2->nobj){
195 impossible("Restobjchn: error reading objchn.");
205 struct monst *mtmp, *mtmp2;
206 struct monst *first = 0;
209 struct permonst *monbegin;
212 mread(fd, (char *)&monbegin, sizeof(monbegin));
213 differ = (char *)(&mons[0]) - (char *)(monbegin);
216 /* suppress "used before set" warning from lint */
220 mread(fd, (char *) &xl, sizeof(xl));
223 if(!first) first = mtmp;
224 else mtmp2->nmon = mtmp;
225 mread(fd, (char *) mtmp, (unsigned) xl + sizeof(struct monst));
227 mtmp->m_id = flags.ident++;
228 mtmp->data = (struct permonst *)
229 ((char *) mtmp->data + differ);
231 mtmp->minvent = restobjchn(fd);
234 if(first && mtmp2->nmon){
235 impossible("Restmonchn: error reading monchn.");