From 88f9d247bddf218999eae75e87dfa1cd835f1866 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 6 Jul 2014 00:29:52 -0700 Subject: [PATCH] Revert "use race::flags|RCF_NOGIVE instead of race::ec_flags|GIVEITEM" E3 Tests (GIVE) did not pass. This reverts commit 5ec3f5b83aa5b599df8ecec0d8afea1612e173f1. --- scripts/tests/e3a.lua | 3 ++- src/economy.c | 9 ++++----- src/kernel/battle.c | 4 ++-- src/kernel/jsonconf.c | 3 +-- src/kernel/jsonconf.test.c | 1 - src/kernel/pool.c | 4 ++-- src/kernel/race.h | 1 - src/kernel/unit.c | 22 ++++++++++++++-------- src/kernel/unit.h | 2 ++ src/kernel/xmlreader.c | 5 ++--- src/laws.c | 10 ++++++---- 11 files changed, 35 insertions(+), 29 deletions(-) diff --git a/scripts/tests/e3a.lua b/scripts/tests/e3a.lua index d37cae476..08cdf4035 100644 --- a/scripts/tests/e3a.lua +++ b/scripts/tests/e3a.lua @@ -429,7 +429,8 @@ function test_canoe_passes_through_land() end function test_give_50_percent_of_money() - local r = region.create(0, 0, "plain") + local r = region.create(0, 0, "plain") + r.name = "50percent" local u1 = unit.create(faction.create("noreply@eressea.de", "human", "de"), r, 1) local u2 = unit.create(faction.create("noreply@eressea.de", "orc", "de"), r, 1) u1.faction.age = 10 diff --git a/src/economy.c b/src/economy.c index e9c6f28fb..0f1a7874e 100644 --- a/src/economy.c +++ b/src/economy.c @@ -776,7 +776,7 @@ static void give_cmd(unit * u, order * ord) else if (p == P_HERBS) { bool given = false; - if (fval(u_race(u), RCF_NOGIVE) && u2 != NULL) { + if (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_nogive", "race", u_race(u))); return; @@ -847,7 +847,7 @@ static void give_cmd(unit * u, order * ord) if (*s == 0) { /* GIVE ALL items that you have */ /* do these checks once, not for each item we have: */ - if (fval(u_race(u), RCF_NOGIVE) && u2 != NULL) { + if (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_nogive", "race", u_race(u))); return; @@ -885,8 +885,7 @@ static void give_cmd(unit * u, order * ord) n = u->number; give_men(n, u, u2, ord); } - } - else if (fval(u_race(u), RCF_NOGIVE) && u2 != NULL) { + } else if (!(u_race(u)->ec_flags & GIVEITEM) && 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)) { @@ -936,7 +935,7 @@ static void give_cmd(unit * u, order * ord) } if (u2 != NULL) { - if (fval(u_race(u), RCF_NOGIVE) && u2 != NULL) { + if (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_nogive", "race", u_race(u))); return; diff --git a/src/kernel/battle.c b/src/kernel/battle.c index bd35ffbb5..ec04dba76 100644 --- a/src/kernel/battle.c +++ b/src/kernel/battle.c @@ -214,7 +214,7 @@ int armedmen(const unit * u, bool siege_weapons) { item *itm; int n = 0; - if (!fval(u_race(u), RCF_NOWEAPONS)) { + if (!(urace(u)->flags & RCF_NOWEAPONS)) { if (effskill(u, SK_WEAPONLESS) >= 1) { /* kann ohne waffen bewachen: fuer drachen */ n = u->number; @@ -784,7 +784,7 @@ weapon_effskill(troop t, troop enemy, const weapon * w, bool attacking, skill += CavalryBonus(tu, enemy, BONUS_SKILL); if (wtype) skill = - skillmod(u_race(tu)->attribs, tu, tu->region, wtype->skill, skill, + skillmod(urace(tu)->attribs, tu, tu->region, wtype->skill, skill, SMF_RIDING); } diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index 24494baed..ef771f8ac 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -332,8 +332,7 @@ static void json_race(cJSON *json, race *rc) { "noteach", "horse", "desert", "illusionary", "absorbpeasants", "noheal", "noweapons", "shapeshift", "", "undead", "dragon", - "coastal", "", "cansail", "invisible", "shipspeed", - "stonegolem", "irongolem", "nogive", 0 + "coastal", "", "cansail", 0 }; if (json->type!=cJSON_Object) { log_error_n("race %s is not a json object: %d", json->string, json->type); diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index d9237cba2..ad525ef33 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -39,7 +39,6 @@ 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_flag(tc, "nogive", RCF_NOGIVE); test_cleanup(); } diff --git a/src/kernel/pool.c b/src/kernel/pool.c index 109fea2d3..49219127d 100644 --- a/src/kernel/pool.c +++ b/src/kernel/pool.c @@ -182,7 +182,7 @@ get_pooled(const unit * u, const resource_type * rtype, unsigned int mode, if (v->items == NULL && rtype->uget == NULL) continue; - if (fval(u_race(v), RCF_NOGIVE)) + if ((urace(v)->ec_flags & GIVEITEM) == 0) 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 (fval(u_race(v), RCF_NOGIVE)) + if ((urace(v)->ec_flags & GIVEITEM) == 0) continue; if (v->items == NULL && rtype->uget == NULL) continue; diff --git a/src/kernel/race.h b/src/kernel/race.h index c1eab55c9..62793bb12 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -213,7 +213,6 @@ extern "C" { #define RCF_SHIPSPEED (1<<26) /* race gets +1 on shipspeed */ #define RCF_STONEGOLEM (1<<27) /* race gets stonegolem properties */ #define RCF_IRONGOLEM (1<<28) /* race gets irongolem properties */ -#define RCF_NOGIVE (1<<29) /* will not GIVE anything away */ /* Economic flags */ #define GIVEITEM (1<<1) /* gibt Gegenstände weg */ diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 266ec0cb1..ae2d9018c 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -196,9 +196,10 @@ static buddy *get_friends(const unit * u, int *numfriends) nf->unit = u2; nf->number = 0; *fr = nf; - } else if (nf->faction == u2->faction && !fval(u_race(u2), RCF_NOGIVE)) { + } else if (nf->faction == u2->faction + && (u_race(u2)->ec_flags & GIVEITEM)) { /* we don't like to gift it to units that won't give it back */ - if (fval(u_race(nf->unit), RCF_NOGIVE)) { + if ((u_race(nf->unit)->ec_flags & GIVEITEM) == 0) { nf->unit = u2; } } @@ -225,7 +226,7 @@ int gift_items(unit * u, int flags) item **itm_p = &u->items; int retval = 0; int rule = rule_give(); - + assert(u->region); assert(u->faction); @@ -238,20 +239,20 @@ int gift_items(unit * u, int flags) flags -= GIFT_SELF; } - if (u->items == NULL || fval(u_race(u), RCF_ILLUSIONARY) || fval(u_race(u), RCF_NOGIVE)) { + if (u->items == NULL || fval(u_race(u), RCF_ILLUSIONARY)) + return 0; + if ((u_race(u)->ec_flags & GIVEITEM) == 0) 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)) { unit *u2, *u3 = NULL; for (u2 = r->units; u2; u2 = u2->next) { if (u2 != u && u2->faction == u->faction && u2->number > 0) { - const race * rc = u_race(u2); /* some units won't take stuff: */ - if (rc->ec_flags & GETITEM) { + if (u_race(u2)->ec_flags & GETITEM) { /* we don't like to gift it to units that won't give it back */ - if (!fval(rc, RCF_NOGIVE)) { + if (u_race(u2)->ec_flags & GIVEITEM) { i_merge(&u2->items, &u->items); u->items = NULL; break; @@ -860,6 +861,11 @@ bool leave(unit * u, bool force) return true; } +const struct race *urace(const struct unit *u) +{ + return u->race_; +} + bool can_survive(const unit * u, const region * r) { if ((fval(r->terrain, WALK_INTO) && (u_race(u)->flags & RCF_WALK)) diff --git a/src/kernel/unit.h b/src/kernel/unit.h index fc11a5d8f..0826fb786 100644 --- a/src/kernel/unit.h +++ b/src/kernel/unit.h @@ -141,6 +141,8 @@ extern "C" { struct unit *utarget(const struct unit *u); void usettarget(struct unit *u, const struct unit *b); + extern const struct race *urace(const struct unit *u); + const char *uprivate(const struct unit *u); void usetprivate(struct unit *u, const char *c); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index dbedc25b4..3832c9bb1 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1721,9 +1721,8 @@ static int parse_races(xmlDocPtr doc) if (xml_bvalue(node, "irongolem", false)) rc->flags |= RCF_IRONGOLEM; - if (xml_bvalue(node, "giveitem", false)) { - rc->flags |= RCF_NOGIVE; - } + if (xml_bvalue(node, "giveitem", false)) + rc->ec_flags |= GIVEITEM; 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 a2c829217..c02be826f 100755 --- a/src/laws.c +++ b/src/laws.c @@ -138,7 +138,9 @@ static void checkorders(void) static bool help_money(const unit * u) { - return !fval(u_race(u), RCF_NOGIVE); + if (u_race(u)->ec_flags & GIVEITEM) + return true; + return false; } static void help_feed(unit * donor, unit * u, int *need_p) @@ -3261,7 +3263,7 @@ static building *age_building(building * b) bt_blessed = bt_find("blessedstonecircle"); ct_astralblock = ct_find("astralblock"); - /* blessed stone circles create an astral protection in the astral region + /* blesses stone circles create an astral protection in the astral region * above the shield, which prevents chaos suction and other spells. * The shield is created when a magician enters the blessed stone circle, * and lasts for as long as his skill level / 2 is, at no mana cost. @@ -3277,7 +3279,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 (!fval(u_race(u), RCF_NOGIVE)) { + if (!(u_race(u)->ec_flags & GIVEITEM) == 0) { int n, unicorns = 0; for (n = 0; n != u->number; ++n) { if (chance(0.02)) { @@ -4039,7 +4041,7 @@ int pay_cmd(unit * u, struct order *ord) int reserve_cmd(unit * u, struct order *ord) { - if (u->number > 0 && (u_race(u)->ec_flags & GETITEM)) { + if (u->number > 0 && (urace(u)->ec_flags & GETITEM)) { int use, count; const resource_type *rtype; const char *s;