xref: /original-bsd/games/battlestar/save.c (revision f1656be1)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12 
13 #ifndef lint
14 static char sccsid[] = "@(#)save.c	5.1 (Berkeley) 05/08/88";
15 #endif /* not lint */
16 
17 #include "externs.h"
18 
19 restore()
20 {
21 	char *getenv();
22 	char *home;
23 	char home1[100];
24 	register int n;
25 	int tmp;
26 	register FILE *fp;
27 
28 	home = getenv("HOME");
29 	strcpy(home1, home);
30 	strcat(home1, "/Bstar");
31 	if ((fp = fopen(home1, "r")) == 0) {
32 		perror(home1);
33 		return;
34 	}
35 	fread(&WEIGHT, sizeof WEIGHT, 1, fp);
36 	fread(&CUMBER, sizeof CUMBER, 1, fp);
37 	fread(&clock, sizeof clock, 1, fp);
38 	fread(&tmp, sizeof tmp, 1, fp);
39 	location = tmp ? dayfile : nightfile;
40 	for (n = 1; n <= NUMOFROOMS; n++) {
41 		fread(location[n].link, sizeof location[n].link, 1, fp);
42 		fread(location[n].objects, sizeof location[n].objects, 1, fp);
43 	}
44 	fread(inven, sizeof inven, 1, fp);
45 	fread(wear, sizeof wear, 1, fp);
46 	fread(injuries, sizeof injuries, 1, fp);
47 	fread(notes, sizeof notes, 1, fp);
48 	fread(&direction, sizeof direction, 1, fp);
49 	fread(&position, sizeof position, 1, fp);
50 	fread(&time, sizeof time, 1, fp);
51 	fread(&fuel, sizeof fuel, 1, fp);
52 	fread(&torps, sizeof torps, 1, fp);
53 	fread(&carrying, sizeof carrying, 1, fp);
54 	fread(&encumber, sizeof encumber, 1, fp);
55 	fread(&rythmn, sizeof rythmn, 1, fp);
56 	fread(&followfight, sizeof followfight, 1, fp);
57 	fread(&ate, sizeof ate, 1, fp);
58 	fread(&snooze, sizeof snooze, 1, fp);
59 	fread(&meetgirl, sizeof meetgirl, 1, fp);
60 	fread(&followgod, sizeof followgod, 1, fp);
61 	fread(&godready, sizeof godready, 1, fp);
62 	fread(&win, sizeof win, 1, fp);
63 	fread(&wintime, sizeof wintime, 1, fp);
64 	fread(&matchlight, sizeof matchlight, 1, fp);
65 	fread(&matchcount, sizeof matchcount, 1, fp);
66 	fread(&loved, sizeof loved, 1, fp);
67 	fread(&pleasure, sizeof pleasure, 1, fp);
68 	fread(&power, sizeof power, 1, fp);
69 	fread(&ego, sizeof ego, 1, fp);
70 }
71 
72 save()
73 {
74 	char *getenv();
75 	char *home;
76 	char home1[100];
77 	register int n;
78 	int tmp;
79 	FILE *fp;
80 
81 	home = getenv("HOME");
82 	strcpy(home1, home);
83 	strcat(home1, "/Bstar");
84 	if ((fp = fopen(home1, "w")) == 0) {
85 		perror(home1);
86 		return;
87 	}
88 	printf("Saved in %s.\n", home1);
89 	fwrite(&WEIGHT, sizeof WEIGHT, 1, fp);
90 	fwrite(&CUMBER, sizeof CUMBER, 1, fp);
91 	fwrite(&clock, sizeof clock, 1, fp);
92 	tmp = location == dayfile;
93 	fwrite(&tmp, sizeof tmp, 1, fp);
94 	for (n = 1; n <= NUMOFROOMS; n++) {
95 		fwrite(location[n].link, sizeof location[n].link, 1, fp);
96 		fwrite(location[n].objects, sizeof location[n].objects, 1, fp);
97 	}
98 	fwrite(inven, sizeof inven, 1, fp);
99 	fwrite(wear, sizeof wear, 1, fp);
100 	fwrite(injuries, sizeof injuries, 1, fp);
101 	fwrite(notes, sizeof notes, 1, fp);
102 	fwrite(&direction, sizeof direction, 1, fp);
103 	fwrite(&position, sizeof position, 1, fp);
104 	fwrite(&time, sizeof time, 1, fp);
105 	fwrite(&fuel, sizeof fuel, 1, fp);
106 	fwrite(&torps, sizeof torps, 1, fp);
107 	fwrite(&carrying, sizeof carrying, 1, fp);
108 	fwrite(&encumber, sizeof encumber, 1, fp);
109 	fwrite(&rythmn, sizeof rythmn, 1, fp);
110 	fwrite(&followfight, sizeof followfight, 1, fp);
111 	fwrite(&ate, sizeof ate, 1, fp);
112 	fwrite(&snooze, sizeof snooze, 1, fp);
113 	fwrite(&meetgirl, sizeof meetgirl, 1, fp);
114 	fwrite(&followgod, sizeof followgod, 1, fp);
115 	fwrite(&godready, sizeof godready, 1, fp);
116 	fwrite(&win, sizeof win, 1, fp);
117 	fwrite(&wintime, sizeof wintime, 1, fp);
118 	fwrite(&matchlight, sizeof matchlight, 1, fp);
119 	fwrite(&matchcount, sizeof matchcount, 1, fp);
120 	fwrite(&loved, sizeof loved, 1, fp);
121 	fwrite(&pleasure, sizeof pleasure, 1, fp);
122 	fwrite(&power, sizeof power, 1, fp);
123 	fwrite(&ego, sizeof ego, 1, fp);
124 }
125