date and time created 88/10/19 19:55:11 by bostic
[unix-history] / usr / src / games / battlestar / save.c
CommitLineData
fdc7d56f 1/*
e95fc82a
KB
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
28c5bacc
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
fdc7d56f
EW
16 */
17
e1b932c3 18#ifndef lint
28c5bacc 19static char sccsid[] = "@(#)save.c 5.2 (Berkeley) %G%";
e95fc82a 20#endif /* not lint */
e1b932c3
EW
21
22#include "externs.h"
23
24restore()
25{
26 char *getenv();
27 char *home;
28 char home1[100];
29 register int n;
30 int tmp;
31 register FILE *fp;
32
33 home = getenv("HOME");
34 strcpy(home1, home);
35 strcat(home1, "/Bstar");
36 if ((fp = fopen(home1, "r")) == 0) {
37 perror(home1);
38 return;
39 }
40 fread(&WEIGHT, sizeof WEIGHT, 1, fp);
41 fread(&CUMBER, sizeof CUMBER, 1, fp);
42 fread(&clock, sizeof clock, 1, fp);
d0c74d25
JB
43 fread(&tmp, sizeof tmp, 1, fp);
44 location = tmp ? dayfile : nightfile;
e1b932c3
EW
45 for (n = 1; n <= NUMOFROOMS; n++) {
46 fread(location[n].link, sizeof location[n].link, 1, fp);
47 fread(location[n].objects, sizeof location[n].objects, 1, fp);
48 }
49 fread(inven, sizeof inven, 1, fp);
50 fread(wear, sizeof wear, 1, fp);
51 fread(injuries, sizeof injuries, 1, fp);
52 fread(notes, sizeof notes, 1, fp);
53 fread(&direction, sizeof direction, 1, fp);
54 fread(&position, sizeof position, 1, fp);
55 fread(&time, sizeof time, 1, fp);
e1b932c3
EW
56 fread(&fuel, sizeof fuel, 1, fp);
57 fread(&torps, sizeof torps, 1, fp);
58 fread(&carrying, sizeof carrying, 1, fp);
59 fread(&encumber, sizeof encumber, 1, fp);
60 fread(&rythmn, sizeof rythmn, 1, fp);
61 fread(&followfight, sizeof followfight, 1, fp);
62 fread(&ate, sizeof ate, 1, fp);
63 fread(&snooze, sizeof snooze, 1, fp);
64 fread(&meetgirl, sizeof meetgirl, 1, fp);
65 fread(&followgod, sizeof followgod, 1, fp);
66 fread(&godready, sizeof godready, 1, fp);
67 fread(&win, sizeof win, 1, fp);
68 fread(&wintime, sizeof wintime, 1, fp);
69 fread(&matchlight, sizeof matchlight, 1, fp);
70 fread(&matchcount, sizeof matchcount, 1, fp);
71 fread(&loved, sizeof loved, 1, fp);
72 fread(&pleasure, sizeof pleasure, 1, fp);
73 fread(&power, sizeof power, 1, fp);
74 fread(&ego, sizeof ego, 1, fp);
75}
76
77save()
78{
79 char *getenv();
80 char *home;
81 char home1[100];
82 register int n;
83 int tmp;
84 FILE *fp;
85
86 home = getenv("HOME");
87 strcpy(home1, home);
88 strcat(home1, "/Bstar");
89 if ((fp = fopen(home1, "w")) == 0) {
90 perror(home1);
91 return;
92 }
93 printf("Saved in %s.\n", home1);
a7c71d1e
EW
94 fwrite(&WEIGHT, sizeof WEIGHT, 1, fp);
95 fwrite(&CUMBER, sizeof CUMBER, 1, fp);
96 fwrite(&clock, sizeof clock, 1, fp);
d0c74d25
JB
97 tmp = location == dayfile;
98 fwrite(&tmp, sizeof tmp, 1, fp);
e1b932c3 99 for (n = 1; n <= NUMOFROOMS; n++) {
a7c71d1e
EW
100 fwrite(location[n].link, sizeof location[n].link, 1, fp);
101 fwrite(location[n].objects, sizeof location[n].objects, 1, fp);
e1b932c3
EW
102 }
103 fwrite(inven, sizeof inven, 1, fp);
104 fwrite(wear, sizeof wear, 1, fp);
105 fwrite(injuries, sizeof injuries, 1, fp);
106 fwrite(notes, sizeof notes, 1, fp);
107 fwrite(&direction, sizeof direction, 1, fp);
108 fwrite(&position, sizeof position, 1, fp);
109 fwrite(&time, sizeof time, 1, fp);
e1b932c3
EW
110 fwrite(&fuel, sizeof fuel, 1, fp);
111 fwrite(&torps, sizeof torps, 1, fp);
112 fwrite(&carrying, sizeof carrying, 1, fp);
113 fwrite(&encumber, sizeof encumber, 1, fp);
114 fwrite(&rythmn, sizeof rythmn, 1, fp);
115 fwrite(&followfight, sizeof followfight, 1, fp);
116 fwrite(&ate, sizeof ate, 1, fp);
117 fwrite(&snooze, sizeof snooze, 1, fp);
118 fwrite(&meetgirl, sizeof meetgirl, 1, fp);
119 fwrite(&followgod, sizeof followgod, 1, fp);
120 fwrite(&godready, sizeof godready, 1, fp);
121 fwrite(&win, sizeof win, 1, fp);
122 fwrite(&wintime, sizeof wintime, 1, fp);
123 fwrite(&matchlight, sizeof matchlight, 1, fp);
124 fwrite(&matchcount, sizeof matchcount, 1, fp);
125 fwrite(&loved, sizeof loved, 1, fp);
126 fwrite(&pleasure, sizeof pleasure, 1, fp);
127 fwrite(&power, sizeof power, 1, fp);
128 fwrite(&ego, sizeof ego, 1, fp);
129}