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:
Enno Rehling 2015-09-13 09:46:40 +02:00
parent a9abf4d87d
commit 90bcf30628
2 changed files with 39 additions and 33 deletions

View File

@ -229,21 +229,21 @@
"production": { "production": {
"iron": { "iron": {
"chance": 0.5, "chance": 0.5,
"level": 1, "level": "1",
"base": 50, "base": "50",
"div": 50 "div": "50"
}, },
"stone": { "stone": {
"chance": 0.5, "chance": 0.5,
"level": 1, "level": "1",
"base": 100, "base": "100",
"div": 100 "div": "100"
}, },
"laen": { "laen": {
"chance": 0.075, "chance": 0.075,
"level": 1, "level": "1",
"base": 4, "base": "4",
"div": 100 "div": "100"
} }
} }
}, },
@ -254,21 +254,21 @@
"production": { "production": {
"iron": { "iron": {
"chance": 0.5, "chance": 0.5,
"level": 1, "level": "1",
"base": 50, "base": "50",
"div": 50 "div": "50"
}, },
"stone": { "stone": {
"chance": 0.5, "chance": 0.5,
"level": 1, "level": "1",
"base": 100, "base": "100",
"div": 100 "div": "100"
}, },
"laen": { "laen": {
"chance": 0.075, "chance": 0.075,
"level": 1, "level": "1",
"base": 4, "base": "4",
"div": 100 "div": "100"
} }
} }
}, },

View File

@ -192,32 +192,38 @@ static void json_terrain_production(cJSON *json, terrain_production *prod) {
assert(json->type == cJSON_Object); assert(json->type == cJSON_Object);
cJSON *child; cJSON *child;
for (child = json->child; child; child = child->next) { for (child = json->child; child; child = child->next) {
char **dst = 0;
switch (child->type) { 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: case cJSON_Number:
if (strcmp(child->string, "chance") == 0) { if (strcmp(child->string, "chance") == 0) {
prod->chance = (float)child->valuedouble; prod->chance = (float)child->valuedouble;
} }
else { 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; break;
default: default:
log_error("terrain_production %s contains unknown attribute %s", json->string, child->string); 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);
}
} }
} }