From f934e4d5e3b8d0abbaa66e4e2ba317852848fd25 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 17 Jul 2017 12:31:47 +0200 Subject: [PATCH 1/2] remove unused ECF_KEEP_ITEM flag. --- res/core/messages.xml | 10 ---------- src/give.c | 19 ------------------- src/kernel/jsonconf.test.c | 1 - src/kernel/pool.c | 6 ------ src/kernel/race.h | 1 - src/kernel/unit.c | 21 +++------------------ src/kernel/xmlreader.c | 2 -- src/laws.c | 2 +- src/upkeep.c | 13 +++---------- 9 files changed, 7 insertions(+), 68 deletions(-) diff --git a/res/core/messages.xml b/res/core/messages.xml index 006abd685..a500a41ac 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -1062,16 +1062,6 @@ "$unit($unit) in $region($region): '$order($command)' - $race($race,0) können nichts stehelen." "$unit($unit) in $region($region): '$order($command)' - $race($race,0) cannot steal anything." - - - - - - - - "$unit($unit) in $region($region): '$order($command)' - $race($race,0) geben nichts weg." - "$unit($unit) in $region($region): '$order($command)' - $race($race,0) do not give things away." - diff --git a/src/give.c b/src/give.c index 26b193d0d..543d29fc9 100644 --- a/src/give.c +++ b/src/give.c @@ -678,11 +678,6 @@ void give_cmd(unit * u, order * ord) } else if (p == P_HERBS) { bool given = false; - 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; - } if (!can_give(u, u2, NULL, GIVE_HERBS)) { feedback_give_not_allowed(u, ord); return; @@ -741,11 +736,6 @@ 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 & ECF_KEEP_ITEM) && u2 != NULL) { - ADDMSG(&u->faction->msgs, - msg_feedback(u, ord, "race_nogive", "race", u_race(u))); - return; - } if (u2 && !(u_race(u2)->ec_flags & GETITEM)) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_notake", "race", u_race(u2))); @@ -785,10 +775,6 @@ void give_cmd(unit * u, order * ord) } } } - 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))); - } else if (u2 && !(u_race(u2)->ec_flags & GETITEM)) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_notake", "race", u_race(u2))); @@ -844,11 +830,6 @@ void give_cmd(unit * u, order * ord) } if (u2 != NULL) { - if ((u_race(u)->ec_flags & ECF_KEEP_ITEM)) { - ADDMSG(&u->faction->msgs, - msg_feedback(u, ord, "race_nogive", "race", u_race(u))); - return; - } if (!(u_race(u2)->ec_flags & GETITEM)) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_notake", "race", u_race(u2))); diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index 2f54eeb8d..d526bc7b8 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -59,7 +59,6 @@ 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, "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 8dfd589c3..dae726566 100644 --- a/src/kernel/pool.c +++ b/src/kernel/pool.c @@ -179,9 +179,6 @@ int count) if (u != v) { int mask; - if ((u_race(v)->ec_flags & ECF_KEEP_ITEM)) - continue; - if (v->faction == f) { mask = (mode >> 3) & (GET_SLACK | GET_RESERVE); } @@ -232,9 +229,6 @@ 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 ((u_race(v)->ec_flags & ECF_KEEP_ITEM)) - continue; - if (v->faction == f) { mask = (mode >> 3) & (GET_SLACK | GET_RESERVE); } diff --git a/src/kernel/race.h b/src/kernel/race.h index a8933dae8..3980bea72 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -233,7 +233,6 @@ extern "C" { #define RCF_FAMILIAR (1<<31) /* may be a familiar */ /* Economic flags */ -#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 bdd5ac232..b4f942a3d 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -225,13 +225,6 @@ static buddy *get_friends(const unit * u, int *numfriends) nf->number = 0; *fr = nf; } - else if (nf->faction == u2->faction - && !(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 & ECF_KEEP_ITEM)) { - nf->unit = u2; - } - } nf->number += u2->number; number += u2->number; } @@ -269,8 +262,6 @@ 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 & ECF_KEEP_ITEM)) - return 0; /* at first, I should try giving my crap to my own units in this region */ if (u->faction && (u->faction->flags & FFL_QUIT) == 0 && (flags & GIFT_SELF)) { @@ -279,15 +270,9 @@ int gift_items(unit * u, int flags) if (u2 != u && u2->faction == u->faction && u2->number > 0) { /* 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 & ECF_KEEP_ITEM)) { - i_merge(&u2->items, &u->items); - u->items = NULL; - break; - } - else { - u3 = u2; - } + i_merge(&u2->items, &u->items); + u->items = NULL; + break; } } } diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 9953f7335..e4f3b960e 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1423,8 +1423,6 @@ static int parse_races(xmlDocPtr doc) if (xml_bvalue(node, "irongolem", false)) rc->flags |= RCF_IRONGOLEM; - 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 ba088a8bb..1d24346e6 100644 --- a/src/laws.c +++ b/src/laws.c @@ -2823,7 +2823,7 @@ static void age_stonecircle(building *b) { if (!mage && is_mage(u)) { mage = u; } - if (rtype && (u_race(u)->ec_flags & ECF_KEEP_ITEM) == 0) { + if (rtype) { int n, unicorns = 0; for (n = 0; n != u->number; ++n) { if (chance(0.02)) { diff --git a/src/upkeep.c b/src/upkeep.c index c4a937a45..d7626084d 100644 --- a/src/upkeep.c +++ b/src/upkeep.c @@ -38,11 +38,6 @@ int lifestyle(const unit * u) return need; } -static bool help_money(const unit * u) -{ - return !(u_race(u)->ec_flags & ECF_KEEP_ITEM); -} - static void help_feed(unit * donor, unit * u, int *need_p) { int need = *need_p; @@ -172,7 +167,7 @@ void get_food(region * r) unit *v; for (v = r->units; need && v; v = v->next) { - if (v->faction == u->faction && help_money(v)) { + if (v->faction == u->faction) { int give = get_money(v) - lifestyle(v); give = MIN(need, give); if (give > 0) { @@ -202,8 +197,7 @@ void get_food(region * r) faction *owner = region_get_owner(r); if (owner && owner != u->faction) { for (v = r->units; v; v = v->next) { - if (v->faction == owner && alliedunit(v, f, HELP_MONEY) - && help_money(v)) { + if (v->faction == owner && alliedunit(v, f, HELP_MONEY)) { help_feed(v, u, &need); break; } @@ -211,8 +205,7 @@ void get_food(region * r) } } for (v = r->units; need && v; v = v->next) { - if (v->faction != f && alliedunit(v, f, HELP_MONEY) - && help_money(v)) { + if (v->faction != f && alliedunit(v, f, HELP_MONEY)) { help_feed(v, u, &need); } } From eb1dc731cb0a9c2c346a907055a46eb996780e2f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 17 Jul 2017 12:33:55 +0200 Subject: [PATCH 2/2] consistently rename ec_flags constants (ECF_*) --- src/give.c | 14 +++++++------- src/give.test.c | 2 +- src/kernel/jsonconf.test.c | 6 +++--- src/kernel/pool.c | 4 ++-- src/kernel/race.h | 6 +++--- src/kernel/unit.c | 4 ++-- src/kernel/xmlreader.c | 6 +++--- src/laws.c | 2 +- src/tests.c | 2 +- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/give.c b/src/give.c index 543d29fc9..d147c41f8 100644 --- a/src/give.c +++ b/src/give.c @@ -682,7 +682,7 @@ void give_cmd(unit * u, order * ord) feedback_give_not_allowed(u, ord); return; } - if (u2 && !(u_race(u2)->ec_flags & GETITEM)) { + if (u2 && !(u_race(u2)->ec_flags & ECF_GETITEM)) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_notake", "race", u_race(u2))); return; @@ -716,7 +716,7 @@ void give_cmd(unit * u, order * ord) } else if (p == P_UNIT) { /* Einheiten uebergeben */ - if (!(u_race(u)->ec_flags & GIVEUNIT)) { + if (!(u_race(u)->ec_flags & ECF_GIVEUNIT)) { cmistake(u, ord, 167, MSG_COMMERCE); return; } @@ -736,7 +736,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 (u2 && !(u_race(u2)->ec_flags & GETITEM)) { + if (u2 && !(u_race(u2)->ec_flags & ECF_GETITEM)) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_notake", "race", u_race(u2))); return; @@ -763,7 +763,7 @@ void give_cmd(unit * u, order * ord) } else { if (isparam(s, u->faction->locale, P_PERSON)) { - if (!(u_race(u)->ec_flags & GIVEPERSON)) { + if (!(u_race(u)->ec_flags & ECF_GIVEPERSON)) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_noregroup", "race", u_race(u))); } @@ -775,7 +775,7 @@ void give_cmd(unit * u, order * ord) } } } - else if (u2 && !(u_race(u2)->ec_flags & GETITEM)) { + else if (u2 && !(u_race(u2)->ec_flags & ECF_GETITEM)) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_notake", "race", u_race(u2))); } @@ -816,7 +816,7 @@ void give_cmd(unit * u, order * ord) if (isparam(s, u->faction->locale, P_PERSON)) { message * msg; - if (!(u_race(u)->ec_flags & GIVEPERSON)) { + if (!(u_race(u)->ec_flags & ECF_GIVEPERSON)) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_noregroup", "race", u_race(u))); return; @@ -830,7 +830,7 @@ void give_cmd(unit * u, order * ord) } if (u2 != NULL) { - if (!(u_race(u2)->ec_flags & GETITEM)) { + if (!(u_race(u2)->ec_flags & ECF_GETITEM)) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_notake", "race", u_race(u2))); return; diff --git a/src/give.test.c b/src/give.test.c index 33a9ebfd9..f38028e10 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -36,7 +36,7 @@ static void setup_give(struct give *env) { assert(env->f1); rc = test_create_race(env->f1->race ? env->f1->race->_name : "humon"); - rc->ec_flags |= GIVEPERSON; + rc->ec_flags |= ECF_GIVEPERSON; env->r = test_create_region(0, 0, ter); env->src = test_create_unit(env->f1, env->r); diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index d526bc7b8..cb79cafc4 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -58,9 +58,9 @@ 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, "giveperson", GIVEPERSON); - check_ec_flag(tc, "giveunit", GIVEUNIT); + check_ec_flag(tc, "getitem", ECF_GETITEM); + check_ec_flag(tc, "giveperson", ECF_GIVEPERSON); + check_ec_flag(tc, "giveunit", ECF_GIVEUNIT); test_cleanup(); } diff --git a/src/kernel/pool.c b/src/kernel/pool.c index dae726566..c252be566 100644 --- a/src/kernel/pool.c +++ b/src/kernel/pool.c @@ -160,7 +160,7 @@ int count) region *r = u->region; int have = get_resource(u, rtype); - if ((u_race(u)->ec_flags & GETITEM) == 0) { + if ((u_race(u)->ec_flags & ECF_GETITEM) == 0) { mode &= (GET_SLACK | GET_RESERVE); } @@ -201,7 +201,7 @@ use_pooled(unit * u, const resource_type * rtype, unsigned int mode, int count) region *r = u->region; int n = 0, have = get_resource(u, rtype); - if ((u_race(u)->ec_flags & GETITEM) == 0) { + if ((u_race(u)->ec_flags & ECF_GETITEM) == 0) { mode &= (GET_SLACK | GET_RESERVE); } diff --git a/src/kernel/race.h b/src/kernel/race.h index 3980bea72..2dec5f06b 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -233,9 +233,9 @@ extern "C" { #define RCF_FAMILIAR (1<<31) /* may be a familiar */ /* Economic flags */ -#define GIVEPERSON (1<<2) /* �bergibt Personen */ -#define GIVEUNIT (1<<3) /* Einheiten an andere Partei �bergeben */ -#define GETITEM (1<<4) /* nimmt Gegenst�nde an */ +#define ECF_GIVEPERSON (1<<2) /* �bergibt Personen */ +#define ECF_GIVEUNIT (1<<3) /* Einheiten an andere Partei �bergeben */ +#define ECF_GETITEM (1<<4) /* nimmt Gegenst�nde an */ #define ECF_REC_ETHEREAL (1<<7) /* Rekrutiert aus dem Nichts */ #define ECF_REC_UNLIMITED (1<<8) /* Rekrutiert ohne Limit */ diff --git a/src/kernel/unit.c b/src/kernel/unit.c index b4f942a3d..821514cd0 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -213,7 +213,7 @@ static buddy *get_friends(const unit * u, int *numfriends) buddy *nf, **fr = &friends; /* some units won't take stuff: */ - if (u_race(u2)->ec_flags & GETITEM) { + if (u_race(u2)->ec_flags & ECF_GETITEM) { while (*fr && (*fr)->faction->no < u2->faction->no) fr = &(*fr)->next; nf = *fr; @@ -269,7 +269,7 @@ int gift_items(unit * u, int flags) for (u2 = r->units; u2; u2 = u2->next) { if (u2 != u && u2->faction == u->faction && u2->number > 0) { /* some units won't take stuff: */ - if (u_race(u2)->ec_flags & GETITEM) { + if (u_race(u2)->ec_flags & ECF_GETITEM) { i_merge(&u2->items, &u->items); u->items = NULL; break; diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index e4f3b960e..a9d38798a 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1424,11 +1424,11 @@ static int parse_races(xmlDocPtr doc) rc->flags |= RCF_IRONGOLEM; if (xml_bvalue(node, "giveperson", false)) - rc->ec_flags |= GIVEPERSON; + rc->ec_flags |= ECF_GIVEPERSON; if (xml_bvalue(node, "giveunit", false)) - rc->ec_flags |= GIVEUNIT; + rc->ec_flags |= ECF_GIVEUNIT; if (xml_bvalue(node, "getitem", false)) - rc->ec_flags |= GETITEM; + rc->ec_flags |= ECF_GETITEM; if (xml_bvalue(node, "recruitethereal", false)) rc->ec_flags |= ECF_REC_ETHEREAL; if (xml_bvalue(node, "recruitunlimited", false)) diff --git a/src/laws.c b/src/laws.c index 1d24346e6..8e9e85ff0 100644 --- a/src/laws.c +++ b/src/laws.c @@ -3533,7 +3533,7 @@ int pay_cmd(unit * u, struct order *ord) static int reserve_i(unit * u, struct order *ord, int flags) { char token[128]; - if (u->number > 0 && (u_race(u)->ec_flags & GETITEM)) { + if (u->number > 0 && (u_race(u)->ec_flags & ECF_GETITEM)) { int use, count, para; const item_type *itype; const char *s; diff --git a/src/tests.c b/src/tests.c index ec2ac2a2f..cfcd6d0ca 100644 --- a/src/tests.c +++ b/src/tests.c @@ -42,7 +42,7 @@ struct race *test_create_race(const char *name) rc->maintenance = 10; rc->hitpoints = 20; rc->maxaura = 100; - rc->ec_flags |= GETITEM; + rc->ec_flags |= ECF_GETITEM; rc->battle_flags = BF_EQUIPMENT; return rc; }