forked from github/server
fix bad terrain definitions in E2 (string, not number: these values are used for dice throws).
clean up the jsonconf.c code for reading these a little bit, report more specific errors.
This commit is contained in:
parent
a9abf4d87d
commit
90bcf30628
|
@ -229,21 +229,21 @@
|
|||
"production": {
|
||||
"iron": {
|
||||
"chance": 0.5,
|
||||
"level": 1,
|
||||
"base": 50,
|
||||
"div": 50
|
||||
"level": "1",
|
||||
"base": "50",
|
||||
"div": "50"
|
||||
},
|
||||
"stone": {
|
||||
"chance": 0.5,
|
||||
"level": 1,
|
||||
"base": 100,
|
||||
"div": 100
|
||||
"level": "1",
|
||||
"base": "100",
|
||||
"div": "100"
|
||||
},
|
||||
"laen": {
|
||||
"chance": 0.075,
|
||||
"level": 1,
|
||||
"base": 4,
|
||||
"div": 100
|
||||
"level": "1",
|
||||
"base": "4",
|
||||
"div": "100"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -254,21 +254,21 @@
|
|||
"production": {
|
||||
"iron": {
|
||||
"chance": 0.5,
|
||||
"level": 1,
|
||||
"base": 50,
|
||||
"div": 50
|
||||
"level": "1",
|
||||
"base": "50",
|
||||
"div": "50"
|
||||
},
|
||||
"stone": {
|
||||
"chance": 0.5,
|
||||
"level": 1,
|
||||
"base": 100,
|
||||
"div": 100
|
||||
"level": "1",
|
||||
"base": "100",
|
||||
"div": "100"
|
||||
},
|
||||
"laen": {
|
||||
"chance": 0.075,
|
||||
"level": 1,
|
||||
"base": 4,
|
||||
"div": 100
|
||||
"level": "1",
|
||||
"base": "4",
|
||||
"div": "100"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -192,32 +192,38 @@ static void json_terrain_production(cJSON *json, terrain_production *prod) {
|
|||
assert(json->type == cJSON_Object);
|
||||
cJSON *child;
|
||||
for (child = json->child; child; child = child->next) {
|
||||
char **dst = 0;
|
||||
switch (child->type) {
|
||||
case cJSON_String:
|
||||
if (strcmp(child->string, "base") == 0) {
|
||||
prod->base = _strdup(child->valuestring);
|
||||
}
|
||||
else if (strcmp(child->string, "level") == 0) {
|
||||
prod->startlevel = _strdup(child->valuestring);
|
||||
}
|
||||
else if (strcmp(child->string, "div") == 0) {
|
||||
prod->divisor = _strdup(child->valuestring);
|
||||
}
|
||||
else {
|
||||
log_error("terrain_production %s contains unknown attribute %s", json->string, child->string);
|
||||
}
|
||||
break;
|
||||
case cJSON_Number:
|
||||
if (strcmp(child->string, "chance") == 0) {
|
||||
prod->chance = (float)child->valuedouble;
|
||||
}
|
||||
else {
|
||||
log_error("terrain_production %s contains unknown attribute %s", json->string, child->string);
|
||||
log_error("terrain_production %s contains unknown number %s", json->string, child->string);
|
||||
}
|
||||
break;
|
||||
case cJSON_String:
|
||||
if (strcmp(child->string, "base") == 0) {
|
||||
dst = &prod->base;
|
||||
}
|
||||
else if (strcmp(child->string, "level") == 0) {
|
||||
dst = &prod->startlevel;
|
||||
}
|
||||
else if (strcmp(child->string, "div") == 0) {
|
||||
dst = &prod->divisor;
|
||||
}
|
||||
else {
|
||||
log_error("terrain_production %s contains unknown string %s", json->string, child->string);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
log_error("terrain_production %s contains unknown attribute %s", json->string, child->string);
|
||||
}
|
||||
if (dst) {
|
||||
free(*dst);
|
||||
assert(child->type == cJSON_String);
|
||||
*dst = _strdup(child->valuestring);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue