-
Notifications
You must be signed in to change notification settings - Fork 0
/
smodule.c
120 lines (107 loc) · 2.75 KB
/
smodule.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "smodule.h"
obj_smodule*
OBJF(obj_smodule,finalize)(obj_smodule* this){
this->finalize=OBJF(obj_smodule,finalize);
this->free=OBJF(obj_smodule,free);
this->clean=OBJF(obj_smodule,clean);
//this->copy=OBJF(obj_smodule,copy);
this->objSize=sizeof(obj_smodule);
//uint16_t objName;
this->smodType=0;
this->name=calloc(SSTRLENG,sizeof(char));
return(this);}
void
OBJF(obj_smodule,free)(obj_smodule* this){
NULL_P_CHECK(this);
free(this);
return;}
void
OBJF(obj_smodule,clean)(obj_smodule* this){
//NULL_P_CHECK(this);
free(this->name);
return;}
void
OBJF(obj_smodule,copy)(obj_smodule* this, obj_smodule* dest){
NULL_P_CHECK(this);
NULL_P_CHECK(dest);
strncpy(dest->name,this->name,SSTRLENG);
STRUCTCOPPIER(dest,this,posx);
STRUCTCOPPIER(dest,this,posy);
STRUCTCOPPIER(dest,this,hp);
STRUCTCOPPIER(dest,this,armor);
STRUCTCOPPIER(dest,this,hitChance);
STRUCTCOPPIER(dest,this,ap);
STRUCTCOPPIER(dest,this,apGen);
STRUCTCOPPIER(dest,this,external);
STRUCTCOPPIER(dest,this,curr_hp);
STRUCTCOPPIER(dest,this,curr_armor);
return;}
obj_smodule*
OBJF(obj_smodule,print)(obj_smodule* this){
NULL_P_CHECK(this);
fprintf(stderr,"\ndumping smodule\n");
DUMP_STRUCT_int(this,smodType);
DUMP_STRUCT_string(this,name);
DUMP_STRUCT_int(this,posx);
DUMP_STRUCT_int(this,posy);
DUMP_STRUCT_int(this,hp);
DUMP_STRUCT_int(this,armor);
DUMP_STRUCT_int(this,powergen);
DUMP_STRUCT_int(this,hitChance);
DUMP_STRUCT_int(this,ap);
DUMP_STRUCT_int(this,curr_hp);
DUMP_STRUCT_int(this,curr_armor);
fprintf(stderr,"\textermal %d\n",this->external);
return(NULL);}
int
smoduleParse(obj_smodule* this, json_stream* js){
NULL_P_CHECK(this);
NULL_P_CHECK(js);
enum json_type type;
const char* str=json_get_string(js,NULL);
bool var=false;
printf("FIRST STRING %s\n",str);
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:
exit(3);
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,"SMODULE END l=%ld\n",json_get_lineno(js));
return(0);}
if(var){
parseVarINT(js,smodType)
parseVarINT(js,posx)
parseVarINT(js,posy)
parseVarINT(js,hp)
parseVarINT(js,armor)
parseVarINT(js,powergen)
parseVarINT(js,hitChance)
parseVarINT(js,ap)
parseVarINT(js,apGen)
parseVarSTR(js,name)
parseVarBOOL(js,external);
parseVarINT(js,curr_hp)
parseVarINT(js,curr_armor)
}
}
return(1);}