make consistent use of get_group.

This commit is contained in:
Enno Rehling 2018-10-26 22:12:43 +02:00
parent d7a8a9b406
commit 1e8c7224a4
7 changed files with 30 additions and 50 deletions

View file

@ -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 */

View file

@ -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);

View file

@ -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,13 +294,10 @@ 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;
g = get_group(u);
if (g) {
return alliedgroup(u->faction, f2, g, mask);
}
}
return alliedfaction(u->faction, f2, mask);
}
return 0;

View file

@ -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)

View file

@ -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);
}
}

View file

@ -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;
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;
}

View file

@ -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);
}