also read the extended race::ec_flags from JSON configuration.

This commit is contained in:
Enno Rehling 2014-07-06 00:53:15 -07:00
parent 88f9d247bd
commit fdae518ef7
2 changed files with 22 additions and 5 deletions

View File

@ -334,6 +334,10 @@ static void json_race(cJSON *json, race *rc) {
"noweapons", "shapeshift", "", "undead", "dragon",
"coastal", "", "cansail", 0
};
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;
}

View File

@ -16,19 +16,27 @@
#include <tests.h>
#include <stdio.h>
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();
}