From 9e16ebc01ad199165eeec4a633ae3e69351601c1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 10 May 2018 22:00:23 +0200 Subject: [PATCH] all kinds of race flag breakage repaired. but now, humans suddenly can't build a ship in E2? --- src/exparse.c | 2 +- src/jsonconf.c | 7 +++---- src/jsonconf.test.c | 6 +++--- src/kernel/race.c | 1 + src/kernel/race.h | 6 +++--- src/monsters.test.c | 14 +++++++++----- src/spy.test.c | 3 +++ src/tests.c | 2 +- src/xmlreader.c | 4 ++-- 9 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/exparse.c b/src/exparse.c index 943b80741..b016c89df 100644 --- a/src/exparse.c +++ b/src/exparse.c @@ -883,7 +883,7 @@ static int nfamiliars; static void XMLCALL start_races(parseinfo *pi, const XML_Char *el, const XML_Char **attr) { race *rc = (race *)pi->object; const char *flag_names[] = { - "!playerrace", "killpeasants", "scarepeasants", "!cansteal", + "playerrace", "killpeasants", "scarepeasants", "!cansteal", "moverandom", "cannotmove", "learn", "fly", "swim", "walk", "!learn", "!teach", "horse", "desert", "illusionary", "absorbpeasants", "noheal", "noweapons", "shapeshift", diff --git a/src/jsonconf.c b/src/jsonconf.c index 51727fe52..29881d6cf 100644 --- a/src/jsonconf.c +++ b/src/jsonconf.c @@ -480,17 +480,16 @@ static void json_ship(cJSON *json, ship_type *st) { static void json_race(cJSON *json, race *rc) { cJSON *child; const char *flags[] = { - "npc", "killpeasants", "scarepeasants", + "player", "killpeasants", "scarepeasants", "nosteal", "moverandom", "cannotmove", "learn", "fly", "swim", "walk", "nolearn", "noteach", "horse", "desert", "illusionary", "absorbpeasants", "noheal", "noweapons", "shapeshift", "", "undead", "dragon", - "coastal", "", "cansail", 0 + "coastal", "", "cansail", NULL }; const char *ecflags[] = { - "", "keepitem", "giveperson", - "giveunit", "getitem", 0 + "giveperson", "giveunit", "getitem", NULL }; if (json->type != cJSON_Object) { log_error("race %s is not a json object: %d", json->string, json->type); diff --git a/src/jsonconf.test.c b/src/jsonconf.test.c index 482337e40..7c15b63f1 100644 --- a/src/jsonconf.test.c +++ b/src/jsonconf.test.c @@ -56,7 +56,7 @@ static void check_flag(CuTest *tc, const char *name, int flag) { static void test_flags(CuTest *tc) { test_setup(); - check_flag(tc, "npc", RCF_NPC); + check_flag(tc, "player", RCF_PLAYABLE); check_flag(tc, "scarepeasants", RCF_SCAREPEASANTS); check_flag(tc, "nosteal", RCF_NOSTEAL); check_flag(tc, "noheal", RCF_NOHEAL); @@ -181,7 +181,7 @@ static void test_races(CuTest * tc) "\"income\" : 30," "\"hp\" : 5," "\"ac\" : 6," - "\"flags\" : [ \"npc\", \"walk\", \"undead\" ]" + "\"flags\" : [ \"player\", \"walk\", \"undead\" ]" "}}}"; cJSON *json = cJSON_Parse(data); const struct race *rc; @@ -195,7 +195,7 @@ static void test_races(CuTest * tc) CuAssertPtrNotNull(tc, races); rc = rc_find("orc"); CuAssertPtrNotNull(tc, rc); - CuAssertIntEquals(tc, RCF_NPC | RCF_WALK | RCF_UNDEAD, rc->flags); + CuAssertIntEquals(tc, RCF_PLAYABLE | RCF_WALK | RCF_UNDEAD, rc->flags); CuAssertStrEquals(tc, "1d4", rc->def_damage); CuAssertTrue(tc, frac_equal(frac_one, rc->magres)); CuAssertIntEquals(tc, 200, rc->maxaura); diff --git a/src/kernel/race.c b/src/kernel/race.c index e77929fbf..ecdb7ae3d 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -356,6 +356,7 @@ race *rc_create(const char *zName) rc->magres.sa[1] = 1; rc->hitpoints = 1; + rc->flags = RCF_DEFAULT; rc->weight = PERSON_WEIGHT; rc->capacity = 540; rc->income = 20; diff --git a/src/kernel/race.h b/src/kernel/race.h index 202b84d4b..de0fd92e0 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -202,7 +202,7 @@ extern "C" { int rc_get_mask(char *list); /* Flags. Do not reorder these without changing json_race() in jsonconf.c */ -#define RCF_NPC (1<<0) /* cannot be the race for a player faction (and other limits?) */ +#define RCF_PLAYABLE (1<<0) /* cannot be the race for a player faction (and other limits?) */ #define RCF_KILLPEASANTS (1<<1) /* a monster that eats peasants */ #define RCF_SCAREPEASANTS (1<<2) /* a monster that scares peasants out of the hex */ #define RCF_NOSTEAL (1<<3) /* this race has high stealth, but is not allowed to steal */ @@ -233,7 +233,7 @@ extern "C" { #define RCF_MIGRANTS (1<<28) /* may have migrant units (human bonus) */ #define RCF_FAMILIAR (1<<29) /* may be a familiar */ -#define RCF_DEFAULT (RCF_NOSTEAL|RCF_CANSAIL|RCF_NOLEARN) +#define RCF_DEFAULT 0 /* Economic flags */ #define ECF_GIVEPERSON (1<<0) /* �bergibt Personen */ @@ -256,7 +256,7 @@ extern "C" { const char *racename(const struct locale *lang, const struct unit *u, const race * rc); -#define playerrace(rc) (!((rc)->flags & RCF_NPC)) +#define playerrace(rc) ((rc)->flags & RCF_PLAYABLE) #define dragonrace(rc) ((rc)->flags & RCF_DRAGON) #define humanoidrace(rc) (((rc)->flags & RCF_UNDEAD) || (rc)==get_race(RC_DRACOID) || playerrace(rc)) #define illusionaryrace(rc) ((rc)->flags & RCF_ILLUSIONARY) diff --git a/src/monsters.test.c b/src/monsters.test.c index 409b86dfe..8fe9a6b7f 100644 --- a/src/monsters.test.c +++ b/src/monsters.test.c @@ -55,12 +55,16 @@ static void create_monsters(unit **up, unit **um) { test_create_horse(); default_locale = test_create_locale(); fp = test_create_faction(NULL); + fm = get_or_create_monsters(); + fset(fm, FFL_NOIDLEOUT); + assert(fval(fm, FFL_NPC)); + assert(fval(fm, FFL_NOIDLEOUT)); + assert(rc_find(fm->race->_name)); rc = rc_get_or_create(fm->race->_name); - fset(rc, RCF_UNARMEDGUARD|RCF_NPC|RCF_DRAGON); - fset(fm, FFL_NOIDLEOUT); - assert(fval(fm, FFL_NPC) && fval(fm->race, RCF_UNARMEDGUARD) && fval(fm->race, RCF_NPC) && fval(fm, FFL_NOIDLEOUT)); + fset(rc, RCF_UNARMEDGUARD|RCF_DRAGON); + assert(!fval(fm->race, RCF_PLAYABLE)); test_create_region(-1, 0, test_create_terrain("ocean", SEA_REGION | SWIM_INTO | FLY_INTO)); test_create_region(1, 0, 0); @@ -261,12 +265,12 @@ static void test_spawn_seaserpent(CuTest *tc) { race *rc; test_setup(); rc = test_create_race("seaserpent"); - rc->flags |= RCF_NPC; + rc->flags &= ~RCF_PLAYABLE; r = test_create_region(0, 0, NULL); f = test_create_faction(NULL); u = spawn_seaserpent(r, f); CuAssertPtrNotNull(tc, u); - CuAssertPtrEquals(tc, 0, u->_name); + CuAssertPtrEquals(tc, NULL, u->_name); test_teardown(); } diff --git a/src/spy.test.c b/src/spy.test.c index c6a74822c..3c4503c98 100644 --- a/src/spy.test.c +++ b/src/spy.test.c @@ -196,7 +196,10 @@ static void test_setstealth_demon_bad(CuTest *tc) { lang = test_create_locale(); rc = test_create_race("demon"); u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, NULL)); + rc = test_create_race("smurf"); + rc->flags &= ~RCF_PLAYABLE; + init_races(lang); u->thisorder = create_order(K_SETSTEALTH, lang, racename(lang, u, rc)); setstealth_cmd(u, u->thisorder); diff --git a/src/tests.c b/src/tests.c index 696baf447..ad9f8eddf 100644 --- a/src/tests.c +++ b/src/tests.c @@ -43,7 +43,7 @@ struct race *test_create_race(const char *name) rc->maintenance = 10; rc->hitpoints = 20; rc->maxaura = 100; - rc->flags |= RCF_WALK; + rc->flags |= (RCF_WALK|RCF_PLAYABLE); rc->ec_flags |= ECF_GETITEM; rc->battle_flags = BF_EQUIPMENT; return rc; diff --git a/src/xmlreader.c b/src/xmlreader.c index cf63a3ccb..b0a0aafcc 100644 --- a/src/xmlreader.c +++ b/src/xmlreader.c @@ -1332,9 +1332,9 @@ static int parse_races(xmlDocPtr doc) rc->flags |= RCF_NOSTEAL; if (!xml_bvalue(node, "learn", true)) rc->flags |= RCF_NOLEARN; - if (!xml_bvalue(node, "playerrace", false)) { + if (xml_bvalue(node, "playerrace", false)) { assert(rc->recruitcost == 0); - rc->flags |= RCF_NPC; + rc->flags |= RCF_PLAYABLE; } if (xml_bvalue(node, "scarepeasants", false)) rc->flags |= RCF_SCAREPEASANTS;