From f06e3371a060335f0b2231adb64921221230df12 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 19 Apr 2015 12:49:39 +0200 Subject: [PATCH] Bug 2089 again. rename giveitem flag to keepitem, because races should default to not holding on to their stuff. --- src/give.c | 8 ++++---- src/kernel/jsonconf.c | 3 ++- src/kernel/jsonconf.test.c | 2 +- src/kernel/pool.c | 4 ++-- src/kernel/race.h | 2 +- src/kernel/unit.c | 8 ++++---- src/kernel/xmlreader.c | 4 ++-- src/laws.c | 2 +- src/tests.c | 2 +- src/upkeep.c | 4 +--- 10 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/give.c b/src/give.c index d875dc34a..93cba504e 100644 --- a/src/give.c +++ b/src/give.c @@ -595,7 +595,7 @@ void give_cmd(unit * u, order * ord) else if (p == P_HERBS) { bool given = false; - if (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) { + if ((u_race(u)->ec_flags & ECF_KEEP_ITEM) && u2 != NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_nogive", "race", u_race(u))); return; @@ -660,7 +660,7 @@ void give_cmd(unit * u, order * ord) if (!s || *s == 0) { /* GIVE ALL items that you have */ /* do these checks once, not for each item we have: */ - if (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) { + if ((u_race(u)->ec_flags & ECF_KEEP_ITEM) && u2 != NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_nogive", "race", u_race(u))); return; @@ -704,7 +704,7 @@ void give_cmd(unit * u, order * ord) } } } - else if (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) { + else if ((u_race(u)->ec_flags & ECF_KEEP_ITEM) && u2 != NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_nogive", "race", u_race(u))); } @@ -763,7 +763,7 @@ void give_cmd(unit * u, order * ord) } if (u2 != NULL) { - if (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) { + if ((u_race(u)->ec_flags & ECF_KEEP_ITEM) && u2 != NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_nogive", "race", u_race(u))); return; diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index 1b6995778..8db61376c 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -62,6 +62,7 @@ static int json_flags(cJSON *json, const char *flags[]) { for (i = 0; flags[i]; ++i) { if (strcmp(flags[i], entry->valuestring) == 0) { result |= (1 << i); + break; } } } @@ -344,7 +345,7 @@ static void json_race(cJSON *json, race *rc) { "coastal", "", "cansail", 0 }; const char *ecflags[] = { - "", "giveitem", "giveperson", + "", "keepitem", "giveperson", "giveunit", "getitem", 0 }; if (json->type != cJSON_Object) { diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index db861fcfc..bbe222fb6 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -51,7 +51,7 @@ static void test_flags(CuTest *tc) { 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, "keepitem", ECF_KEEP_ITEM); check_ec_flag(tc, "giveperson", GIVEPERSON); check_ec_flag(tc, "giveunit", GIVEUNIT); test_cleanup(); diff --git a/src/kernel/pool.c b/src/kernel/pool.c index e487abf23..12e314fd3 100644 --- a/src/kernel/pool.c +++ b/src/kernel/pool.c @@ -179,7 +179,7 @@ int count) if (u != v && (v->items || rtype->uget)) { int mask; - if ((urace(v)->ec_flags & GIVEITEM) == 0) + if ((urace(v)->ec_flags & ECF_KEEP_ITEM)) continue; if (v->faction == f) { @@ -232,7 +232,7 @@ use_pooled(unit * u, const resource_type * rtype, unsigned int mode, int count) for (v = r->units; use > 0 && v != NULL; v = v->next) { if (u != v) { int mask; - if ((urace(v)->ec_flags & GIVEITEM) == 0) + if ((urace(v)->ec_flags & ECF_KEEP_ITEM)) continue; if (v->items == NULL && rtype->uget == NULL) continue; diff --git a/src/kernel/race.h b/src/kernel/race.h index cccc88167..d8246a382 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -215,7 +215,7 @@ extern "C" { #define RCF_IRONGOLEM (1<<28) /* race gets irongolem properties */ /* Economic flags */ -#define GIVEITEM (1<<1) /* gibt Gegenstände weg */ +#define ECF_KEEP_ITEM (1<<1) /* gibt Gegenstände weg */ #define GIVEPERSON (1<<2) /* übergibt Personen */ #define GIVEUNIT (1<<3) /* Einheiten an andere Partei übergeben */ #define GETITEM (1<<4) /* nimmt Gegenstände an */ diff --git a/src/kernel/unit.c b/src/kernel/unit.c index d65c7b3c2..a946caae0 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -257,9 +257,9 @@ static buddy *get_friends(const unit * u, int *numfriends) *fr = nf; } else if (nf->faction == u2->faction - && (u_race(u2)->ec_flags & GIVEITEM)) { + && !(u_race(u2)->ec_flags & ECF_KEEP_ITEM)) { /* we don't like to gift it to units that won't give it back */ - if ((u_race(nf->unit)->ec_flags & GIVEITEM) == 0) { + if ((u_race(nf->unit)->ec_flags & ECF_KEEP_ITEM)) { nf->unit = u2; } } @@ -300,7 +300,7 @@ int gift_items(unit * u, int flags) if (u->items == NULL || fval(u_race(u), RCF_ILLUSIONARY)) return 0; - if ((u_race(u)->ec_flags & GIVEITEM) == 0) + if ((u_race(u)->ec_flags & ECF_KEEP_ITEM)) return 0; /* at first, I should try giving my crap to my own units in this region */ @@ -311,7 +311,7 @@ int gift_items(unit * u, int flags) /* some units won't take stuff: */ if (u_race(u2)->ec_flags & GETITEM) { /* we don't like to gift it to units that won't give it back */ - if (u_race(u2)->ec_flags & GIVEITEM) { + if (!(u_race(u2)->ec_flags & ECF_KEEP_ITEM)) { i_merge(&u2->items, &u->items); u->items = NULL; break; diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 00f10b8ac..ae9cf9c43 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1693,8 +1693,8 @@ static int parse_races(xmlDocPtr doc) if (xml_bvalue(node, "irongolem", false)) rc->flags |= RCF_IRONGOLEM; - if (xml_bvalue(node, "giveitem", true)) - rc->ec_flags |= GIVEITEM; + if (!xml_bvalue(node, "keepitem", false)) + rc->ec_flags |= ECF_KEEP_ITEM; if (xml_bvalue(node, "giveperson", false)) rc->ec_flags |= GIVEPERSON; if (xml_bvalue(node, "giveunit", false)) diff --git a/src/laws.c b/src/laws.c index 8caf8eb60..9a1358733 100755 --- a/src/laws.c +++ b/src/laws.c @@ -3092,7 +3092,7 @@ static building *age_building(building * b) * find out if there's a magician in there. */ for (u = r->units; u; u = u->next) { if (b == u->building && inside_building(u)) { - if (!(u_race(u)->ec_flags & GIVEITEM) == 0) { + if ((u_race(u)->ec_flags & ECF_KEEP_ITEM) == 0) { int n, unicorns = 0; for (n = 0; n != u->number; ++n) { if (chance(0.02)) { diff --git a/src/tests.c b/src/tests.c index ed554915b..9c03e1e18 100644 --- a/src/tests.c +++ b/src/tests.c @@ -31,7 +31,7 @@ struct race *test_create_race(const char *name) { race *rc = rc_get_or_create(name); rc->maintenance = 10; - rc->ec_flags |= GETITEM | GIVEITEM; + rc->ec_flags |= GETITEM; return rc; } diff --git a/src/upkeep.c b/src/upkeep.c index 5eecc1b42..d1c34f476 100644 --- a/src/upkeep.c +++ b/src/upkeep.c @@ -42,9 +42,7 @@ int lifestyle(const unit * u) static bool help_money(const unit * u) { - if (u_race(u)->ec_flags & GIVEITEM) - return true; - return false; + return !(u_race(u)->ec_flags & ECF_KEEP_ITEM); } static void help_feed(unit * donor, unit * u, int *need_p)