2015-01-30 20:37:14 +01:00
|
|
|
/*
|
2014-06-08 07:17:48 +02:00
|
|
|
+-------------------+
|
|
|
|
| | Enno Rehling <enno@eressea.de>
|
|
|
|
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
|
|
|
|
| (c) 1998 - 2004 | Katja Zedel <katze@felidae.kn-bremen.de>
|
|
|
|
| | Henning Peters <faroul@beyond.kn-bremen.de>
|
|
|
|
+-------------------+
|
|
|
|
|
|
|
|
This program may not be used, modified or distributed
|
|
|
|
without prior permission by the authors of Eressea.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <platform.h>
|
|
|
|
#include "jsonconf.h"
|
|
|
|
|
|
|
|
/* kernel includes */
|
2018-02-14 20:00:48 +01:00
|
|
|
#include "kernel/building.h"
|
|
|
|
#include "kernel/calendar.h"
|
|
|
|
#include "kernel/config.h"
|
|
|
|
#include "kernel/equipment.h"
|
|
|
|
#include "kernel/item.h"
|
|
|
|
#include "kernel/messages.h"
|
|
|
|
#include "kernel/race.h"
|
|
|
|
#include "kernel/region.h"
|
|
|
|
#include "kernel/resources.h"
|
|
|
|
#include "kernel/ship.h"
|
|
|
|
#include "kernel/terrain.h"
|
|
|
|
#include "kernel/spell.h"
|
|
|
|
#include "kernel/spellbook.h"
|
2015-09-12 12:49:12 +02:00
|
|
|
|
2014-06-08 07:17:48 +02:00
|
|
|
/* util includes */
|
2018-09-29 11:37:17 +02:00
|
|
|
#include "kernel/attrib.h"
|
2018-02-14 20:00:48 +01:00
|
|
|
#include "util/crmessage.h"
|
|
|
|
#include "util/functions.h"
|
2018-09-29 18:13:32 +02:00
|
|
|
#include "util/keyword.h"
|
2018-02-14 20:00:48 +01:00
|
|
|
#include "util/language.h"
|
|
|
|
#include "util/log.h"
|
|
|
|
#include "util/message.h"
|
|
|
|
#include "util/nrmessage.h"
|
|
|
|
#include "util/path.h"
|
2018-05-18 00:08:30 +02:00
|
|
|
#include "util/pofile.h"
|
2018-02-14 20:00:48 +01:00
|
|
|
#include "util/strings.h"
|
2014-06-08 07:17:48 +02:00
|
|
|
|
2018-01-14 17:50:54 +01:00
|
|
|
/* game modules */
|
|
|
|
#include "direction.h"
|
|
|
|
#include "move.h"
|
|
|
|
#include "prefix.h"
|
|
|
|
#include "skill.h"
|
2018-04-24 21:50:49 +02:00
|
|
|
#include "exparse.h"
|
2018-01-14 17:50:54 +01:00
|
|
|
|
2014-06-08 07:17:48 +02:00
|
|
|
/* external libraries */
|
|
|
|
#include <cJSON.h>
|
|
|
|
|
|
|
|
/* libc includes */
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <limits.h>
|
2014-06-13 17:04:06 +02:00
|
|
|
#include <stdlib.h>
|
2014-06-08 07:17:48 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2014-07-01 04:21:28 +02:00
|
|
|
static int json_flags(cJSON *json, const char *flags[]) {
|
2014-06-17 07:43:40 +02:00
|
|
|
cJSON *entry;
|
|
|
|
int result = 0;
|
2015-01-30 20:37:14 +01:00
|
|
|
assert(json->type == cJSON_Array);
|
|
|
|
for (entry = json->child; entry; entry = entry->next) {
|
2014-06-17 07:43:40 +02:00
|
|
|
if (entry->type == cJSON_String) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; flags[i]; ++i) {
|
2015-01-30 20:37:14 +01:00
|
|
|
if (strcmp(flags[i], entry->valuestring) == 0) {
|
|
|
|
result |= (1 << i);
|
2015-04-19 12:49:39 +02:00
|
|
|
break;
|
2014-06-17 07:43:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-07-01 04:21:28 +02:00
|
|
|
static void json_requirements(cJSON *json, requirement **matp) {
|
2014-06-13 17:04:06 +02:00
|
|
|
cJSON *child;
|
2014-07-01 04:21:28 +02:00
|
|
|
int i;
|
2018-12-15 19:38:40 +01:00
|
|
|
requirement *mat = calloc(1 + cJSON_GetArraySize(json), sizeof(requirement));
|
2018-12-15 20:01:51 +01:00
|
|
|
if (!mat) abort();
|
2015-01-30 20:37:14 +01:00
|
|
|
for (i = 0, child = json->child; child; child = child->next, ++i) {
|
2014-07-01 04:21:28 +02:00
|
|
|
mat[i].number = child->valueint;
|
|
|
|
mat[i].rtype = rt_get_or_create(child->string);
|
|
|
|
}
|
|
|
|
*matp = mat;
|
|
|
|
}
|
|
|
|
|
2014-07-05 06:48:17 +02:00
|
|
|
static void json_maintenance_i(cJSON *json, maintenance *mt) {
|
|
|
|
cJSON *child;
|
|
|
|
for (child = json->child; child; child = child->next) {
|
|
|
|
switch (child->type) {
|
|
|
|
case cJSON_Number:
|
|
|
|
if (strcmp(child->string, "amount") == 0) {
|
|
|
|
mt->number = child->valueint;
|
|
|
|
}
|
|
|
|
else {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("maintenance contains unknown attribute %s", child->string);
|
2014-07-05 06:48:17 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case cJSON_String:
|
|
|
|
if (strcmp(child->string, "type") == 0) {
|
|
|
|
mt->rtype = rt_get_or_create(child->valuestring);
|
|
|
|
}
|
|
|
|
else {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("maintenance contains unknown attribute %s", child->string);
|
2014-07-05 06:48:17 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case cJSON_Array:
|
|
|
|
if (strcmp(child->string, "flags") == 0) {
|
2016-10-01 18:34:38 +02:00
|
|
|
const char * flags[] = { "variable", 0 };
|
2014-07-05 06:48:17 +02:00
|
|
|
mt->flags = json_flags(child, flags);
|
|
|
|
}
|
|
|
|
else {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("maintenance contains unknown array %s", child->string);
|
2014-07-05 06:48:17 +02:00
|
|
|
}
|
2014-07-06 03:21:20 +02:00
|
|
|
break;
|
2014-07-05 06:48:17 +02:00
|
|
|
default:
|
2016-02-01 13:59:35 +01:00
|
|
|
log_error("maintenance contains unknown attribute %s of type %d", child->string, child->type);
|
2014-07-05 06:48:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void json_maintenance(cJSON *json, maintenance **mtp) {
|
|
|
|
cJSON *child;
|
|
|
|
maintenance *mt;
|
2018-02-11 15:57:31 +01:00
|
|
|
int size = 1;
|
2014-07-05 06:48:17 +02:00
|
|
|
|
|
|
|
if (json->type == cJSON_Array) {
|
|
|
|
size = cJSON_GetArraySize(json);
|
|
|
|
}
|
|
|
|
else if (json->type != cJSON_Object) {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("maintenance is not a json object or array (%d)", json->type);
|
2014-07-05 06:48:17 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-12-15 19:38:40 +01:00
|
|
|
*mtp = mt = (struct maintenance *) calloc(size + 1, sizeof(struct maintenance));
|
2014-07-05 06:48:17 +02:00
|
|
|
if (json->type == cJSON_Array) {
|
2018-02-11 15:57:31 +01:00
|
|
|
int i;
|
2014-07-05 06:48:17 +02:00
|
|
|
for (i = 0, child = json->child; child; child = child->next, ++i) {
|
|
|
|
if (child->type == cJSON_Object) {
|
2015-01-30 20:37:14 +01:00
|
|
|
json_maintenance_i(child, mt + i);
|
2014-07-05 06:48:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-01 13:59:35 +01:00
|
|
|
else {
|
|
|
|
json_maintenance_i(json, mt);
|
|
|
|
}
|
2014-07-05 06:48:17 +02:00
|
|
|
}
|
|
|
|
|
2014-07-01 04:21:28 +02:00
|
|
|
static void json_construction(cJSON *json, construction **consp) {
|
|
|
|
cJSON *child;
|
2017-02-18 21:15:14 +01:00
|
|
|
construction * cons;
|
|
|
|
|
2014-07-01 04:21:28 +02:00
|
|
|
if (json->type != cJSON_Object) {
|
2014-12-31 13:17:54 +01:00
|
|
|
log_error("construction %s is not a json object: %d", json->string, json->type);
|
2014-06-13 17:04:06 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-12-15 19:38:40 +01:00
|
|
|
cons = (construction *)calloc(1, sizeof(construction));
|
2018-12-15 20:01:51 +01:00
|
|
|
if (!cons) abort();
|
2015-01-30 20:37:14 +01:00
|
|
|
for (child = json->child; child; child = child->next) {
|
|
|
|
switch (child->type) {
|
2014-07-01 04:21:28 +02:00
|
|
|
case cJSON_Object:
|
2015-01-30 20:37:14 +01:00
|
|
|
if (strcmp(child->string, "materials") == 0) {
|
2014-07-01 04:21:28 +02:00
|
|
|
json_requirements(child, &cons->materials);
|
|
|
|
}
|
|
|
|
break;
|
2014-06-13 17:04:06 +02:00
|
|
|
case cJSON_Number:
|
2015-01-30 20:37:14 +01:00
|
|
|
if (strcmp(child->string, "maxsize") == 0) {
|
2014-06-13 17:04:06 +02:00
|
|
|
cons->maxsize = child->valueint;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
else if (strcmp(child->string, "reqsize") == 0) {
|
2014-06-13 17:04:06 +02:00
|
|
|
cons->reqsize = child->valueint;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
else if (strcmp(child->string, "minskill") == 0) {
|
2014-06-13 17:04:06 +02:00
|
|
|
cons->minskill = child->valueint;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
break;
|
2014-06-13 17:04:06 +02:00
|
|
|
default:
|
2014-12-31 13:17:54 +01:00
|
|
|
log_error("construction %s contains unknown attribute %s", json->string, child->string);
|
2014-06-13 17:04:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
*consp = cons;
|
|
|
|
}
|
|
|
|
|
2015-09-11 12:12:53 +02:00
|
|
|
static void json_terrain_production(cJSON *json, terrain_production *prod) {
|
|
|
|
cJSON *child;
|
2017-02-18 21:15:14 +01:00
|
|
|
assert(json->type == cJSON_Object);
|
2015-09-11 12:12:53 +02:00
|
|
|
for (child = json->child; child; child = child->next) {
|
2015-09-13 09:46:40 +02:00
|
|
|
char **dst = 0;
|
2015-09-11 12:12:53 +02:00
|
|
|
switch (child->type) {
|
2015-09-13 09:46:40 +02:00
|
|
|
case cJSON_Number:
|
|
|
|
if (strcmp(child->string, "chance") == 0) {
|
|
|
|
prod->chance = (float)child->valuedouble;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
log_error("terrain_production %s contains unknown number %s", json->string, child->string);
|
|
|
|
}
|
|
|
|
break;
|
2015-09-11 12:12:53 +02:00
|
|
|
case cJSON_String:
|
|
|
|
if (strcmp(child->string, "base") == 0) {
|
2015-09-13 09:46:40 +02:00
|
|
|
dst = &prod->base;
|
2015-09-11 12:12:53 +02:00
|
|
|
}
|
|
|
|
else if (strcmp(child->string, "level") == 0) {
|
2015-09-13 09:46:40 +02:00
|
|
|
dst = &prod->startlevel;
|
2015-09-11 12:12:53 +02:00
|
|
|
}
|
|
|
|
else if (strcmp(child->string, "div") == 0) {
|
2015-09-13 09:46:40 +02:00
|
|
|
dst = &prod->divisor;
|
2015-09-11 12:12:53 +02:00
|
|
|
}
|
|
|
|
else {
|
2015-09-13 09:46:40 +02:00
|
|
|
log_error("terrain_production %s contains unknown string %s", json->string, child->string);
|
2015-09-11 12:12:53 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
log_error("terrain_production %s contains unknown attribute %s", json->string, child->string);
|
|
|
|
}
|
2015-09-13 09:46:40 +02:00
|
|
|
if (dst) {
|
|
|
|
free(*dst);
|
|
|
|
assert(child->type == cJSON_String);
|
2017-12-28 18:29:40 +01:00
|
|
|
*dst = str_strdup(child->valuestring);
|
2015-09-13 09:46:40 +02:00
|
|
|
}
|
2015-09-11 12:12:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 04:21:28 +02:00
|
|
|
static void json_terrain(cJSON *json, terrain_type *ter) {
|
2014-06-14 02:36:05 +02:00
|
|
|
cJSON *child;
|
2015-01-30 20:37:14 +01:00
|
|
|
if (json->type != cJSON_Object) {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("terrain %s is not a json object: %d", json->string, json->type);
|
2014-06-14 02:36:05 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
for (child = json->child; child; child = child->next) {
|
|
|
|
switch (child->type) {
|
2015-09-11 12:12:53 +02:00
|
|
|
case cJSON_Object:
|
|
|
|
if (strcmp(child->string, "production") == 0) {
|
|
|
|
cJSON *entry;
|
2015-09-11 12:52:18 +02:00
|
|
|
int size = cJSON_GetArraySize(child);
|
|
|
|
if (size > 0) {
|
|
|
|
int n;
|
|
|
|
ter->production = (terrain_production *)calloc(size + 1, sizeof(terrain_production));
|
2018-12-15 20:01:51 +01:00
|
|
|
if (!ter->production) abort();
|
2015-09-11 12:52:18 +02:00
|
|
|
ter->production[size].type = 0;
|
|
|
|
for (n = 0, entry = child->child; entry; entry = entry->next, ++n) {
|
|
|
|
ter->production[n].type = rt_get_or_create(entry->string);
|
|
|
|
if (entry->type != cJSON_Object) {
|
|
|
|
log_error("terrain %s contains invalid production %s", json->string, entry->string);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
json_terrain_production(entry, ter->production + n);
|
|
|
|
}
|
2015-09-11 12:12:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
log_error("terrain %s contains unknown attribute %s", json->string, child->string);
|
|
|
|
}
|
|
|
|
break;
|
2014-06-17 07:19:19 +02:00
|
|
|
case cJSON_Array:
|
2015-01-30 20:37:14 +01:00
|
|
|
if (strcmp(child->string, "flags") == 0) {
|
2014-06-17 07:19:19 +02:00
|
|
|
const char * flags[] = {
|
|
|
|
"land", "sea", "forest", "arctic", "cavalry", "forbidden", "sail", "fly", "swim", "walk", 0
|
|
|
|
};
|
2014-06-17 07:43:40 +02:00
|
|
|
ter->flags = json_flags(child, flags);
|
2015-01-30 20:37:14 +01:00
|
|
|
}
|
2015-09-11 12:12:53 +02:00
|
|
|
else if (strcmp(child->string, "herbs") == 0) {
|
|
|
|
cJSON *entry;
|
2015-09-11 12:52:18 +02:00
|
|
|
int size = cJSON_GetArraySize(child);
|
|
|
|
if (size > 0) {
|
|
|
|
int n;
|
2015-10-14 21:37:27 +02:00
|
|
|
free(ter->herbs);
|
2015-09-11 12:52:18 +02:00
|
|
|
ter->herbs = malloc(sizeof(const item_type *) * (size + 1));
|
2018-12-15 20:01:51 +01:00
|
|
|
if (!ter->herbs) abort();
|
2015-09-11 12:52:18 +02:00
|
|
|
ter->herbs[size] = 0;
|
|
|
|
for (n = 0, entry = child->child; entry; entry = entry->next) {
|
|
|
|
ter->herbs[n++] = it_get_or_create(rt_get_or_create(entry->valuestring));
|
|
|
|
}
|
2015-09-11 12:12:53 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
else {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("terrain %s contains unknown attribute %s", json->string, child->string);
|
2014-06-17 07:19:19 +02:00
|
|
|
}
|
|
|
|
break;
|
2015-09-11 12:12:53 +02:00
|
|
|
case cJSON_Number:
|
|
|
|
if (strcmp(child->string, "size") == 0) {
|
|
|
|
ter->size = child->valueint;
|
|
|
|
}
|
|
|
|
else if (strcmp(child->string, "road") == 0) {
|
|
|
|
ter->max_road = (short)child->valueint;
|
|
|
|
}
|
|
|
|
else if (strcmp(child->string, "seed") == 0) {
|
|
|
|
ter->distribution = (short)child->valueint;
|
|
|
|
}
|
2015-09-11 21:14:10 +02:00
|
|
|
else {
|
|
|
|
log_error("terrain %s contains unknown attribute %s", json->string, child->string);
|
|
|
|
}
|
|
|
|
break;
|
2014-06-17 07:19:19 +02:00
|
|
|
default:
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("terrain %s contains unknown attribute %s", json->string, child->string);
|
2014-06-17 07:19:19 +02:00
|
|
|
}
|
2014-06-14 02:36:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-01 15:32:06 +02:00
|
|
|
static void json_stage(cJSON *json, building_stage *stage) {
|
|
|
|
cJSON *child;
|
|
|
|
|
|
|
|
if (json->type != cJSON_Object) {
|
|
|
|
log_error("building stages is not a json object: %d", json->type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (child = json->child; child; child = child->next) {
|
|
|
|
switch (child->type) {
|
|
|
|
case cJSON_Object:
|
|
|
|
if (strcmp(child->string, "construction") == 0) {
|
|
|
|
json_construction(child, &stage->construction);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case cJSON_String:
|
|
|
|
if (strcmp(child->string, "name") == 0) {
|
|
|
|
stage->name = str_strdup(child->valuestring);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void json_stages(cJSON *json, building_type *bt) {
|
|
|
|
cJSON *child;
|
|
|
|
building_stage *stage, **sp = &bt->stages;
|
|
|
|
int size = 0;
|
|
|
|
|
|
|
|
if (json->type != cJSON_Array) {
|
|
|
|
log_error("building stages is not a json array: %d", json->type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (child = json->child; child; child = child->next) {
|
|
|
|
switch (child->type) {
|
|
|
|
case cJSON_Object:
|
2018-12-15 19:38:40 +01:00
|
|
|
stage = calloc(1, sizeof(building_stage));
|
2018-12-15 20:01:51 +01:00
|
|
|
if (!stage) abort();
|
2018-05-01 15:32:06 +02:00
|
|
|
json_stage(child, stage);
|
|
|
|
if (stage->construction->maxsize > 0) {
|
|
|
|
stage->construction->maxsize -= size;
|
|
|
|
size += stage->construction->maxsize;
|
|
|
|
}
|
|
|
|
*sp = stage;
|
|
|
|
sp = &stage->next;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
log_error("building stage contains non-object type %d", child->type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 04:21:28 +02:00
|
|
|
static void json_building(cJSON *json, building_type *bt) {
|
2014-06-13 07:14:07 +02:00
|
|
|
cJSON *child;
|
2014-07-28 14:27:30 +02:00
|
|
|
const char *flags[] = {
|
2015-11-11 14:36:56 +01:00
|
|
|
"nodestroy", "nobuild", "unique", "decay", "dynamic", "magic", "oneperturn", "namechange", "fort", 0
|
2014-07-28 14:27:30 +02:00
|
|
|
};
|
|
|
|
if (json->type != cJSON_Object) {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("building %s is not a json object: %d", json->string, json->type);
|
2014-06-13 07:14:07 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
for (child = json->child; child; child = child->next) {
|
|
|
|
switch (child->type) {
|
2014-07-01 04:21:28 +02:00
|
|
|
case cJSON_Array:
|
2018-05-01 15:32:06 +02:00
|
|
|
if (strcmp(child->string, "stages") == 0) {
|
|
|
|
if (!bt->stages) {
|
|
|
|
json_stages(child, bt);
|
|
|
|
}
|
2014-07-01 04:21:28 +02:00
|
|
|
}
|
2014-07-05 06:48:17 +02:00
|
|
|
else if (strcmp(child->string, "maintenance") == 0) {
|
|
|
|
json_maintenance(child, &bt->maintenance);
|
|
|
|
}
|
2014-07-28 14:27:30 +02:00
|
|
|
else if (strcmp(child->string, "flags") == 0) {
|
|
|
|
json_flags(child, flags);
|
|
|
|
}
|
2014-07-01 04:21:28 +02:00
|
|
|
break;
|
2014-06-14 02:36:05 +02:00
|
|
|
case cJSON_Object:
|
2015-01-30 20:37:14 +01:00
|
|
|
if (strcmp(child->string, "construction") == 0) {
|
2018-05-01 15:32:06 +02:00
|
|
|
/* simple, single-stage building */
|
|
|
|
if (!bt->stages) {
|
2018-12-15 19:38:40 +01:00
|
|
|
building_stage *stage = calloc(1, sizeof(building_stage));
|
2018-12-15 20:01:51 +01:00
|
|
|
if (!stage) abort();
|
2018-05-01 15:32:06 +02:00
|
|
|
json_construction(child, &stage->construction);
|
|
|
|
bt->stages = stage;
|
|
|
|
}
|
2014-06-14 02:36:05 +02:00
|
|
|
}
|
2018-05-01 15:32:06 +02:00
|
|
|
if (strcmp(child->string, "maintenance") == 0) {
|
2014-07-05 06:48:17 +02:00
|
|
|
json_maintenance(child, &bt->maintenance);
|
|
|
|
}
|
2014-06-14 02:36:05 +02:00
|
|
|
break;
|
2014-06-29 01:55:28 +02:00
|
|
|
case cJSON_String:
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("building %s contains unknown attribute %s", json->string, child->string);
|
2014-06-29 01:55:28 +02:00
|
|
|
break;
|
2014-06-14 02:36:05 +02:00
|
|
|
default:
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("building %s contains unknown attribute %s", json->string, child->string);
|
2014-06-14 02:36:05 +02:00
|
|
|
}
|
2014-06-13 07:14:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 04:21:28 +02:00
|
|
|
static void json_item(cJSON *json, item_type *itype) {
|
2014-06-25 07:44:05 +02:00
|
|
|
cJSON *child;
|
2014-06-25 17:00:09 +02:00
|
|
|
const char *flags[] = {
|
|
|
|
"herb", "cursed", "nodrop", "big", "animal", "vehicle", 0
|
|
|
|
};
|
2015-01-30 20:37:14 +01:00
|
|
|
if (json->type != cJSON_Object) {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("ship %s is not a json object: %d", json->string, json->type);
|
2014-06-25 07:44:05 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
for (child = json->child; child; child = child->next) {
|
|
|
|
switch (child->type) {
|
2014-06-25 17:00:09 +02:00
|
|
|
case cJSON_Number:
|
2015-01-30 20:37:14 +01:00
|
|
|
if (strcmp(child->string, "weight") == 0) {
|
2014-06-25 17:00:09 +02:00
|
|
|
itype->weight = child->valueint;
|
|
|
|
break;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
if (strcmp(child->string, "capacity") == 0) {
|
2014-06-25 17:00:09 +02:00
|
|
|
itype->capacity = child->valueint;
|
|
|
|
break;
|
|
|
|
}
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("item %s contains unknown attribute %s", json->string, child->string);
|
2014-06-25 17:00:09 +02:00
|
|
|
break;
|
|
|
|
case cJSON_Array:
|
2015-01-30 20:37:14 +01:00
|
|
|
if (strcmp(child->string, "flags") == 0) {
|
2014-06-25 17:00:09 +02:00
|
|
|
itype->flags = json_flags(child, flags);
|
|
|
|
break;
|
|
|
|
}
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("item %s contains unknown attribute %s", json->string, child->string);
|
2014-06-25 07:44:05 +02:00
|
|
|
case cJSON_Object:
|
|
|
|
default:
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("item %s contains unknown attribute %s", json->string, child->string);
|
2014-06-25 07:44:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 04:21:28 +02:00
|
|
|
static void json_ship(cJSON *json, ship_type *st) {
|
2014-06-18 06:33:42 +02:00
|
|
|
cJSON *child, *iter;
|
2015-01-30 20:37:14 +01:00
|
|
|
if (json->type != cJSON_Object) {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("ship %s is not a json object: %d", json->string, json->type);
|
2014-06-13 07:14:07 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
for (child = json->child; child; child = child->next) {
|
2014-06-18 06:33:42 +02:00
|
|
|
int i;
|
2015-01-30 20:37:14 +01:00
|
|
|
switch (child->type) {
|
2014-06-13 17:04:06 +02:00
|
|
|
case cJSON_Object:
|
2015-01-30 20:37:14 +01:00
|
|
|
if (strcmp(child->string, "construction") == 0) {
|
2014-06-13 17:04:06 +02:00
|
|
|
json_construction(child, &st->construction);
|
2015-01-30 20:37:14 +01:00
|
|
|
}
|
|
|
|
else {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("ship %s contains unknown attribute %s", json->string, child->string);
|
2014-06-17 07:19:19 +02:00
|
|
|
}
|
|
|
|
break;
|
2014-06-18 06:33:42 +02:00
|
|
|
case cJSON_Array:
|
2014-12-31 01:00:10 +01:00
|
|
|
st->coasts = (terrain_type **)
|
2015-01-30 20:37:14 +01:00
|
|
|
malloc(sizeof(terrain_type *) * (1 + cJSON_GetArraySize(child)));
|
2018-12-15 20:01:51 +01:00
|
|
|
if (!st->coasts) abort();
|
2015-01-30 20:37:14 +01:00
|
|
|
for (i = 0, iter = child->child; iter; iter = iter->next) {
|
|
|
|
if (iter->type == cJSON_String) {
|
2014-06-18 06:33:42 +02:00
|
|
|
terrain_type *ter = get_or_create_terrain(iter->valuestring);
|
|
|
|
if (ter) {
|
|
|
|
st->coasts[i++] = ter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
st->coasts[i] = 0;
|
|
|
|
break;
|
2014-06-17 07:19:19 +02:00
|
|
|
case cJSON_Number:
|
2015-01-30 20:37:14 +01:00
|
|
|
if (strcmp(child->string, "range") == 0) {
|
2014-06-17 07:19:19 +02:00
|
|
|
st->range = child->valueint;
|
2015-01-30 20:37:14 +01:00
|
|
|
}
|
2015-04-18 11:41:50 +02:00
|
|
|
else if (strcmp(child->string, "maxrange") == 0) {
|
|
|
|
st->range_max = child->valueint;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
else {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("ship %s contains unknown attribute %s", json->string, child->string);
|
2014-06-13 17:04:06 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("ship %s contains unknown attribute %s", json->string, child->string);
|
2014-06-13 17:04:06 +02:00
|
|
|
}
|
2014-06-13 07:14:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 04:21:28 +02:00
|
|
|
static void json_race(cJSON *json, race *rc) {
|
2014-06-08 07:17:48 +02:00
|
|
|
cJSON *child;
|
2014-06-17 07:43:40 +02:00
|
|
|
const char *flags[] = {
|
2018-05-10 22:00:23 +02:00
|
|
|
"player", "killpeasants", "scarepeasants",
|
2014-07-06 04:29:12 +02:00
|
|
|
"nosteal", "moverandom", "cannotmove",
|
2014-06-17 07:43:40 +02:00
|
|
|
"learn", "fly", "swim", "walk", "nolearn",
|
|
|
|
"noteach", "horse", "desert",
|
2015-01-30 20:37:14 +01:00
|
|
|
"illusionary", "absorbpeasants", "noheal",
|
2014-06-17 07:43:40 +02:00
|
|
|
"noweapons", "shapeshift", "", "undead", "dragon",
|
2018-05-10 22:00:23 +02:00
|
|
|
"coastal", "", "cansail", NULL
|
2014-06-17 07:43:40 +02:00
|
|
|
};
|
2014-07-06 09:53:15 +02:00
|
|
|
const char *ecflags[] = {
|
2018-05-10 22:00:23 +02:00
|
|
|
"giveperson", "giveunit", "getitem", NULL
|
2014-07-06 09:53:15 +02:00
|
|
|
};
|
|
|
|
if (json->type != cJSON_Object) {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("race %s is not a json object: %d", json->string, json->type);
|
2014-06-08 07:17:48 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
for (child = json->child; child; child = child->next) {
|
|
|
|
switch (child->type) {
|
2014-06-08 07:17:48 +02:00
|
|
|
case cJSON_String:
|
2015-01-30 20:37:14 +01:00
|
|
|
if (strcmp(child->string, "damage") == 0) {
|
2017-12-28 18:29:40 +01:00
|
|
|
rc->def_damage = str_strdup(child->valuestring);
|
2014-06-08 07:17:48 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case cJSON_Number:
|
2015-01-30 20:37:14 +01:00
|
|
|
if (strcmp(child->string, "magres") == 0) {
|
2017-02-24 20:47:47 +01:00
|
|
|
rc->magres = frac_make(child->valueint, 100);
|
2014-06-08 07:17:48 +02:00
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
else if (strcmp(child->string, "maxaura") == 0) {
|
2017-02-03 20:06:01 +01:00
|
|
|
rc->maxaura = child->valueint;
|
2014-06-08 07:17:48 +02:00
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
else if (strcmp(child->string, "regaura") == 0) {
|
2014-06-08 07:17:48 +02:00
|
|
|
rc->regaura = (float)child->valuedouble;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
else if (strcmp(child->string, "speed") == 0) {
|
2014-06-08 07:17:48 +02:00
|
|
|
rc->speed = (float)child->valuedouble;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
else if (strcmp(child->string, "recruitcost") == 0) {
|
2014-06-08 07:17:48 +02:00
|
|
|
rc->recruitcost = child->valueint;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
else if (strcmp(child->string, "maintenance") == 0) {
|
2014-06-08 07:17:48 +02:00
|
|
|
rc->maintenance = child->valueint;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
else if (strcmp(child->string, "weight") == 0) {
|
2014-06-08 07:17:48 +02:00
|
|
|
rc->weight = child->valueint;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
else if (strcmp(child->string, "capacity") == 0) {
|
2014-06-08 07:17:48 +02:00
|
|
|
rc->capacity = child->valueint;
|
|
|
|
}
|
2016-10-04 09:14:49 +02:00
|
|
|
else if (strcmp(child->string, "income") == 0) {
|
|
|
|
rc->income = child->valueint;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
else if (strcmp(child->string, "hp") == 0) {
|
2014-06-08 07:17:48 +02:00
|
|
|
rc->hitpoints = child->valueint;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
else if (strcmp(child->string, "ac") == 0) {
|
2014-06-08 07:17:48 +02:00
|
|
|
rc->armor = child->valueint;
|
|
|
|
}
|
2017-02-18 21:15:14 +01:00
|
|
|
/* TODO: studyspeed (orcs only) */
|
2014-06-08 07:17:48 +02:00
|
|
|
break;
|
2014-06-17 07:43:40 +02:00
|
|
|
case cJSON_Array:
|
2015-01-30 20:37:14 +01:00
|
|
|
if (strcmp(child->string, "flags") == 0) {
|
2014-06-17 07:43:40 +02:00
|
|
|
rc->flags = json_flags(child, flags);
|
2014-07-06 09:53:15 +02:00
|
|
|
rc->ec_flags = json_flags(child, ecflags);
|
2014-06-08 07:17:48 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-12 12:49:12 +02:00
|
|
|
static void json_prefixes(cJSON *json) {
|
|
|
|
cJSON *child;
|
|
|
|
if (json->type != cJSON_Array) {
|
|
|
|
log_error("prefixes is not a json array: %d", json->type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (child = json->child; child; child = child->next) {
|
|
|
|
add_raceprefix(child->valuestring);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-12 17:37:29 +02:00
|
|
|
/** disable a feature.
|
2016-04-09 18:49:25 +02:00
|
|
|
* features are identified by one of:
|
2015-09-12 17:37:29 +02:00
|
|
|
* 1. the keyword for their orders,
|
|
|
|
* 2. the name of the skill they use,
|
|
|
|
* 3. a "module.enabled" flag in the settings
|
|
|
|
*/
|
|
|
|
static void disable_feature(const char *str) {
|
2015-09-12 17:43:31 +02:00
|
|
|
char name[32];
|
2015-09-12 17:37:29 +02:00
|
|
|
int k;
|
2015-09-12 17:43:31 +02:00
|
|
|
skill_t sk;
|
2017-01-07 21:09:39 +01:00
|
|
|
size_t len;
|
|
|
|
|
2015-09-12 17:43:31 +02:00
|
|
|
sk = findskill(str);
|
|
|
|
if (sk != NOSKILL) {
|
|
|
|
enable_skill(sk, false);
|
|
|
|
return;
|
|
|
|
}
|
2016-04-09 18:49:25 +02:00
|
|
|
k = findkeyword(str);
|
|
|
|
if (k!=NOKEYWORD) {
|
|
|
|
log_debug("disable keyword %s\n", str);
|
|
|
|
enable_keyword(k, false);
|
|
|
|
return;
|
2015-09-12 17:37:29 +02:00
|
|
|
}
|
2017-01-07 21:09:39 +01:00
|
|
|
len = strlen(str);
|
|
|
|
assert(len <= sizeof(name) - 9);
|
|
|
|
memcpy(name, str, len);
|
|
|
|
strcpy(name+len, ".enabled");
|
2015-09-12 17:43:31 +02:00
|
|
|
log_info("disable feature %s\n", name);
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set(name, "0");
|
2015-09-12 17:37:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void json_disable_features(cJSON *json) {
|
2015-09-12 17:06:47 +02:00
|
|
|
cJSON *child;
|
|
|
|
if (json->type != cJSON_Array) {
|
2015-09-12 17:37:29 +02:00
|
|
|
log_error("disabled is not a json array: %d", json->type);
|
2015-09-12 17:06:47 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (child = json->child; child; child = child->next) {
|
2015-09-12 17:37:29 +02:00
|
|
|
disable_feature(child->valuestring);
|
2015-09-12 17:06:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 04:21:28 +02:00
|
|
|
static void json_terrains(cJSON *json) {
|
2014-06-14 02:36:05 +02:00
|
|
|
cJSON *child;
|
2015-01-30 20:37:14 +01:00
|
|
|
if (json->type != cJSON_Object) {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("terrains is not a json object: %d", json->type);
|
2014-06-14 02:36:05 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
for (child = json->child; child; child = child->next) {
|
2014-06-16 06:19:47 +02:00
|
|
|
json_terrain(child, get_or_create_terrain(child->string));
|
2014-06-14 02:36:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 04:21:28 +02:00
|
|
|
static void json_buildings(cJSON *json) {
|
2014-06-13 07:14:07 +02:00
|
|
|
cJSON *child;
|
2015-01-30 20:37:14 +01:00
|
|
|
if (json->type != cJSON_Object) {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("buildings is not a json object: %d", json->type);
|
2014-06-13 07:14:07 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
for (child = json->child; child; child = child->next) {
|
2014-06-13 07:14:07 +02:00
|
|
|
json_building(child, bt_get_or_create(child->string));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-03 06:15:22 +02:00
|
|
|
static void json_spells(cJSON *json) {
|
|
|
|
cJSON *child;
|
|
|
|
if (json->type != cJSON_Object) {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("spells is not a json object: %d", json->type);
|
2014-07-03 06:15:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (child = json->child; child; child = child->next) {
|
|
|
|
if (child->type == cJSON_Object) {
|
|
|
|
spell *sp;
|
2017-05-01 17:04:28 +02:00
|
|
|
cJSON * item;
|
|
|
|
sp = create_spell(child->string);
|
2014-07-03 06:15:22 +02:00
|
|
|
for (item = child->child; item; item = item->next) {
|
|
|
|
if (strcmp(item->string, "index") == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (strcmp(item->string, "syntax") == 0) {
|
2017-12-28 18:29:40 +01:00
|
|
|
sp->syntax = str_strdup(item->valuestring);
|
2014-07-03 06:15:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 04:21:28 +02:00
|
|
|
static void json_items(cJSON *json) {
|
2014-06-25 07:44:05 +02:00
|
|
|
cJSON *child;
|
2015-01-30 20:37:14 +01:00
|
|
|
if (json->type != cJSON_Object) {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("items is not a json object: %d", json->type);
|
2014-06-25 07:44:05 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
for (child = json->child; child; child = child->next) {
|
2014-06-25 07:44:05 +02:00
|
|
|
resource_type *rtype = rt_get_or_create(child->string);
|
|
|
|
item_type *itype = rtype->itype;
|
|
|
|
if (!itype) {
|
|
|
|
rtype->itype = itype = it_get_or_create(rtype);
|
|
|
|
}
|
|
|
|
json_item(child, itype);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 04:21:28 +02:00
|
|
|
static void json_ships(cJSON *json) {
|
2014-06-13 07:14:07 +02:00
|
|
|
cJSON *child;
|
2015-01-30 20:37:14 +01:00
|
|
|
if (json->type != cJSON_Object) {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("ships is not a json object: %d", json->type);
|
2014-06-13 07:14:07 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
for (child = json->child; child; child = child->next) {
|
2014-06-13 07:14:07 +02:00
|
|
|
json_ship(child, st_get_or_create(child->string));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 04:21:28 +02:00
|
|
|
static void json_locale(cJSON *json, struct locale *lang) {
|
2014-06-28 19:37:40 +02:00
|
|
|
cJSON *child;
|
2015-01-30 20:37:14 +01:00
|
|
|
if (json->type != cJSON_Object) {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("strings is not a json object: %d", json->type);
|
2014-06-28 19:37:40 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
for (child = json->child; child; child = child->next) {
|
|
|
|
if (child->type == cJSON_String) {
|
2014-06-28 19:37:40 +02:00
|
|
|
locale_setstring(lang, child->string, child->valuestring);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 04:21:28 +02:00
|
|
|
static void json_strings(cJSON *json) {
|
2014-06-28 19:37:40 +02:00
|
|
|
cJSON *child;
|
2015-01-30 20:37:14 +01:00
|
|
|
if (json->type != cJSON_Object) {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("strings is not a json object: %d", json->type);
|
2014-06-28 19:37:40 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
for (child = json->child; child; child = child->next) {
|
|
|
|
if (child->type == cJSON_Object) {
|
2017-02-12 06:06:33 +01:00
|
|
|
struct locale *lang = get_locale(child->string);
|
2014-06-28 19:37:40 +02:00
|
|
|
json_locale(child, lang);
|
2015-01-30 20:37:14 +01:00
|
|
|
}
|
|
|
|
else {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("strings for locale `%s` are not a json object: %d", child->string, child->type);
|
2014-06-28 19:37:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-16 07:17:08 +02:00
|
|
|
static void json_direction(cJSON *json, struct locale *lang) {
|
|
|
|
cJSON *child;
|
2015-01-30 20:37:14 +01:00
|
|
|
if (json->type != cJSON_Object) {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("directions for locale `%s` not a json object: %d", locale_name(lang), json->type);
|
2014-06-16 07:17:08 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
for (child = json->child; child; child = child->next) {
|
2014-06-16 07:17:08 +02:00
|
|
|
direction_t dir = finddirection(child->string);
|
2015-01-30 20:37:14 +01:00
|
|
|
if (dir != NODIRECTION) {
|
|
|
|
if (child->type == cJSON_String) {
|
2014-06-16 07:17:08 +02:00
|
|
|
init_direction(lang, dir, child->valuestring);
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
else if (child->type == cJSON_Array) {
|
2014-06-16 07:17:08 +02:00
|
|
|
cJSON *entry;
|
2015-01-30 20:37:14 +01:00
|
|
|
for (entry = child->child; entry; entry = entry->next) {
|
2014-06-16 07:17:08 +02:00
|
|
|
init_direction(lang, dir, entry->valuestring);
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
}
|
|
|
|
else {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("invalid type %d for direction `%s`", child->type, child->string);
|
2014-06-16 07:17:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-07 17:46:51 +02:00
|
|
|
static void json_calendar(cJSON *json) {
|
|
|
|
cJSON *child;
|
|
|
|
if (json->type != cJSON_Object) {
|
|
|
|
log_error("calendar is not an object: %d", json->type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (child = json->child; child; child = child->next) {
|
|
|
|
if (strcmp(child->string, "start") == 0) {
|
|
|
|
config_set_int("game.start", child->valueint);
|
|
|
|
}
|
|
|
|
else if (strcmp(child->string, "weeks") == 0) {
|
|
|
|
cJSON *entry;
|
|
|
|
int i;
|
|
|
|
if (child->type != cJSON_Array) {
|
|
|
|
log_error("calendar.weeks is not an array: %d", json->type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
weeks_per_month = cJSON_GetArraySize(child);
|
|
|
|
free(weeknames);
|
|
|
|
weeknames = malloc(sizeof(char *) * weeks_per_month);
|
2018-12-15 20:01:51 +01:00
|
|
|
if (!weeknames) abort();
|
2017-05-07 17:46:51 +02:00
|
|
|
for (i = 0, entry = child->child; entry; entry = entry->next, ++i) {
|
|
|
|
if (entry->type == cJSON_String) {
|
2017-12-28 18:29:40 +01:00
|
|
|
weeknames[i] = str_strdup(entry->valuestring);
|
2017-05-07 17:46:51 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
log_error("calendar.weeks[%d] is not a string: %d", i, json->type);
|
|
|
|
free(weeknames);
|
|
|
|
weeknames = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(i == weeks_per_month);
|
|
|
|
free(weeknames2);
|
|
|
|
weeknames2 = malloc(sizeof(char *) * weeks_per_month);
|
2018-12-15 20:01:51 +01:00
|
|
|
if (!weeknames2) abort();
|
2017-05-07 17:46:51 +02:00
|
|
|
for (i = 0; i != weeks_per_month; ++i) {
|
|
|
|
weeknames2[i] = malloc(strlen(weeknames[i]) + 3);
|
|
|
|
sprintf(weeknames2[i], "%s_d", weeknames[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (strcmp(child->string, "months") == 0) {
|
|
|
|
cJSON *jmonth;
|
|
|
|
int i;
|
|
|
|
if (child->type != cJSON_Array) {
|
|
|
|
log_error("calendar.seasons is not an array: %d", json->type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
free(month_season);
|
|
|
|
month_season = NULL;
|
|
|
|
free(storms);
|
|
|
|
months_per_year = cJSON_GetArraySize(child);
|
|
|
|
storms = malloc(sizeof(int) * months_per_year);
|
2018-12-15 20:01:51 +01:00
|
|
|
if (!storms) abort();
|
2017-05-07 17:46:51 +02:00
|
|
|
month_season = malloc(sizeof(int) * months_per_year);
|
2018-12-15 20:01:51 +01:00
|
|
|
if (!month_season) abort();
|
2017-05-07 17:46:51 +02:00
|
|
|
for (i = 0, jmonth = child->child; jmonth; jmonth = jmonth->next, ++i) {
|
|
|
|
if (jmonth->type == cJSON_Object) {
|
|
|
|
storms[i] = cJSON_GetObjectItem(jmonth, "storm")->valueint;
|
|
|
|
month_season[i] = cJSON_GetObjectItem(jmonth, "season")->valueint;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
log_error("calendar.months[%d] is not an object: %d", i, json->type);
|
|
|
|
free(storms);
|
|
|
|
storms = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 04:21:28 +02:00
|
|
|
static void json_directions(cJSON *json) {
|
2014-06-16 07:17:08 +02:00
|
|
|
cJSON *child;
|
2015-01-30 20:37:14 +01:00
|
|
|
if (json->type != cJSON_Object) {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("directions is not a json object: %d", json->type);
|
2014-06-16 07:17:08 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
for (child = json->child; child; child = child->next) {
|
2017-02-12 06:06:33 +01:00
|
|
|
struct locale * lang = get_locale(child->string);
|
2014-06-16 07:17:08 +02:00
|
|
|
json_direction(child, lang);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-21 17:53:14 +02:00
|
|
|
static void json_skill(cJSON *json, struct locale *lang) {
|
|
|
|
cJSON *child;
|
2015-01-30 20:37:14 +01:00
|
|
|
if (json->type != cJSON_Object) {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("skill for locale `%s` not a json object: %d", locale_name(lang), json->type);
|
2014-06-21 17:53:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
for (child = json->child; child; child = child->next) {
|
2014-06-21 17:53:14 +02:00
|
|
|
skill_t sk = findskill(child->string);
|
2015-01-30 20:37:14 +01:00
|
|
|
if (sk != NOSKILL) {
|
|
|
|
if (child->type == cJSON_String) {
|
2014-06-21 17:53:14 +02:00
|
|
|
init_skill(lang, sk, child->valuestring);
|
|
|
|
locale_setstring(lang, mkname("skill", skillnames[sk]), child->valuestring);
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
else if (child->type == cJSON_Array) {
|
2014-06-21 17:53:14 +02:00
|
|
|
cJSON *entry;
|
2015-01-30 20:37:14 +01:00
|
|
|
for (entry = child->child; entry; entry = entry->next) {
|
2014-06-21 17:53:14 +02:00
|
|
|
init_skill(lang, sk, entry->valuestring);
|
2015-01-30 20:37:14 +01:00
|
|
|
if (entry == child->child) {
|
|
|
|
locale_setstring(lang, mkname("skill", skillnames[sk]), entry->valuestring);
|
2014-06-21 17:53:14 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
}
|
|
|
|
else {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("invalid type %d for skill `%s`", child->type, child->string);
|
2014-06-21 17:53:14 +02:00
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
}
|
|
|
|
else {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("unknown skill `%s` for locale `%s`", child->string, locale_name(lang));
|
2014-06-21 17:53:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-16 20:30:23 +02:00
|
|
|
static void json_keyword(cJSON *json, struct locale *lang) {
|
|
|
|
cJSON *child;
|
2015-01-30 20:37:14 +01:00
|
|
|
if (json->type != cJSON_Object) {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("keywords for locale `%s` not a json object: %d", locale_name(lang), json->type);
|
2014-06-16 20:30:23 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
for (child = json->child; child; child = child->next) {
|
2014-06-16 20:30:23 +02:00
|
|
|
keyword_t kwd = findkeyword(child->string);
|
2018-09-15 18:35:27 +02:00
|
|
|
if (kwd != NOKEYWORD && keywords[kwd]) {
|
2015-01-30 20:37:14 +01:00
|
|
|
if (child->type == cJSON_String) {
|
2014-06-16 20:30:23 +02:00
|
|
|
init_keyword(lang, kwd, child->valuestring);
|
2014-06-17 05:41:08 +02:00
|
|
|
locale_setstring(lang, mkname("keyword", keywords[kwd]), child->valuestring);
|
2014-06-16 20:30:23 +02:00
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
else if (child->type == cJSON_Array) {
|
2014-06-16 20:30:23 +02:00
|
|
|
cJSON *entry;
|
2015-01-30 20:37:14 +01:00
|
|
|
for (entry = child->child; entry; entry = entry->next) {
|
2014-06-16 20:30:23 +02:00
|
|
|
init_keyword(lang, kwd, entry->valuestring);
|
2015-01-30 20:37:14 +01:00
|
|
|
if (entry == child->child) {
|
|
|
|
locale_setstring(lang, mkname("keyword", keywords[kwd]), entry->valuestring);
|
2014-06-17 05:41:08 +02:00
|
|
|
}
|
2014-06-16 20:30:23 +02:00
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
}
|
|
|
|
else {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("invalid type %d for keyword `%s`", child->type, child->string);
|
2014-06-16 20:30:23 +02:00
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
}
|
|
|
|
else {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("unknown keyword `%s` for locale `%s`", child->string, locale_name(lang));
|
2014-06-16 20:30:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 04:21:28 +02:00
|
|
|
static void json_skills(cJSON *json) {
|
2014-06-21 17:53:14 +02:00
|
|
|
cJSON *child;
|
2015-01-30 20:37:14 +01:00
|
|
|
if (json->type != cJSON_Object) {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("skills is not a json object: %d", json->type);
|
2014-06-21 17:53:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
for (child = json->child; child; child = child->next) {
|
2017-02-12 06:06:33 +01:00
|
|
|
struct locale * lang = get_locale(child->string);
|
2014-06-21 17:53:14 +02:00
|
|
|
json_skill(child, lang);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 04:21:28 +02:00
|
|
|
static void json_keywords(cJSON *json) {
|
2014-06-16 20:30:23 +02:00
|
|
|
cJSON *child;
|
2015-01-30 20:37:14 +01:00
|
|
|
if (json->type != cJSON_Object) {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("keywords is not a json object: %d", json->type);
|
2014-06-16 20:30:23 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
for (child = json->child; child; child = child->next) {
|
2017-02-12 06:06:33 +01:00
|
|
|
struct locale * lang = get_locale(child->string);
|
2014-06-16 20:30:23 +02:00
|
|
|
json_keyword(child, lang);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-10 23:16:17 +02:00
|
|
|
static void json_settings(cJSON *json) {
|
|
|
|
cJSON *child;
|
|
|
|
if (json->type != cJSON_Object) {
|
|
|
|
log_error("settings is not a json object: %d", json->type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (child = json->child; child; child = child->next) {
|
2017-03-01 21:17:37 +01:00
|
|
|
if (config_get(child->string) == NULL) {
|
|
|
|
if (child->valuestring) {
|
|
|
|
config_set(child->string, child->valuestring);
|
2015-09-11 09:17:07 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-03-01 21:17:37 +01:00
|
|
|
char value[32];
|
|
|
|
if (child->type == cJSON_Number && child->valuedouble && child->valueint < child->valuedouble) {
|
|
|
|
sprintf(value, "%f", child->valuedouble);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sprintf(value, "%d", child->valueint);
|
|
|
|
}
|
2017-01-21 20:59:16 +01:00
|
|
|
config_set(child->string, value);
|
|
|
|
}
|
2015-09-10 23:16:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 04:21:28 +02:00
|
|
|
static void json_races(cJSON *json) {
|
2014-06-08 07:17:48 +02:00
|
|
|
cJSON *child;
|
2014-10-29 07:50:06 +01:00
|
|
|
if (json->type != cJSON_Object) {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("races is not a json object: %d", json->type);
|
2014-06-08 07:17:48 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-10-29 07:50:06 +01:00
|
|
|
for (child = json->child; child; child = child->next) {
|
2014-06-13 07:14:07 +02:00
|
|
|
json_race(child, rc_get_or_create(child->string));
|
2014-06-08 07:17:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-29 19:40:09 +01:00
|
|
|
const char * json_relpath;
|
|
|
|
|
2018-02-05 19:35:15 +01:00
|
|
|
/* TODO: much more configurable authority-to-file lookup */
|
|
|
|
static const char * authority_to_path(const char *authority, char *name, size_t size) {
|
|
|
|
/* source and destination cannot share the same buffer */
|
|
|
|
assert(authority < name || authority > name + size);
|
|
|
|
|
|
|
|
return join_path(json_relpath, authority, name, size);
|
|
|
|
}
|
|
|
|
|
2018-02-05 03:44:26 +01:00
|
|
|
static const char * uri_to_file(const char * uri, char *name, size_t size) {
|
2018-02-05 19:35:15 +01:00
|
|
|
const char *pos, *scheme, *path = uri;
|
|
|
|
|
|
|
|
/* source and destination cannot share the same buffer */
|
|
|
|
assert(uri < name || uri > name + size);
|
2018-02-05 03:44:26 +01:00
|
|
|
|
2018-02-05 19:35:15 +01:00
|
|
|
/* identify scheme */
|
|
|
|
scheme = uri;
|
|
|
|
pos = strstr(scheme, "://");
|
2018-02-05 03:44:26 +01:00
|
|
|
if (pos) {
|
2018-02-05 19:35:15 +01:00
|
|
|
size_t slen = pos - scheme;
|
|
|
|
if (strncmp(scheme, "config", slen) == 0) {
|
|
|
|
const char *authority = pos + 3;
|
|
|
|
/* authority */
|
|
|
|
pos = strstr(authority, "/");
|
|
|
|
if (pos) {
|
|
|
|
char buffer[16];
|
|
|
|
size_t alen = pos - authority;
|
|
|
|
assert(alen < sizeof(buffer));
|
|
|
|
memcpy(buffer, authority, alen);
|
|
|
|
buffer[alen] = 0;
|
|
|
|
|
|
|
|
path = authority_to_path(buffer, name, size);
|
|
|
|
path = path_join(path, pos + 1, name, size);
|
|
|
|
}
|
2018-02-05 03:44:26 +01:00
|
|
|
}
|
2018-02-05 19:35:15 +01:00
|
|
|
else {
|
|
|
|
log_fatal("unknown URI scheme: %s", uri);
|
2018-02-05 03:44:26 +01:00
|
|
|
}
|
2018-02-04 18:25:38 +01:00
|
|
|
}
|
2018-02-05 19:35:15 +01:00
|
|
|
return path;
|
2018-02-05 03:44:26 +01:00
|
|
|
}
|
|
|
|
|
2018-02-06 18:46:28 +01:00
|
|
|
static int include_json(const char *uri) {
|
2018-02-05 03:44:26 +01:00
|
|
|
FILE *F;
|
|
|
|
char name[PATH_MAX];
|
|
|
|
const char *filename = uri_to_file(uri, name, sizeof(name));
|
2018-02-08 08:33:27 +01:00
|
|
|
int result = -1;
|
2018-02-05 03:44:26 +01:00
|
|
|
|
|
|
|
F = fopen(filename, "r");
|
2018-02-04 18:25:38 +01:00
|
|
|
if (F) {
|
|
|
|
long pos;
|
|
|
|
fseek(F, 0, SEEK_END);
|
|
|
|
pos = ftell(F);
|
|
|
|
rewind(F);
|
|
|
|
if (pos > 0) {
|
|
|
|
cJSON *config;
|
|
|
|
char *data;
|
|
|
|
size_t sz;
|
|
|
|
|
|
|
|
data = malloc(pos + 1);
|
2018-12-15 20:01:51 +01:00
|
|
|
if (!data) abort();
|
2018-02-04 18:25:38 +01:00
|
|
|
sz = fread(data, 1, (size_t)pos, F);
|
|
|
|
data[sz] = 0;
|
|
|
|
config = cJSON_Parse(data);
|
|
|
|
free(data);
|
|
|
|
if (config) {
|
|
|
|
json_config(config);
|
|
|
|
cJSON_Delete(config);
|
2018-02-08 08:33:27 +01:00
|
|
|
result = 0;
|
2018-02-04 18:25:38 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-02-05 03:44:26 +01:00
|
|
|
log_error("could not parse JSON from %s", uri);
|
2018-02-08 08:33:27 +01:00
|
|
|
result = -1;
|
2018-02-04 18:25:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(F);
|
|
|
|
}
|
2018-02-08 08:33:27 +01:00
|
|
|
return result;
|
2018-02-04 18:25:38 +01:00
|
|
|
}
|
|
|
|
|
2018-02-06 18:46:28 +01:00
|
|
|
static int include_xml(const char *uri) {
|
2018-02-04 18:25:38 +01:00
|
|
|
char name[PATH_MAX];
|
2018-02-05 03:44:26 +01:00
|
|
|
const char *filename = uri_to_file(uri, name, sizeof(name));
|
2018-04-24 21:50:49 +02:00
|
|
|
int err;
|
|
|
|
err = exparse_readfile(filename);
|
|
|
|
if (err != 0) {
|
2018-02-05 03:44:26 +01:00
|
|
|
log_error("could not parse XML from %s", uri);
|
2018-02-04 18:25:38 +01:00
|
|
|
}
|
2018-02-06 18:46:28 +01:00
|
|
|
return err;
|
2018-02-04 18:25:38 +01:00
|
|
|
}
|
|
|
|
|
2018-05-17 16:54:59 +02:00
|
|
|
static int add_po_string(const char *msgid, const char *msgstr, const char *msgctxt, void *data) {
|
|
|
|
struct locale * lang = (struct locale *)data;
|
|
|
|
const char * key = msgid;
|
|
|
|
if (msgctxt) {
|
|
|
|
key = mkname(msgctxt, msgid);
|
|
|
|
}
|
|
|
|
locale_setstring(lang, key, msgstr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int include_po(const char *uri) {
|
2018-12-09 03:42:08 +01:00
|
|
|
char name[PATH_MAX];
|
2018-05-17 16:54:59 +02:00
|
|
|
const char *filename = uri_to_file(uri, name, sizeof(name));
|
|
|
|
const char *pos = strstr(filename, ".po");
|
|
|
|
if (pos) {
|
2018-05-17 23:53:44 +02:00
|
|
|
size_t len;
|
2018-05-17 16:54:59 +02:00
|
|
|
const char *str = --pos;
|
2018-12-09 03:42:08 +01:00
|
|
|
char lname[8];
|
|
|
|
|
2018-05-17 16:54:59 +02:00
|
|
|
while (str > filename && *str != '.') --str;
|
2018-05-17 23:53:44 +02:00
|
|
|
len = (size_t)(pos - str);
|
|
|
|
if (len < sizeof(lname)) {
|
2018-05-17 16:54:59 +02:00
|
|
|
struct locale * lang;
|
2018-05-17 23:53:44 +02:00
|
|
|
memcpy(lname, str+1, len);
|
|
|
|
lname[len] = 0;
|
2018-05-17 16:54:59 +02:00
|
|
|
lang = get_or_create_locale(lname);
|
|
|
|
if (lang) {
|
|
|
|
int err = pofile_read(filename, add_po_string, lang);
|
|
|
|
if (err < 0) {
|
2018-05-18 21:14:14 +02:00
|
|
|
log_error("could not parse translations from %s", uri);
|
2018-05-17 16:54:59 +02:00
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-10-29 19:40:09 +01:00
|
|
|
static void json_include(cJSON *json) {
|
2014-10-29 07:50:06 +01:00
|
|
|
cJSON *child;
|
|
|
|
if (json->type != cJSON_Array) {
|
|
|
|
log_error("config is not a json array: %d", json->type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (child = json->child; child; child = child->next) {
|
2018-02-05 03:44:26 +01:00
|
|
|
const char *uri = child->valuestring;
|
2018-02-06 18:46:28 +01:00
|
|
|
int err;
|
2018-02-05 03:44:26 +01:00
|
|
|
|
2018-05-17 16:54:59 +02:00
|
|
|
if (strstr(uri, ".po") != NULL) {
|
|
|
|
err = include_po(uri);
|
|
|
|
}
|
|
|
|
else if (strstr(uri, ".xml") != NULL) {
|
2018-02-06 18:46:28 +01:00
|
|
|
err = include_xml(uri);
|
2014-10-29 19:40:09 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-02-06 18:46:28 +01:00
|
|
|
err = include_json(uri);
|
|
|
|
}
|
|
|
|
if (err != 0) {
|
|
|
|
log_error("no data found in %s", uri);
|
2014-10-29 07:50:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-08 07:17:48 +02:00
|
|
|
void json_config(cJSON *json) {
|
|
|
|
cJSON *child;
|
2015-09-11 22:41:57 +02:00
|
|
|
assert(json);
|
2015-01-30 20:37:14 +01:00
|
|
|
if (json->type != cJSON_Object) {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("config is not a json object: %d", json->type);
|
2014-06-08 07:17:48 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-10-29 19:40:09 +01:00
|
|
|
reset_locales();
|
2015-01-30 20:37:14 +01:00
|
|
|
for (child = json->child; child; child = child->next) {
|
|
|
|
if (strcmp(child->string, "races") == 0) {
|
2014-06-14 02:36:05 +02:00
|
|
|
json_races(child);
|
|
|
|
}
|
2014-10-29 07:50:06 +01:00
|
|
|
else if (strcmp(child->string, "items") == 0) {
|
2014-06-25 07:54:10 +02:00
|
|
|
json_items(child);
|
|
|
|
}
|
2014-10-29 19:40:09 +01:00
|
|
|
else if (strcmp(child->string, "include") == 0) {
|
|
|
|
json_include(child);
|
2014-10-29 07:50:06 +01:00
|
|
|
}
|
|
|
|
else if (strcmp(child->string, "ships") == 0) {
|
2014-06-14 02:36:05 +02:00
|
|
|
json_ships(child);
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
else if (strcmp(child->string, "strings") == 0) {
|
2014-06-28 19:37:40 +02:00
|
|
|
json_strings(child);
|
|
|
|
}
|
2017-05-07 17:46:51 +02:00
|
|
|
else if (strcmp(child->string, "calendar") == 0) {
|
|
|
|
json_calendar(child);
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
else if (strcmp(child->string, "directions") == 0) {
|
2014-06-16 07:17:08 +02:00
|
|
|
json_directions(child);
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
else if (strcmp(child->string, "keywords") == 0) {
|
2014-06-16 20:30:23 +02:00
|
|
|
json_keywords(child);
|
|
|
|
}
|
2015-09-10 23:16:17 +02:00
|
|
|
else if (strcmp(child->string, "settings") == 0) {
|
|
|
|
json_settings(child);
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
else if (strcmp(child->string, "skills") == 0) {
|
2014-06-21 17:53:14 +02:00
|
|
|
json_skills(child);
|
|
|
|
}
|
2014-07-03 06:15:22 +02:00
|
|
|
else if (strcmp(child->string, "buildings") == 0) {
|
2014-06-14 02:36:05 +02:00
|
|
|
json_buildings(child);
|
|
|
|
}
|
2014-07-03 06:15:22 +02:00
|
|
|
else if (strcmp(child->string, "spells") == 0) {
|
|
|
|
json_spells(child);
|
|
|
|
}
|
2015-09-12 12:49:12 +02:00
|
|
|
else if (strcmp(child->string, "prefixes") == 0) {
|
|
|
|
json_prefixes(child);
|
|
|
|
}
|
2015-09-12 17:37:29 +02:00
|
|
|
else if (strcmp(child->string, "disabled") == 0) {
|
|
|
|
json_disable_features(child);
|
2015-09-12 17:06:47 +02:00
|
|
|
}
|
2014-07-03 06:15:22 +02:00
|
|
|
else if (strcmp(child->string, "terrains") == 0) {
|
2014-06-14 02:36:05 +02:00
|
|
|
json_terrains(child);
|
2015-09-11 21:14:10 +02:00
|
|
|
init_terrains();
|
2015-01-30 20:37:14 +01:00
|
|
|
}
|
|
|
|
else {
|
2014-08-11 12:02:16 +02:00
|
|
|
log_error("config contains unknown attribute %s", child->string);
|
2014-06-14 02:36:05 +02:00
|
|
|
}
|
2014-06-13 07:14:07 +02:00
|
|
|
}
|
2014-06-08 07:17:48 +02:00
|
|
|
}
|
2014-06-09 18:54:48 +02:00
|
|
|
|