-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave.c
77 lines (66 loc) · 1.33 KB
/
save.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* Save and load user actions
* vim:set cin sm ts=8 sw=4 sts=4: - Sec <sec@42.org>
* $Id: save.c,v 1.7 2003/03/26 18:26:39 sec Exp $
*/
#include "brillion.h"
a_save* init_save(){
a_save*s;
const char *g;
int a;
s=calloc(1,sizeof(a_save));
s->len=1000;
s->game=malloc(1001);
#ifdef SAVE
s->what=R_RECORD;
#else
s->what=R_NONE;
#endif
if(0){
s->len=strlen(g);
s->what=R_PLAY;
for(a=0;a<=s->len;a++){
if(g[a]=='<') s->game[a]=0;
if(g[a]=='.') s->game[a]=1;
if(g[a]=='>') s->game[a]=2;
};
};
s->pos=0;
return(s);
}
signed int handle_save(signed int dir){
a_save *s=play->s;
if(s->what==R_NONE)
return(dir);
if(s->what==R_RECORD){
if(s->pos < s->len){
s->game[s->pos++]=dir+1;
}else{
/* Whoops, overflow %) */
};
return(dir);
};
if(s->what==R_PLAY){
if(s->pos < s->len){
return((signed int)s->game[s->pos++]-1);
} else {
printf("FATAL: Ran off end of savegame\n");
exit(-1);
};
};
printf("Save type %d not supported\n",s->what);
exit(-1);
}
void print_save(a_save *s){
int a;
FILE *f;
if(s->what!=R_RECORD)
return;
f=fopen(".save","a");
fprintf(f,"%d:",play->level+1);
for(a=0;a<s->pos;a++){
putc("<.>"[(int)s->game[a]],f);
};
putc('\n',f);
s->pos=0; /* XXX */
fclose(f);
}