-
Notifications
You must be signed in to change notification settings - Fork 0
/
encounter.c
101 lines (83 loc) · 2.31 KB
/
encounter.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "encounter.h"
obj_encounter*
OBJF(obj_encounter,finalize)(obj_encounter* this){
NULL_P_CHECK(this);
#ifdef DEBUG
fprintf(stderr,"DEBUG %s calling empty constructor on %p\n",__func__,(void*)this);
#endif
this->encounterName=calloc(SSTRLENG,sizeof(char));
OBJF(obj_map,finalize)(&this->map);
TEMPLATE3(arr,Finalize,obj_player)(&this->players);
return(this);}
void
OBJF(obj_encounter,clean)(obj_encounter* this){
NULL_P_CHECK(this);
#ifdef DEBUG
fprintf(stderr,"DEBUG %s calling empty destructor on %p\n",__func__,(void*)this);
#endif
free(this->encounterName);
OBJF(obj_map,clean)(&this->map);
TEMPLATE3(arr,Clean,obj_player)(&this->players);
return;}
void
OBJF(obj_encounter,copy)(obj_encounter* this, obj_encounter* dest){
NULL_P_CHECK(this);
NULL_P_CHECK(dest);
strncpy(dest->encounterName,this->encounterName,SSTRLENG);
OBJF(obj_map,copy)(&this->map,&dest->map);
TEMPLATE3(arr,Copyto,obj_player)(&this->players,&dest->players);}
void
OBJF(obj_encounter,print)(obj_encounter* this){
NULL_P_CHECK(this);
fprintf(stderr,"\ndumping obj_encounter %p\n",(void*)this);
DUMP_STRUCT_string(this,encounterName);
OBJF(obj_map,print)(&this->map);
TEMPLATE3(arr,dump,obj_player)(&this->players);
fprintf(stderr,"\nEND of obj_encounter %p\n",(void*)this);
}
int
encounterParse(obj_encounter* this, json_stream* js){
NULL_P_CHECK(this);
NULL_P_CHECK(js);
enum json_type type;
const char* str=json_get_string(js,NULL);
printf("FIRST %s STRING %s\n",__func__,str);
bool var=false;
//bool arrloop=false;
while(true){
type=json_next(js);
switch(type){
case JSON_ERROR:
PARSE_EMSG(js,json_typename[type]);
fprintf(stderr,"JSON ERR %s\n",\
json_get_error(js));
break;
case JSON_NULL:
case JSON_TRUE:
case JSON_FALSE:
case JSON_NUMBER:
break;
case JSON_STRING:
var=true;
break;
case JSON_ARRAY:
case JSON_OBJECT:
case JSON_DONE:
PARSE_EMSG(js,json_typename[type]);
break;
case JSON_ARRAY_END:
PARSE_EMSG(js,json_typename[type]);
return(1);
case JSON_OBJECT_END:
fprintf(stderr,"SHIP END l=%ld\n",json_get_lineno(js));
return(0);}
if(var){
parseOBJ(js,mapParse,map);
parseVarSTR(js,encounterName);
/*
* parseARRobj(js,players,obj_player, \
* playerParse,&this->players)
*/
}
}
return(1);}