diff --git a/src/battle.c b/src/battle.c index 8ed79a732..3a1628dfe 100644 --- a/src/battle.c +++ b/src/battle.c @@ -3108,9 +3108,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) if (fval(u, UFL_ANON_FACTION) != 0) flags |= SIDE_STEALTH; if (!(AllianceAuto() & HELP_FIGHT) && fval(u, UFL_GROUP)) { - const attrib *agroup = a_find(u->attribs, &at_group); - if (agroup != NULL) - g = (const group *)agroup->data.v; + g = get_group(u); } /* Illusionen und Zauber kaempfen nicht */ diff --git a/src/creport.c b/src/creport.c index 517160a07..d6cc403cd 100644 --- a/src/creport.c +++ b/src/creport.c @@ -799,13 +799,11 @@ void cr_output_unit(stream *out, const faction * f, } if (u->faction == f) { - const attrib *a = NULL; unit *mage; + group * g; - if (fval(u, UFL_GROUP)) - a = a_find(u->attribs, &at_group); - if (a != NULL) { - const group *g = (const group *)a->data.v; + g = get_group(u); + if (g) { stream_printf(out, "%d;gruppe\n", g->gid); } mage = get_familiar_mage(u); diff --git a/src/kernel/ally.c b/src/kernel/ally.c index b439975f3..2e1a4b47b 100644 --- a/src/kernel/ally.c +++ b/src/kernel/ally.c @@ -282,6 +282,8 @@ int alliedunit(const unit * u, const faction * f2, int mask) return 0; } if (u->faction != NULL && f2 != NULL) { + group *g; + if (mask & HELP_FIGHT) { if ((u->flags & UFL_DEFENDER) || (u->faction->flags & FFL_DEFENDER)) { faction *owner = region_get_owner(u->region); @@ -292,12 +294,9 @@ int alliedunit(const unit * u, const faction * f2, int mask) } } - if (fval(u, UFL_GROUP)) { - const attrib *a = a_find(u->attribs, &at_group); - if (a != NULL) { - group *g = (group *)a->data.v; - return alliedgroup(u->faction, f2, g, mask); - } + g = get_group(u); + if (g) { + return alliedgroup(u->faction, f2, g, mask); } return alliedfaction(u->faction, f2, mask); } diff --git a/src/kernel/race.c b/src/kernel/race.c index 8a8311991..53abd339f 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -531,14 +531,9 @@ const char *rc_name_s(const race * rc, name_t n) const char *raceprefix(const unit * u) { - attrib *asource = u->faction->attribs; - - if (fval(u, UFL_GROUP)) { - attrib *agroup = a_find(u->attribs, &at_group); - if (agroup != NULL) - asource = ((const group *)(agroup->data.v))->attribs; - } - return get_prefix(asource); + group *g = get_group(u); + attrib *attr = g ? g->attribs : u->faction->attribs; + return get_prefix(attr); } const char *racename(const struct locale *loc, const unit * u, const race * rc) diff --git a/src/kernel/unit.c b/src/kernel/unit.c index b5346e04d..d63cd724c 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1454,10 +1454,9 @@ unit *create_unit(region * r, faction * f, int number, const struct race *urace, } /* Gruppen */ - if (creator->faction == f && fval(creator, UFL_GROUP)) { - a = a_find(creator->attribs, &at_group); - if (a) { - group *g = (group *)a->data.v; + if (creator->faction == f) { + group *g = get_group(creator); + if (g) { set_group(u, g); } } diff --git a/src/laws.c b/src/laws.c index de10a2719..61eac6a0b 100644 --- a/src/laws.c +++ b/src/laws.c @@ -1317,9 +1317,9 @@ int ally_cmd(unit * u, struct order *ord) sfp = &u->faction->allies; if (fval(u, UFL_GROUP)) { - attrib *a = a_find(u->attribs, &at_group); - if (a) { - sfp = &((group *)a->data.v)->allies; + group *g = get_group(u); + if (g) { + sfp = &g->allies; } } @@ -1453,12 +1453,8 @@ int prefix_cmd(unit * u, struct order *ord) s = gettoken(token, sizeof(token)); if (!s || !*s) { - attrib *a = NULL; - if (fval(u, UFL_GROUP)) { - a = a_find(u->attribs, &at_group); - } - if (a) { - group *g = (group *)a->data.v; + group *g = get_group(u); + if (g) { a_removeall(&g->attribs, &at_raceprefix); } else { @@ -1473,13 +1469,12 @@ int prefix_cmd(unit * u, struct order *ord) cmistake(u, ord, 299, MSG_EVENT); } else { - ap = &u->faction->attribs; - if (fval(u, UFL_GROUP)) { - attrib *a = a_find(u->attribs, &at_group); - if (a) { - group *g = (group *)a->data.v; - ap = &g->attribs; - } + group *g = get_group(u); + if (g) { + ap = &g->attribs; + } + else { + ap = &u->faction->attribs; } set_prefix(ap, race_prefixes[var.i]); } @@ -1839,11 +1834,8 @@ int name_cmd(struct unit *u, struct order *ord) case P_GROUP: { - attrib *a = NULL; - if (fval(u, UFL_GROUP)) - a = a_find(u->attribs, &at_group); - if (a) { - group *g = (group *)a->data.v; + group *g = get_group(u); + if (g) { s = &g->name; break; } diff --git a/src/reports.c b/src/reports.c index 375a28884..12154b70d 100644 --- a/src/reports.c +++ b/src/reports.c @@ -697,9 +697,8 @@ bufunit(const faction * f, const unit * u, seen_mode mode, char *buf, if (!isbattle) { if (u->faction == f) { if (fval(u, UFL_GROUP)) { - attrib *a = a_find(u->attribs, &at_group); - if (a) { - group *g = (group *)a->data.v; + group *g = get_group(u); + if (g) { bufp = STRLCPY(bufp, ", ", size); bufp = STRLCPY(bufp, groupid(g, f), size); }