diff --git a/src/common/kernel/unit.c b/src/common/kernel/unit.c index 17059991a..c581703c3 100644 --- a/src/common/kernel/unit.c +++ b/src/common/kernel/unit.c @@ -1013,22 +1013,19 @@ u_setfaction(unit * u, faction * f) if (u->faction==f) return; if (u->faction) { - unit ** iunit; set_number(u, 0); if (count_unit(u)) --u->faction->no_units; join_group(u, NULL); free_orders(&u->orders); set_order(&u->thisorder, NULL); - iunit = &u->faction->units; - while (*iunit && *iunit!=u) { - iunit=&(*iunit)->nextF; - } - assert(*iunit); - *iunit = u->nextF; + if (u->nextF) u->nextF->prevF = u->prevF; + if (u->prevF) u->prevF->nextF = u->nextF; + else f->units = u->nextF; } if (f!=NULL) { + u->prevF = NULL; u->nextF = f->units; f->units = u; } diff --git a/src/common/kernel/unit.h b/src/common/kernel/unit.h index d1fe8a8d9..4bc1eaca5 100644 --- a/src/common/kernel/unit.h +++ b/src/common/kernel/unit.h @@ -72,6 +72,7 @@ extern int countheroes(const struct faction * f); typedef struct unit { struct unit *next; /* needs to be first entry, for region's unitlist */ struct unit *nextF; /* nächste Einheit der Partei */ + struct unit *prevF; /* vorherige Einheit der Partei */ struct region *region; int no; int hp;