xref: /netbsd-src/games/battlestar/save.c (revision 76dfffe33547c37f8bdd446e3e4ab0f3c16cea4b)
1 /*	$NetBSD: save.c,v 1.3 1995/03/21 15:07:57 cgd Exp $	*/
2 
3 /*
4  * Copyright (c) 1983, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the University of
18  *	California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  */
35 
36 #ifndef lint
37 #if 0
38 static char sccsid[] = "@(#)save.c	8.1 (Berkeley) 5/31/93";
39 #else
40 static char rcsid[] = "$NetBSD: save.c,v 1.3 1995/03/21 15:07:57 cgd Exp $";
41 #endif
42 #endif /* not lint */
43 
44 #include "externs.h"
45 
46 restore()
47 {
48 	char *getenv();
49 	char *home;
50 	char home1[100];
51 	register int n;
52 	int tmp;
53 	register FILE *fp;
54 
55 	home = getenv("HOME");
56 	strcpy(home1, home);
57 	strcat(home1, "/Bstar");
58 	if ((fp = fopen(home1, "r")) == 0) {
59 		perror(home1);
60 		return;
61 	}
62 	fread(&WEIGHT, sizeof WEIGHT, 1, fp);
63 	fread(&CUMBER, sizeof CUMBER, 1, fp);
64 	fread(&clock, sizeof clock, 1, fp);
65 	fread(&tmp, sizeof tmp, 1, fp);
66 	location = tmp ? dayfile : nightfile;
67 	for (n = 1; n <= NUMOFROOMS; n++) {
68 		fread(location[n].link, sizeof location[n].link, 1, fp);
69 		fread(location[n].objects, sizeof location[n].objects, 1, fp);
70 	}
71 	fread(inven, sizeof inven, 1, fp);
72 	fread(wear, sizeof wear, 1, fp);
73 	fread(injuries, sizeof injuries, 1, fp);
74 	fread(notes, sizeof notes, 1, fp);
75 	fread(&direction, sizeof direction, 1, fp);
76 	fread(&position, sizeof position, 1, fp);
77 	fread(&time, sizeof time, 1, fp);
78 	fread(&fuel, sizeof fuel, 1, fp);
79 	fread(&torps, sizeof torps, 1, fp);
80 	fread(&carrying, sizeof carrying, 1, fp);
81 	fread(&encumber, sizeof encumber, 1, fp);
82 	fread(&rythmn, sizeof rythmn, 1, fp);
83 	fread(&followfight, sizeof followfight, 1, fp);
84 	fread(&ate, sizeof ate, 1, fp);
85 	fread(&snooze, sizeof snooze, 1, fp);
86 	fread(&meetgirl, sizeof meetgirl, 1, fp);
87 	fread(&followgod, sizeof followgod, 1, fp);
88 	fread(&godready, sizeof godready, 1, fp);
89 	fread(&win, sizeof win, 1, fp);
90 	fread(&wintime, sizeof wintime, 1, fp);
91 	fread(&matchlight, sizeof matchlight, 1, fp);
92 	fread(&matchcount, sizeof matchcount, 1, fp);
93 	fread(&loved, sizeof loved, 1, fp);
94 	fread(&pleasure, sizeof pleasure, 1, fp);
95 	fread(&power, sizeof power, 1, fp);
96 	fread(&ego, sizeof ego, 1, fp);
97 }
98 
99 save()
100 {
101 	char *getenv();
102 	char *home;
103 	char home1[100];
104 	register int n;
105 	int tmp;
106 	FILE *fp;
107 
108 	home = getenv("HOME");
109 	strcpy(home1, home);
110 	strcat(home1, "/Bstar");
111 	if ((fp = fopen(home1, "w")) == 0) {
112 		perror(home1);
113 		return;
114 	}
115 	printf("Saved in %s.\n", home1);
116 	fwrite(&WEIGHT, sizeof WEIGHT, 1, fp);
117 	fwrite(&CUMBER, sizeof CUMBER, 1, fp);
118 	fwrite(&clock, sizeof clock, 1, fp);
119 	tmp = location == dayfile;
120 	fwrite(&tmp, sizeof tmp, 1, fp);
121 	for (n = 1; n <= NUMOFROOMS; n++) {
122 		fwrite(location[n].link, sizeof location[n].link, 1, fp);
123 		fwrite(location[n].objects, sizeof location[n].objects, 1, fp);
124 	}
125 	fwrite(inven, sizeof inven, 1, fp);
126 	fwrite(wear, sizeof wear, 1, fp);
127 	fwrite(injuries, sizeof injuries, 1, fp);
128 	fwrite(notes, sizeof notes, 1, fp);
129 	fwrite(&direction, sizeof direction, 1, fp);
130 	fwrite(&position, sizeof position, 1, fp);
131 	fwrite(&time, sizeof time, 1, fp);
132 	fwrite(&fuel, sizeof fuel, 1, fp);
133 	fwrite(&torps, sizeof torps, 1, fp);
134 	fwrite(&carrying, sizeof carrying, 1, fp);
135 	fwrite(&encumber, sizeof encumber, 1, fp);
136 	fwrite(&rythmn, sizeof rythmn, 1, fp);
137 	fwrite(&followfight, sizeof followfight, 1, fp);
138 	fwrite(&ate, sizeof ate, 1, fp);
139 	fwrite(&snooze, sizeof snooze, 1, fp);
140 	fwrite(&meetgirl, sizeof meetgirl, 1, fp);
141 	fwrite(&followgod, sizeof followgod, 1, fp);
142 	fwrite(&godready, sizeof godready, 1, fp);
143 	fwrite(&win, sizeof win, 1, fp);
144 	fwrite(&wintime, sizeof wintime, 1, fp);
145 	fwrite(&matchlight, sizeof matchlight, 1, fp);
146 	fwrite(&matchcount, sizeof matchcount, 1, fp);
147 	fwrite(&loved, sizeof loved, 1, fp);
148 	fwrite(&pleasure, sizeof pleasure, 1, fp);
149 	fwrite(&power, sizeof power, 1, fp);
150 	fwrite(&ego, sizeof ego, 1, fp);
151 }
152