From c57918ede00a230f6e0ce3d1e32b69efc3e88d72 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 11 Sep 2015 22:41:57 +0200 Subject: [PATCH] replace XML terrains for E3 and E4 with JSON configuration --- conf/e3/config.json | 3 +- conf/e3/config.xml | 1 - conf/e3/terrains.json | 235 ++++++++++++++++++++++++++++++++++++++++++ conf/e4/config.json | 3 +- conf/e4/config.xml | 1 - res/e3a/terrains.xml | 61 ----------- src/kernel/jsonconf.c | 10 +- 7 files changed, 247 insertions(+), 67 deletions(-) create mode 100644 conf/e3/terrains.json delete mode 100644 res/e3a/terrains.xml diff --git a/conf/e3/config.json b/conf/e3/config.json index 33b0aa52d..d28dda80f 100644 --- a/conf/e3/config.json +++ b/conf/e3/config.json @@ -1,6 +1,7 @@ { "include": [ - "keywords.json" + "keywords.json", + "e3/terrains.json" ], "settings": { "game.id": 3, diff --git a/conf/e3/config.xml b/conf/e3/config.xml index a1dff207a..f1f403ecd 100644 --- a/conf/e3/config.xml +++ b/conf/e3/config.xml @@ -14,7 +14,6 @@ - diff --git a/conf/e3/terrains.json b/conf/e3/terrains.json new file mode 100644 index 000000000..2688312ab --- /dev/null +++ b/conf/e3/terrains.json @@ -0,0 +1,235 @@ +{ + "terrains": { + "ocean": { + "size": 100, + "flags": [ "sea", "swim", "sail", "fly" ] + }, + "plain": { + "size": 4000, + "herbs": [ "h0", "h4" ], + "seed": 3, + "road": 50, + "flags": [ "forest", "cavalry", "land", "walk", "sail", "fly" ], + "production": { + "iron": { + "chance": 0.1, + "level": "2d4-1", + "base": "5d8", + "div": "2d20+10" + }, + "stone": { + "chance": 0.15, + "level": "1d4", + "base": "5d8", + "div": "2d30+20" + }, + "laen": { + "chance": 0.01, + "level": "1d4", + "base": "1d4", + "div": "2d20+50" + } + } + }, + "swamp": { + "size": 1200, + "herbs": [ "h6", "h8" ], + "seed": 2, + "road": 75, + "flags": [ "land", "walk", "sail", "fly" ], + "production": { + "iron": { + "chance": 0.02, + "level": "2d4-1", + "base": "5d8", + "div": "2d20+10" + }, + "stone": { + "chance": 0.02, + "level": "1d4", + "base": "5d8", + "div": "2d30+20" + }, + "laen": { + "chance": 0.02, + "level": "1d4", + "base": "1d4", + "div": "2d20+50" + } + } + }, + "desert": { + "size": 400, + "seed": 2, + "road": 75, + "flags": [ "cavalry", "land", "walk", "sail", "fly" ], + "herbs": [ "h9", "h11" ], + "production": { + "iron": { + "chance": 0.15, + "level": "2d4-1", + "base": "5d8", + "div": "2d20+10" + }, + "stone": { + "chance": 0.25, + "level": "1d4", + "base": "5d8", + "div": "2d30+20" + }, + "laen": { + "chance": 0.025, + "level": "1d4", + "base": "1d4", + "div": "2d20+50" + } + } + }, + "highland": { + "size": 2300, + "seed": 2, + "road": 100, + "flags": [ "cavalry", "land", "walk", "sail", "fly" ], + "herbs": [ "h12", "h14" ], + "production": { + "iron": { + "chance": 0.15, + "level": "2d4-1", + "base": "5d8", + "div": "2d20+10" + }, + "stone": { + "chance": 0.25, + "level": "1d4", + "base": "5d8", + "div": "2d30+20" + }, + "laen": { + "chance": 0.025, + "level": "1d4", + "base": "1d4", + "div": "2d20+50" + } + } + }, + "mountain": { + "size": 600, + "seed": 2, + "road": 250, + "flags": [ "land", "walk", "sail", "fly" ], + "herbs": [ "h15", "h17" ], + "production": { + "iron": { + "chance": 1.0, + "level": "1", + "base": "50", + "div": "50" + }, + "stone": { + "chance": 1.0, + "level": "1", + "base": "100", + "div": "100" + }, + "laen": { + "chance": 0.05, + "level": "1", + "base": "4", + "div": "100" + } + } + }, + "glacier": { + "size": 150, + "seed": 2, + "road": 250, + "flags": [ "arctic", "land", "walk", "sail", "fly" ], + "herbs": [ "h18", "h20" ], + "production": { + "iron": { + "chance": 1.0, + "level": "1", + "base": "3", + "div": "50" + }, + "stone": { + "chance": 1.0, + "level": "1", + "base": "2", + "div": "100" + }, + "laen": { + "chance": 0.05, + "level": "1", + "base": "4", + "div": "100" + } + } + }, + "packice": { + "flags": [ "arctic", "swim", "walk", "sail", "fly" ] + }, + "firewall": { + "flags": [ "forbidden" ] + }, + "volcano": { + "size": 400, + "seed": 1, + "road": 250, + "flags": [ "land", "walk", "sail", "fly" ], + "production": { + "iron": { + "chance": 0.5, + "level": "1", + "base": "50", + "div": "50" + }, + "stone": { + "chance": 0.5, + "level": "1", + "base": "100", + "div": "100" + }, + "laen": { + "chance": 0.075, + "level": "1", + "base": "4", + "div": "100" + } + } + }, + "activevolcano": { + "size": 400, + "road": 250, + "flags": [ "land", "walk", "sail", "fly" ], + "production": { + "iron": { + "chance": 0.5, + "level": "1", + "base": "50", + "div": "50" + }, + "stone": { + "chance": 0.5, + "level": "1", + "base": "100", + "div": "100" + }, + "laen": { + "chance": 0.075, + "level": "1", + "base": "4", + "div": "100" + } + } + }, + "default": { + "size": 0, + "herbs": [], + "seed": 0, + "road": 0, + "flags": [ "land", "walk", "sail", "fly" ], + "production": {} + } + } +} \ No newline at end of file diff --git a/conf/e4/config.json b/conf/e4/config.json index 0f31d8362..b6a0e16ab 100644 --- a/conf/e4/config.json +++ b/conf/e4/config.json @@ -1,6 +1,7 @@ { "include": [ - "keywords.json" + "keywords.json", + "e3/terrains.xml" ], "settings": { "game.id": 4, diff --git a/conf/e4/config.xml b/conf/e4/config.xml index 8e0fad67c..011f19821 100644 --- a/conf/e4/config.xml +++ b/conf/e4/config.xml @@ -14,7 +14,6 @@ - diff --git a/res/e3a/terrains.xml b/res/e3a/terrains.xml deleted file mode 100644 index 8d9d6f17a..000000000 --- a/res/e3a/terrains.xml +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index 2453cdfc6..b9fe278b5 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -784,14 +784,20 @@ static void json_include(cJSON *json) { fclose(F); config = cJSON_Parse(data); free(data); - json_config(config); - cJSON_Delete(config); + if (config) { + json_config(config); + cJSON_Delete(config); + } + else { + log_error("invalid JSON, could not parse %s", child->valuestring); + } } } } void json_config(cJSON *json) { cJSON *child; + assert(json); if (json->type != cJSON_Object) { log_error("config is not a json object: %d", json->type); return;