diff --git a/src/economy.c b/src/economy.c index 0f1a7874e..e9c6f28fb 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 (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) { + if (fval(u_race(u), RCF_NOGIVE) && 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 (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) { + if (fval(u_race(u), RCF_NOGIVE) && u2 != NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_nogive", "race", u_race(u))); return; @@ -885,7 +885,8 @@ static void give_cmd(unit * u, order * ord) n = u->number; give_men(n, u, u2, ord); } - } else if (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) { + } + else if (fval(u_race(u), RCF_NOGIVE) && 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)) { @@ -935,7 +936,7 @@ static void give_cmd(unit * u, order * ord) } if (u2 != NULL) { - if (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) { + if (fval(u_race(u), RCF_NOGIVE) && 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 ec04dba76..bd35ffbb5 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 (!(urace(u)->flags & RCF_NOWEAPONS)) { + if (!fval(u_race(u), 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(urace(tu)->attribs, tu, tu->region, wtype->skill, skill, + skillmod(u_race(tu)->attribs, tu, tu->region, wtype->skill, skill, SMF_RIDING); } diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index ef771f8ac..24494baed 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -332,7 +332,8 @@ static void json_race(cJSON *json, race *rc) { "noteach", "horse", "desert", "illusionary", "absorbpeasants", "noheal", "noweapons", "shapeshift", "", "undead", "dragon", - "coastal", "", "cansail", 0 + "coastal", "", "cansail", "invisible", "shipspeed", + "stonegolem", "irongolem", "nogive", 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 ad525ef33..d9237cba2 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -39,6 +39,7 @@ 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 49219127d..109fea2d3 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 ((urace(v)->ec_flags & GIVEITEM) == 0) + if (fval(u_race(v), RCF_NOGIVE)) 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 (fval(u_race(v), RCF_NOGIVE)) continue; if (v->items == NULL && rtype->uget == NULL) continue; diff --git a/src/kernel/race.h b/src/kernel/race.h index 62793bb12..c1eab55c9 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -213,6 +213,7 @@ 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 ae2d9018c..266ec0cb1 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -196,10 +196,9 @@ static buddy *get_friends(const unit * u, int *numfriends) nf->unit = u2; nf->number = 0; *fr = nf; - } else if (nf->faction == u2->faction - && (u_race(u2)->ec_flags & GIVEITEM)) { + } else if (nf->faction == u2->faction && !fval(u_race(u2), RCF_NOGIVE)) { /* 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 (fval(u_race(nf->unit), RCF_NOGIVE)) { nf->unit = u2; } } @@ -226,7 +225,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); @@ -239,20 +238,20 @@ int gift_items(unit * u, int flags) flags -= GIFT_SELF; } - if (u->items == NULL || fval(u_race(u), RCF_ILLUSIONARY)) - return 0; - if ((u_race(u)->ec_flags & GIVEITEM) == 0) + if (u->items == NULL || fval(u_race(u), RCF_ILLUSIONARY) || fval(u_race(u), RCF_NOGIVE)) { 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 (u_race(u2)->ec_flags & GETITEM) { + if (rc->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 (!fval(rc, RCF_NOGIVE)) { i_merge(&u2->items, &u->items); u->items = NULL; break; @@ -861,11 +860,6 @@ 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 0826fb786..fc11a5d8f 100644 --- a/src/kernel/unit.h +++ b/src/kernel/unit.h @@ -141,8 +141,6 @@ 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 3832c9bb1..dbedc25b4 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1721,8 +1721,9 @@ static int parse_races(xmlDocPtr doc) if (xml_bvalue(node, "irongolem", false)) rc->flags |= RCF_IRONGOLEM; - if (xml_bvalue(node, "giveitem", false)) - rc->ec_flags |= GIVEITEM; + if (xml_bvalue(node, "giveitem", false)) { + rc->flags |= RCF_NOGIVE; + } 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 c02be826f..a2c829217 100755 --- a/src/laws.c +++ b/src/laws.c @@ -138,9 +138,7 @@ static void checkorders(void) static bool help_money(const unit * u) { - if (u_race(u)->ec_flags & GIVEITEM) - return true; - return false; + return !fval(u_race(u), RCF_NOGIVE); } static void help_feed(unit * donor, unit * u, int *need_p) @@ -3263,7 +3261,7 @@ static building *age_building(building * b) bt_blessed = bt_find("blessedstonecircle"); ct_astralblock = ct_find("astralblock"); - /* blesses stone circles create an astral protection in the astral region + /* blessed 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. @@ -3279,7 +3277,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 (!fval(u_race(u), RCF_NOGIVE)) { int n, unicorns = 0; for (n = 0; n != u->number; ++n) { if (chance(0.02)) { @@ -4041,7 +4039,7 @@ int pay_cmd(unit * u, struct order *ord) int reserve_cmd(unit * u, struct order *ord) { - if (u->number > 0 && (urace(u)->ec_flags & GETITEM)) { + if (u->number > 0 && (u_race(u)->ec_flags & GETITEM)) { int use, count; const resource_type *rtype; const char *s;