all kinds of race flag breakage repaired.

but now, humans suddenly can't build a ship in E2?
This commit is contained in:
Enno Rehling 2018-05-10 22:00:23 +02:00
parent 5de2a9e2ae
commit 9e16ebc01a
9 changed files with 26 additions and 19 deletions

View File

@ -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",

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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) /* <20>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)

View File

@ -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();
}

View File

@ -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);

View File

@ -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;

View File

@ -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;