diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index b9fe278b5..5fdd82e65 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -31,6 +31,9 @@ without prior permission by the authors of Eressea. #include "spellbook.h" #include "calendar.h" +/* game modules */ +#include "prefix.h" + /* util includes */ #include #include @@ -487,6 +490,17 @@ static void json_race(cJSON *json, race *rc) { } } +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); + } +} + static void json_terrains(cJSON *json) { cJSON *child; if (json->type != cJSON_Object) { @@ -837,6 +851,9 @@ void json_config(cJSON *json) { else if (strcmp(child->string, "spells") == 0) { json_spells(child); } + else if (strcmp(child->string, "prefixes") == 0) { + json_prefixes(child); + } else if (strcmp(child->string, "terrains") == 0) { json_terrains(child); init_terrains(); diff --git a/src/prefix.c b/src/prefix.c index ee9494e61..b6adb7c02 100644 --- a/src/prefix.c +++ b/src/prefix.c @@ -1,18 +1,23 @@ #include #include "prefix.h" +#include #include #include #include char **race_prefixes = NULL; +static size_t size = 4; +static unsigned int next = 0; void add_raceprefix(const char *prefix) { - static size_t size = 4; - static unsigned int next = 0; - if (race_prefixes == NULL) + assert(prefix); + if (race_prefixes == NULL) { + next = 0; + size = 4; race_prefixes = malloc(size * sizeof(char *)); + } if (next + 1 == size) { size *= 2; race_prefixes = realloc(race_prefixes, size * sizeof(char *));