From fdae518ef710701893d89f33e0742e210f503254 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 6 Jul 2014 00:53:15 -0700 Subject: [PATCH] also read the extended race::ec_flags from JSON configuration. --- src/kernel/jsonconf.c | 7 ++++++- src/kernel/jsonconf.test.c | 20 ++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index ef771f8ac..829e93113 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -334,7 +334,11 @@ static void json_race(cJSON *json, race *rc) { "noweapons", "shapeshift", "", "undead", "dragon", "coastal", "", "cansail", 0 }; - if (json->type!=cJSON_Object) { + const char *ecflags[] = { + "", "giveitem", "giveperson", + "giveunit", "getitem", 0 + }; + if (json->type != cJSON_Object) { log_error_n("race %s is not a json object: %d", json->string, json->type); return; } @@ -381,6 +385,7 @@ static void json_race(cJSON *json, race *rc) { case cJSON_Array: if (strcmp(child->string, "flags")==0) { rc->flags = json_flags(child, flags); + rc->ec_flags = json_flags(child, ecflags); } break; } diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index ad525ef33..5083f8e73 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -16,19 +16,27 @@ #include #include -static void check_flag(CuTest *tc, const char *name, int flag) { +static const struct race * race_with_flag(const char * name) { char data[1024]; - const struct race *rc; cJSON *json; sprintf(data, "{\"races\" : { \"orc\": { \"speed\" : 1, \"flags\" : [ \"%s\"] }}}", name); json = cJSON_Parse(data); free_races(); json_config(json); - rc = rc_find("orc"); + return rc_find("orc"); +} + +static void check_ec_flag(CuTest *tc, const char *name, int flag) { + const struct race *rc = race_with_flag(name); + CuAssertPtrNotNull(tc, rc); + CuAssertIntEquals(tc, flag, rc->ec_flags); +} + +static void check_flag(CuTest *tc, const char *name, int flag) { + const struct race *rc = race_with_flag(name); CuAssertPtrNotNull(tc, rc); CuAssertIntEquals(tc, flag, rc->flags); - CuAssertDblEquals(tc, 1.0f, rc->speed, 0.0f); } static void test_flags(CuTest *tc) { @@ -39,6 +47,10 @@ static void test_flags(CuTest *tc) { check_flag(tc, "undead", RCF_UNDEAD); check_flag(tc, "dragon", RCF_DRAGON); check_flag(tc, "fly", RCF_FLY); + check_ec_flag(tc, "getitem", GETITEM); + check_ec_flag(tc, "giveitem", GIVEITEM); + check_ec_flag(tc, "giveperson", GIVEPERSON); + check_ec_flag(tc, "giveunit", GIVEUNIT); test_cleanup(); }